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

Merged
merged 5 commits into from
Aug 23, 2025
Merged
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") {
Copy link
Contributor

Choose a reason for hiding this comment

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

just to clarify, will this work on Windows if emcc.bat is used?

Copy link
Member

Choose a reason for hiding this comment

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

No idea 🤷 Are you able to check?

Copy link
Contributor

Choose a reason for hiding this comment

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

only tomorrow...

Copy link
Contributor

Choose a reason for hiding this comment

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

@Kobzol failed to compile nightly-2025-08-25

[2025-08-25T10:10:59.151Z INFO  opt_dist::exec] Executing `RUSTC=C:/msys64/clang64\bin\rustc.exe RUSTC_BOOTSTRAP=1 C:/msys64/clang64\bin\cargo.exe build -p collector [at C:/msys64/home/maksa/forks/MINGW-packages/mingw-w64-rust/src/rustc-nightly-src\opt-artifacts-CLANG64\rustc-perf]`
error: failed to select a version for the requirement `analyzeme = "^12.0.0"` (locked to 12.0.0)
candidate versions found which didn't match: 12.0.3
location searched: directory source `C:\msys64\home\maksa\forks\MINGW-packages\mingw-w64-rust\src\rustc-nightly-src\vendor` (which is replacing registry `crates-io`)
required by package `collector v0.1.0 (C:\msys64\home\maksa\forks\MINGW-packages\mingw-w64-rust\src\rustc-nightly-src\opt-artifacts-CLANG64\rustc-perf\collector)`
perhaps a crate was updated and forgotten to be re-vendored?

Copy link
Member

Choose a reason for hiding this comment

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

That seems unrelated to this PR. Maybe the recent cargo update bump?

Copy link
Contributor

@ognevny ognevny Aug 25, 2025

Choose a reason for hiding this comment

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

yeah I meant that I can't test the code :D

edit: yeah, analyzeme is probably missing in lockfile

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I forgot to up-to-date rustc-perf checkout. I switched to tarball source and now it works, sorry for noise...

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, it works on my machine, fine then

// 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.

Copy link
Contributor Author

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?

I'm not very sure about the variable changes... maybe I renamed it for clarity?
If I remember correctly installing gcc-multilib was in response to the script failing locally.

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.

wasm32-wasip1 depends on the wasi sdk, which is based on clang. You can see it installed on line 44-46 of the test-various Dockerfile.

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