Skip to content

Fix host code appearing in Wasm binaries #137457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,23 @@ 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")
&& (build.config.optimized_compiler_builtins(*target)
|| build.config.rust_std_features.contains("compiler-builtins-c"))
{
let cc_tool = build.cc_tool(*target);
if !cc_tool.is_like_clang() && !cc_tool.path().ends_with("emcc") {
// emcc works as well
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()
);
}
}

if (target.contains("-none-") || target.contains("nvptx"))
&& build.no_std(*target) == Some(false)
{
Expand Down
6 changes: 6 additions & 0 deletions src/ci/docker/host-x86_64/dist-various-1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ 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-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

Expand Down
12 changes: 12 additions & 0 deletions src/ci/docker/host-x86_64/dist-various-1/install-emscripten.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/ci/docker/host-x86_64/dist-various-2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions src/ci/docker/host-x86_64/test-various/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Comment on lines -62 to +64
Copy link
Contributor

@tgross35 tgross35 Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is going on with the changes in this file btw? It looks like a variable rename, which should be inconsequential, plus installing gcc-multilib?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why is this wasi build succeeding? We don't set CC_wasm32_wasip1 to Clang anywhere, which would mean GCC is the default.

I think it would be good to set the CC_* variables even if it works for some reason, to make it explicit that we want clang.

tests/run-make \
tests/ui \
tests/mir-opt \
Expand Down Expand Up @@ -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
Loading