Skip to content

Commit

Permalink
chore(cargo-build-sbf): allow using it from nix store (#3762)
Browse files Browse the repository at this point in the history
* allow using tools from nix store

* feat: allow to run sbf build without autoinstall of tooling
  • Loading branch information
dzmitry-lahoda authored Nov 27, 2024
1 parent 2372ec8 commit 5c8cde0
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 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> {
dump: bool,
features: Vec<String>,
force_tools_install: bool,
skip_tools_install: bool,
generate_child_script_on_failure: bool,
no_default_features: bool,
offline: bool,
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Default for Config<'_> {
dump: false,
features: vec![],
force_tools_install: false,
skip_tools_install: false,
generate_child_script_on_failure: false,
no_default_features: false,
offline: false,
Expand Down Expand Up @@ -661,40 +663,43 @@ fn build_solana_package(
} else {
"x86_64"
};
let platform_tools_download_file_name = if cfg!(target_os = "windows") {
format!("platform-tools-windows-{arch}.tar.bz2")
} else if cfg!(target_os = "macos") {
format!("platform-tools-osx-{arch}.tar.bz2")
} else {
format!("platform-tools-linux-{arch}.tar.bz2")
};
let package = "platform-tools";
let target_path = make_platform_tools_path_for_version(package, &platform_tools_version);
install_if_missing(
config,
package,
"https://github.com/anza-xyz/platform-tools/releases/download",
platform_tools_download_file_name.as_str(),
&platform_tools_version,
&target_path,
)
.unwrap_or_else(|err| {
// The package version directory doesn't contain a valid
// installation, and it should be removed.
let target_path_parent = target_path.parent().expect("Invalid package path");
if target_path_parent.exists() {
fs::remove_dir_all(target_path_parent).unwrap_or_else(|err| {
error!(
"Failed to remove {} while recovering from installation failure: {}",
target_path_parent.to_string_lossy(),
err,
);
exit(1);
});
}
error!("Failed to install platform-tools: {}", err);
exit(1);
});

if !config.skip_tools_install {
let platform_tools_download_file_name = if cfg!(target_os = "windows") {
format!("platform-tools-windows-{arch}.tar.bz2")
} else if cfg!(target_os = "macos") {
format!("platform-tools-osx-{arch}.tar.bz2")
} else {
format!("platform-tools-linux-{arch}.tar.bz2")
};
let package = "platform-tools";
let target_path = make_platform_tools_path_for_version(package, &platform_tools_version);
install_if_missing(
config,
package,
"https://github.com/anza-xyz/platform-tools/releases/download",
platform_tools_download_file_name.as_str(),
&platform_tools_version,
&target_path,
)
.unwrap_or_else(|err| {
// The package version directory doesn't contain a valid
// installation, and it should be removed.
let target_path_parent = target_path.parent().expect("Invalid package path");
if target_path_parent.exists() {
fs::remove_dir_all(target_path_parent).unwrap_or_else(|err| {
error!(
"Failed to remove {} while recovering from installation failure: {}",
target_path_parent.to_string_lossy(),
err,
);
exit(1);
});
}
error!("Failed to install platform-tools: {}", err);
exit(1);
});
}
link_solana_toolchain(config);

let llvm_bin = config
Expand Down Expand Up @@ -1034,8 +1039,16 @@ fn main() {
Arg::new("force_tools_install")
.long("force-tools-install")
.takes_value(false)
.conflicts_with("skip_tools_install")
.help("Download and install platform-tools even when existing tools are located"),
)
.arg(
Arg::new("skip_tools_install")
.long("skip-tools-install")
.takes_value(false)
.conflicts_with("force_tools_install")
.help("Skip downloading and installing platform-tools, assuming they are properly mounted"),
)
.arg(
Arg::new("generate_child_script_on_failure")
.long("generate-child-script-on-failure")
Expand Down Expand Up @@ -1159,6 +1172,7 @@ fn main() {
dump: matches.is_present("dump"),
features: matches.values_of_t("features").ok().unwrap_or_default(),
force_tools_install: matches.is_present("force_tools_install"),
skip_tools_install: matches.is_present("skip_tools_install"),
generate_child_script_on_failure: matches.is_present("generate_child_script_on_failure"),
no_default_features: matches.is_present("no_default_features"),
remap_cwd: !matches.is_present("remap_cwd"),
Expand Down

0 comments on commit 5c8cde0

Please sign in to comment.