From 39d23c455b617ac4350a843aab26bfe0a2c0534b Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Wed, 20 Apr 2022 11:22:01 +0200 Subject: [PATCH 01/10] Add pthread_[s,g]etschedparam to emscripten. --- src/unix/linux_like/emscripten/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 5494aad378cf2..db00f564ea729 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1879,6 +1879,16 @@ extern "C" { f: extern "C" fn(*mut ::c_void) -> *mut ::c_void, value: *mut ::c_void, ) -> ::c_int; + pub fn pthread_setschedparam( + native: ::pthread_t, + policy: ::c_int, + param: *const ::sched_param, + ) -> ::c_int; + pub fn pthread_getschedparam( + native: ::pthread_t, + policy: *mut ::c_int, + param: *mut ::sched_param, + ) -> ::c_int; } cfg_if! { From a51c2d876f4b5120e65e428a4ff695c8c8df1faf Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Fri, 22 Apr 2022 14:55:37 +0200 Subject: [PATCH 02/10] Enable pthread support in libc-test for emscripten --- libc-test/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8790a6db00171..813cd65a17a9e 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2454,6 +2454,7 @@ fn test_emscripten(target: &str) { let mut cfg = ctest_cfg(); cfg.define("_GNU_SOURCE", None); // FIXME: ?? + cfg.flag("-pthread"); // Enable POSIX threads support. headers! { cfg: "aio.h", From 06ac3016fa45a72ed2c1cf53c3e6bbe6a4520d28 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Fri, 22 Apr 2022 16:25:45 +0200 Subject: [PATCH 03/10] Enable shared memory for emscripten test. --- libc-test/build.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 813cd65a17a9e..8153b6912bc6a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2454,7 +2454,10 @@ fn test_emscripten(target: &str) { let mut cfg = ctest_cfg(); cfg.define("_GNU_SOURCE", None); // FIXME: ?? - cfg.flag("-pthread"); // Enable POSIX threads support. + cfg.flag("-pthread"); + cfg.flag("-mbulk-memory"); + cfg.flag("-matomics"); + cfg.flag("-Wl,--shared-memory"); headers! { cfg: "aio.h", From 85f5ceff07e956c6d62c26d6bf956e62dc08d428 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Tue, 26 Apr 2022 16:40:07 +0200 Subject: [PATCH 04/10] Bump the emscripten and node versions. --- ci/emscripten-entry.sh | 2 +- ci/emscripten.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/emscripten-entry.sh b/ci/emscripten-entry.sh index 80b091903b1fc..de6f2cb16adbc 100755 --- a/ci/emscripten-entry.sh +++ b/ci/emscripten-entry.sh @@ -7,6 +7,6 @@ source /emsdk-portable/emsdk_env.sh &> /dev/null # emsdk-portable provides a node binary, but we need version 8 to run wasm # NOTE: Do not forget to sync Node.js version with `emscripten.sh`! -export PATH="/node-v14.17.0-linux-x64/bin:$PATH" +export PATH="/node-v18.0.0-linux-x64/bin:$PATH" exec "$@" diff --git a/ci/emscripten.sh b/ci/emscripten.sh index c16e793bb4e1f..730ce6ed0bcd1 100644 --- a/ci/emscripten.sh +++ b/ci/emscripten.sh @@ -2,7 +2,7 @@ set -ex -EMSDK_VERSION=1.39.20 +EMSDK_VERSION=3.1.9 hide_output() { set +x @@ -39,5 +39,5 @@ chmod a+rxw -R /emsdk-portable # node 8 is required to run wasm # NOTE: Do not forget to sync Node.js version with `emscripten-entry.sh`! cd / -curl --retry 5 -L https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz | \ +curl --retry 5 -L https://nodejs.org/dist/v18.0.0/node-v18.0.0-linux-x64.tar.xz | \ tar -xJ From 5f1b18f23d89cda8e50ac2bd8758350311319952 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Thu, 28 Apr 2022 17:43:11 +0200 Subject: [PATCH 05/10] Remove the extra flags for emscripten. --- libc-test/build.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8153b6912bc6a..8790a6db00171 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2454,10 +2454,6 @@ fn test_emscripten(target: &str) { let mut cfg = ctest_cfg(); cfg.define("_GNU_SOURCE", None); // FIXME: ?? - cfg.flag("-pthread"); - cfg.flag("-mbulk-memory"); - cfg.flag("-matomics"); - cfg.flag("-Wl,--shared-memory"); headers! { cfg: "aio.h", From 8390ea46fd5f95a6c05c0cd17059ead406f54f58 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Fri, 29 Apr 2022 16:35:06 +0200 Subject: [PATCH 06/10] Remove the sys/sendfile.h inclusion for emscripten. --- libc-test/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 8790a6db00171..73c801f3c23d8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2511,7 +2511,6 @@ fn test_emscripten(target: &str) { "sys/reboot.h", "sys/resource.h", "sys/sem.h", - "sys/sendfile.h", "sys/shm.h", "sys/signalfd.h", "sys/socket.h", From 176a76f08dee251feda16c725745f79420f48c34 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Sat, 7 May 2022 20:28:23 +0200 Subject: [PATCH 07/10] Remove non-existing sched_param fields for emscripten. Emscripten has these removed in the newer version this PR upgrades to, hence the crate should not have those as well. --- src/unix/linux_like/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 125c5d4e43a65..478e46e8f7c81 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -108,13 +108,13 @@ s! { pub struct sched_param { pub sched_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_env = "musl")] pub sched_ss_low_priority: ::c_int, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_env = "musl")] pub sched_ss_repl_period: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_env = "musl")] pub sched_ss_init_budget: ::timespec, - #[cfg(any(target_env = "musl", target_os = "emscripten"))] + #[cfg(target_env = "musl")] pub sched_ss_max_repl: ::c_int, } From 0c2de530f1d79ee3183c6f33e5fd27324bc36d23 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Tue, 17 May 2022 18:39:07 +0200 Subject: [PATCH 08/10] Try overriding the -g4 flag to -g3 in emscripten. --- ci/run.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/run.sh b/ci/run.sh index 3ef84d42ac0dc..c9bd57f1e72c5 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -109,6 +109,10 @@ if [ "$TARGET" = "s390x-unknown-linux-gnu" ]; then sleep 1 done else + if [ "$TARGET" = "asmjs-unknown-emscripten" ]; then + # Rust uses -g4 by default what causes link issues. + export EMCC_CFLAGS="-g3" + fi cargo test --no-default-features --manifest-path libc-test/Cargo.toml \ --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} From 5e27da1c17ce189e9f8af2f7aee6e5277fa73e6b Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Tue, 7 Jun 2022 15:45:37 +0200 Subject: [PATCH 09/10] Set RUSTFLAGS to disable generating code map for WASM. This allows the CI to proceed. --- ci/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/run.sh b/ci/run.sh index c9bd57f1e72c5..30427d27acc96 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -111,7 +111,8 @@ if [ "$TARGET" = "s390x-unknown-linux-gnu" ]; then else if [ "$TARGET" = "asmjs-unknown-emscripten" ]; then # Rust uses -g4 by default what causes link issues. - export EMCC_CFLAGS="-g3" + # This should disable the -g4 option. + export RUSTFLAGS="-Cdebuginfo=0" fi cargo test --no-default-features --manifest-path libc-test/Cargo.toml \ --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} From 78a91f337934b274d4d04e1890d83ce72e7d7f5d Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Thu, 9 Jun 2022 09:55:38 +0200 Subject: [PATCH 10/10] Try enabling USE_PTHREADS in ci/run.sh for emscripten. This should enable pthread functionality for emcc. --- ci/run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/run.sh b/ci/run.sh index 30427d27acc96..303a4afacea0a 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -113,6 +113,8 @@ else # Rust uses -g4 by default what causes link issues. # This should disable the -g4 option. export RUSTFLAGS="-Cdebuginfo=0" + export EMCC_FLAGS="-s USE_PTHREADS=1 --shared-memory" + export EMCC_CFLAGS="-s USE_PTHREADS=1 --shared-memory" fi cargo test --no-default-features --manifest-path libc-test/Cargo.toml \ --target "${TARGET}" ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}