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

Commit 67eae21

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 a3b0943 commit 67eae21

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct Config<'a> {
3232
verbose: bool,
3333
workspace: bool,
3434
jobs: Option<String>,
35+
arch: &'a str,
3536
}
3637

3738
impl Default for Config<'_> {
@@ -56,6 +57,7 @@ impl Default for Config<'_> {
5657
verbose: false,
5758
workspace: false,
5859
jobs: None,
60+
arch: "sbf",
5961
}
6062
}
6163
}
@@ -527,6 +529,16 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
527529
debug!("RUSTFLAGS={}", &rustflags);
528530
};
529531

532+
let mut target_rustflags = env::var("CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS")
533+
.ok().unwrap_or_default();
534+
if config.arch == "sbfv2" {
535+
target_rustflags = format!("{} {}", "-C target_cpu=sbfv2", target_rustflags);
536+
env::set_var(
537+
"CARGO_TARGET_SBF_SOLANA_SOLANA_RUSTFLAGS",
538+
&target_rustflags,
539+
);
540+
}
541+
530542
let cargo_build = PathBuf::from("cargo");
531543
let mut cargo_build_args = vec![
532544
"+sbf",
@@ -535,6 +547,9 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
535547
"sbf-solana-solana",
536548
"--release",
537549
];
550+
if config.arch == "sbfv2" {
551+
cargo_build_args.push("-Zbuild-std=std,panic_abort");
552+
}
538553
if config.no_default_features {
539554
cargo_build_args.push("--no-default-features");
540555
}
@@ -818,6 +833,13 @@ fn main() {
818833
.validator(|val| val.parse::<usize>().map_err(|e| e.to_string()))
819834
.help("Number of parallel jobs, defaults to # of CPUs"),
820835
)
836+
.arg(
837+
Arg::new("arch")
838+
.long("arch")
839+
.possible_values(&["sbf", "sbfv2"])
840+
.default_value("sbf")
841+
.help("Build for the given SBF version"),
842+
)
821843
.get_matches_from(args);
822844

823845
let sbf_sdk: PathBuf = matches.value_of_t_or_exit("sbf_sdk");
@@ -854,6 +876,7 @@ fn main() {
854876
verbose: matches.is_present("verbose"),
855877
workspace: matches.is_present("workspace"),
856878
jobs: matches.value_of_t("jobs").ok(),
879+
arch: matches.value_of("arch").unwrap(),
857880
};
858881
let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
859882
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)