Skip to content

Commit 2aafa46

Browse files
authored
Rollup merge of rust-lang#63649 - tlively:emscripten-upstream-upgrade, r=alexcrichton
Upgrade Emscripten targets to use upstream LLVM backend - Refactors the Emscripten target spec to share code with other wasm targets. - Replaces the incorrect wasm32 C call ABI with the old asmjs version, which is correct for both wasm32 and JS. - Updates the varargs ABI used by Emscripten and deletes the old one. - Removes the obsolete wasm32-experimental-emscripten target. - Temporarily makes Emscripten targets use panic=abort by default because supporting unwinding will require an LLVM patch.
2 parents 42ec683 + b04d5f7 commit 2aafa46

File tree

100 files changed

+166
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+166
-424
lines changed

config.toml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377
# but you can also optionally enable the "emscripten" backend for asm.js or
378378
# make this an empty array (but that probably won't get too far in the
379379
# bootstrap)
380+
# FIXME: remove the obsolete emscripten backend option.
380381
#codegen-backends = ["llvm"]
381382

382383
# This is the name of the directory in which codegen backends will get installed

src/bootstrap/test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,9 @@ impl Step for Compiletest {
10461046

10471047
// Also provide `rust_test_helpers` for the host.
10481048
builder.ensure(native::TestHelpers { target: compiler.host });
1049+
// As well as the target
1050+
builder.ensure(native::TestHelpers { target });
10491051

1050-
// wasm32 can't build the test helpers
1051-
if !target.contains("wasm32") {
1052-
builder.ensure(native::TestHelpers { target });
1053-
}
10541052
builder.ensure(RemoteCopyLibs { compiler, target });
10551053

10561054
let mut cmd = builder.tool_cmd(Tool::Compiletest);

src/ci/docker/asmjs/Dockerfile

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1111
cmake \
1212
sudo \
1313
gdb \
14-
xz-utils
14+
xz-utils \
15+
bzip2
1516

1617
COPY scripts/emscripten.sh /scripts/
1718
RUN bash /scripts/emscripten.sh
@@ -20,28 +21,17 @@ COPY scripts/sccache.sh /scripts/
2021
RUN sh /scripts/sccache.sh
2122

2223
ENV PATH=$PATH:/emsdk-portable
23-
ENV PATH=$PATH:/emsdk-portable/clang/e1.38.15_64bit/
24-
ENV PATH=$PATH:/emsdk-portable/emscripten/1.38.15/
25-
ENV PATH=$PATH:/emsdk-portable/node/8.9.1_64bit/bin/
26-
ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.38.15/
27-
ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.38.15_64bit/binaryen/
24+
ENV PATH=$PATH:/emsdk-portable/upstream/emscripten/
25+
ENV PATH=$PATH:/emsdk-portable/node/12.9.1_64bit/bin/
26+
ENV BINARYEN_ROOT=/emsdk-portable/upstream/
2827
ENV EM_CONFIG=/emsdk-portable/.emscripten
2928

3029
ENV TARGETS=asmjs-unknown-emscripten
3130

32-
ENV RUST_CONFIGURE_ARGS --enable-emscripten --disable-optimize-tests
31+
# TODO: Run run-fail, libcore, libstd, etc. once exceptions are enabled
32+
ENV SCRIPT python2.7 ../x.py test --target $TARGETS src/test/ui
3333

34-
ENV SCRIPT python2.7 ../x.py test --target $TARGETS \
35-
src/test/ui \
36-
src/test/run-fail \
37-
src/libstd \
38-
src/liballoc \
39-
src/libcore
40-
41-
# Debug assertions in rustc are largely covered by other builders, and LLVM
42-
# assertions cause this builder to slow down by quite a large amount and don't
43-
# buy us a huge amount over other builders (not sure if we've ever seen an
44-
# asmjs-specific backend assertion trip), so disable assertions for these
45-
# tests.
46-
ENV NO_LLVM_ASSERTIONS=1
34+
# This is almost identical to the wasm32-unknown-emscripten target, so
35+
# running with assertions again is not useful
4736
ENV NO_DEBUG_ASSERTIONS=1
37+
ENV NO_LLVM_ASSERTIONS=1

src/ci/docker/disabled/wasm32-exp/Dockerfile

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/ci/docker/disabled/wasm32-exp/node.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ci/docker/disabled/wasm32/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1111
cmake \
1212
sudo \
1313
gdb \
14-
xz-utils
14+
xz-utils \
15+
bzip2
1516

16-
# emscripten
1717
COPY scripts/emscripten.sh /scripts/
1818
RUN bash /scripts/emscripten.sh
1919

2020
COPY scripts/sccache.sh /scripts/
2121
RUN sh /scripts/sccache.sh
2222

2323
ENV PATH=$PATH:/emsdk-portable
24-
ENV PATH=$PATH:/emsdk-portable/clang/e1.38.15_64bit/
25-
ENV PATH=$PATH:/emsdk-portable/emscripten/1.38.15/
26-
ENV PATH=$PATH:/emsdk-portable/node/8.9.1_64bit/bin/
27-
ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.38.15/
28-
ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.38.15_64bit/binaryen/
24+
ENV PATH=$PATH:/emsdk-portable/upstream/emscripten/
25+
ENV PATH=$PATH:/emsdk-portable/node/12.9.1_64bit/bin/
26+
ENV BINARYEN_ROOT=/emsdk-portable/upstream/
2927
ENV EM_CONFIG=/emsdk-portable/.emscripten
3028

3129
ENV TARGETS=wasm32-unknown-emscripten
32-
ENV SCRIPT python2.7 ../x.py test --target $TARGETS
30+
31+
# TODO: Run run-fail, libcore, libstd, etc. once exceptions are enabled
32+
ENV SCRIPT python2.7 ../x.py test --target $TARGETS src/test/ui

src/ci/docker/scripts/emscripten-wasm.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/ci/docker/scripts/emscripten.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,15 @@ exit 1
1717
set -x
1818
}
1919

