Skip to content

Commit 7dc410d

Browse files
committed
Enable more tests for Emscripten targets
Specifically, enable SIMD intrinsic tests, target-independent asm! tests, and tests that were ignored due to old fastcomp bugs that have long since become irrelevant. Also re-enables asmjs tests that pass -g by reducing the corresponding Emscripten debug level so that it does not error out with a message about source maps being unsupported. This required fixing the asmjs target's `arch` string to be `"asmjs"` rather than `"wasm32"`, and that in turn required auditing many cfg attributes and fixing them to include both asmjs and wasm32. For many tests that could not be re-enabled, also adds an explanatory comment to make future auditing easier. In particular, tests requiring threads are left to be re-enabled in future work.
1 parent 1389494 commit 7dc410d

File tree

118 files changed

+80
-225
lines changed

Some content is hidden

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

118 files changed

+80
-225
lines changed

src/bootstrap/native.rs

-4
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,6 @@ impl Step for TestHelpers {
520520
builder.info("Building test helpers");
521521
t!(fs::create_dir_all(&dst));
522522
let mut cfg = cc::Build::new();
523-
// FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
524-
if target.contains("emscripten") {
525-
cfg.pic(false);
526-
}
527523

528524
// We may have found various cross-compilers a little differently due to our
529525
// extra configuration, so inform gcc of these compilers. Note, though, that

src/ci/docker/scripts/emscripten.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ exit 1
1919

2020
git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
2121
cd /emsdk-portable
22-
hide_output ./emsdk install 1.38.46-upstream
23-
./emsdk activate 1.38.46-upstream
22+
hide_output ./emsdk install 1.39.5
23+
./emsdk activate 1.39.5

src/ci/docker/wasm32/Dockerfile

+1-9
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,4 @@ ENV EMCC_CFLAGS=-O1
3333
# Emscripten installation is user-specific
3434
ENV NO_CHANGE_USER=1
3535

36-
# FIXME: Re-enable these tests once https://github.com/rust-lang/cargo/pull/7476
37-
# is picked up by CI
38-
ENV SCRIPT python2.7 ../x.py test --target $TARGETS \
39-
--exclude src/libcore \
40-
--exclude src/liballoc \
41-
--exclude src/libproc_macro \
42-
--exclude src/libstd \
43-
--exclude src/libterm \
44-
--exclude src/libtest
36+
ENV SCRIPT python2.7 ../x.py test --target $TARGETS

src/liballoc/collections/linked_list/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn test_insert_prev() {
181181
}
182182

183183
#[test]
184-
#[cfg_attr(target_os = "emscripten", ignore)]
184+
#[cfg_attr(target_os = "emscripten", ignore)] // Emscripten does not support threads
185185
#[cfg_attr(miri, ignore)] // Miri does not support threads
186186
fn test_send() {
187187
let n = list_from(&[1, 2, 3]);

src/liballoc/tests/binary_heap.rs

-2
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ fn assert_covariance() {
345345
// even if the order may not be correct.
346346
//
347347
// Destructors must be called exactly once per element.
348-
// FIXME: re-enable emscripten once it can unwind again
349348
#[test]
350-
#[cfg(not(target_os = "emscripten"))]
351349
fn panic_safe() {
352350
use rand::{seq::SliceRandom, thread_rng};
353351
use std::cmp;

src/liballoc/tests/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ fn hash<T: Hash>(t: &T) -> u64 {
3636
s.finish()
3737
}
3838

39-
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
40-
// See https://github.com/kripken/emscripten-fastcomp/issues/169
41-
#[cfg(not(target_os = "emscripten"))]
4239
#[test]
4340
fn test_boxed_hasher() {
4441
let ordinary_hash = hash(&5u32);

src/liballoc/tests/slice.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,6 @@ fn test_box_slice_clone() {
13951395

13961396
#[test]
13971397
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
1398-
#[cfg_attr(target_os = "emscripten", ignore)]
13991398
fn test_box_slice_clone_panics() {
14001399
use std::sync::atomic::{AtomicUsize, Ordering};
14011400
use std::sync::Arc;
@@ -1636,7 +1635,6 @@ macro_rules! test {
16361635
thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
16371636

16381637
#[test]
1639-
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
16401638
fn panic_safe() {
16411639
let prev = panic::take_hook();
16421640
panic::set_hook(Box::new(move |info| {

src/liballoc/tests/vec.rs

-4
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,7 @@ fn drain_filter_complex() {
937937
}
938938
}
939939

940-
// FIXME: re-enable emscripten once it can unwind again
941940
#[test]
942-
#[cfg(not(target_os = "emscripten"))]
943941
fn drain_filter_consumed_panic() {
944942
use std::rc::Rc;
945943
use std::sync::Mutex;
@@ -989,9 +987,7 @@ fn drain_filter_consumed_panic() {
989987
}
990988
}
991989

992-
// FIXME: Re-enable emscripten once it can catch panics
993990
#[test]
994-
#[cfg(not(target_os = "emscripten"))]
995991
fn drain_filter_unconsumed_panic() {
996992
use std::rc::Rc;
997993
use std::sync::Mutex;

src/libcore/fmt/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ macro_rules! impl_Display {
258258

259259
// Include wasm32 in here since it doesn't reflect the native pointer size, and
260260
// often cares strongly about getting a smaller code size.
261-
#[cfg(any(target_pointer_width = "64", target_arch = "wasm32"))]
261+
#[cfg(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "asmjs"))]
262262
mod imp {
263263
use super::*;
264264
impl_Display!(
@@ -267,7 +267,7 @@ mod imp {
267267
);
268268
}
269269

270-
#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))]
270+
#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "asmjs")))]
271271
mod imp {
272272
use super::*;
273273
impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32);

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
426426
// Haswell E processors. LLVM is more able to optimize if we give a struct a
427427
// #[repr(simd)], even if we don't actually use this struct directly.
428428
//
429-
// FIXME repr(simd) broken on emscripten and redox
430-
#[cfg_attr(not(any(target_os = "emscripten", target_os = "redox")), repr(simd))]
429+
// FIXME repr(simd) broken on redox
430+
#[cfg_attr(not(target_os = "redox"), repr(simd))]
431431
struct Block(u64, u64, u64, u64);
432432
struct UnalignedBlock(u64, u64, u64, u64);
433433

src/libcore/sync/atomic.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2517,15 +2517,7 @@ unsafe fn atomic_umin<T>(dst: *mut T, val: T, order: Ordering) -> T {
25172517
/// [`Relaxed`]: enum.Ordering.html#variant.Relaxed
25182518
#[inline]
25192519
#[stable(feature = "rust1", since = "1.0.0")]
2520-
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
25212520
pub fn fence(order: Ordering) {
2522-
// On wasm32 it looks like fences aren't implemented in LLVM yet in that
2523-
// they will cause LLVM to abort. The wasm instruction set doesn't have
2524-
// fences right now. There's discussion online about the best way for tools
2525-
// to conventionally implement fences at
2526-
// https://github.com/WebAssembly/tool-conventions/issues/59. We should
2527-
// follow that discussion and implement a solution when one comes about!
2528-
#[cfg(not(target_arch = "wasm32"))]
25292521
unsafe {
25302522
match order {
25312523
Acquire => intrinsics::atomic_fence_acq(),

src/libcore/tests/hash/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ fn test_custom_state() {
127127
assert_eq!(hash(&Custom { hash: 5 }), 5);
128128
}
129129

130-
// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
131-
// See https://github.com/kripken/emscripten-fastcomp/issues/169
132-
#[cfg(not(target_os = "emscripten"))]
133130
#[test]
134131
fn test_indirect_hasher() {
135132
let mut hasher = MyHasher { hash: 0 };

src/libcore/tests/num/dec2flt/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ macro_rules! test_literal {
2323
}};
2424
}
2525

26-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
2726
#[test]
2827
fn ordinary() {
2928
test_literal!(1.0);
@@ -40,7 +39,6 @@ fn ordinary() {
4039
test_literal!(2.2250738585072014e-308);
4140
}
4241

43-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
4442
#[test]
4543
fn special_code_paths() {
4644
test_literal!(36893488147419103229.0); // 2^65 - 3, triggers half-to-even with even significand

src/libcore/tests/num/dec2flt/rawfp.rs

-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ fn rounding_overflow() {
8383
assert_eq!(rounded.k, adjusted_k + 1);
8484
}
8585

86-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
8786
#[test]
8887
fn prev_float_monotonic() {
8988
let mut x = 1.0;
@@ -119,7 +118,6 @@ fn next_float_inf() {
119118
assert_eq!(next_float(f64::INFINITY), f64::INFINITY);
120119
}
121120

122-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
123121
#[test]
124122
fn next_prev_identity() {
125123
for &x in &SOME_FLOATS {
@@ -130,7 +128,6 @@ fn next_prev_identity() {
130128
}
131129
}
132130

133-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
134131
#[test]
135132
fn next_float_monotonic() {
136133
let mut x = 0.49999999999999;

src/libcore/tests/num/flt2dec/random.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(target_arch = "wasm32"))]
2-
31
use std::i16;
42
use std::str;
53

@@ -89,9 +87,6 @@ where
8987
F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
9088
G: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
9189
{
92-
if cfg!(target_os = "emscripten") {
93-
return; // using rng pulls in i128 support, which doesn't work
94-
}
9590
let mut rng = StdRng::from_entropy();
9691
let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
9792
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
@@ -105,9 +100,6 @@ where
105100
F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
106101
G: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
107102
{
108-
if cfg!(target_os = "emscripten") {
109-
return; // using rng pulls in i128 support, which doesn't work
110-
}
111103
let mut rng = StdRng::from_entropy();
112104
let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
113105
iterate("f64_random_equivalence_test", k, n, f, g, |_| {

src/libcore/tests/num/flt2dec/strategy/dragon.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn test_mul_pow10() {
1313
}
1414
}
1515

16-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
1716
#[test]
1817
fn shortest_sanity_test() {
1918
f64_shortest_sanity_test(format_shortest);

src/libcore/tests/num/flt2dec/strategy/grisu.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fn test_max_pow10_no_more_than() {
3232
}
3333
}
3434

35-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
3635
#[test]
3736
fn shortest_sanity_test() {
3837
f64_shortest_sanity_test(format_shortest);

src/libcore/tests/slice.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,6 @@ fn brute_force_rotate_test_1() {
12211221
}
12221222

12231223
#[test]
1224-
#[cfg(not(target_arch = "wasm32"))]
12251224
fn sort_unstable() {
12261225
use core::cmp::Ordering::{Equal, Greater, Less};
12271226
use core::slice::heapsort;
@@ -1301,7 +1300,6 @@ fn sort_unstable() {
13011300
}
13021301

13031302
#[test]
1304-
#[cfg(not(target_arch = "wasm32"))]
13051303
#[cfg_attr(miri, ignore)] // Miri is too slow
13061304
fn partition_at_index() {
13071305
use core::cmp::Ordering::{Equal, Greater, Less};

src/librustc_codegen_ssa/back/linker.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ impl<'a> GccLinker<'a> {
154154
// platforms where currently this is guaranteed to *not* be the case:
155155
//
156156
// * On OSX they have their own linker, not binutils'
157-
// * For WebAssembly the only functional linker is LLD, which doesn't
157+
// * For WebAssembly/JS the only functional linker is LLD, which doesn't
158158
// support hint flags
159-
!self.sess.target.target.options.is_like_osx && self.sess.target.target.arch != "wasm32"
159+
!self.sess.target.target.options.is_like_osx && self.sess.target.target.arch != "wasm32" &&
160+
self.sess.target.target.arch != "asmjs"
160161
}
161162

162163
// Some platforms take hints about whether a library is static or dynamic.
@@ -866,7 +867,9 @@ impl<'a> Linker for EmLinker<'a> {
866867
self.cmd.arg(match self.sess.opts.debuginfo {
867868
DebugInfo::None => "-g0",
868869
DebugInfo::Limited => "-g3",
869-
DebugInfo::Full => "-g4",
870+
// FIXME: wasm2js errors with -g3 and above because it does not support source maps.
871+
// See https://github.com/WebAssembly/binaryen/issues/2410
872+
DebugInfo::Full => if self.sess.target.target.arch == "asmjs" { "-g3" } else { "-g4" },
870873
});
871874
}
872875

src/librustc_codegen_ssa/back/write.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ pub struct ModuleConfig {
8686
pub merge_functions: bool,
8787
pub inline_threshold: Option<usize>,
8888
// Instead of creating an object file by doing LLVM codegen, just
89-
// make the object file bitcode. Provides easy compatibility with
90-
// emscripten's ecc compiler, when used as the linker.
89+
// make the object file bitcode.
9190
pub obj_is_bitcode: bool,
9291
pub no_integrated_as: bool,
9392
pub embed_bitcode: bool,

src/librustc_target/spec/asmjs_unknown_emscripten.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ pub fn target() -> Result<Target, String> {
88
.entry(LinkerFlavor::Em)
99
.or_default()
1010
.extend(vec!["-s".to_string(), "WASM=0".to_string()]);
11+
target.arch = "asmjs".to_string();
1112
Ok(target)
1213
}

src/libstd/f64.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,6 @@ mod tests {
10541054
assert_eq!(Fp::Zero, neg_zero.classify());
10551055
}
10561056

1057-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
10581057
#[test]
10591058
fn test_one() {
10601059
let one: f64 = 1.0f64;
@@ -1107,7 +1106,6 @@ mod tests {
11071106
assert!((-109.2f64).is_finite());
11081107
}
11091108

1110-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
11111109
#[test]
11121110
fn test_is_normal() {
11131111
let nan: f64 = NAN;
@@ -1125,7 +1123,6 @@ mod tests {
11251123
assert!(!1e-308f64.is_normal());
11261124
}
11271125

1128-
#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
11291126
#[test]
11301127
fn test_classify() {
11311128
let nan: f64 = NAN;

src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ mod tests {
24162416
use crate::ops::Deref;
24172417

24182418
#[test]
2419-
#[cfg_attr(target_os = "emscripten", ignore)]
2419+
#[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), ignore)]
24202420
fn read_until() {
24212421
let mut buf = Cursor::new(&b"12"[..]);
24222422
let mut v = Vec::new();

src/libstd/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl TcpListener {
758758
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
759759
// On WASM, `TcpStream` is uninhabited (as it's unsupported) and so
760760
// the `a` variable here is technically unused.
761-
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
761+
#[cfg_attr(any(target_arch = "wasm32", target_arch = "asmjs"), allow(unused_variables))]
762762
self.0.accept().map(|(a, b)| (TcpStream(a), b))
763763
}
764764

src/libstd/sys/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cfg_if::cfg_if! {
4141
} else if #[cfg(target_os = "wasi")] {
4242
mod wasi;
4343
pub use self::wasi::*;
44-
} else if #[cfg(target_arch = "wasm32")] {
44+
} else if #[cfg(any(target_arch = "wasm32", target_arch = "asmjs"))] {
4545
mod wasm;
4646
pub use self::wasm::*;
4747
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
@@ -64,7 +64,8 @@ cfg_if::cfg_if! {
6464
pub use self::ext as unix_ext;
6565
} else if #[cfg(any(target_os = "cloudabi",
6666
target_os = "hermit",
67-
target_arch = "wasm32",
67+
all(not(target_os = "emscripten"),
68+
target_arch = "wasm32"),
6869
all(target_vendor = "fortanix", target_env = "sgx")))] {
6970
// On CloudABI and wasm right now the module below doesn't compile
7071
// (missing things in `libc` which is empty) so just omit everything
@@ -88,7 +89,8 @@ cfg_if::cfg_if! {
8889
#[stable(feature = "rust1", since = "1.0.0")]
8990
pub use self::ext as windows_ext;
9091
} else if #[cfg(any(target_os = "cloudabi",
91-
target_arch = "wasm32",
92+
all(not(target_os = "emscripten"),
93+
target_arch = "wasm32"),
9294
all(target_vendor = "fortanix", target_env = "sgx")))] {
9395
// On CloudABI and wasm right now the shim below doesn't compile, so
9496
// just omit it

src/libstd/sys/unix/env.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,7 @@ pub mod os {
108108
pub const EXE_EXTENSION: &str = "";
109109
}
110110

111-
#[cfg(all(target_os = "emscripten", target_arch = "asmjs"))]
112-
pub mod os {
113-
pub const FAMILY: &str = "unix";
114-
pub const OS: &str = "emscripten";
115-
pub const DLL_PREFIX: &str = "lib";
116-
pub const DLL_SUFFIX: &str = ".so";
117-
pub const DLL_EXTENSION: &str = "so";
118-
pub const EXE_SUFFIX: &str = ".js";
119-
pub const EXE_EXTENSION: &str = "js";
120-
}
121-
122-
#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))]
111+
#[cfg(target_os = "emscripten")]
123112
pub mod os {
124113
pub const FAMILY: &str = "unix";
125114
pub const OS: &str = "emscripten";

src/libstd/sys_common/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub mod mutex;
5757
target_os = "cloudabi",
5858
target_os = "hermit",
5959
target_arch = "wasm32",
60+
target_arch = "asmjs",
6061
all(target_vendor = "fortanix", target_env = "sgx")))]
6162
pub mod os_str_bytes;
6263
pub mod poison;

0 commit comments

Comments
 (0)