diff --git a/Makefile b/Makefile index 89c3b40..fcf8ab8 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,10 @@ build/compiler-rt.BUILT: build/llvm.BUILT # Do the build, and install it. mkdir -p build/compiler-rt cd build/compiler-rt && cmake -G Ninja \ + -DCMAKE_C_COMPILER_WORKS=ON \ + -DCMAKE_CXX_COMPILER_WORKS=ON \ + -DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \ + -DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \ -DCOMPILER_RT_BAREMETAL_BUILD=On \ @@ -104,7 +108,7 @@ build/compiler-rt.BUILT: build/llvm.BUILT -DCOMPILER_RT_ENABLE_IOS=OFF \ -DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \ -DWASI_SDK_PREFIX=$(BUILD_PREFIX) \ - -DCMAKE_C_FLAGS="-O1 $(DEBUG_PREFIX_MAP)" \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ -DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \ -DCOMPILER_RT_OS_DIR=wasi \ -DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \ @@ -117,6 +121,10 @@ build/compiler-rt.BUILT: build/llvm.BUILT # Flags for libcxx. LIBCXX_CMAKE_FLAGS = \ + -DCMAKE_C_COMPILER_WORKS=ON \ + -DCMAKE_CXX_COMPILER_WORKS=ON \ + -DCMAKE_AR=$(BUILD_PREFIX)/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 \ @@ -138,14 +146,12 @@ LIBCXX_CMAKE_FLAGS = \ -DWASI_SDK_PREFIX=$(BUILD_PREFIX) \ --debug-trycompile - #-DCMAKE_STAGING_PREFIX= - build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUILT # Do the build. mkdir -p build/libcxx cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ + -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ -DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxx ninja $(NINJA_FLAGS) -v -C build/libcxx @@ -155,9 +161,11 @@ build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUI # Flags for libcxxabi. LIBCXXABI_CMAKE_FLAGS = \ - -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ - -DCMAKE_CXX_COMPILER_WORKS=ON \ -DCMAKE_C_COMPILER_WORKS=ON \ + -DCMAKE_CXX_COMPILER_WORKS=ON \ + -DCMAKE_AR=$(BUILD_PREFIX)/bin/ar \ + -DCMAKE_MODULE_PATH=$(ROOT_DIR)/cmake \ + -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF \ -DLIBCXXABI_ENABLE_SHARED:BOOL=OFF \ -DLIBCXXABI_SILENT_TERMINATE:BOOL=ON \ @@ -183,8 +191,8 @@ build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT # Do the build. mkdir -p build/libcxxabi cd build/libcxxabi && cmake -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ - -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ + -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ + -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) --sysroot=$(BUILD_PREFIX)/share/wasi-sysroot" \ -DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxxabi ninja $(NINJA_FLAGS) -v -C build/libcxxabi diff --git a/cmake/Platform/WASI.cmake b/cmake/Platform/WASI.cmake new file mode 100644 index 0000000..b49713f --- /dev/null +++ b/cmake/Platform/WASI.cmake @@ -0,0 +1 @@ +set(WASI 1) diff --git a/wasi-sdk.cmake b/wasi-sdk.cmake index 18c9901..3245a4c 100644 --- a/wasi-sdk.cmake +++ b/wasi-sdk.cmake @@ -3,7 +3,7 @@ # This is arbitrary, AFAIK, for now. cmake_minimum_required(VERSION 3.4.0) -set(CMAKE_SYSTEM_NAME Wasm) +set(CMAKE_SYSTEM_NAME WASI) set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_PROCESSOR wasm32) set(triple wasm32-wasi) @@ -16,15 +16,10 @@ endif() set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX}) set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX}) -set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar${WASI_HOST_EXE_SUFFIX} CACHE STRING "wasi-sdk build") -set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib${WASI_HOST_EXE_SUFFIX} CACHE STRING "wasi-sdk build") -set(CMAKE_C_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") -set(CMAKE_CXX_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") -set(CMAKE_C_FLAGS "-v" CACHE STRING "wasi-sdk build") -set(CMAKE_CXX_FLAGS "-v -std=c++11" CACHE STRING "wasi-sdk build") - -set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") -set(CMAKE_STAGING_PREFIX ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") +set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) # Don't look in the sysroot for executables to run during the build set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) @@ -32,7 +27,3 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -# Some other hacks -set(CMAKE_C_COMPILER_WORKS ON) -set(CMAKE_CXX_COMPILER_WORKS ON)