diff --git a/LLVM.makefile b/LLVM.makefile index fcf6d8f..cef5095 100644 --- a/LLVM.makefile +++ b/LLVM.makefile @@ -34,8 +34,12 @@ very-clean-libc: clean-libc .PHONY: clean-libs clean-libs: clean-libc + # compiler-rt clean rm -rf $(BUILD_DIR)/compiler-rt $(BUILD_DIR)/compiler-rt.BUILT + # libcxx clean rm -rf $(BUILD_DIR)/libcxx $(BUILD_DIR)/libcxx.BUILT + rm -rf $(FAASM_SYSROOT)/include/wasm32-wasi/c++ + rm -rf $(FAASM_SYSROOT)/include/wasm32-wasi-threads/c++ .PHONY: clean-all clean-all: @@ -185,8 +189,8 @@ $(BUILD_DIR)/libcxx.BUILT: $(BUILD_DIR)/llvm.BUILT ${BUILD_DIR}/wasi-libc.BUILT mkdir -p $(BUILD_DIR)/libcxx-threads cd $(BUILD_DIR)/libcxx-threads && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,ON,OFF) \ -DCMAKE_SYSROOT=${FAASM_SYSROOT} \ - -DCMAKE_C_FLAGS="--target=wasm32-wasi-threads" \ - -DCMAKE_CXX_FLAGS="--target=wasm32-wasi-threads" \ + -DCMAKE_C_FLAGS="-pthread --target=wasm32-wasi-threads" \ + -DCMAKE_CXX_FLAGS="-pthread --target=wasm32-wasi-threads" \ -DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi-threads \ -DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi-threads \ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ diff --git a/WasiToolchain.cmake b/WasiToolchain.cmake index 45402e1..4108878 100644 --- a/WasiToolchain.cmake +++ b/WasiToolchain.cmake @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.5.0) -# project("Faasm WASM compilation toolchain" C CXX) # ----------------------------------------- # A useful reference for this file is the wasi-sdk equivalent: @@ -19,7 +18,7 @@ set(UNIX 1) set(CMAKE_SYSTEM_NAME WASI) set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_PROCESSOR wasm32) -set(WASM_TRIPLE $ENV{FAASM_WASM_TRIPLE}) +set(WASM_TRIPLE $ENV{FAASM_WASM_TRIPLE}) set(WASI_HOST_EXE_SUFFIX "") @@ -27,11 +26,12 @@ if(FAASM_BUILD_SHARED) message(STATUS "Faasm building SHARED libraries") # See note in README about shared libraries targeting Emscripten + # TODO: what happens with shared lirbaries now? set(WASM_TRIPLE $ENV{FAASM_WASM_HOST_SHARED}) else() message(STATUS "Faasm building STATIC libraries") - set(WASM_TRIPLE $ENV{FAASM_WASM_HOST_STATIC}) + # set(WASM_TRIPLE $ENV{WASM_TRIPLE}) endif() # Specify LLVM toolchain @@ -41,10 +41,10 @@ set(CMAKE_ASM_COMPILER $ENV{FAASM_WASM_CC}) set(CMAKE_AR $ENV{FAASM_WASM_AR} CACHE STRING "faasm build") set(CMAKE_NM $ENV{FAASM_WASM_NM} CACHE STRING "faasm build") set(CMAKE_RANLIB $ENV{FAASM_WASM_RANLIB} CACHE STRING "faasm build") -set(CMAKE_C_COMPILER_TARGET ${WASM_TRIPLE} CACHE STRING "faasm build") -set(CMAKE_CXX_COMPILER_TARGET ${WASM_TRIPLE} CACHE STRING "faasm build") -set(CMAKE_ASM_COMPILER_TARGET ${WASM_TRIPLE} CACHE STRING "faasm build") -message(STATUS "Faasm building target ${CMAKE_CXX_COMPILER_TARGET}") +set(CMAKE_C_COMPILER_TARGET $ENV{WASM_TRIPLE} CACHE STRING "faasm build") +set(CMAKE_CXX_COMPILER_TARGET $ENV{WASM_TRIPLE} CACHE STRING "faasm build") +set(CMAKE_ASM_COMPILER_TARGET $ENV{WASM_TRIPLE} CACHE STRING "faasm build") +message(STATUS "Faasm building target $ENV{CMAKE_CXX_COMPILER_TARGET}") # We define dynamic linking functions in Faasm unset(CMAKE_DL_LIBS CACHE) @@ -56,12 +56,12 @@ if(FAASM_BUILD_SHARED) set(FAASM_COMPILER_FLAGS "$ENV{FAASM_WASM_CFLAGS} $ENV{FAASM_WASM_CFLAGS_SHARED}") endif() -set(CMAKE_SYSROOT ${FAASM_SYSROOT} CACHE STRING "faasm build") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{FAASM_WASM_CFLAGS}" CACHE STRING "faasm build") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{FAASM_WASM_CXXFLAGS}" CACHE STRING "faasm build") -set(CMAKE_LINKER_FLAGS $ENV{FAASM_WASM_LINKER_FLAGS} CACHE STRING "faasm build") -set(CMAKE_SHARED_LINKER_FLAGS $ENV{FAASM_WASM_SHARED_LINKER_FLAGS} CACHE STRING "faasm build") -set(CMAKE_EXE_LINKER_FLAGS $ENV{FAASM_WASM_EXE_LINKER_FLAGS} CACHE STRING "faasm build") +set(CMAKE_SYSROOT $ENV{FAASM_SYSROOT} CACHE STRING "faasm build") +set(CMAKE_C_FLAGS "$ENV{CMAKE_C_FLAGS} $ENV{FAASM_WASM_CFLAGS}" CACHE STRING "faasm build") +set(CMAKE_CXX_FLAGS "$ENV{CMAKE_CXX_FLAGS} $ENV{FAASM_WASM_CXXFLAGS}" CACHE STRING "faasm build") +set(CMAKE_LINKER_FLAGS "$ENV{FAASM_WASM_LINKER_FLAGS}" CACHE STRING "faasm build") +set(CMAKE_SHARED_LINKER_FLAGS "$ENV{FAASM_WASM_SHARED_LINKER_FLAGS}" CACHE STRING "faasm build") +set(CMAKE_EXE_LINKER_FLAGS "$ENV{FAASM_WASM_EXE_LINKER_FLAGS}" CACHE STRING "faasm build") # This is important to ensure the right search path set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) diff --git a/docker/cpp-sysroot.dockerfile b/docker/cpp-sysroot.dockerfile index 16e80ba..6ec26f1 100644 --- a/docker/cpp-sysroot.dockerfile +++ b/docker/cpp-sysroot.dockerfile @@ -42,21 +42,29 @@ RUN cd /code/cpp \ libfaasmpi --native --shared \ # Install toolchain files && inv install \ + # Temporarily using llvm --clean as we debug new versions of the toolchain + # to avoid having to re-build the base image + # TODO: remove me + && inv llvm --clean \ # Build wasi-libc and reset the sysroot. The second call to LLVM just # installs some headers that are purged - && inv llvm.libc --purge llvm \ + # && inv llvm.libc --purge llvm \ # Build Faasm WASM libraries && inv \ libemscripten \ + libemscripten --threads \ libfaasm \ + libfaasm --threads \ libfaasmp \ libfaasmpi - # # Lastly, build the libraries that populate the sysroot -# && inv \ + # Lastly, build the libraries that populate the sysroot + && inv \ + libffi \ + libffi --threads \ + zlib \ + zlib --threads # clapack \ # clapack --clean --shared \ - # libffi \ - # zlib # CLI setup WORKDIR /code/cpp diff --git a/faasmtools/build.py b/faasmtools/build.py index 9cf7dea..ffa45d3 100644 --- a/faasmtools/build.py +++ b/faasmtools/build.py @@ -242,12 +242,15 @@ def get_faasm_build_env_dict(is_threads=False): "sign-ext", "simd128", ] - build_env_dicts[ - "FAASM_WASM_EXE_LINKER_FLAGS" - ] += " -Wl,--import-memory" - build_env_dicts[ - "FAASM_WASM_EXE_LINKER_FLAGS" - ] += " -Wl,--export-memory" + # TODO: it seems that this import/export here are a requirement of + # the wasi-threads spec (see wasi-sdk/wasi-sdk-pthread.cmake). It + # is still not clear if we need it or not. +# build_env_dicts[ +# "FAASM_WASM_EXE_LINKER_FLAGS" +# ] += " -Wl,--import-memory" +# build_env_dicts[ +# "FAASM_WASM_EXE_LINKER_FLAGS" +# ] += " -Wl,--export-memory" else: wasm_triple = "wasm32-wasi" build_env_dicts["FAASM_WASM_TRIPLE"] = wasm_triple diff --git a/libfaasmp/CMakeLists.txt b/libfaasmp/CMakeLists.txt index 673cc33..a186bbc 100644 --- a/libfaasmp/CMakeLists.txt +++ b/libfaasmp/CMakeLists.txt @@ -16,12 +16,17 @@ set(LIB_FILES if (CMAKE_SYSTEM_NAME STREQUAL "WASI") message(STATUS "Libfaasmp WebAssembly build") + set(LLVM_OMP_SRC_DIR "/opt/llvm-project/openmp/runtime/src") + set(LLVM_OMP_BUILD_SRC_DIR "/opt/llvm-project/build/llvm/projects/openmp/runtime/src") + # set(LIBOMP_ASMFILES "${LLVM_OMP_SRC_DIR}/z_Linux_asm.S") set(LIBOMP_ASMFILES "z_Linux_asm.S") + set(LIBOMP_HEADERS "${LLVM_OMP_BUILD_SRC_DIR}/omp.h") set_source_files_properties(${LIBOMP_ASMFILES} PROPERTIES LANGUAGE C) set(LIB_FILES ${LIBOMP_ASMFILES} ${LIB_FILES}) add_library(faasmp STATIC ${LIB_FILES}) set_target_properties(faasmp PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}") + # target_include_directories(faasmp PUBLIC ${LLVM_OMP_BUILD_SRC_DIR} ${LLVM_OMP_SRC_DIR}) # Install in WASM sysroot install( @@ -37,6 +42,13 @@ if (CMAKE_SYSTEM_NAME STREQUAL "WASI") DESTINATION $ENV{FAASM_WASM_LIB_INSTALL_DIR} RENAME libfaasmp.imports ) + + # Add omp.h header copied from clang source + # TODO: can we copy it directly from LLVM source, for each LLVM version? + install( + FILES ${LIBOMP_HEADERS} + DESTINATION $ENV{FAASM_WASM_HEADER_INSTALL_DIR} + ) else () message(STATUS "Libfaasmp native build") diff --git a/libfaasmp/README.md b/libfaasmp/README.md index a99b332..5aa93b9 100644 --- a/libfaasmp/README.md +++ b/libfaasmp/README.md @@ -19,8 +19,8 @@ and the Faasm host interface. LLVM adds GNU compatibility data symbols on some features for synchronisation. The wasm linker needs to be aware of the sizes and the names of the symbols, which are not valid C/C++ identifiers, and as such are resolved in assembly in -`libfaasmp/z_Linux_asm.S` file. +`libfaasmp/z_Linux_asm.S` file. -An error from the linker when compiling new parts of the API implies you need to -you need to add the symbol to this file. +An error from the linker when compiling new parts of the API implies you need +to add the symbol to this file.