From f76d1aecd6a5e239fa5c6b719440657cb13a3231 Mon Sep 17 00:00:00 2001 From: Jayden Qi Date: Sat, 22 Feb 2025 13:03:50 -0800 Subject: [PATCH 1/6] fix: wasm-bare targets compiling x86 builtins Added sanity check to bootstrap to hard error on wasm builds without clang, and changed distribution image `dist-various-2` to use clang to build for official targets. --- src/bootstrap/src/core/sanity.rs | 11 +++++++++++ src/ci/docker/host-x86_64/dist-various-2/Dockerfile | 4 ++++ src/ci/docker/host-x86_64/test-various/Dockerfile | 7 ++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index f2119e84cce74..3efd365739479 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -326,6 +326,17 @@ than building it. .entry(*target) .or_insert_with(|| Target::from_triple(&target.triple)); + // compiler-rt c fallbacks for wasm cannot be built with gcc + if target.contains("wasm") // bare metal targets without wasi sdk + && (build.config.optimized_compiler_builtins(*target) + || build.config.rust_std_features.contains("compiler-builtins-c")) + { + let is_clang = build.cc_tool(*target).is_like_clang(); + if !is_clang { + panic!("only clang supports building c code for wasm targets"); + } + } + if (target.contains("-none-") || target.contains("nvptx")) && build.no_std(*target) == Some(false) { diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index e1d83d360872c..931cc688402fb 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -59,6 +59,10 @@ ENV \ CXX_i686_unknown_uefi=clang++-11 \ CC_x86_64_unknown_uefi=clang-11 \ CXX_x86_64_unknown_uefi=clang++-11 \ + CC_wasm32_unknown_unknown=clang-11 \ + CXX_wasm32_unknown_unknown=clang++-11 \ + CC_wasm32v1_none=clang-11 \ + CXX_wasm32v1_none=clang++-11 \ CC=gcc-9 \ CXX=g++-9 diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index 8d2e45ae497ef..6c3e62267e1c2 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -4,6 +4,7 @@ ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ clang-11 \ llvm-11 \ + gcc-multilib \ g++ \ make \ ninja-build \ @@ -59,8 +60,8 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v19.0 tar -xJ ENV PATH "$PATH:/wasmtime-v19.0.0-x86_64-linux" -ENV WASM_TARGETS=wasm32-wasip1 -ENV WASM_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_TARGETS \ +ENV WASM_WASIP_TARGET=wasm32-wasip1 +ENV WASM_WASIP_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_WASIP_TARGET \ tests/run-make \ tests/ui \ tests/mir-opt \ @@ -90,4 +91,4 @@ ENV UEFI_TARGETS=aarch64-unknown-uefi,i686-unknown-uefi,x86_64-unknown-uefi \ ENV UEFI_SCRIPT python3 /checkout/x.py --stage 2 build --host='' --target $UEFI_TARGETS && \ python3 -u /uefi_qemu_test/run.py -ENV SCRIPT $WASM_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT && $UEFI_SCRIPT +ENV SCRIPT $WASM_WASIP_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT && $UEFI_SCRIPT From 1611320a922c2c3973e9678db48cfb3cd9165504 Mon Sep 17 00:00:00 2001 From: Jayden Qi Date: Fri, 14 Mar 2025 18:40:11 -0700 Subject: [PATCH 2/6] fix: install correct cc for wasm32-unknown-emscripten Also fixed a typo in the sanity check for bootstrap, as we are checking for clang-likeness in every wasm target. --- src/bootstrap/src/core/sanity.rs | 2 +- src/ci/docker/host-x86_64/dist-various-1/Dockerfile | 9 +++++++++ .../host-x86_64/dist-various-1/install-emscripten.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 src/ci/docker/host-x86_64/dist-various-1/install-emscripten.sh diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 3efd365739479..43e44273bfbaa 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -327,7 +327,7 @@ than building it. .or_insert_with(|| Target::from_triple(&target.triple)); // compiler-rt c fallbacks for wasm cannot be built with gcc - if target.contains("wasm") // bare metal targets without wasi sdk + if target.contains("wasm") && (build.config.optimized_compiler_builtins(*target) || build.config.rust_std_features.contains("compiler-builtins-c")) { diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index 5c459e5cd180b..1e45ef45c9be4 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -55,6 +55,15 @@ RUN ./install-riscv64-none-elf.sh COPY host-x86_64/dist-various-1/install-riscv32-none-elf.sh /build RUN ./install-riscv32-none-elf.sh +COPY host-x86_64/dist-various-1/install-llvm-mingw.sh /build +RUN ./install-llvm-mingw.sh + +COPY host-x86_64/dist-various-1/install-emscripten.sh /build +RUN ./install-emscripten.sh + +# Add Emscripten to PATH +ENV PATH="/build/emsdk:/build/emsdk/upstream/emscripten:/build/emsdk/node/current/bin:${PATH}" + # Suppress some warnings in the openwrt toolchains we downloaded ENV STAGING_DIR=/tmp diff --git a/src/ci/docker/host-x86_64/dist-various-1/install-emscripten.sh b/src/ci/docker/host-x86_64/dist-various-1/install-emscripten.sh new file mode 100755 index 0000000000000..eeb54ca67f7ba --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-various-1/install-emscripten.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -ex + +apt-get update +apt-get install -y --no-install-recommends \ + nodejs \ + default-jre + +git clone https://github.com/emscripten-core/emsdk.git +cd emsdk +./emsdk install latest +./emsdk activate latest From c0d6e733d87310a5e4cd28ef92ee43acece1d716 Mon Sep 17 00:00:00 2001 From: Jayden Qi Date: Tue, 1 Jul 2025 14:12:01 -0700 Subject: [PATCH 3/6] fix: error message --- src/bootstrap/src/core/sanity.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 43e44273bfbaa..34df5fd9152d8 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -331,9 +331,14 @@ than building it. && (build.config.optimized_compiler_builtins(*target) || build.config.rust_std_features.contains("compiler-builtins-c")) { - let is_clang = build.cc_tool(*target).is_like_clang(); - if !is_clang { - panic!("only clang supports building c code for wasm targets"); + let cc_tool = build.cc_tool(*target); + if !cc_tool.is_like_clang() { + panic!( + "Clang is required to build C code for Wasm targets, got `{}` instead\n\ + this is because compiler-builtins is configured to build C source. Either \ + ensure Clang is used, or adjust this configuration.", + cc_tool.path().display() + ); } } From e5802b376e2716307cf2910279448d540ffe8442 Mon Sep 17 00:00:00 2001 From: Jayden Qi Date: Tue, 1 Jul 2025 14:12:21 -0700 Subject: [PATCH 4/6] fix: remove unneeded(?) install script --- src/ci/docker/host-x86_64/dist-various-1/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile index 1e45ef45c9be4..4d5980027cac1 100644 --- a/src/ci/docker/host-x86_64/dist-various-1/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-1/Dockerfile @@ -55,9 +55,6 @@ RUN ./install-riscv64-none-elf.sh COPY host-x86_64/dist-various-1/install-riscv32-none-elf.sh /build RUN ./install-riscv32-none-elf.sh -COPY host-x86_64/dist-various-1/install-llvm-mingw.sh /build -RUN ./install-llvm-mingw.sh - COPY host-x86_64/dist-various-1/install-emscripten.sh /build RUN ./install-emscripten.sh From bb984a2554ec9235c02fb068dec884b40638f565 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Thu, 3 Jul 2025 16:00:41 +0800 Subject: [PATCH 5/6] [DO NOT MERGE] ----- force different commit hash ----- From 59dfbcdc0387a8a6148b5b2f1deffbae22603e1e Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Thu, 3 Jul 2025 16:03:10 +0800 Subject: [PATCH 6/6] remove trailing whitespace --- src/ci/docker/host-x86_64/test-various/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/test-various/Dockerfile b/src/ci/docker/host-x86_64/test-various/Dockerfile index 6c3e62267e1c2..33b6bda2c38cf 100644 --- a/src/ci/docker/host-x86_64/test-various/Dockerfile +++ b/src/ci/docker/host-x86_64/test-various/Dockerfile @@ -60,7 +60,7 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v19.0 tar -xJ ENV PATH "$PATH:/wasmtime-v19.0.0-x86_64-linux" -ENV WASM_WASIP_TARGET=wasm32-wasip1 +ENV WASM_WASIP_TARGET=wasm32-wasip1 ENV WASM_WASIP_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_WASIP_TARGET \ tests/run-make \ tests/ui \