Skip to content

Commit

Permalink
[js] export default vis
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Nov 20, 2024
1 parent a5045f7 commit 5f82b38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
21 changes: 12 additions & 9 deletions build_tools/build_llvm_wasi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ echo "*********************** BUILDING LLVM *********************************"
# hack to emit html wrappers
# https://stackoverflow.com/a/75596433/9045206
sed -i.bak 's/CMAKE_EXECUTABLE_SUFFIX ".js"/CMAKE_EXECUTABLE_SUFFIX ".html"/g' "$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
sed -i.bak 's/if(LLVM_ENABLE_PIC)/if(LLVM_ENABLE_PIC)\nreturn()\nendif()\nif(LLVM_ENABLE_PIC)/g' "${LLVM_SOURCE_DIR}/mlir/lib/ExecutionEngine/CMakeLists.txt"

# all emscripten settings here https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
# wasm-ld exports https://lld.llvm.org/WebAssembly.html#exports
# -sLINKABLE=1 combined with CMAKE_CXX_VISIBILITY_PRESET=default will cause all symbols to be exported
# -sEXPORT_ALL=1 put all of the exported function in the wasm on the JS module
cmake_options=(
-GNinja
-S "${LLVM_SOURCE_DIR}/llvm"
-B "${LLVM_BUILD_DIR}"
-DCMAKE_C_FLAGS="-Os"
-DCMAKE_CXX_FLAGS="-Os"
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_EXE_LINKER_FLAGS="--emit-symbol-map -sSTANDALONE_WASM=1 -sWASM=1 -sWASM_BIGINT=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,getValue,setValue,writeAsciiToMemory,wasmTable --minify 0 -lembind"
-DCMAKE_EXE_LINKER_FLAGS="--emit-symbol-map -sSTANDALONE_WASM=1 -sWASM=1 -sWASM_BIGINT=1 -sLINKABLE=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,getValue,setValue,writeAsciiToMemory,wasmTable --minify 0 -lembind"
-DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}"
-DCMAKE_SYSTEM_NAME=Emscripten
-DCMAKE_TOOLCHAIN_FILE="$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
Expand All @@ -58,10 +59,12 @@ cmake --build "${LLVM_BUILD_DIR}" \
--target install-mlirdevelopment-distribution

sed -i.bak 's/CMAKE_EXECUTABLE_SUFFIX ".html"/CMAKE_EXECUTABLE_SUFFIX ".js"/g' "$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
# https://stackoverflow.com/a/1252191/9045206
sed -i.bak -e ':a' -e 'N' -e '$!ba' -e 's/if(LLVM_ENABLE_PIC)\nreturn()\nendif()\n//g' "${LLVM_SOURCE_DIR}/mlir/lib/ExecutionEngine/CMakeLists.txt"


# wasi files aren't installed for some reason
cp "${LLVM_BUILD_DIR}"/bin/* "${LLVM_INSTALL_DIR}/bin"
cp "${LLVM_BUILD_DIR}"/lib/*.symbols "${LLVM_INSTALL_DIR}/lib"
cp "${LLVM_BUILD_DIR}"/bin/mlir-opt.* "${LLVM_INSTALL_DIR}/bin"
# cp "${LLVM_BUILD_DIR}"/lib/*.symbols "${LLVM_INSTALL_DIR}/lib"

# prevent symbol collisions
# sed -i.bak 's/if(LLVM_ENABLE_PIC)/if(LLVM_ENABLE_PIC)\nreturn()\nendif()\nif(LLVM_ENABLE_PIC)/g' "${LLVM_SOURCE_DIR}/mlir/lib/ExecutionEngine/CMakeLists.txt"
# https://stackoverflow.com/a/1252191/9045206
# sed -i.bak -e ':a' -e 'N' -e '$!ba' -e 's/if(LLVM_ENABLE_PIC)\nreturn()\nendif()\n//g' "${LLVM_SOURCE_DIR}/mlir/lib/ExecutionEngine/CMakeLists.txt"
14 changes: 7 additions & 7 deletions build_tools/cmake/llvm_wasm_cache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ set(LLVM_ENABLE_LIBPFM OFF CACHE BOOL "")
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
set(LLVM_ENABLE_OCAMLDOC OFF CACHE BOOL "")

set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
set(MLIR_BUILD_MLIR_C_DYLIB ON CACHE BOOL "")
set(LLVM_BUILD_LLVM_DYLIB OFF CACHE BOOL "")
set(MLIR_BUILD_MLIR_C_DYLIB OFF CACHE BOOL "")
# when building libLLVM
# relocation R_WASM_MEMORY_ADDR_SLEB cannot be used against symbol
set(LLVM_ENABLE_PIC ON CACHE BOOL "")
set(LLVM_ENABLE_PIC OFF CACHE BOOL "")
set(MLIR_ENABLE_SPIRV_CPU_RUNNER OFF)
set(MLIR_ENABLE_EXECUTION_ENGINE OFF)

Expand All @@ -41,7 +41,7 @@ set(LLVM_MlirDevelopment_DISTRIBUTION_COMPONENTS
llvm-headers
llvm-libraries
cmake-exports
opt
# opt
# triggers LLVMMlirDevelopmentExports.cmake
mlirdevelopment-cmake-exports
# triggers MLIRMlirDevelopmentTargets.cmake
Expand All @@ -51,7 +51,7 @@ set(LLVM_MlirDevelopment_DISTRIBUTION_COMPONENTS
mlir-headers
mlir-libraries
mlir-opt
mlir-reduce
mlir-tblgen
mlir-translate
# mlir-reduce
# mlir-tblgen
# mlir-translate
CACHE STRING "")
15 changes: 10 additions & 5 deletions build_tools/cmake/llvm_wasm_project_include.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
# so that the correct LLVM_ABI macros get set
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__ELF__")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__ELF__")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sSIDE_MODULE=1 -sEXPORT_ALL=1 --emit-symbol-map")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sSIDE_MODULE=1 -sEXPORT_ALL=1 --emit-symbol-map")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-sLINKABLE=1 -sEXPORT_ALL=1")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-sLINKABLE=1 -sEXPORT_ALL=1")
# prevent duplicated libs from being linked
# will need to be renamed to DEDUPLICATION when CMake version catches up
# https://github.com/Kitware/CMake/commit/5617c34c3135f7ec203d5a48b803eb323f458bc3#diff-17fc647759070cdaddd99e9ad994c4478860d9c301ed9a9a9f061a8825c8b690L20
set(CMAKE_C_LINK_LIBRARIES_PROCESSING ORDER=FORWARD UNICITY=ALL)
set(CMAKE_CXX_LINK_LIBRARIES_PROCESSING ORDER=FORWARD UNICITY=ALL)
# hack to prevent -Bsymbolic
set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS ON)

## hack to prevent -Bsymbolic
#set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS ON)

set(CMAKE_SHARED_LIBRARY_SUFFIX ".wasm")
set(CMAKE_STRIP FALSE)
set(CMAKE_STRIP FALSE)
set(LLVM_NO_DEAD_STRIP ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_VISIBILITY_PRESET default)

0 comments on commit 5f82b38

Please sign in to comment.