Skip to content

Commit

Permalink
Compile the Wasm node with -Os (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Dec 8, 2021
1 parent c28ebb4 commit a8f268f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ jobs:
- run: cargo install twiggy # TODO: somehow cache this in order to not compile twiggy every single time
- run: git checkout ${{ github.event.pull_request.base.sha }}
- run: cd bin/wasm-node/javascript && npm ci && npm run-script build
- run: cp ./target/wasm32-wasi/release/smoldot_light_wasm.wasm ./.ci-parent-build.wasm # TODO: update path after https://github.com/paritytech/smoldot/pull/1729
- run: cp ./target/wasm32-wasi/release/smoldot_light_wasm.wasm ./.ci-parent-build.wasm # TODO: update the path, plus maybe get the path from the `npm build` output or something?
- run: git checkout ${{ github.event.pull_request.head.sha }}
- run: cd bin/wasm-node/javascript && npm ci && npm run-script build
- run: twiggy diff ./.ci-parent-build.wasm ./target/wasm32-wasi/release/smoldot_light_wasm.wasm > ./twiggy-diff # TODO: update path after https://github.com/paritytech/smoldot/pull/1729
- run: twiggy diff ./.ci-parent-build.wasm ./target/wasm32-wasi/min-size-release/smoldot_light_wasm.wasm > ./twiggy-diff # TODO: maybe get the path from the `npm build` output or something?
# Now that we've generated the diff in a `./twiggy-diff` file, the next step is to upload
# the PR number and diff content as an artifact that will then be picked up by a
# `workflow_run` action that does the actual commenting.
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ panic = "abort"
lto = true
#strip = "symbols" # TODO: uncomment once stable

[profile.min-size-release]
inherits = "release"
lto = true
opt-level = "z"

[[bench]]
name = "header"
harness = false
12 changes: 6 additions & 6 deletions bin/wasm-node/javascript/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ if (process.argv.slice(2).indexOf("--debug") !== -1) {
if (process.argv.slice(2).indexOf("--release") !== -1) {
if (build_profile)
throw new Error("Can't pass both --debug and --release");
build_profile = 'release';
build_profile = 'min-size-release';
}
if (build_profile != 'debug' && build_profile != 'release')
if (build_profile != 'debug' && build_profile != 'min-size-release')
throw new Error("Either --debug or --release must be passed");

// The Rust version to use.
Expand Down Expand Up @@ -61,8 +61,8 @@ child_process.execSync(
// The important step in this script is running `cargo build --target wasm32-wasi` on the Rust
// code. This generates a `wasm` file in `target/wasm32-wasi`.
child_process.execSync(
"cargo +" + rust_version + " build --package smoldot-light-wasm --target wasm32-wasi --no-default-features"
+ (build_profile == 'debug' ? '' : ' --' + build_profile),
"cargo +" + rust_version + " build --package smoldot-light-wasm --target wasm32-wasi --no-default-features " +
(build_profile == 'debug' ? '' : ("--profile " + build_profile)),
{ 'stdio': 'inherit' }
);

Expand All @@ -71,9 +71,9 @@ child_process.execSync(
// use the `.wasm` generated by the Rust compiler.
let fallback_copy = false;
try {
if (build_profile == 'release') {
if (build_profile == 'min-size-release') {
child_process.execSync(
"wasm-opt -o src/autogen/tmp.wasm -Os --strip-debug --vacuum --dce "
"wasm-opt -o src/autogen/tmp.wasm -Oz --strip-debug --vacuum --dce "
+ "../../../target/wasm32-wasi/" + build_profile + "/smoldot_light_wasm.wasm",
{ 'stdio': 'inherit' }
);
Expand Down

0 comments on commit a8f268f

Please sign in to comment.