From a78b05064a75bf00e2f75937ad90ab5449c5f52c Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Sun, 12 Sep 2021 16:34:04 +1000 Subject: [PATCH 1/3] Add slop --- cli/src/lib.rs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7dcf401460..a39af9f9e7 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -74,6 +74,13 @@ pub enum Command { /// only. #[clap(short, long)] solana_version: Option, + #[clap( + required = false, + takes_value = true, + multiple_values = true, + last = true + )] + slop: Vec, }, /// Verifies the on-chain bytecode matches the locally compiled artifact. /// Run this command inside a program subdirectory, i.e., in the dir @@ -261,6 +268,7 @@ pub fn entry(opts: Opts) -> Result<()> { verifiable, program_name, solana_version, + slop, } => build( &opts.cfg_override, idl, @@ -269,6 +277,7 @@ pub fn entry(opts: Opts) -> Result<()> { solana_version, None, None, + Some(slop), ), Command::Verify { program_id, @@ -441,6 +450,7 @@ pub fn build( solana_version: Option, stdout: Option, // Used for the package registry server. stderr: Option, // Used for the package registry server. + slop: Option>, ) -> Result<()> { // Change to the workspace member directory, if needed. if let Some(program_name) = program_name.as_ref() { @@ -477,6 +487,7 @@ pub fn build( solana_version, stdout, stderr, + slop, )?, // If the Cargo.toml is at the root, build the entire workspace. Some(cargo) if cargo.path().parent() == cfg.path().parent() => build_all( @@ -487,6 +498,7 @@ pub fn build( solana_version, stdout, stderr, + slop, )?, // Cargo.toml represents a single package. Build it. Some(cargo) => build_cwd( @@ -497,6 +509,7 @@ pub fn build( solana_version, stdout, stderr, + slop, )?, } @@ -513,6 +526,7 @@ fn build_all( solana_version: Option, stdout: Option, // Used for the package registry server. stderr: Option, // Used for the package registry server. + slop: Option>, ) -> Result<()> { let cur_dir = std::env::current_dir()?; let r = match cfg_path.parent() { @@ -527,6 +541,7 @@ fn build_all( solana_version.clone(), stdout.as_ref().map(|f| f.try_clone()).transpose()?, stderr.as_ref().map(|f| f.try_clone()).transpose()?, + slop.clone(), )?; } Ok(()) @@ -545,13 +560,14 @@ fn build_cwd( solana_version: Option, stdout: Option, stderr: Option, + slop: Option>, ) -> Result<()> { match cargo_toml.parent() { None => return Err(anyhow!("Unable to find parent")), Some(p) => std::env::set_current_dir(&p)?, }; match verifiable { - false => _build_cwd(idl_out), + false => _build_cwd(idl_out, slop), true => build_cwd_verifiable(cfg, cargo_toml, solana_version, stdout, stderr), } } @@ -780,9 +796,11 @@ fn docker_build( Ok(()) } -fn _build_cwd(idl_out: Option) -> Result<()> { +fn _build_cwd(idl_out: Option, slop: Option>) -> Result<()> { let exit = std::process::Command::new("cargo") .arg("build-bpf") + //.arg("--") + .args(slop.unwrap_or(vec![])) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output() @@ -832,6 +850,7 @@ fn verify( }, None, None, + None, )?; std::env::set_current_dir(&cur_dir)?; @@ -1322,7 +1341,7 @@ fn test( with_workspace(cfg_override, |cfg| { // Build if needed. if !skip_build { - build(cfg_override, None, false, None, None, None, None)?; + build(cfg_override, None, false, None, None, None, None, None)?; } // Run the deploy against the cluster in two cases: @@ -2022,6 +2041,18 @@ fn publish(cfg_override: &ConfigOverride, program_name: String) -> Result<()> { let anchor_package = AnchorPackage::from(program_name.clone(), &cfg)?; let anchor_package_bytes = serde_json::to_vec(&anchor_package)?; + // Build the program before sending it to the server. + build( + cfg_override, + None, + true, + Some(program_name.clone()), + cfg.solana_version.clone(), + None, + None, + None, + )?; + // Set directory to top of the workspace. let workspace_dir = cfg.path().parent().unwrap(); std::env::set_current_dir(workspace_dir)?; @@ -2110,6 +2141,7 @@ fn publish(cfg_override: &ConfigOverride, program_name: String) -> Result<()> { cfg.solana_version.clone(), None, None, + None, )?; // Success. Now we can finally upload to the server without worrying From 96b7693d969e8ffea1946f50a8bb2131a79d3da8 Mon Sep 17 00:00:00 2001 From: Arrowana <8245419+Arrowana@users.noreply.github.com> Date: Mon, 27 Sep 2021 09:45:19 +1000 Subject: [PATCH 2/3] remove comment --- cli/src/lib.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index a39af9f9e7..873d457ec2 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -799,7 +799,6 @@ fn docker_build( fn _build_cwd(idl_out: Option, slop: Option>) -> Result<()> { let exit = std::process::Command::new("cargo") .arg("build-bpf") - //.arg("--") .args(slop.unwrap_or(vec![])) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -2041,18 +2040,6 @@ fn publish(cfg_override: &ConfigOverride, program_name: String) -> Result<()> { let anchor_package = AnchorPackage::from(program_name.clone(), &cfg)?; let anchor_package_bytes = serde_json::to_vec(&anchor_package)?; - // Build the program before sending it to the server. - build( - cfg_override, - None, - true, - Some(program_name.clone()), - cfg.solana_version.clone(), - None, - None, - None, - )?; - // Set directory to top of the workspace. let workspace_dir = cfg.path().parent().unwrap(); std::env::set_current_dir(workspace_dir)?; From 8b09d783ca2425ee8eed45229654c3f78b14b1ba Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Sun, 26 Sep 2021 17:14:45 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 218f30978d..2fa1a98a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ incremented for features. * lang: Add `--detach` flag to `anchor test` ([#770](https://github.com/project-serum/anchor/pull/770)). * lang: Add `associated_token` keyword for initializing associated token accounts within `#[derive(Accounts)]` ([#790](https://github.com/project-serum/anchor/pull/790)). +* cli: Allow passing through cargo flags for build command ([#719](https://github.com/project-serum/anchor/pull/719)). ## [0.16.1] - 2021-09-17