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

Commit ab6802b

Browse files
alessandroddmakarov
authored andcommitted
cargo-build-sbf, cargo-test-sbf: add --arch option
--arch allows selecting the target SBF version. See anza-xyz/llvm-project#26.
1 parent 8797ad0 commit ab6802b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct Config<'a> {
3333
verbose: bool,
3434
workspace: bool,
3535
jobs: Option<String>,
36+
arch: &'a str,
3637
}
3738

3839
impl Default for Config<'_> {
@@ -57,6 +58,7 @@ impl Default for Config<'_> {
5758
verbose: false,
5859
workspace: false,
5960
jobs: None,
61+
arch: "sbf",
6062
}
6163
}
6264
}
@@ -542,6 +544,17 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
542544
env::remove_var("RUSTC")
543545
}
544546

547+
let mut target_rustflags = env::var("CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS")
548+
.ok()
549+
.unwrap_or_default();
550+
if config.arch == "sbfv2" {
551+
target_rustflags = format!("{} {}", "-C target_cpu=sbfv2", target_rustflags);
552+
env::set_var(
553+
"CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS",
554+
&target_rustflags,
555+
);
556+
}
557+
545558
let cargo_build = PathBuf::from("cargo");
546559
let mut cargo_build_args = vec![
547560
"+sbf",
@@ -550,6 +563,9 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
550563
"sbf-solana-solana",
551564
"--release",
552565
];
566+
if config.arch == "sbfv2" {
567+
cargo_build_args.push("-Zbuild-std=std,panic_abort");
568+
}
553569
if config.no_default_features {
554570
cargo_build_args.push("--no-default-features");
555571
}
@@ -833,6 +849,13 @@ fn main() {
833849
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
834850
.help("Number of parallel jobs, defaults to # of CPUs"),
835851
)
852+
.arg(
853+
Arg::new("arch")
854+
.long("arch")
855+
.possible_values(&["sbf", "sbfv2"])
856+
.default_value("sbf")
857+
.help("Build for the given SBF version"),
858+
)
836859
.get_matches_from(args);
837860

838861
let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk");
@@ -869,6 +892,7 @@ fn main() {
869892
verbose: matches.is_present("verbose"),
870893
workspace: matches.is_present("workspace"),
871894
jobs: matches.value_of_t("jobs").ok(),
895+
arch: matches.value_of("arch").unwrap(),
872896
};
873897
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
874898
if config.verbose {

sdk/cargo-test-sbf/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use {
1010
},
1111
};
1212

13-
struct Config {
13+
struct Config<'a> {
1414
sbf_sdk: Option<String>,
1515
sbf_out_dir: Option<String>,
1616
cargo: PathBuf,
@@ -25,9 +25,10 @@ struct Config {
2525
verbose: bool,
2626
workspace: bool,
2727
jobs: Option<String>,
28+
arch: &'a str,
2829
}
2930

30-
impl Default for Config {
31+
impl Default for Config<'_> {
3132
fn default() -> Self {
3233
Self {
3334
sbf_sdk: None,
@@ -44,6 +45,7 @@ impl Default for Config {
4445
verbose: false,
4546
workspace: false,
4647
jobs: None,
48+
arch: "sbf",
4749
}
4850
}
4951
}
@@ -129,6 +131,9 @@ fn test_sbf_package(config: &Config, target_directory: &Path, package: &cargo_me
129131
build_sbf_args.push("--sbf-out-dir");
130132
build_sbf_args.push(&sbf_out_dir);
131133

134+
build_sbf_args.push("--arch");
135+
build_sbf_args.push(config.arch);
136+
132137
spawn(
133138
&config.cargo_build_sbf,
134139
&build_sbf_args,
@@ -311,6 +316,13 @@ fn main() {
311316
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
312317
.help("Number of parallel jobs, defaults to # of CPUs"),
313318
)
319+
.arg(
320+
Arg::new("arch")
321+
.long("arch")
322+
.possible_values(&["sbf", "sbfv2"])
323+
.default_value("sbf")
324+
.help("Build for the given SBF version"),
325+
)
314326
.arg(
315327
Arg::new("extra_cargo_test_args")
316328
.value_name("extra args for cargo test and the test binary")
@@ -337,6 +349,7 @@ fn main() {
337349
verbose: matches.is_present("verbose"),
338350
workspace: matches.is_present("workspace"),
339351
jobs: matches.value_of_t("jobs").ok(),
352+
arch: matches.value_of("arch").unwrap(),
340353
..Config::default()
341354
};
342355

0 commit comments

Comments
 (0)