Skip to content

Commit

Permalink
Make cargo-build-bpf pass additional options to cargo build command
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
dmakarov committed Jun 18, 2021
1 parent 5a99fa3 commit 3570b00
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sdk/cargo-build-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use {
tar::Archive,
};

struct Config {
struct Config<'a> {
cargo_args: Option<Vec<&'a str>>,
bpf_out_dir: Option<PathBuf>,
bpf_sdk: PathBuf,
dump: bool,
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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::<Vec<_>>()),
bpf_sdk: fs::canonicalize(&bpf_sdk).unwrap_or_else(|err| {
eprintln!(
"BPF SDK path does not exist: {}: {}",
Expand Down

0 comments on commit 3570b00

Please sign in to comment.