diff --git a/sdk/cargo-build-bpf/src/main.rs b/sdk/cargo-build-bpf/src/main.rs index d22737d092b1ba..5475c0e29ae601 100644 --- a/sdk/cargo-build-bpf/src/main.rs +++ b/sdk/cargo-build-bpf/src/main.rs @@ -31,6 +31,7 @@ struct Config<'a> { offline: bool, verbose: bool, workspace: bool, + arch: &'a str, } impl Default for Config<'_> { @@ -53,6 +54,7 @@ impl Default for Config<'_> { offline: false, verbose: false, workspace: false, + arch: "sbf", } } } @@ -516,11 +518,13 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m env::set_var("OBJDUMP", llvm_bin.join("llvm-objdump")); env::set_var("OBJCOPY", llvm_bin.join("llvm-objcopy")); + let mut rustflags = env::var("RUSTFLAGS").ok().unwrap_or_else(String::new); + if config.arch == "sbfv2" { + rustflags = format!("{} {}", "-C target_cpu=sbfv2", rustflags); + env::set_var("RUSTFLAGS", &rustflags); + } if config.verbose { - println!( - "RUSTFLAGS={}", - env::var("RUSTFLAGS").ok().as_deref().unwrap_or("") - ); + println!("RUSTFLAGS={}", rustflags); }; let cargo_build = PathBuf::from("cargo"); @@ -531,6 +535,9 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m "bpfel-unknown-unknown", "--release", ]; + if config.arch == "sbfv2" { + cargo_build_args.push("-Zbuild-std=std,panic_abort"); + } if config.no_default_features { cargo_build_args.push("--no-default-features"); } @@ -793,6 +800,13 @@ fn main() { .alias("all") .help("Build all BPF packages in the workspace"), ) + .arg( + Arg::with_name("arch") + .long("arch") + .possible_values(&["sbf", "sbfv2"]) + .default_value("sbf") + .help("Build for the given SBF version"), + ) .get_matches_from(args); let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf); @@ -829,6 +843,7 @@ fn main() { offline: matches.is_present("offline"), verbose: matches.is_present("verbose"), workspace: matches.is_present("workspace"), + arch: matches.value_of("arch").unwrap(), }; let manifest_path = value_t!(matches, "manifest_path", PathBuf).ok(); build_bpf(config, manifest_path);