Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a3crypto.wasm #311

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
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/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/
31 changes: 31 additions & 0 deletions cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ 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(
primitives.wasm
$<TARGET_OBJECTS:srs_objects>
$<TARGET_OBJECTS:numeric_objects>
$<TARGET_OBJECTS:crypto_sha256_objects>
$<TARGET_OBJECTS:crypto_aes128_objects>
$<TARGET_OBJECTS:crypto_blake2s_objects>
$<TARGET_OBJECTS:crypto_blake3s_objects>
$<TARGET_OBJECTS:crypto_generators_objects>
$<TARGET_OBJECTS:crypto_keccak_objects>
$<TARGET_OBJECTS:crypto_schnorr_objects>
$<TARGET_OBJECTS:crypto_pedersen_hash_objects>
$<TARGET_OBJECTS:crypto_pedersen_commitment_objects>
$<TARGET_OBJECTS:ecc_objects>
)

target_link_options(
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
)

find_program(WASM_OPT wasm-opt)

if(NOT WASM_OPT)
Expand All @@ -124,6 +148,13 @@ if(WASM)
VERBATIM
)

add_custom_command(
TARGET primitives.wasm
POST_BUILD
COMMAND wasm-opt "$<TARGET_FILE:primitives.wasm>" -O2 -o "$<TARGET_FILE:primitives.wasm>"
VERBATIM
)

if(INSTALL_BARRETENBERG)
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand Down