Compile clang into WASM using WASI-SDK

63 Views Asked by At

I'm trying to compile "clang" and "lld" into web assembly with the WASI-SDK 21.0 as my system root directory. I got build errors while compiling but I cannot resolve them properly.

I'm using LLVM 17.0.6 which is currently the same version as for the release of WASI-SDK 21.0.

As you can see, I'm using the right -DCMAKE_SYSROOT and also -D_WASI_EMULATED_SIGNAL which should be sufficent for fake-signals to be resolved, right?

Here is how I compile "clang" and "lld" into web assembly:

cmake -G "Ninja" \
    -DCMAKE_SYSROOT="$cwd/wasi-sdk/share/wasi-sysroot" \
    -DCMAKE_AR="$cwd/wasi-sdk/bin/llvm-ar" \
    -DCMAKE_RANLIB="$cwd/wasi-sdk/bin/llvm-ranlib" \
    -DCMAKE_C_COMPILER="$cwd/wasi-sdk/bin/clang" \
    -DCMAKE_CXX_COMPILER="$cwd/wasi-sdk/bin/clang++" \
    -DCMAKE_BUILD_TYPE="MinSizeRel" \
    -DCMAKE_SKIP_INSTALL_RPATH="ON" \
    -DCMAKE_SKIP_RPATH="ON" \
    -DCMAKE_C_FLAGS="-D_WASI_EMULATED_SIGNAL" \
    -DCMAKE_CXX_FLAGS="-D_WASI_EMULATED_SIGNAL -fno-exceptions" \
    -DCLANG_ENABLE_ARCMT="OFF" \
    -DCLANG_ENABLE_STATIC_ANALYZER="OFF" \
    -DCLANG_BUILD_TOOLS="OFF" \
    -DCLANG_TABLEGEN="$cwd/llvm-project/build-native/bin/clang-tblgen" \
    -DLLVM_TABLEGEN="$cwd/llvm-project/build-native/bin/llvm-tblgen" \
    -DLLVM_HOST_TRIPLE="x86_64" \
    -DLLVM_TARGETS_TO_BUILD="WebAssembly" \
    -DLLVM_ENABLE_PROJECTS="lld;clang" \
    -DLLVM_DEFAULT_TARGET_TRIPLE="wasm32-wasi" \
    -DLLVM_BUILD_TOOLS="OFF" \
    -DLLVM_INCLUDE_UTILS="OFF" \
    -DLLVM_INCLUDE_EXAMPLES="OFF" \
    -DLLVM_INCLUDE_TESTS="OFF" \
    -DLLVM_INCLUDE_BENCHMARKS="OFF" \
    -DLLVM_ENABLE_BINDINGS="OFF" \
    -DLLVM_BUILD_DOCS="OFF" \
    -DLLVM_ENABLE_OCAMLDOC="OFF" \
    -DLLVM_ENABLE_THREADS="OFF" \
    -DLLVM_ENABLE_BACKTRACES="OFF" \
    -DLLVM_BUILD_STATIC="ON" \
    -DLLVM_ENABLE_PIC="OFF" \
    -DLLVM_ENABLE_UNWIND_TABLES="OFF" \
    -DLLVM_ENABLE_CRASH_OVERRIDES="OFF" \
    -DLLVM_ENABLE_TERMINFO="OFF" \
    -DLLVM_ENABLE_LIBXML2="OFF" \
    -DLLVM_ENABLE_LIBEDIT="OFF" \
    -DLLVM_ENABLE_LIBPFM="OFF" \
    -DLLVM_ENABLE_ZLIB="OFF" \
    -DLLVM_ENABLE_ZSTD="OFF" \
    -DLLVM_HAVE_LIBXAR="OFF" \
    ../llvm

Here are my build errors:

/mnt/c/Data/Code/pixel-studio/wasi-sdk/bin/clang++ --sysroot=/mnt/c/Data/Code/pixel-studio/wasi-sdk/share/wasi-sysroot -DGTEST_HAS_RTTI=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/mnt/c/Data/Code/pixel-studio/llvm-project/build-wasm/lib/Support -I/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support -I/mnt/c/Data/Code/pixel-studio/llvm-project/build-wasm/include -I/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/include -D_WASI_EMULATED_SIGNAL -fno-exceptions -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections  -Os -DNDEBUG -std=c++17  -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.o -c /mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:34:5: error: no type named 'jmp_buf' in the global namespace
34 |   ::jmp_buf JumpBuffer;
   |   ~~^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:350:25: error: variable has incomplete type 'struct sigaction'
350 | static struct sigaction PrevActions[NumSignals];
    |                         ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:350:15: note: forward declaration of 'sigaction'
350 | static struct sigaction PrevActions[NumSignals];
    |               ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:376:3: error: use of undeclared identifier 'sigemptyset'
376 |   sigemptyset(&SigMask);
    |   ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:377:3: error: use of undeclared identifier 'sigaddset'
377 |   sigaddset(&SigMask, Signal);
    |   ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:378:15: error: use of undeclared identifier 'SIG_UNBLOCK'
378 |   sigprocmask(SIG_UNBLOCK, &SigMask, nullptr);
    |               ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:395:20: error: variable has incomplete type 'struct sigaction'
395 |   struct sigaction Handler;
    |                    ^
/mnt/c/Data/Code/pixel-studio/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:350:15: note: forward declaration of 'sigaction'
350 | static struct sigaction PrevActions[NumSignals];
    |               ^
6 errors generated.
0

There are 0 best solutions below