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

Commit 33799bd

Browse files
committed
cargo-build-sbf, cargo-test-sbf: add --arch option
--arch allows selecting the target SBF version. See anza-xyz/llvm-project#26.
1 parent 8ca8a61 commit 33799bd

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
@@ -31,6 +31,7 @@ struct Config<'a> {
3131
verbose: bool,
3232
workspace: bool,
3333
jobs: Option<String>,
34+
arch: &'a str,
3435
}
3536

3637
impl Default for Config<'_> {
@@ -54,6 +55,7 @@ impl Default for Config<'_> {
5455
verbose: false,
5556
workspace: false,
5657
jobs: None,
58+
arch: "sbf",
5759
}
5860
}
5961
}
@@ -522,6 +524,17 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
522524
);
523525
};
524526

527+
let mut target_rustflags = env::var("CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS")
528+
.ok()
529+
.unwrap_or_else(String::new);
530+
if config.arch == "sbfv2" {
531+
target_rustflags = format!("{} {}", "-C target_cpu=sbfv2", target_rustflags);
532+
env::set_var(
533+
"CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS",
534+
&target_rustflags,
535+
);
536+
}
537+
525538
let cargo_build = PathBuf::from("cargo");
526539
let mut cargo_build_args = vec![
527540
"+sbf",
@@ -530,6 +543,9 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
530543
"sbf-solana-solana",
531544
"--release",
532545
];
546+
if config.arch == "sbfv2" {
547+
cargo_build_args.push("-Zbuild-std=std,panic_abort");
548+
}
533549
if config.no_default_features {
534550
cargo_build_args.push("--no-default-features");
535551
}
@@ -806,6 +822,13 @@ fn main() {
806822
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
807823
.help("Number of parallel jobs, defaults to # of CPUs"),
808824
)
825+
.arg(
826+
Arg::new("arch")
827+
.long("arch")
828+
.possible_values(&["sbf", "sbfv2"])
829+
.default_value("sbf")
830+
.help("Build for the given SBF version"),
831+
)
809832
.get_matches_from(args);
810833

811834
let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk");
@@ -841,6 +864,7 @@ fn main() {
841864
verbose: matches.is_present("verbose"),
842865
workspace: matches.is_present("workspace"),
843866
jobs: matches.value_of_t("jobs").ok(),
867+
arch: matches.value_of("arch").unwrap(),
844868
};
845869
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
846870
build_sbf(config, manifest_path);

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)