-
Notifications
You must be signed in to change notification settings - Fork 52
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
Rust build image optimizations #1054
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96fd64d
(fix): Dockerfile template updated for rust
namesty cc07ae5
(feat): rust image performance tests
namesty 49874f0
(fix): performance test
namesty e9d24f1
(chore): improved mustache template
namesty b085f3e
(chore): removed unnecessary code from template
namesty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
80 changes: 80 additions & 0 deletions
80
packages/test-cases/cases/cli/wasm/build-benchmarks/001-rust/current/Dockerfile
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,80 @@ | ||
FROM rust:1.60.0 as base | ||
|
||
# Install the wasm32 rust build target | ||
RUN rustup target add wasm32-unknown-unknown | ||
|
||
WORKDIR /build-deps | ||
|
||
# Install curl | ||
RUN apt-get update | ||
RUN apt-get -y install curl clang llvm build-essential | ||
|
||
# Install wasm-opt | ||
RUN curl -L https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz | tar -xz \ | ||
&& chmod +x binaryen-version_101/bin/wasm-opt \ | ||
&& cp binaryen-version_101/bin/wasm-opt /usr/local/bin/ \ | ||
&& rm -rf binary-version_101 | ||
|
||
# Install the toml-cli | ||
RUN cargo install -f toml-cli | ||
|
||
# Install wasm-snip | ||
RUN cargo install -f wasm-snip | ||
|
||
# Install wasm-bindgen | ||
RUN cargo install -f wasm-bindgen-cli | ||
|
||
WORKDIR /project | ||
|
||
# Copy all manifest files | ||
COPY polywrap.yaml . | ||
COPY polywrap.build.yaml . | ||
|
||
# Copy all source files | ||
COPY ./Cargo.toml ./Cargo.toml | ||
COPY ./src ./src | ||
COPY ./schema.graphql ./schema.graphql | ||
COPY ./plugin.schema.graphql ./plugin.schema.graphql | ||
|
||
# Remove any Cargo.lock files | ||
RUN rm -rf ./Cargo.lock | ||
|
||
# Ensure the Wasm module is configured to use imported memory | ||
ENV RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory" | ||
|
||
# Ensure the module at . has the crate-type = ["cdylib"] | ||
RUN toml set ././Cargo.toml lib.crate-type ["cdylib"] > ././Cargo-local.toml && \ | ||
rm -rf ././Cargo.toml && \ | ||
mv ././Cargo-local.toml ././Cargo.toml && \ | ||
true | ||
|
||
# Clean up artifacts left by the toml CLI program ("["cdylib"]" -> ["cdylib"]) | ||
RUN sed -i 's/"\[cdylib\]"/\["cdylib"\]/g' ././Cargo.toml | ||
|
||
# Ensure the package name = "module" | ||
RUN toml set ././Cargo.toml package.name "module" > ././Cargo-local.toml && \ | ||
rm -rf ././Cargo.toml && \ | ||
mv ././Cargo-local.toml ././Cargo.toml && \ | ||
true | ||
|
||
# Make the build directory | ||
RUN rm -rf ./build | ||
RUN mkdir ./build | ||
|
||
# Build the module at . | ||
RUN cargo build --manifest-path ././Cargo.toml \ | ||
--target wasm32-unknown-unknown --release | ||
|
||
# Enable the "WASM_INTERFACE_TYPES" feature, which will remove the __wbindgen_throw import. | ||
# See: https://github.com/rustwasm/wasm-bindgen/blob/7f4663b70bd492278bf0e7bba4eeddb3d840c868/crates/cli-support/src/lib.rs#L397-L403 | ||
ENV WASM_INTERFACE_TYPES=1 | ||
|
||
# Run wasm-bindgen over the module, replacing all placeholder __wbindgen_... imports | ||
RUN wasm-bindgen ././target/wasm32-unknown-unknown/release/module.wasm --out-dir ./build --out-name bg_module.wasm | ||
|
||
RUN wasm-snip ./build/bg_module.wasm -o ./build/snipped_module.wasm && \ | ||
rm -rf ./build/bg_module.wasm | ||
|
||
# Use wasm-opt to perform the "asyncify" post-processing step over all modules | ||
RUN wasm-opt --asyncify -Os ./build/snipped_module.wasm -o ./build/wrap.wasm && \ | ||
rm -rf ./build/snipped_module.wasm |
24 changes: 24 additions & 0 deletions
24
packages/test-cases/cases/wrappers/wasm-rs/benchmarks/Cargo.toml
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,24 @@ | ||
[package] | ||
name = "module" | ||
version = "0.1.0" | ||
description = "Query module of bigint-type e2e test" | ||
authors = [ | ||
"Kobby Pentangeli <kobbypentangeli@gmail.com>", | ||
"Jordan Ellis <jelli@dorg.tech>" | ||
] | ||
repository = "https://github.com/polywrap/monorepo" | ||
license = "MIT" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
polywrap-wasm-rs = { path = "../../../../../../wasm/rs" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
ethers = "0.14.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[profile.release] | ||
opt-level = 's' | ||
lto = true | ||
panic = 'abort' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge this as
skip
ped for now, but we should probably make a benchmarking project that does this in the near future.