Skip to content

Commit

Permalink
sdk: Add --jobs parameter in build/test bpf (#24359)
Browse files Browse the repository at this point in the history
  • Loading branch information
joncinque authored Apr 15, 2022
1 parent 7cf80a3 commit d54ec40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sdk/cargo-build-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Config<'a> {
offline: bool,
verbose: bool,
workspace: bool,
jobs: Option<String>,
}

impl Default for Config<'_> {
Expand All @@ -51,6 +52,7 @@ impl Default for Config<'_> {
offline: false,
verbose: false,
workspace: false,
jobs: None,
}
}
}
Expand Down Expand Up @@ -545,6 +547,10 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
if config.verbose {
cargo_build_args.push("--verbose");
}
if let Some(jobs) = &config.jobs {
cargo_build_args.push("--jobs");
cargo_build_args.push(jobs);
}
if let Some(args) = &config.cargo_args {
for arg in args {
cargo_build_args.push(arg);
Expand Down Expand Up @@ -793,6 +799,15 @@ fn main() {
.alias("all")
.help("Build all BPF packages in the workspace"),
)
.arg(
Arg::new("jobs")
.short('j')
.long("jobs")
.takes_value(true)
.value_name("N")
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
.help("Number of parallel jobs, defaults to # of CPUs"),
)
.get_matches_from(args);

let bpf_sdk: PathBuf = matches.value_of_t_or_exit("bpf_sdk");
Expand Down Expand Up @@ -827,6 +842,7 @@ fn main() {
offline: matches.is_present("offline"),
verbose: matches.is_present("verbose"),
workspace: matches.is_present("workspace"),
jobs: matches.value_of_t("jobs").ok(),
};
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
build_bpf(config, manifest_path);
Expand Down
16 changes: 16 additions & 0 deletions sdk/cargo-test-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Config {
offline: bool,
verbose: bool,
workspace: bool,
jobs: Option<String>,
}

impl Default for Config {
Expand All @@ -42,6 +43,7 @@ impl Default for Config {
offline: false,
verbose: false,
workspace: false,
jobs: None,
}
}
}
Expand Down Expand Up @@ -116,6 +118,10 @@ fn test_bpf_package(config: &Config, target_directory: &Path, package: &cargo_me
if config.verbose {
cargo_args.push("--verbose");
}
if let Some(jobs) = &config.jobs {
cargo_args.push("--jobs");
cargo_args.push(jobs);
}

let mut build_bpf_args = cargo_args.clone();
if let Some(bpf_sdk) = config.bpf_sdk.as_ref() {
Expand Down Expand Up @@ -294,6 +300,15 @@ fn main() {
.alias("all")
.help("Test all BPF packages in the workspace"),
)
.arg(
Arg::new("jobs")
.short('j')
.long("jobs")
.takes_value(true)
.value_name("N")
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
.help("Number of parallel jobs, defaults to # of CPUs"),
)
.arg(
Arg::new("extra_cargo_test_args")
.value_name("extra args for cargo test and the test binary")
Expand All @@ -319,6 +334,7 @@ fn main() {
offline: matches.is_present("offline"),
verbose: matches.is_present("verbose"),
workspace: matches.is_present("workspace"),
jobs: matches.value_of_t("jobs").ok(),
..Config::default()
};

Expand Down

0 comments on commit d54ec40

Please sign in to comment.