From 3570b00560b5b7b1499bb2dd0e9ebc02be0c315e Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Thu, 17 Jun 2021 18:27:13 -0700 Subject: [PATCH] Make cargo-build-bpf pass additional options to cargo build command Users need to be able to pass additional command line options such as -p that are not supported by 'cargo build-bpf' but are meaningful for the 'cargo build' command. This change allows cargo-build-bpf to pass all command line options specified after '--' option to 'cargo build'. --- sdk/cargo-build-bpf/src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sdk/cargo-build-bpf/src/main.rs b/sdk/cargo-build-bpf/src/main.rs index 8ab27fc553..ea5b1e2275 100644 --- a/sdk/cargo-build-bpf/src/main.rs +++ b/sdk/cargo-build-bpf/src/main.rs @@ -20,7 +20,8 @@ use { tar::Archive, }; -struct Config { +struct Config<'a> { + cargo_args: Option>, bpf_out_dir: Option, bpf_sdk: PathBuf, dump: bool, @@ -31,9 +32,10 @@ struct Config { workspace: bool, } -impl Default for Config { +impl Default for Config<'_> { fn default() -> Self { Self { + cargo_args: None, bpf_sdk: env::current_exe() .expect("Unable to get current executable") .parent() @@ -461,6 +463,11 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m if config.verbose { cargo_build_args.push("--verbose"); } + if let Some(args) = &config.cargo_args { + for arg in args { + cargo_build_args.push(arg); + } + } let output = spawn(&cargo_build, &cargo_build_args); if config.verbose { println!("{}", output); @@ -656,12 +663,16 @@ fn main() { .alias("all") .help("Build all BPF packages in the workspace"), ) + .arg(Arg::with_name("cargo_args").multiple(true).last(true)) .get_matches_from(args); let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf); let bpf_out_dir = value_t!(matches, "bpf_out_dir", PathBuf).ok(); let config = Config { + cargo_args: matches + .values_of("cargo_args") + .map(|vals| vals.collect::>()), bpf_sdk: fs::canonicalize(&bpf_sdk).unwrap_or_else(|err| { eprintln!( "BPF SDK path does not exist: {}: {}",