Skip to content
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

WASI support #304

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/llvm/llvm-project
url = https://github.com/turbolent/llvm-project
[submodule "src/wasi-libc"]
path = src/wasi-libc
url = https://github.com/CraneStation/wasi-libc
Expand Down
32 changes: 21 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PATH_PREFIX=$(shell cygpath.exe -u $(BUILD_PREFIX))

else

WASI_SDK?=/opt/wasi-sdk
PREFIX?=/opt/wasi-sdk
DESTDIR=$(abspath build/install)
BUILD_PREFIX=$(DESTDIR)$(PREFIX)
Expand Down Expand Up @@ -55,14 +56,23 @@ clean:
build/llvm.BUILT:
mkdir -p build/llvm
cd build/llvm && cmake -G Ninja \
-DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \
-DWASI_SDK_PREFIX=$(WASI_SDK) \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DLLVM_HOST_TRIPLE=wasm32-wasi \
-DLLVM_ENABLE_THREADS=OFF \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_STATIC_LINK_CXX_STDLIB=ON \
-DLLVM_HAVE_LIBXAR=OFF \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCLANG_ENABLE_ARCMT=OFF \
-DCLANG_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_UTILS=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
Copy link
Member

Choose a reason for hiding this comment

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

I think we can/should probably land this hunk separately and without delay since I think it would speed up our builds.

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure if these things were needed. I'll have a look how much more work it is to support e.g. tests, that would help with validating the changes.

Copy link
Member

Choose a reason for hiding this comment

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

They are not needed as far as I know, we don't use any of those binaries.

Copy link
Member

Choose a reason for hiding this comment

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

Can you rebase this now that #309 has landed?

-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
-DLLVM_TARGETS_TO_BUILD=WebAssembly \
-DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-wasi \
Expand Down Expand Up @@ -101,9 +111,9 @@ build/llvm.BUILT:

build/wasi-libc.BUILT: build/llvm.BUILT
$(MAKE) -C $(ROOT_DIR)/src/wasi-libc \
CC=$(BUILD_PREFIX)/bin/clang \
AR=$(BUILD_PREFIX)/bin/llvm-ar \
NM=$(BUILD_PREFIX)/bin/llvm-nm \
CC=$(WASI_SDK)/bin/clang \
AR=$(WASI_SDK)/bin/llvm-ar \
NM=$(WASI_SDK)/bin/llvm-nm \
SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot
touch build/wasi-libc.BUILT

Expand All @@ -114,7 +124,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \
-DCMAKE_AR=$(WASI_SDK)/bin/ar \
-DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
Expand All @@ -124,9 +134,9 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT
-DCOMPILER_RT_HAS_FPIC_FLAG=OFF \
-DCOMPILER_RT_ENABLE_IOS=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \
-DWASI_SDK_PREFIX=$(BUILD_PREFIX) \
-DWASI_SDK_PREFIX=$(WASI_SDK) \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/NATIVE/bin/llvm-config \
-DCOMPILER_RT_OS_DIR=wasi \
-DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
Expand All @@ -140,11 +150,11 @@ build/compiler-rt.BUILT: build/llvm.BUILT build/wasi-libc.BUILT
LIBCXX_CMAKE_FLAGS = \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \
-DCMAKE_AR=$(WASI_SDK)/bin/ar \
-DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DCMAKE_STAGING_PREFIX=$(PREFIX)/share/wasi-sysroot \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/NATIVE/bin/llvm-config \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCXX_SUPPORTS_CXX11=ON \
-DLIBCXX_ENABLE_THREADS:BOOL=OFF \
Expand All @@ -171,7 +181,7 @@ LIBCXX_CMAKE_FLAGS = \
-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXXABI_HAS_WIN32_THREAD_API:BOOL=OFF \
-DLIBCXXABI_ENABLE_PIC:BOOL=OFF \
-DWASI_SDK_PREFIX=$(BUILD_PREFIX) \
-DWASI_SDK_PREFIX=$(WASI_SDK) \
-DUNIX:BOOL=ON \
--debug-trycompile

Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 50 files
+1 −1 clang/lib/Driver/Driver.cpp
+10 −0 clang/lib/Frontend/ASTUnit.cpp
+10 −0 clang/lib/Frontend/PrecompiledPreamble.cpp
+22 −0 clang/lib/Tooling/AllTUsExecution.cpp
+22 −0 lld/COFF/Driver.cpp
+10 −1 lld/Common/ErrorHandler.cpp
+7 −0 lld/Common/Filesystem.cpp
+6 −0 lld/ELF/InputFiles.cpp
+4 −0 lld/ELF/InputSection.cpp
+18 −0 lld/MachO/Writer.cpp
+4 −0 lld/include/lld/Common/ErrorHandler.h
+6 −1 llvm/cmake/modules/HandleLLVMOptions.cmake
+1 −1 llvm/include/llvm/CodeGen/TargetFrameLowering.h
+8 −0 llvm/include/llvm/Debuginfod/Debuginfod.h
+14 −3 llvm/include/llvm/IR/ValueMap.h
+2 −0 llvm/include/llvm/PassRegistry.h
+4 −0 llvm/include/llvm/Support/FileCollector.h
+4 −0 llvm/include/llvm/Support/Mutex.h
+4 −0 llvm/include/llvm/Support/RWMutex.h
+1 −1 llvm/include/llvm/Support/SwapByteOrder.h
+4 −0 llvm/include/llvm/Support/ThreadPool.h
+6 −0 llvm/lib/CodeGen/ParallelCG.cpp
+4 −0 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+20 −0 llvm/lib/Debuginfod/Debuginfod.cpp
+14 −3 llvm/lib/IR/PassRegistry.cpp
+4 −0 llvm/lib/IR/PassTimingInfo.cpp
+20 −3 llvm/lib/LTO/LTO.cpp
+10 −0 llvm/lib/LTO/LTOBackend.cpp
+16 −0 llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+6 −2 llvm/lib/Support/CodeGenCoverage.cpp
+24 −2 llvm/lib/Support/CrashRecoveryContext.cpp
+12 −1 llvm/lib/Support/DynamicLibrary.cpp
+6 −0 llvm/lib/Support/FileCollector.cpp
+13 −0 llvm/lib/Support/LockFileManager.cpp
+6 −0 llvm/lib/Support/ManagedStatic.cpp
+4 −0 llvm/lib/Support/Parallel.cpp
+10 −0 llvm/lib/Support/PluginLoader.cpp
+13 −0 llvm/lib/Support/RandomNumberGenerator.cpp
+16 −0 llvm/lib/Support/Statistic.cpp
+4 −0 llvm/lib/Support/ThreadPool.cpp
+10 −0 llvm/lib/Support/TimeProfiler.cpp
+26 −5 llvm/lib/Support/Timer.cpp
+21 −0 llvm/lib/Support/Unix/Memory.inc
+100 −3 llvm/lib/Support/Unix/Path.inc
+10 −0 llvm/lib/Support/Unix/Process.inc
+21 −0 llvm/lib/Support/Unix/Program.inc
+19 −0 llvm/lib/Support/Unix/Signals.inc
+2 −0 llvm/lib/Support/Unix/Unix.h
+4 −0 llvm/lib/Support/Unix/Watchdog.inc
+4 −0 llvm/lib/Transforms/Instrumentation/InstrOrderFile.cpp