1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -118,7 +118,10 @@
}
pub fn platform_tools_cache_dir() -> PathBuf {
- platform_tools_cache_dir_from(env::var_os("SOLANA_PLATFORM_TOOLS_DIR"))
+ platform_tools_cache_dir_from(
+ env::var_os("SOLANA_PLATFORM_TOOLS_DIR")
+ .or_else(|| Some("/usr/lib/solana/platform-tools".into())),
+ )
}
pub fn is_version_string(arg: &str) -> Result<(), String> {
--- a/src/toolchain.rs
+++ b/src/toolchain.rs
@@ -21,7 +21,7 @@
tar::Archive,
};
-pub const DEFAULT_PLATFORM_TOOLS_VERSION: &str = "v1.57";
+pub const DEFAULT_PLATFORM_TOOLS_VERSION: &str = "v1.58";
pub const DEFAULT_RUST_VERSION: &str = "1.95.0";
// Common headers used for Github API.
@@ -383,6 +383,7 @@
}
// check whether custom solana toolchain is linked, and link it if it is not.
+#[allow(dead_code)]
fn link_solana_toolchain(
config: &Config,
platform_tools_dir: &Path,
@@ -526,30 +527,23 @@
install_tools(config, &platform_tools_version, false);
}
- if config.no_rustup_override {
- let target_triple = rust_target_triple(config);
- check_solana_target_installed(&target_triple);
- } else {
- let platform_tools_dir = make_platform_tools_path_for_version(&platform_tools_version);
- link_solana_toolchain(config, &platform_tools_dir, &platform_tools_version);
- // RUSTC variable overrides cargo +<toolchain> mechanism of
- // selecting the rust compiler and makes cargo run a rust compiler
- // other than the one linked in Solana toolchain. We have to prevent
- // this by removing RUSTC from the child process environment.
- if env::var("RUSTC").is_ok() {
- warn!(
- "Removed RUSTC from cargo environment, because it overrides +solana cargo command \
- line option."
- );
- // Safety: cargo-build-sbf doesn't spawn any threads until final child process is spawned
- unsafe { env::remove_var("RUSTC") }
- }
+ // cargo is the binary inside the toolchain directory, not `cargo +toolchain`.
+ // Arch rust is not rustup. A host RUSTC would still override the toolchain.
+ if env::var("RUSTC").is_ok() {
+ warn!("Removed RUSTC from cargo environment so the platform-tools rustc is used.");
+ // Safety: cargo-build-sbf doesn't spawn any threads until final child process is spawned
+ unsafe { env::remove_var("RUSTC") }
+ }
+ if env::var("RUSTUP_TOOLCHAIN").is_ok() {
+ // Safety: same as above.
+ unsafe { env::remove_var("RUSTUP_TOOLCHAIN") }
}
platform_tools_version
}
// allow user to set proper `rustc` into RUSTC or into PATH
+#[allow(dead_code)]
fn check_solana_target_installed(target: &str) {
let rustc = env::var("RUSTC").unwrap_or("rustc".to_owned());
let rustc = PathBuf::from(rustc);
--- a/src/bin/build_sbf.rs
+++ b/src/bin/build_sbf.rs
@@ -4,7 +4,7 @@
post_processing::post_process,
toolchain::{
DEFAULT_PLATFORM_TOOLS_VERSION, DEFAULT_RUST_VERSION, corrupted_toolchain,
- generate_toolchain_name, install_and_link_tools, install_tools,
+ install_and_link_tools, install_tools,
make_platform_tools_path_for_version, rust_target_triple,
validate_platform_tools_version,
},
@@ -120,15 +120,22 @@
);
}
- let cargo_build = PathBuf::from("cargo");
+ // cargo resolves `rustc` from PATH. An absolute cargo does not select the
+ // sibling rustc, and Arch rustc is not rustup, so `cargo +toolchain` cannot.
+ let mut path_prepend = platform_tools_dir.join("rust").join("bin").into_os_string();
+ path_prepend.push(if cfg!(windows) { ";" } else { ":" });
+ path_prepend.push(llvm_bin.as_os_str());
+ path_prepend.push(if cfg!(windows) { ";" } else { ":" });
+ path_prepend.push(env::var_os("PATH").unwrap_or_default());
+ // Safety: cargo-build-sbf doesn't spawn any threads until final child process is spawned
+ unsafe { env::set_var("PATH", path_prepend) };
+ let cargo_build = platform_tools_dir.join("rust").join("bin").join(if cfg!(windows) {
+ "cargo.exe"
+ } else {
+ "cargo"
+ });
let mut cargo_build_args = vec![];
-
- let mut toolchain_name: String;
- if !config.no_rustup_override {
- toolchain_name = generate_toolchain_name(validated_toolchain_version.as_str());
- toolchain_name = format!("+{toolchain_name}");
- cargo_build_args.push(toolchain_name.as_str());
- };
+ let _ = &validated_toolchain_version;
cargo_build_args.append(&mut vec!["build", "--target", &target_triple]);
if !config.debug {
|