From f5676516d8905b35828b40f9f9019035e9a7f1c3 Mon Sep 17 00:00:00 2001 From: spalladino Date: Tue, 4 Apr 2023 08:32:24 +0000 Subject: [PATCH 1/3] Build a3crypto.wasm Builds a smaller wasm than full barretenberg with crypto primitives to be used from aztec3-packages. --- cpp/dockerfiles/Dockerfile.wasm-linux-clang | 5 ++-- cpp/src/CMakeLists.txt | 27 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/cpp/dockerfiles/Dockerfile.wasm-linux-clang index f4a19bba53..19fd4d7114 100644 --- a/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -5,10 +5,11 @@ WORKDIR /usr/src/barretenberg/cpp/src RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv - WORKDIR /usr/src/barretenberg/cpp COPY . . -# Build both honk_tests barretenberg.wasm +# Build both honk_tests barretenberg.wasm a3crypto.wasm # This ensures that we aren't using features that would be incompatible with WASM for Honk -RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm +RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target a3crypto.wasm FROM alpine:3.17 COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm +COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/a3crypto.wasm /usr/src/barretenberg/cpp/build/bin/a3crypto.wasm COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/ diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index eb21af651d..45d92538ce 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -111,6 +111,26 @@ if(WASM) -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 ) + add_executable( + a3crypto.wasm + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + ) + + target_link_options( + a3crypto.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) @@ -124,6 +144,13 @@ if(WASM) VERBATIM ) + add_custom_command( + TARGET a3crypto.wasm + POST_BUILD + COMMAND wasm-opt "$" -O2 --asyncify -o "$" + VERBATIM + ) + if(INSTALL_BARRETENBERG) install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() From 16ce77fbfbee6a70eff90ef0dfe8764c2da874fd Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 4 Apr 2023 15:29:11 +0100 Subject: [PATCH 2/3] Rename to primitives and remove asyncify --- cpp/dockerfiles/Dockerfile.wasm-linux-clang | 6 +++--- cpp/src/CMakeLists.txt | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/cpp/dockerfiles/Dockerfile.wasm-linux-clang index 19fd4d7114..d1c41f0ce7 100644 --- a/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -5,11 +5,11 @@ WORKDIR /usr/src/barretenberg/cpp/src RUN curl -s -L https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz | tar zxfv - WORKDIR /usr/src/barretenberg/cpp COPY . . -# Build both honk_tests barretenberg.wasm a3crypto.wasm +# Build both honk_tests barretenberg.wasm primitives.wasm # This ensures that we aren't using features that would be incompatible with WASM for Honk -RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target a3crypto.wasm +RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm --target primitives.wasm FROM alpine:3.17 COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm -COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/a3crypto.wasm /usr/src/barretenberg/cpp/build/bin/a3crypto.wasm +COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/primitives.wasm /usr/src/barretenberg/cpp/build/bin/primitives.wasm COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/ diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index 45d92538ce..d32aa2beb2 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -111,8 +111,10 @@ if(WASM) -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 ) + # Repeat the above but for the smaller primitives.wasm + # Used in packages where we don't need the full contents of barretenberg add_executable( - a3crypto.wasm + primitives.wasm $ $ $ @@ -126,7 +128,7 @@ if(WASM) ) target_link_options( - a3crypto.wasm + primitives.wasm PRIVATE -nostartfiles -O2 -Wl,--no-entry -Wl,--export-dynamic -Wl,--import-memory -Wl,--allow-undefined -Wl,--stack-first -Wl,-z,stack-size=1048576 ) @@ -145,9 +147,9 @@ if(WASM) ) add_custom_command( - TARGET a3crypto.wasm + TARGET primitives.wasm POST_BUILD - COMMAND wasm-opt "$" -O2 --asyncify -o "$" + COMMAND wasm-opt "$" -O2 -o "$" VERBATIM ) From 72f1372cba97122d5213283ee3d53c6e8f69c32a Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 4 Apr 2023 16:23:54 +0100 Subject: [PATCH 3/3] Add missing modules for tests --- cpp/src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index d32aa2beb2..37ca6acf90 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -115,11 +115,13 @@ if(WASM) # Used in packages where we don't need the full contents of barretenberg add_executable( primitives.wasm + $ $ $ $ $ $ + $ $ $ $