Skip to content

Commit

Permalink
wasilibc: 19 -> 20
Browse files Browse the repository at this point in the history
pkgsCross.wasi32.llvmPackages: 12 -> 16

* It appears BULK_MEMORY_SOURCES no longer needs to be set to be empty
  to compile firefox. Without it, the build of wasilibc would fail if
  enableThreads is true.

* Include preliminary support for the experimental threads support in
  wasilibc which provides pthreads API. If wasilibc is built with
  support, is exposed via passthru and libcxx / libcxxabi are built with
  threads support accordingly.

  See also:
  - WebAssembly/wasi-sdk#274
  - WebAssembly/wasi-sdk#301
  - WebAssembly/wasi-sdk#314

  wasi-sdk ships it by default, but as a separate variant of libc which
  would be a hassle for us. Let's just make it optional for now.

  You can try it out using the following overlay:

      self: super: {
        wasilibc = super.wasilibc.override { enableThreads = true; };
      }

  Flags for libc++abi are copied from wasi-sdk.
  • Loading branch information
sternenseemann committed Jul 5, 2023
1 parent 6a03c05 commit bf5423c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/16/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ stdenv.mkDerivation rec {
++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1"
++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON"
++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_THREADS=${if stdenv.cc.libc.hasThreads then "ON" else "OFF"}"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"
Expand Down
24 changes: 20 additions & 4 deletions pkgs/development/compilers/llvm/16/libcxxabi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,26 @@ stdenv.mkDerivation rec {
] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
"-DLLVM_ENABLE_LIBCXX=ON"
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [
] ++ lib.optionals stdenv.hostPlatform.isWasm (
[
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
# CMake tests for -fno-exceptions together with -lc++ -lc++abi which fails
# here, without -fno-exceptions, libc++abi is unusable later.
# See also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260005
# TODO(@sternenseemann): make this unconditional?
"-DCXX_SUPPORTS_FNO_EXCEPTIONS_FLAG=ON"
]
++ (if stdenv.cc.libc.hasThreads then [
"-DLIBCXXABI_ENABLE_THREADS=ON"
"-DLIBCXXABI_HAS_PTHREAD_API=ON"
"-DLIBCXXABI_HAS_EXTERNAL_THREAD_API=OFF"
"-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY=OFF"
"-DLIBCXXABI_HAS_WIN32_THREAD_API=OFF"
] else [
"-DLIBCXXABI_ENABLE_THREADS=OFF"
])
)
++ lib.optionals (!enableShared) [
"-DLIBCXXABI_ENABLE_SHARED=OFF"
];

Expand Down
17 changes: 11 additions & 6 deletions pkgs/development/libraries/wasilibc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
, buildPackages
, fetchFromGitHub
, lib
# Enable experimental wasilibc pthread support
, enableThreads ? false
# For tests
, firefox-unwrapped
, firefox-esr-unwrapped
}:

let
pname = "wasilibc";
version = "19";
version = "20";
in
stdenv.mkDerivation {
inherit pname version;
Expand All @@ -17,7 +20,7 @@ stdenv.mkDerivation {
owner = "WebAssembly";
repo = "wasi-libc";
rev = "refs/tags/wasi-sdk-${version}";
hash = "sha256-yQSKoSil/C/1lIHwEO9eQKC/ye3PJIFGYjHyNDn61y4=";
sha256 = "0knm5ch499dksmv1k0kh7356pjd9n1gjn0p3vp9bw57mn478zp8z";
fetchSubmodules = true;
};

Expand All @@ -38,8 +41,7 @@ stdenv.mkDerivation {
"SYSROOT_LIB:=$SYSROOT_LIB"
"SYSROOT_INC:=$SYSROOT_INC"
"SYSROOT_SHARE:=$SYSROOT_SHARE"
# https://bugzilla.mozilla.org/show_bug.cgi?id=1773200
"BULK_MEMORY_SOURCES:="
"THREAD_MODEL=${if enableThreads then "posix" else "single"}"
)
'';
Expand All @@ -53,8 +55,11 @@ stdenv.mkDerivation {
ln -s $share/share/undefined-symbols.txt $out/lib/wasi.imports
'';

passthru.tests = {
inherit firefox-unwrapped firefox-esr-unwrapped;
passthru = {
tests = {
inherit firefox-unwrapped firefox-esr-unwrapped;
};
hasThreads = enableThreads;
};

meta = with lib; {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16125,7 +16125,7 @@ with pkgs;
else if platform.isFreeBSD then 12
else if platform.isAndroid then 12
else if platform.isLinux then 11
else if platform.isWasm then 12
else if platform.isWasm then 16
else 14;
# We take the "max of the mins". Why? Since those are lower bounds of the
# supported version set, this is like intersecting those sets and then
Expand Down

0 comments on commit bf5423c

Please sign in to comment.