Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: env flag for external parameters of docker build and regular build #226

Merged
merged 23 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
06fd256
chore: add `--env` argument to cargo near build/deploy commands
Sep 18, 2024
e9e88e2
chore: update `interactive-clap` revision in Cargo.lock (patched from…
Sep 18, 2024
8a32372
chore: add `env` argument to `cargo_near_build::near::abi::generate` …
Sep 18, 2024
bb8e24b
chore: update `interactive-clap` from crates.io
Sep 18, 2024
404981a
feat: use external `env` field in `cargo_near_build::near::build::run…
Sep 18, 2024
5b67da9
chore: add `env` flags to command export in `build::input::Opts::get_…
Sep 18, 2024
982bcc7
feat: add support of `--env` flag in docker build without cmd in mani…
Sep 18, 2024
15a11c9
chore: split `metadata::ReproducibleBuild::validate`
Sep 19, 2024
f1b3198
chore: add optional `passed_env` to toml manifest metadata for reprod…
Sep 19, 2024
687502f
feat: add arguments from `passed_env` in toml to cmd in docker
Sep 19, 2024
97670a8
chore: update `near new` template with added `passed_env` manifest field
Sep 19, 2024
d31c5a4
chore: add space for visual prowess
Sep 20, 2024
3693ba5
chore: move `check_flag_confilicts_with_manifest_command` to start of…
Sep 20, 2024
779467b
chore: better error msg for `--env` flag conflict with `container_bui…
Sep 20, 2024
99c3be1
chore: revert `cargo near new` template
Sep 23, 2024
db47ac4
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 23, 2024
1f3f024
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 23, 2024
1bbf544
review: partially fix nit https://github.com/near/cargo-near/pull/226…
Sep 23, 2024
e131c98
review: somewhat fix nit https://github.com/near/cargo-near/pull/226#…
Sep 23, 2024
e6a3be9
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 24, 2024
631367e
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 24, 2024
62e21ae
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 24, 2024
8f6dd73
review: fix nit https://github.com/near/cargo-near/pull/226#discussio…
Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
dj8yfo marked this conversation as resolved.
Show resolved Hide resolved
};
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
Loading