-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Use the specified Rust image | ||
FROM rust:1.73.0-alpine3.18 | ||
|
||
# Add the WebAssembly target | ||
RUN rustup target add wasm32-unknown-unknown | ||
|
||
# Set up build dependencies | ||
RUN apk add --no-cache build-base cmake git clang | ||
|
||
# Clone Binaryen and build it | ||
RUN git clone --branch version_116 --recurse-submodules https://github.com/WebAssembly/binaryen.git && \ | ||
cd binaryen && \ | ||
mkdir build && \ | ||
cd build && \ | ||
cmake .. && \ | ||
make && \ | ||
make install | ||
|
||
# Set the working directory | ||
WORKDIR /contract | ||
|
||
# Build, optimize, and compress the WebAssembly binaries | ||
# Note: Since Alpine uses ash shell by default, the entrypoint is adjusted to use sh instead of bash. | ||
ENTRYPOINT ["/bin/sh", "-c", "\ | ||
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --locked && \ | ||
(mkdir -p ./optimized-wasm/ && rm -f ./optimized-wasm/* && cp ./target/wasm32-unknown-unknown/release/*.wasm ./optimized-wasm/) && \ | ||
for w in ./optimized-wasm/*.wasm; do \ | ||
wasm-opt -Oz $w -o $w ; \ | ||
done && \ | ||
(cd ./optimized-wasm && gzip -n -9 -f *) \ | ||
"] |