Skip to content

Commit

Permalink
fix: Check for wasm-opt during configure & run on post_build (AztecPr…
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Feb 24, 2023
1 parent 4bf54a9 commit f3df393
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions circuits/cpp/barretenberg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 10 additions & 9 deletions circuits/cpp/barretenberg/cpp/src/aztec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
Expand All @@ -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 "$<TARGET_FILE:barretenberg.wasm>" -O2 --asyncify -o "$<TARGET_FILE:barretenberg.wasm>"
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(
Expand Down

0 comments on commit f3df393

Please sign in to comment.