Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 4059fa4

Browse files
committed
cargo-build-bpf: add --arch option
--arch allows selecting the target SBF version. See anza-xyz/llvm-project#26.
1 parent 61d7bdd commit 4059fa4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

sdk/cargo-build-bpf/src/main.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct Config<'a> {
3131
offline: bool,
3232
verbose: bool,
3333
workspace: bool,
34+
arch: &'a str,
3435
}
3536

3637
impl Default for Config<'_> {
@@ -53,6 +54,7 @@ impl Default for Config<'_> {
5354
offline: false,
5455
verbose: false,
5556
workspace: false,
57+
arch: "sbf",
5658
}
5759
}
5860
}
@@ -516,11 +518,13 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
516518
env::set_var("OBJDUMP", llvm_bin.join("llvm-objdump"));
517519
env::set_var("OBJCOPY", llvm_bin.join("llvm-objcopy"));
518520

521+
let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or_else(String::new);
522+
if config.arch == "sbfv2" {
523+
rustflags = format!("{} {}", "-C target_cpu=sbfv2", rustflags);
524+
env::set_var("RUSTFLAGS", &rustflags);
525+
}
519526
if config.verbose {
520-
println!(
521-
"RUSTFLAGS={}",
522-
env::var("RUSTFLAGS").ok().as_deref().unwrap_or("")
523-
);
527+
println!("RUSTFLAGS={}", rustflags);
524528
};
525529

526530
let cargo_build = PathBuf::from("cargo");
@@ -531,6 +535,9 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
531535
"bpfel-unknown-unknown",
532536
"--release",
533537
];
538+
if config.arch == "sbfv2" {
539+
cargo_build_args.push("-Zbuild-std=std,panic_abort");
540+
}
534541
if config.no_default_features {
535542
cargo_build_args.push("--no-default-features");
536543
}
@@ -793,6 +800,13 @@ fn main() {
793800
.alias("all")
794801
.help("Build all BPF packages in the workspace"),
795802
)
803+
.arg(
804+
Arg::with_name("arch")
805+
.long("arch")
806+
.possible_values(&["sbf", "sbfv2"])
807+
.default_value("sbf")
808+
.help("Build for the given SBF version"),
809+
)
796810
.get_matches_from(args);
797811

798812
let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf);
@@ -829,6 +843,7 @@ fn main() {
829843
offline: matches.is_present("offline"),
830844
verbose: matches.is_present("verbose"),
831845
workspace: matches.is_present("workspace"),
846+
arch: matches.value_of("arch").unwrap(),
832847
};
833848
let manifest_path = value_t!(matches, "manifest_path", PathBuf).ok();
834849
build_bpf(config, manifest_path);

0 commit comments

Comments
 (0)