20-
cd /
21-
curl -fL https://mozilla-games.s3.amazonaws.com/emscripten/releases/emsdk-portable.tar.gz | \
22-
tar -xz
23-
20+
git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
2421
cd /emsdk-portable
25-
./emsdk update
26-
hide_output ./emsdk install sdk-1.38.15-64bit
27-
./emsdk activate sdk-1.38.15-64bit
22+
hide_output ./emsdk install 1.38.46-upstream
23+
./emsdk activate 1.38.46-upstream
2824

2925
# Compile and cache libc
3026
source ./emsdk_env.sh
3127
echo "main(){}" > a.c
3228
HOME=/emsdk-portable/ emcc a.c
33-
HOME=/emsdk-portable/ emcc -s BINARYEN=1 a.c
3429
rm -f a.*
3530

3631
# Make emsdk usable by any user

src/libcore/ffi.rs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ impl fmt::Debug for c_void {
4949
/// Basic implementation of a `va_list`.
5050
// The name is WIP, using `VaListImpl` for now.
5151
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
52-
not(target_arch = "x86_64"), not(target_arch = "asmjs")),
52+
not(target_arch = "x86_64")),
5353
all(target_arch = "aarch64", target_os = "ios"),
54+
target_arch = "wasm32",
55+
target_arch = "asmjs",
5456
windows))]
5557
#[repr(transparent)]
5658
#[unstable(feature = "c_variadic",
@@ -67,8 +69,10 @@ pub struct VaListImpl<'f> {
6769
}
6870

6971
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
70-
not(target_arch = "x86_64"), not(target_arch = "asmjs")),
72+
not(target_arch = "x86_64")),
7173
all(target_arch = "aarch64", target_os = "ios"),
74+
target_arch = "wasm32",
75+
target_arch = "asmjs",
7276
windows))]
7377
#[unstable(feature = "c_variadic",
7478
reason = "the `c_variadic` feature has not been properly tested on \
@@ -137,38 +141,6 @@ pub struct VaListImpl<'f> {
137141
_marker: PhantomData<&'f mut &'f c_void>,
138142
}
139143

140-
/// asm.js ABI implementation of a `va_list`.
141-
// asm.js uses the PNaCl ABI, which specifies that a `va_list` is
142-
// an array of 4 32-bit integers, according to the old PNaCl docs at
143-
// https://web.archive.org/web/20130518054430/https://www.chromium.org/nativeclient/pnacl/bitcode-abi#TOC-Derived-Types
144-
// and clang does the same in `CreatePNaClABIBuiltinVaListDecl` from `lib/AST/ASTContext.cpp`
145-
#[cfg(all(target_arch = "asmjs", not(windows)))]
146-
#[repr(C)]
147-
#[unstable(feature = "c_variadic",
148-
reason = "the `c_variadic` feature has not been properly tested on \
149-
all supported platforms",
150-
issue = "44930")]
151-
#[lang = "va_list"]
152-
pub struct VaListImpl<'f> {
153-
inner: [crate::mem::MaybeUninit<i32>; 4],
154-
_marker: PhantomData<&'f mut &'f c_void>,
155-
}
156-
157-
#[cfg(all(target_arch = "asmjs", not(windows)))]
158-
#[unstable(feature = "c_variadic",
159-
reason = "the `c_variadic` feature has not been properly tested on \
160-
all supported platforms",
161-
issue = "44930")]
162-
impl<'f> fmt::Debug for VaListImpl<'f> {
163-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164-
unsafe {
165-
write!(f, "va_list* [{:#x}, {:#x}, {:#x}, {:#x}]",
166-
self.inner[0].read(), self.inner[1].read(),
167-
self.inner[2].read(), self.inner[3].read())
168-
}
169-
}
170-
}
171-
172144
/// A wrapper for a `va_list`
173145
#[repr(transparent)]
174146
#[derive(Debug)]
@@ -178,23 +150,29 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
178150
issue = "44930")]
179151
pub struct VaList<'a, 'f: 'a> {
180152
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
181-
not(target_arch = "x86_64"), not(target_arch = "asmjs")),
153+
not(target_arch = "x86_64")),
182154
all(target_arch = "aarch64", target_os = "ios"),
155+
target_arch = "wasm32",
156+
target_arch = "asmjs",
183157
windows))]
184158
inner: VaListImpl<'f>,
185159

