Skip to content

Enable more tests for Emscripten targets #68082

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

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 0 additions & 4 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,6 @@ impl Step for TestHelpers {
builder.info("Building test helpers");
t!(fs::create_dir_all(&dst));
let mut cfg = cc::Build::new();
// FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
if target.contains("emscripten") {
cfg.pic(false);
}

// We may have found various cross-compilers a little differently due to our
// extra configuration, so inform gcc of these compilers. Note, though, that
Expand Down
2 changes: 2 additions & 0 deletions src/ci/azure-pipelines/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- template: steps/run.yml
strategy:
matrix:
wasm32: {}
asmjs: {}
x86_64-gnu-llvm-7: {}
mingw-check: {}
x86_64-gnu-tools:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ ENV EMCC_CFLAGS=-O1
# Emscripten installation is user-specific
ENV NO_CHANGE_USER=1

ENV SCRIPT python2.7 ../x.py test --target $TARGETS
# libcore takes about 15 minutes to build, so skip it
ENV SCRIPT python2.7 ../x.py test --target $TARGETS --exclude src/libcore

# This is almost identical to the wasm32-unknown-emscripten target, so
# running with assertions again is not useful
Expand Down
4 changes: 2 additions & 2 deletions src/ci/docker/scripts/emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ exit 1

git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
cd /emsdk-portable
hide_output ./emsdk install 1.38.46-upstream
./emsdk activate 1.38.46-upstream
hide_output ./emsdk install 1.39.5
./emsdk activate 1.39.5
11 changes: 2 additions & 9 deletions src/ci/docker/wasm32/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,5 @@ ENV EMCC_CFLAGS=-O1
# Emscripten installation is user-specific
ENV NO_CHANGE_USER=1

# FIXME: Re-enable these tests once https://github.com/rust-lang/cargo/pull/7476
# is picked up by CI
ENV SCRIPT python2.7 ../x.py test --target $TARGETS \
--exclude src/libcore \
--exclude src/liballoc \
--exclude src/libproc_macro \
--exclude src/libstd \
--exclude src/libterm \
--exclude src/libtest
# libcore takes about 15 minutes to build, so skip it
ENV SCRIPT python2.7 ../x.py test --target $TARGETS --exclude src/libcore
2 changes: 1 addition & 1 deletion src/liballoc/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn test_insert_prev() {
}

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg_attr(target_os = "emscripten", ignore)] // Emscripten does not support threads
#[cfg_attr(miri, ignore)] // Miri does not support threads
fn test_send() {
let n = list_from(&[1, 2, 3]);
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/tests/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ fn assert_covariance() {
// even if the order may not be correct.
//
// Destructors must be called exactly once per element.
// FIXME: re-enable emscripten once it can unwind again
#[test]
#[cfg(not(target_os = "emscripten"))]
fn panic_safe() {
use rand::{seq::SliceRandom, thread_rng};
use std::cmp;
Expand Down
3 changes: 0 additions & 3 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ fn hash<T: Hash>(t: &T) -> u64 {
s.finish()
}

// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
// See https://github.com/kripken/emscripten-fastcomp/issues/169
#[cfg(not(target_os = "emscripten"))]
#[test]
fn test_boxed_hasher() {
let ordinary_hash = hash(&5u32);
Expand Down
2 changes: 0 additions & 2 deletions src/liballoc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,6 @@ fn test_box_slice_clone() {

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

#[test]
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
fn panic_safe() {
let prev = panic::take_hook();
panic::set_hook(Box::new(move |info| {
Expand Down
4 changes: 0 additions & 4 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,7 @@ fn drain_filter_complex() {
}
}

// FIXME: re-enable emscripten once it can unwind again
#[test]
#[cfg(not(target_os = "emscripten"))]
fn drain_filter_consumed_panic() {
use std::rc::Rc;
use std::sync::Mutex;
Expand Down Expand Up @@ -989,9 +987,7 @@ fn drain_filter_consumed_panic() {
}
}

// FIXME: Re-enable emscripten once it can catch panics
#[test]
#[cfg(not(target_os = "emscripten"))]
fn drain_filter_unconsumed_panic() {
use std::rc::Rc;
use std::sync::Mutex;
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ macro_rules! impl_Display {

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

#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))]
#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32", target_arch = "asmjs")))]
mod imp {
use super::*;
impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32);
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
// Haswell E processors. LLVM is more able to optimize if we give a struct a
// #[repr(simd)], even if we don't actually use this struct directly.
//
// FIXME repr(simd) broken on emscripten and redox
#[cfg_attr(not(any(target_os = "emscripten", target_os = "redox")), repr(simd))]
// FIXME repr(simd) broken on redox
#[cfg_attr(not(target_os = "redox"), repr(simd))]
struct Block(u64, u64, u64, u64);
struct UnalignedBlock(u64, u64, u64, u64);

Expand Down
8 changes: 0 additions & 8 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2517,15 +2517,7 @@ unsafe fn atomic_umin<T>(dst: *mut T, val: T, order: Ordering) -> T {
/// [`Relaxed`]: enum.Ordering.html#variant.Relaxed
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
pub fn fence(order: Ordering) {
// On wasm32 it looks like fences aren't implemented in LLVM yet in that
// they will cause LLVM to abort. The wasm instruction set doesn't have
// fences right now. There's discussion online about the best way for tools
// to conventionally implement fences at
// https://github.com/WebAssembly/tool-conventions/issues/59. We should
// follow that discussion and implement a solution when one comes about!
#[cfg(not(target_arch = "wasm32"))]
unsafe {
match order {
Acquire => intrinsics::atomic_fence_acq(),
Expand Down
3 changes: 0 additions & 3 deletions src/libcore/tests/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ fn test_custom_state() {
assert_eq!(hash(&Custom { hash: 5 }), 5);
}

// FIXME: Instantiated functions with i128 in the signature is not supported in Emscripten.
// See https://github.com/kripken/emscripten-fastcomp/issues/169
#[cfg(not(target_os = "emscripten"))]
#[test]
fn test_indirect_hasher() {
let mut hasher = MyHasher { hash: 0 };
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/tests/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ macro_rules! test_literal {
}};
}

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

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn special_code_paths() {
test_literal!(36893488147419103229.0); // 2^65 - 3, triggers half-to-even with even significand
Expand Down
3 changes: 0 additions & 3 deletions src/libcore/tests/num/dec2flt/rawfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn rounding_overflow() {
assert_eq!(rounded.k, adjusted_k + 1);
}

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

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn next_prev_identity() {
for &x in &SOME_FLOATS {
Expand All @@ -130,7 +128,6 @@ fn next_prev_identity() {
}
}

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn next_float_monotonic() {
let mut x = 0.49999999999999;
Expand Down
8 changes: 0 additions & 8 deletions src/libcore/tests/num/flt2dec/random.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(target_arch = "wasm32"))]

use std::i16;
use std::str;

Expand Down Expand Up @@ -89,9 +87,6 @@ where
F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
G: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
{
if cfg!(target_os = "emscripten") {
return; // using rng pulls in i128 support, which doesn't work
}
let mut rng = StdRng::from_entropy();
let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
Expand All @@ -105,9 +100,6 @@ where
F: FnMut(&Decoded, &mut [u8]) -> Option<(usize, i16)>,
G: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
{
if cfg!(target_os = "emscripten") {
return; // using rng pulls in i128 support, which doesn't work
}
let mut rng = StdRng::from_entropy();
let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
iterate("f64_random_equivalence_test", k, n, f, g, |_| {
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn test_mul_pow10() {
}
}

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn shortest_sanity_test() {
f64_shortest_sanity_test(format_shortest);
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fn test_max_pow10_no_more_than() {
}
}

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn shortest_sanity_test() {
f64_shortest_sanity_test(format_shortest);
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,6 @@ fn brute_force_rotate_test_1() {
}

#[test]
#[cfg(not(target_arch = "wasm32"))]
fn sort_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};
use core::slice::heapsort;
Expand Down Expand Up @@ -1301,7 +1300,6 @@ fn sort_unstable() {
}

#[test]
#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn partition_at_index() {
use core::cmp::Ordering::{Equal, Greater, Less};
Expand Down
16 changes: 13 additions & 3 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ impl<'a> GccLinker<'a> {
// platforms where currently this is guaranteed to *not* be the case:
//
// * On OSX they have their own linker, not binutils'
// * For WebAssembly the only functional linker is LLD, which doesn't
// * For WebAssembly/JS the only functional linker is LLD, which doesn't
// support hint flags
!self.sess.target.target.options.is_like_osx && self.sess.target.target.arch != "wasm32"
!self.sess.target.target.options.is_like_osx
&& self.sess.target.target.arch != "wasm32"
&& self.sess.target.target.arch != "asmjs"
}

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

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ pub struct ModuleConfig {
pub merge_functions: bool,
pub inline_threshold: Option<usize>,
// Instead of creating an object file by doing LLVM codegen, just
// make the object file bitcode. Provides easy compatibility with
// emscripten's ecc compiler, when used as the linker.
// make the object file bitcode.
pub obj_is_bitcode: bool,
pub no_integrated_as: bool,
pub embed_bitcode: bool,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/asmjs_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub fn target() -> Result<Target, String> {
.entry(LinkerFlavor::Em)
.or_default()
.extend(vec!["-s".to_string(), "WASM=0".to_string()]);
target.arch = "asmjs".to_string();
Ok(target)
}
3 changes: 0 additions & 3 deletions src/libstd/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,6 @@ mod tests {
assert_eq!(Fp::Zero, neg_zero.classify());
}

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

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

#[cfg_attr(all(target_arch = "wasm32", target_os = "emscripten"), ignore)] // issue 42630
#[test]
fn test_classify() {
let nan: f64 = NAN;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ mod tests {
use crate::ops::Deref;

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), ignore)]
fn read_until() {
let mut buf = Cursor::new(&b"12"[..]);
let mut v = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl TcpListener {
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
// On WASM, `TcpStream` is uninhabited (as it's unsupported) and so
// the `a` variable here is technically unused.
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
#[cfg_attr(any(target_arch = "wasm32", target_arch = "asmjs"), allow(unused_variables))]
self.0.accept().map(|(a, b)| (TcpStream(a), b))
}

Expand Down
6 changes: 4 additions & 2 deletions src/libstd/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ cfg_if::cfg_if! {
pub use self::ext as unix_ext;
} else if #[cfg(any(target_os = "cloudabi",
target_os = "hermit",
target_arch = "wasm32",
all(not(target_os = "emscripten"),
target_arch = "wasm32"),
all(target_vendor = "fortanix", target_env = "sgx")))] {
// On CloudABI and wasm right now the module below doesn't compile
// (missing things in `libc` which is empty) so just omit everything
Expand All @@ -88,7 +89,8 @@ cfg_if::cfg_if! {
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::ext as windows_ext;
} else if #[cfg(any(target_os = "cloudabi",
target_arch = "wasm32",
all(not(target_os = "emscripten"),
target_arch = "wasm32"),
all(target_vendor = "fortanix", target_env = "sgx")))] {
// On CloudABI and wasm right now the shim below doesn't compile, so
// just omit it
Expand Down
Loading