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

Commit cf96803

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 b107008 commit cf96803

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
}
@@ -539,6 +541,17 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
539541
env::remove_var("RUSTC")
540542
}
541543

544+
let mut target_rustflags = env::var("CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS")
545+
.ok()
546+
.unwrap_or_default();
547+
if config.arch == "sbfv2" {
548+
target_rustflags = format!("{} {}", "-C target_cpu=sbfv2", target_rustflags);
549+
env::set_var(
550+
"CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS",
551+
&target_rustflags,
552+
);
553+
}
554+
542555
let cargo_build = PathBuf::from("cargo");
543556
let mut cargo_build_args = vec![
544557
"+sbf",
@@ -547,6 +560,9 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
547560
"sbf-solana-solana",
548561
"--release",
549562
];
563+
if config.arch == "sbfv2" {
564+
cargo_build_args.push("-Zbuild-std=std,panic_abort");
565+
}
550566
if config.no_default_features {
551567
cargo_build_args.push("--no-default-features");
552568
}
@@ -830,6 +846,13 @@ fn main() {
830846
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
831847
.help("Number of parallel jobs, defaults to # of CPUs"),
832848
)
849+
.arg(
850+
Arg::new("arch")
851+
.long("arch")
852+
.possible_values(&["sbf", "sbfv2"])
853+
.default_value("sbf")
854+
.help("Build for the given SBF version"),
855+
)
833856
.get_matches_from(args);
834857

835858
let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk");
@@ -866,6 +889,7 @@ fn main() {
866889
verbose: matches.is_present("verbose"),
867890
workspace: matches.is_present("workspace"),
868891
jobs: matches.value_of_t("jobs").ok(),
892+
arch: matches.value_of("arch").unwrap(),
869893
};
870894
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
871895
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)