Skip to content

Commit

Permalink
Merge branch 'main' into fix-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yfo authored Sep 24, 2024
2 parents 47ff389 + b0e2996 commit 6bb53dd
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 126 deletions.
64 changes: 32 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cargo-near-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ home = { version = "0.5.9", optional = true }
pathdiff = { version = "0.2.1", features = ["camino"], optional = true }
unix_path = { version = "1.0.1", optional = true }
tempfile = { version = "3.10.1", optional = true }
shell-words = { version = "1.0.0", optional = true}

[target.'cfg(target_os = "linux")'.dependencies]
nix = { version = "0.29.0", features = ["user", "process"], optional = true }
Expand All @@ -48,6 +49,6 @@ abi_build = []
docker = [
"dep:url", "dep:serde", "dep:git2",
"dep:home", "dep:pathdiff", "dep:unix_path",
"dep:tempfile", "dep:nix"
"dep:tempfile", "dep:nix", "dep:shell-words"
]

2 changes: 1 addition & 1 deletion cargo-near-build/src/cargo_native/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
ColorPreference::Never => cmd.args(["--color", "never"]),
};

tracing::info!("Invoking cargo: {:?}", cmd);
tracing::info!("Invoking cargo: {:#?}", cmd);

let mut child = cmd
// capture the stdout to return from this function as bytes
Expand Down
15 changes: 10 additions & 5 deletions cargo-near-build/src/near/abi/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn procedure(
generate_docs: bool,
hide_warnings: bool,
cargo_feature_args: &[&str],
env: &[(&str, &str)],
color: ColorPreference,
) -> eyre::Result<near_abi::AbiRoot> {
let root_node = crate_metadata
Expand Down Expand Up @@ -68,15 +69,19 @@ pub fn procedure(

pretty_print::step("Generating ABI");

let dylib_artifact = cargo_native::compile::run::<Dylib>(
&crate_metadata.manifest_path,
cargo_args.as_slice(),
vec![
let compile_env = {
let compile_env = vec![
("CARGO_PROFILE_DEV_OPT_LEVEL", "0"),
("CARGO_PROFILE_DEV_DEBUG", "0"),
("CARGO_PROFILE_DEV_LTO", "off"),
(env_keys::BUILD_RS_ABI_STEP_HINT, "true"),
],
];
[&compile_env, env].concat()
};
let dylib_artifact = cargo_native::compile::run::<Dylib>(
&crate_metadata.manifest_path,
cargo_args.as_slice(),
compile_env,
hide_warnings,
color,
)?;
Expand Down
1 change: 1 addition & 0 deletions cargo-near-build/src/near/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn build(args: abi_types::Opts) -> eyre::Result<()> {
!args.no_doc,
false,
&[],
&[],
color,
)?;
let abi_types::Result { path } = write_to_file(
Expand Down
29 changes: 21 additions & 8 deletions cargo-near-build/src/near/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub fn run(args: Opts) -> eyre::Result<CompilationArtifact> {
let out_dir = crate_metadata.resolve_output_dir(args.out_dir.map(Into::into))?;

let mut build_env = vec![("RUSTFLAGS", "-C link-arg=-s")];
build_env.extend(
args.env
.iter()
.map(|(key, value)| (key.as_ref(), value.as_ref())),
);
let mut cargo_args = vec!["--target", COMPILATION_TARGET];
let cargo_feature_args = {
let mut feat_args = vec![];
Expand All @@ -76,14 +81,22 @@ pub fn run(args: Opts) -> eyre::Result<CompilationArtifact> {
let (builder_version, builder_version_mismatch) =
VersionMismatch::get_coerced_builder_version()?;
if !args.no_abi {
let mut contract_abi = abi::generate::procedure(
&crate_metadata,
args.no_locked,
!args.no_doc,
true,
&cargo_feature_args,
color.clone(),
)?;
let mut contract_abi = {
let env = args
.env
.iter()
.map(|(key, value)| (key.as_ref(), value.as_ref()))
.collect::<Vec<_>>();
abi::generate::procedure(
&crate_metadata,
args.no_locked,
!args.no_doc,
true,
&cargo_feature_args,
&env,
color.clone(),
)?
};

let embedding_binary = args.cli_description.cli_name_abi;
contract_abi.metadata.build = Some(BuildInfo {
Expand Down
21 changes: 16 additions & 5 deletions cargo-near-build/src/near/docker_build/subprocess_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ pub fn run(

let env = env_vars::EnvVars::new(&docker_build_meta, cloned_repo)?;
let env_args = env.docker_args();
let cargo_cmd = opts
.get_cli_build_command_in_docker(docker_build_meta.container_build_command.clone())?;
println!("{} {}", "build command in container:".green(), cargo_cmd);
let shell_escaped_cargo_cmd = {
let cargo_cmd = opts.get_cli_build_command_in_docker(
docker_build_meta.container_build_command.clone(),
docker_build_meta.passed_env.clone(),
)?;
tracing::debug!("cli_build_command_in_docker {:#?}", cargo_cmd);
shell_words::join(cargo_cmd)
};
println!(
"{} {}",
"build command in container:".green(),
shell_escaped_cargo_cmd
);
println!();

let docker_args = {
let mut docker_args = vec![
Expand All @@ -74,8 +85,8 @@ pub fn run(

docker_args.extend(vec![&docker_image, "/bin/bash", "-c"]);

docker_args.push(&cargo_cmd);
tracing::debug!("docker command : {:?}", docker_args);
docker_args.push(&shell_escaped_cargo_cmd);
tracing::debug!("docker command : {:#?}", docker_args);
docker_args
};

Expand Down
Loading

0 comments on commit 6bb53dd

Please sign in to comment.