diff --git a/sdk/cargo-build-sbf/src/main.rs b/sdk/cargo-build-sbf/src/main.rs index b5401ec9d65085..24da450f45f616 100644 --- a/sdk/cargo-build-sbf/src/main.rs +++ b/sdk/cargo-build-sbf/src/main.rs @@ -32,6 +32,7 @@ struct Config<'a> { verbose: bool, workspace: bool, jobs: Option, + arch: &'a str, } impl Default for Config<'_> { @@ -56,6 +57,7 @@ impl Default for Config<'_> { verbose: false, workspace: false, jobs: None, + arch: "sbf", } } } @@ -527,6 +529,16 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m debug!("RUSTFLAGS={}", &rustflags); }; + let mut target_rustflags = env::var("CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS") + .ok().unwrap_or_default(); + if config.arch == "sbfv2" { + target_rustflags = format!("{} {}", "-C target_cpu=sbfv2", target_rustflags); + env::set_var( + "CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS", + &target_rustflags, + ); + } + let cargo_build = PathBuf::from("cargo"); let mut cargo_build_args = vec![ "+sbf", @@ -535,6 +547,9 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m "sbf-solana-solana", "--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"); } @@ -818,6 +833,13 @@ fn main() { .validator(|val| val.parse::().map_err(|e| e.to_string())) .help("Number of parallel jobs, defaults to # of CPUs"), ) + .arg( + Arg::new("arch") + .long("arch") + .possible_values(&["sbf", "sbfv2"]) + .default_value("sbf") + .help("Build for the given SBF version"), + ) .get_matches_from(args); let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk"); @@ -854,6 +876,7 @@ fn main() { verbose: matches.is_present("verbose"), workspace: matches.is_present("workspace"), jobs: matches.value_of_t("jobs").ok(), + arch: matches.value_of("arch").unwrap(), }; let manifest_path: Option = matches.value_of_t("manifest_path").ok(); build_sbf(config, manifest_path); diff --git a/sdk/cargo-test-sbf/src/main.rs b/sdk/cargo-test-sbf/src/main.rs index e5e76574c0be9a..90e6dab09597dd 100644 --- a/sdk/cargo-test-sbf/src/main.rs +++ b/sdk/cargo-test-sbf/src/main.rs @@ -10,7 +10,7 @@ use { }, }; -struct Config { +struct Config<'a> { sbf_sdk: Option, sbf_out_dir: Option, cargo: PathBuf, @@ -25,9 +25,10 @@ struct Config { verbose: bool, workspace: bool, jobs: Option, + arch: &'a str, } -impl Default for Config { +impl Default for Config<'_> { fn default() -> Self { Self { sbf_sdk: None, @@ -44,6 +45,7 @@ impl Default for Config { verbose: false, workspace: false, jobs: None, + arch: "sbf", } } } @@ -129,6 +131,9 @@ fn test_sbf_package(config: &Config, target_directory: &Path, package: &cargo_me build_sbf_args.push("--sbf-out-dir"); build_sbf_args.push(&sbf_out_dir); + build_sbf_args.push("--arch"); + build_sbf_args.push(config.arch); + spawn( &config.cargo_build_sbf, &build_sbf_args, @@ -311,6 +316,13 @@ fn main() { .validator(|val| val.parse::().map_err(|e| e.to_string())) .help("Number of parallel jobs, defaults to # of CPUs"), ) + .arg( + Arg::new("arch") + .long("arch") + .possible_values(&["sbf", "sbfv2"]) + .default_value("sbf") + .help("Build for the given SBF version"), + ) .arg( Arg::new("extra_cargo_test_args") .value_name("extra args for cargo test and the test binary") @@ -337,6 +349,7 @@ fn main() { verbose: matches.is_present("verbose"), workspace: matches.is_present("workspace"), jobs: matches.value_of_t("jobs").ok(), + arch: matches.value_of("arch").unwrap(), ..Config::default() };