Skip to content

Commit 467c89c

Browse files
authored
Rollup merge of #137457 - JayAndJef:issue-132802-fix, r=Kobzol
Fix host code appearing in Wasm binaries This is a direct fix for issue [132802](#132802). Followed the outline as follows: > * give a hard error in bootstrap when using gcc to compile for wasm > * change our CI to use clang instead of gcc > * add a test that compiling a sample program for wasm32-unknown doesn't give any linker warnings The `test-various` ci job was also changed. try-job: test-various try-job: dist-various-1 try-job: dist-various-2 try-job: x86_64-msvc-1
2 parents 85c9af5 + dee1b19 commit 467c89c

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

src/bootstrap/src/core/sanity.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,23 @@ than building it.
327327
.entry(*target)
328328
.or_insert_with(|| Target::from_triple(&target.triple));
329329

330+
// compiler-rt c fallbacks for wasm cannot be built with gcc
331+
if target.contains("wasm")
332+
&& (build.config.optimized_compiler_builtins(*target)
333+
|| build.config.rust_std_features.contains("compiler-builtins-c"))
334+
{
335+
let cc_tool = build.cc_tool(*target);
336+
if !cc_tool.is_like_clang() && !cc_tool.path().ends_with("emcc") {
337+
// emcc works as well
338+
panic!(
339+
"Clang is required to build C code for Wasm targets, got `{}` instead\n\
340+
this is because compiler-builtins is configured to build C source. Either \
341+
ensure Clang is used, or adjust this configuration.",
342+
cc_tool.path().display()
343+
);
344+
}
345+
}
346+
330347
if (target.contains("-none-") || target.contains("nvptx"))
331348
&& build.no_std(*target) == Some(false)
332349
{

src/ci/docker/host-x86_64/dist-various-1/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ RUN ./install-riscv64-none-elf.sh
5555
COPY host-x86_64/dist-various-1/install-riscv32-none-elf.sh /build
5656
RUN ./install-riscv32-none-elf.sh
5757

58+
COPY host-x86_64/dist-various-1/install-emscripten.sh /build
59+
RUN ./install-emscripten.sh
60+
61+
# Add Emscripten to PATH
62+
ENV PATH="/build/emsdk:/build/emsdk/upstream/emscripten:/build/emsdk/node/current/bin:${PATH}"
63+
5864
# Suppress some warnings in the openwrt toolchains we downloaded
5965
ENV STAGING_DIR=/tmp
6066

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
apt-get update
5+
apt-get install -y --no-install-recommends \
6+
nodejs \
7+
default-jre
8+
9+
git clone https://github.com/emscripten-core/emsdk.git
10+
cd emsdk
11+
./emsdk install latest
12+
./emsdk activate latest

src/ci/docker/host-x86_64/dist-various-2/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ ENV \
5959
CXX_i686_unknown_uefi=clang++-11 \
6060
CC_x86_64_unknown_uefi=clang-11 \
6161
CXX_x86_64_unknown_uefi=clang++-11 \
62+
CC_wasm32_unknown_unknown=clang-11 \
63+
CXX_wasm32_unknown_unknown=clang++-11 \
64+
CC_wasm32v1_none=clang-11 \
65+
CXX_wasm32v1_none=clang++-11 \
6266
CC=gcc-9 \
6367
CXX=g++-9
6468

src/ci/docker/host-x86_64/test-various/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ARG DEBIAN_FRONTEND=noninteractive
44
RUN apt-get update && apt-get install -y --no-install-recommends \
55
clang-11 \
66
llvm-11 \
7+
gcc-multilib \
78
g++ \
89
make \
910
ninja-build \
@@ -59,8 +60,8 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v19.0
5960
tar -xJ
6061
ENV PATH "$PATH:/wasmtime-v19.0.0-x86_64-linux"
6162

62-
ENV WASM_TARGETS=wasm32-wasip1
63-
ENV WASM_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_TARGETS \
63+
ENV WASM_WASIP_TARGET=wasm32-wasip1
64+
ENV WASM_WASIP_SCRIPT python3 /checkout/x.py --stage 2 test --host='' --target $WASM_WASIP_TARGET \
6465
tests/run-make \
6566
tests/ui \
6667
tests/mir-opt \
@@ -91,4 +92,4 @@ ENV UEFI_SCRIPT python3 /checkout/x.py --stage 2 build --host='' --target $UEFI_
9192
python3 /checkout/x.py --stage 2 test tests/run-make/uefi-qemu/rmake.rs --target i686-unknown-uefi && \
9293
python3 /checkout/x.py --stage 2 test tests/run-make/uefi-qemu/rmake.rs --target x86_64-unknown-uefi
9394

94-
ENV SCRIPT $WASM_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT && $UEFI_SCRIPT
95+
ENV SCRIPT $WASM_WASIP_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT && $UEFI_SCRIPT

0 commit comments

Comments
 (0)