From f3df393c2ab5bf156d629e855fef8ac07a74f056 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 24 Feb 2023 08:03:37 -0700 Subject: [PATCH] fix: Check for wasm-opt during configure & run on post_build (https://github.com/AztecProtocol/barretenberg/pull/175) --- circuits/cpp/barretenberg/README.md | 1 + .../barretenberg/cpp/src/aztec/CMakeLists.txt | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/circuits/cpp/barretenberg/README.md b/circuits/cpp/barretenberg/README.md index 8699c470b7e..5fa9ef762fa 100644 --- a/circuits/cpp/barretenberg/README.md +++ b/circuits/cpp/barretenberg/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/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt b/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt index 954198911e4..a778e332b04 100644 --- a/circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt +++ b/circuits/cpp/barretenberg/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(