Skip to content
Open
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
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 @@ -84,7 +84,7 @@ stdenv.mkDerivation rec {
# libcxx appears to require unwind and doesn't pull it in via other means.
"-DLIBCXX_ADDITIONAL_LIBRARIES=unwind"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_THREADS=${if stdenv.cc.libc.hasThreads then "ON" else "OFF"}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lib.cmakeBool

"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
"-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker
Expand Down
23 changes: 16 additions & 7 deletions pkgs/development/compilers/llvm/16/libcxxabi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ stdenv.mkDerivation rec {
# pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
"-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
"-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DCMAKE_C_COMPILER_WORKS=ON"
"-DCMAKE_CXX_COMPILER_WORKS=ON"
"-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
"-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker
] ++ lib.optionals (!enableShared) [
] ++ lib.optionals stdenv.hostPlatform.isWasm (
[
"-DCMAKE_C_COMPILER_WORKS=ON"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
"-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker
]
++ (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
50 changes: 46 additions & 4 deletions pkgs/development/libraries/wasilibc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
, buildPackages
, fetchFromGitHub
, lib
# Enable experimental wasilibc pthread support
, enableThreads ? false
# For tests
, firefox-unwrapped
, firefox-esr-unwrapped
, pkgsCross
, wasmtime
}:

let
Expand Down Expand Up @@ -38,8 +43,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 +57,46 @@ 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;
simple-c-cxx-binaries = pkgsCross.wasi32.runCommandCC "simple-c-cxx-binaries" {
nativeBuildInputs = [
wasmtime
];
} ''
cat > test.c <<EOF
#include <stdio.h>
int main(void) {
puts("Hello from C");
return 0;
}
EOF
cat > test.cpp <<EOF
#include <iostream>
int main(void) {
std::cout<<"Hello from C++\n";
return 0;
}
EOF

mkdir -p "$out/bin"
# TODO(@sternenseemann): compile with -pthread if enableThreads
$CC -o "$out/bin/test-c" test.c
$CXX -o "$out/bin/test-cxx" test.cpp -lc++ -lc++abi

export HOME=$TMPDIR
export WASMTIME_FLAGS=(${
lib.escapeShellArgs (lib.optionals enableThreads [
"--wasm-features=threads"
"--wasi-modules=experimental-wasi-threads"
])
})
wasmtime run "''${WASMTIME_FLAGS[@]}" "$out/bin/test-c"
wasmtime run "''${WASMTIME_FLAGS[@]}" "$out/bin/test-cxx"
'';
};
hasThreads = enableThreads;
};

meta = with lib; {
Expand Down