Skip to content

Commit 7870050

Browse files
committed
Auto 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 2e72448 + 4a4df29 commit 7870050

File tree

142 files changed

+377
-537
lines changed

Some content is hidden

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

142 files changed

+377
-537
lines changed

config.toml.example

+1
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/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ impl<'a> Builder<'a> {
970970
Some("-Wl,-rpath,@loader_path/../lib")
971971
} else if !target.contains("windows") &&
972972
!target.contains("wasm32") &&
973+
!target.contains("emscripten") &&
973974
!target.contains("fuchsia") {
974975
Some("-Wl,-rpath,$ORIGIN/../lib")
975976
} else {

src/bootstrap/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,11 @@ impl Step for Compiletest {
10471047
// Also provide `rust_test_helpers` for the host.
10481048
builder.ensure(native::TestHelpers { target: compiler.host });
10491049

1050-
// wasm32 can't build the test helpers
1051-
if !target.contains("wasm32") {
1050+
// As well as the target, except for plain wasm32, which can't build it
1051+
if !target.contains("wasm32") || target.contains("emscripten") {
10521052
builder.ensure(native::TestHelpers { target });
10531053
}
1054+
10541055
builder.ensure(RemoteCopyLibs { compiler, target });
10551056

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

src/ci/docker/asmjs/Dockerfile

+9-20
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,16 @@ 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+
ENV SCRIPT python2.7 ../x.py test --target $TARGETS
3332

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
33+
# This is almost identical to the wasm32-unknown-emscripten target, so
34+
# running with assertions again is not useful
4735
ENV NO_DEBUG_ASSERTIONS=1
36+
ENV NO_LLVM_ASSERTIONS=1

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

-35
This file was deleted.

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

-9
This file was deleted.

src/ci/docker/disabled/wasm32/Dockerfile

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ 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+
# FIXME: Re-enable these tests once Cargo stops trying to execute wasms
32+
ENV SCRIPT python2.7 ../x.py test --target $TARGETS \
33+
--exclude src/libcore \
34+
--exclude src/liballoc \
35+
--exclude src/libproc_macro \
36+
--exclude src/libstd \
37+
--exclude src/libterm \
38+
--exclude src/libtest

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

-37
This file was deleted.

src/ci/docker/scripts/emscripten.sh

+3-8
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/liballoc/tests/binary_heap.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use std::cmp;
21
use std::collections::BinaryHeap;
32
use std::collections::binary_heap::{Drain, PeekMut};
4-
use std::panic::{self, AssertUnwindSafe};
5-
use std::sync::atomic::{AtomicUsize, Ordering};
6-
7-
use rand::{thread_rng, seq::SliceRandom};
83

94
#[test]
105
fn test_iterator() {
@@ -281,9 +276,15 @@ fn assert_covariance() {
281276
// even if the order may not be correct.
282277
//
283278
// Destructors must be called exactly once per element.
279+
// FIXME: re-enable emscripten once it can unwind again
284280
#[test]
285-
#[cfg(not(miri))] // Miri does not support catching panics
281+
#[cfg(not(any(miri, target_os = "emscripten")))] // Miri does not support catching panics
286282
fn panic_safe() {
283+
use std::cmp;
284+
use std::panic::{self, AssertUnwindSafe};
285+
use std::sync::atomic::{AtomicUsize, Ordering};
286+
use rand::{thread_rng, seq::SliceRandom};
287+
287288
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
288289

289290
#[derive(Eq, PartialEq, Ord, Clone, Debug)]

src/liballoc/tests/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ mod slice_index {
483483
}
484484

485485
#[test]
486-
#[cfg(not(target_arch = "asmjs"))] // hits an OOM
486+
#[cfg(not(target_os = "emscripten"))] // hits an OOM
487487
#[cfg(not(miri))] // Miri is too slow
488488
fn simple_big() {
489489
fn a_million_letter_x() -> String {

src/liballoc/tests/str.rs.rej

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs (rejected hunks)
2+
@@ -483,7 +483,7 @@ mod slice_index {
3+
}
4+
5+
#[test]
6+
- #[cfg(not(target_arch = "asmjs"))] // hits an OOM
7+
+ #[cfg(not(target_arch = "js"))] // hits an OOM
8+
#[cfg(not(miri))] // Miri is too slow
9+
fn simple_big() {
10+
fn a_million_letter_x() -> String {

src/liballoc/tests/vec.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,10 @@ fn drain_filter_complex() {
944944
}
945945
}
946946

947+
// Miri does not support catching panics
948+
// FIXME: re-enable emscripten once it can unwind again
947949
#[test]
948-
#[cfg(not(miri))] // Miri does not support catching panics
950+
#[cfg(not(any(miri, target_os = "emscripten")))]
949951
fn drain_filter_consumed_panic() {
950952
use std::rc::Rc;
951953
use std::sync::Mutex;
@@ -995,8 +997,9 @@ fn drain_filter_consumed_panic() {
995997
}
996998
}
997999

1000+
// FIXME: Re-enable emscripten once it can catch panics
9981001
#[test]
999-
#[cfg(not(miri))] // Miri does not support catching panics
1002+
#[cfg(not(any(miri, target_os = "emscripten")))] // Miri does not support catching panics
10001003
fn drain_filter_unconsumed_panic() {
10011004
use std::rc::Rc;
10021005
use std::sync::Mutex;

src/libcore/ffi.rs

+18-38
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 \

0 commit comments

Comments
 (0)