diff --git a/README.md b/README.md index 8699c470b7..5fa9ef762f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - clang >= 10 or gcc >= 10 - clang-format - libomp (if multithreading is required. Multithreading can be disabled using the compiler flag `-DMULTITHREADING 0`) +- wasm-opt (part of the [Binaryen](https://github.com/WebAssembly/binaryen) toolkit) ### Installing openMP (Linux) diff --git a/cpp/src/aztec/CMakeLists.txt b/cpp/src/aztec/CMakeLists.txt index 954198911e..a778e332b0 100644 --- a/cpp/src/aztec/CMakeLists.txt +++ b/cpp/src/aztec/CMakeLists.txt @@ -62,7 +62,7 @@ if(WASM) # that as functions in 'env' should be implemented in JS itself. # It turns out that just explicitly telling the wasm module which object files to include was easiest. add_executable( - barretenberg-step1.wasm + barretenberg.wasm $ $ $ @@ -88,22 +88,23 @@ if(WASM) # Presumably the -O3 when compiling the object files is fine as it's llvms IR optimiser. # The backend optimiser is presumably triggered after linking. target_link_options( - barretenberg-step1.wasm + barretenberg.wasm PRIVATE -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 ) + find_program(WASM_OPT wasm-opt) + if(NOT WASM_OPT) + message(FATAL_ERROR "wasm-opt executable not found. Please install binaryen.") + endif() + add_custom_command( - OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm - COMMAND wasm-opt ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg-step1.wasm -O2 --asyncify -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm - DEPENDS barretenberg-step1.wasm + TARGET barretenberg.wasm + POST_BUILD + COMMAND wasm-opt "$" -O2 --asyncify -o "$" VERBATIM ) - add_custom_target( - barretenberg.wasm - DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/barretenberg.wasm - ) # For use when compiling dependent cpp projects for WASM message(STATUS "Compiling all-in-one barretenberg WASM archive") add_library(