Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 780b30a

Browse files
authoredMar 13, 2025
Rollup merge of rust-lang#137457 - JayAndJef:issue-132802-fix, r=Kobzol
fix for issue 132802: x86 code in `wasm32-unknown-unknown` binaries This is a direct fix for issue [132802](rust-lang#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-2 try-job: x86_64-msvc-1
2 parents a490334 + e1bb12d commit 780b30a

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed
 

‎src/bootstrap/src/core/sanity.rs

+11
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ than building it.
311311
.entry(*target)
312312
.or_insert_with(|| Target::from_triple(&target.triple));
313313

314+
// compiler-rt c fallbacks for wasm cannot be built with gcc
315+
if target.contains("wasm") // bare metal targets without wasi sdk
316+
&& (build.config.optimized_compiler_builtins(*target)
317+
|| build.config.rust_std_features.contains("compiler-builtins-c"))
318+
{
319+
let is_clang = build.cc_tool(*target).is_like_clang();
320+
if !is_clang {
321+
panic!("only clang supports building c code for wasm targets");
322+
}
323+
}
324+
314325
if (target.contains("-none-") || target.contains("nvptx"))
315326
&& build.no_std(*target) == Some(false)
316327
{

‎src/bootstrap/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::{env, fs, io, str};
2727

2828
use build_helper::ci::gha;
2929
use build_helper::exit;
30+
use cc::Tool;
3031
use termcolor::{ColorChoice, StandardStream, WriteColor};
3132
use utils::build_stamp::BuildStamp;
3233
use utils::channel::GitInfo;
@@ -1218,6 +1219,11 @@ Executed at: {executed_at}"#,
12181219
self.cc.borrow()[&target].path().into()
12191220
}
12201221

1222+
/// Returns the internal `cc::Tool`
1223+
fn cc_tool(&self, target: TargetSelection) -> Tool {
1224+
self.cc.borrow()[&target].clone()
1225+
}
1226+
12211227
/// Returns C flags that `cc-rs` thinks should be enabled for the
12221228
/// specified target by default.
12231229
fn cc_handled_clags(&self, target: TargetSelection, c: CLang) -> Vec<String> {

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

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ ENV \
6565
CXX_i686_unknown_uefi=clang++-11 \
6666
CC_x86_64_unknown_uefi=clang-11 \
6767
CXX_x86_64_unknown_uefi=clang++-11 \
68+
CC_wasm32_unknown_unknown=clang-11 \
69+
CXX_wasm32_unknown_unknown=clang++-11 \
70+
CC_wasm32v1_none=clang-11 \
71+
CXX_wasm32v1_none=clang++-11 \
6872
CC=gcc-9 \
6973
CXX=g++-9
7074

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

+4-3
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 \
@@ -90,4 +91,4 @@ ENV UEFI_TARGETS=aarch64-unknown-uefi,i686-unknown-uefi,x86_64-unknown-uefi \
9091
ENV UEFI_SCRIPT python3 /checkout/x.py --stage 2 build --host='' --target $UEFI_TARGETS && \
9192
python3 -u /uefi_qemu_test/run.py
9293

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

0 commit comments

Comments
 (0)
Failed to load comments.