diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2024-04-15 09:27:34 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2024-04-15 14:27:41 -0700 |
| commit | 8bb9d30a02552cb04fe9d7f7b57ee378fbe6f246 (patch) | |
| tree | 0561172a4163add08f7e4c202d4c49922c975d5f /src/bootstrap | |
| parent | 023084804e5e8ea42877451c2b3030e7050281cc (diff) | |
| download | rust-8bb9d30a02552cb04fe9d7f7b57ee378fbe6f246.tar.gz rust-8bb9d30a02552cb04fe9d7f7b57ee378fbe6f246.zip | |
Update how WASI toolchains are used in CI and bootstrap
This commit updates how the WASI targets are configured with their toolchain. Long ago a `config.toml` option of `wasi-root` was added to enable building with the WASI files produced by wasi-libc. Additionally for CI testing and release building the Rust toolchain has been using a hard-coded commit of wasi-libc which is bundled with the release of the `wasm32-wasip1` target, for example. Nowadays though the wasi-sdk project, the C/C++ toolchain for WASI, is the go-to solution for compiling/linking WASI code and contains the more-or-less official releases of wasi-libc. This commit migrates CI to using wasi-sdk releases and additionally updates `bootstrap` to recognize when this is configured. This means that with `$WASI_SDK_PATH` configured there's no further configuration necessary to get a working build. Notably this also works better for the new targets of WASI as well, such as `wasm32-wasip2` and `wasm32-wasip1-threads` where the wasi-sdk release now has libraries for all targets bundled within it.
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/core/build_steps/compile.rs | 25 | ||||
| -rw-r--r-- | src/bootstrap/src/lib.rs | 21 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/cc_detect.rs | 12 |
3 files changed, 38 insertions, 20 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 9420e40d6c2..50149d370d5 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -394,16 +394,13 @@ fn copy_self_contained_objects( target_deps.push((libunwind_path, DependencyType::TargetSelfContained)); } } else if target.contains("-wasi") { - let srcdir = builder - .wasi_root(target) - .unwrap_or_else(|| { - panic!( - "Target {:?} does not have a \"wasi-root\" key in Config.toml", - target.triple - ) - }) - .join("lib") - .join(target.to_string().replace("-preview1", "").replace("p2", "").replace("p1", "")); + let srcdir = builder.wasi_libdir(target).unwrap_or_else(|| { + panic!( + "Target {:?} does not have a \"wasi-root\" key in Config.toml \ + or `$WASI_SDK_PATH` set", + target.triple + ) + }); for &obj in &["libc.a", "crt1-command.o", "crt1-reactor.o"] { copy_and_stamp( builder, @@ -514,12 +511,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car } if target.contains("-wasi") { - if let Some(p) = builder.wasi_root(target) { - let root = format!( - "native={}/lib/{}", - p.to_str().unwrap(), - target.to_string().replace("-preview1", "") - ); + if let Some(dir) = builder.wasi_libdir(target) { + let root = format!("native={}", dir.to_str().unwrap()); cargo.rustflag("-L").rustflag(&root); } } diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 1a8322c0dfd..027bcac045c 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1351,9 +1351,24 @@ impl Build { self.musl_root(target).map(|root| root.join("lib")) } - /// Returns the sysroot for the wasi target, if defined - fn wasi_root(&self, target: TargetSelection) -> Option<&Path> { - self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p) + /// Returns the `lib` directory for the WASI target specified, if + /// configured. + /// + /// This first consults `wasi-root` as configured in per-target + /// configuration, and failing that it assumes that `$WASI_SDK_PATH` is + /// set in the environment, and failing that `None` is returned. + fn wasi_libdir(&self, target: TargetSelection) -> Option<PathBuf> { + let configured = + self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p); + if let Some(path) = configured { + return Some(path.join("lib").join(target.to_string())); + } + let mut env_root = PathBuf::from(std::env::var_os("WASI_SDK_PATH")?); + env_root.push("share"); + env_root.push("wasi-sysroot"); + env_root.push("lib"); + env_root.push(target.to_string()); + Some(env_root) } /// Returns `true` if this is a no-std `target`, if defined diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 3ba4e0cb686..7e59b7f6f57 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -47,7 +47,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> { Some(PathBuf::from("ar")) } else if target.contains("vxworks") { Some(PathBuf::from("wr-ar")) - } else if target.contains("android") { + } else if target.contains("android") || target.contains("-wasi") { Some(cc.parent().unwrap().join(PathBuf::from("llvm-ar"))) } else { let parent = cc.parent().unwrap(); @@ -223,6 +223,16 @@ fn default_compiler( } } + t if t.contains("-wasi") => { + let root = PathBuf::from(std::env::var_os("WASI_SDK_PATH")?); + let compiler = match compiler { + Language::C => format!("{t}-clang"), + Language::CPlusPlus => format!("{t}-clang++"), + }; + let compiler = root.join("bin").join(compiler); + Some(compiler) + } + _ => None, } } |
