From b7e7e4159c10cc249cdfc27d54b72218eebcea65 Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Tue, 12 Jul 2022 15:52:11 -0700 Subject: [PATCH] Prevent cargo from running a non-BPF compiler for BPF target --- ci/test-stable.sh | 5 +++-- sdk/cargo-build-sbf/src/main.rs | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ci/test-stable.sh b/ci/test-stable.sh index adaa62b47c..550da41f47 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -72,8 +72,9 @@ test-stable-bpf) done |& tee cargo.log solana_program_count=$(grep -c 'solana-program v' cargo.log) rm -f cargo.log - if ((solana_program_count > 4)); then - echo "Regression of build redundancy. Review dependency features that trigger redundant rebuilds of solana-program." + if ((solana_program_count > 10)); then + echo "Regression of build redundancy ${solana_program_count}." + echo "Review dependency features that trigger redundant rebuilds of solana-program." exit 1 fi diff --git a/sdk/cargo-build-sbf/src/main.rs b/sdk/cargo-build-sbf/src/main.rs index b5401ec9d6..466aae3ee5 100644 --- a/sdk/cargo-build-sbf/src/main.rs +++ b/sdk/cargo-build-sbf/src/main.rs @@ -18,6 +18,7 @@ use { tar::Archive, }; +#[derive(Debug)] struct Config<'a> { cargo_args: Option>, sbf_out_dir: Option, @@ -524,8 +525,19 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m env::set_var("RUSTFLAGS", &rustflags); } if config.verbose { - debug!("RUSTFLAGS={}", &rustflags); - }; + debug!( + "RUSTFLAGS=\"{}\"", + env::var("RUSTFLAGS").ok().unwrap_or_default() + ); + } + + // RUSTC variable overrides cargo + mechanism of + // selecting the rust compiler and makes cargo run a rust compiler + // other than the one linked in BPF toolchain. We have to prevent + // this by removing RUSTC from the child process environment. + if env::var("RUSTC").is_ok() { + env::remove_var("RUSTC") + } let cargo_build = PathBuf::from("cargo"); let mut cargo_build_args = vec![ @@ -856,5 +868,9 @@ fn main() { jobs: matches.value_of_t("jobs").ok(), }; let manifest_path: Option = matches.value_of_t("manifest_path").ok(); + if config.verbose { + debug!("{:?}", config); + debug!("manifest_path: {:?}", manifest_path); + } build_sbf(config, manifest_path); }