186160
#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc",
187-
target_arch = "x86_64", target_arch = "asmjs"),
161+
target_arch = "x86_64"),
188162
any(not(target_arch = "aarch64"), not(target_os = "ios")),
163+
not(target_arch = "wasm32"),
164+
not(target_arch = "asmjs"),
189165
not(windows)))]
190166
inner: &'a mut VaListImpl<'f>,
191167

192168
_marker: PhantomData<&'a mut VaListImpl<'f>>,
193169
}
194170

195171
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
196-
not(target_arch = "x86_64"), not(target_arch = "asmjs")),
172+
not(target_arch = "x86_64")),
197173
all(target_arch = "aarch64", target_os = "ios"),
174+
target_arch = "wasm32",
175+
target_arch = "asmjs",
198176
windows))]
199177
#[unstable(feature = "c_variadic",
200178
reason = "the `c_variadic` feature has not been properly tested on \
@@ -212,8 +190,10 @@ impl<'f> VaListImpl<'f> {
212190
}
213191

214192
#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc",
215-
target_arch = "x86_64", target_arch = "asmjs"),
193+
target_arch = "x86_64"),
216194
any(not(target_arch = "aarch64"), not(target_os = "ios")),
195+
not(target_arch = "wasm32"),
196+
not(target_arch = "asmjs"),
217197
not(windows)))]
218198
#[unstable(feature = "c_variadic",
219199
reason = "the `c_variadic` feature has not been properly tested on \

src/libcore/hint.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,8 @@ pub fn black_box<T>(dummy: T) -> T {
114114
// this. LLVM's intepretation of inline assembly is that it's, well, a black
115115
// box. This isn't the greatest implementation since it probably deoptimizes
116116
// more than we want, but it's so far good enough.
117-
#[cfg(not(any(
118-
target_arch = "asmjs",
119-
all(
120-
target_arch = "wasm32",
121-
target_os = "emscripten"
122-
)
123-
)))]
124117
unsafe {
125118
asm!("" : : "r"(&dummy));
126119
return dummy;
127120
}
128-
129-
// Not all platforms support inline assembly so try to do something without
130-
// inline assembly which in theory still hinders at least some optimizations
131-
// on those targets. This is the "best effort" scenario.
132-
unsafe {
133-
let ret = crate::ptr::read_volatile(&dummy);
134-
crate::mem::forget(dummy);
135-
ret
136-
}
137121
}

src/librustc_codegen_llvm/llvm_util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ pub fn target_feature_whitelist(sess: &Session)
257257
"hexagon" => HEXAGON_WHITELIST,
258258
"mips" | "mips64" => MIPS_WHITELIST,
259259
"powerpc" | "powerpc64" => POWERPC_WHITELIST,
260-
// wasm32 on emscripten does not support these target features
261-
"wasm32" if !sess.target.target.options.is_like_emscripten => WASM_WHITELIST,
260+
"wasm32" => WASM_WHITELIST,
262261
_ => &[],
263262
}
264263
}

src/librustc_codegen_ssa/back/write.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,12 @@ impl ModuleConfig {
143143
// Copy what clang does by turning on loop vectorization at O2 and
144144
// slp vectorization at O3. Otherwise configure other optimization aspects
145145
// of this pass manager builder.
146-
// Turn off vectorization for emscripten, as it's not very well supported.
147146
self.vectorize_loop = !sess.opts.cg.no_vectorize_loops &&
148147
(sess.opts.optimize == config::OptLevel::Default ||
149-
sess.opts.optimize == config::OptLevel::Aggressive) &&
150-
!sess.target.target.options.is_like_emscripten;
148+
sess.opts.optimize == config::OptLevel::Aggressive);
151149

152150
self.vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
153-
sess.opts.optimize == config::OptLevel::Aggressive &&
154-
!sess.target.target.options.is_like_emscripten;
151+
sess.opts.optimize == config::OptLevel::Aggressive;
155152

156153
// Some targets (namely, NVPTX) interact badly with the MergeFunctions
157154
// pass. This is because MergeFunctions can generate new function calls

0 commit comments

Comments
 (0)