diff --git a/CMakeLists.txt b/CMakeLists.txt index 98c3e9d8..611f1f9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,24 +58,36 @@ add_executable(starling.wasm runtime/script_loader.cpp ) +option(USE_WASM_OPT "use wasm-opt to optimize the StarlingMonkey binary" ON) + # For release builds, use wasm-opt to optimize the generated wasm file. -if (CMAKE_BUILD_TYPE STREQUAL "Release") - add_custom_command( - TARGET starling.wasm - POST_BUILD - COMMAND ${WASM_OPT} --strip-debug -O3 -o starling.wasm starling.wasm - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) -elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - add_custom_command( +if (USE_WASM_OPT) + if (CMAKE_BUILD_TYPE STREQUAL "Release") + add_custom_command( + TARGET starling.wasm + POST_BUILD + COMMAND ${WASM_OPT} --strip-debug -O3 -o starling.wasm starling.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + add_custom_command( + TARGET starling.wasm + POST_BUILD + COMMAND ${WASM_OPT} -O3 -o starling.wasm starling.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif() +else() + if (CMAKE_BUILD_TYPE STREQUAL "Release") + add_custom_command( TARGET starling.wasm POST_BUILD - COMMAND ${WASM_OPT} -O3 -o starling.wasm starling.wasm + COMMAND ${WASM_TOOLS_BIN} strip -a -o starling.wasm starling.wasm WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) + ) + endif() endif() - target_link_libraries(starling.wasm PRIVATE host_api extension_api builtins spidermonkey rust-url) set(RUNTIME_FILE "starling.wasm") diff --git a/cmake/wasm-tools.cmake b/cmake/wasm-tools.cmake index 191d5c2e..ebfbd86e 100644 --- a/cmake/wasm-tools.cmake +++ b/cmake/wasm-tools.cmake @@ -3,3 +3,4 @@ set(WASM_TOOLS_VERSION 1.0.54) set(WASM_TOOLS_URL https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-${WASM_TOOLS_VERSION}/wasm-tools-${WASM_TOOLS_VERSION}-${HOST_ARCH}-${HOST_OS}.tar.gz) CPMAddPackage(NAME wasm-tools URL ${WASM_TOOLS_URL} DOWNLOAD_ONLY TRUE) set(WASM_TOOLS_DIR ${CPM_PACKAGE_wasm-tools_SOURCE_DIR}) +set(WASM_TOOLS_BIN ${WASM_TOOLS_DIR}/wasm-tools)