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

cargo-build-sbf, cargo-test-sbf: add --arch option #23465

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions sdk/cargo-build-sbf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Config<'a> {
verbose: bool,
workspace: bool,
jobs: Option<String>,
arch: &'a str,
}

impl Default for Config<'_> {
Expand All @@ -57,6 +58,7 @@ impl Default for Config<'_> {
verbose: false,
workspace: false,
jobs: None,
arch: "sbf",
}
}
}
Expand Down Expand Up @@ -539,6 +541,17 @@ fn build_sbf_package(config: &Config, target_directory: &Path, package: &cargo_m
env::remove_var("RUSTC")
}

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",
Expand All @@ -547,6 +560,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");
}
Expand Down Expand Up @@ -830,6 +846,13 @@ fn main() {
.validator(|val| val.parse::<usize>().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");
Expand Down Expand Up @@ -866,6 +889,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<PathBuf> = matches.value_of_t("manifest_path").ok();
if config.verbose {
Expand Down
17 changes: 15 additions & 2 deletions sdk/cargo-test-sbf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
},
};

struct Config {
struct Config<'a> {
sbf_sdk: Option<String>,
sbf_out_dir: Option<String>,
cargo: PathBuf,
Expand All @@ -25,9 +25,10 @@ struct Config {
verbose: bool,
workspace: bool,
jobs: Option<String>,
arch: &'a str,
}

impl Default for Config {
impl Default for Config<'_> {
fn default() -> Self {
Self {
sbf_sdk: None,
Expand All @@ -44,6 +45,7 @@ impl Default for Config {
verbose: false,
workspace: false,
jobs: None,
arch: "sbf",
}
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -311,6 +316,13 @@ fn main() {
.validator(|val| val.parse::<usize>().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")
Expand All @@ -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()
};

Expand Down