From a8f268f2355a3ead9a4ced6c934d271c16b8d6b2 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 8 Dec 2021 12:19:48 +0100 Subject: [PATCH] Compile the Wasm node with -Os (#1729) --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 5 +++++ bin/wasm-node/javascript/prepare.js | 12 ++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b65a311c0..8cfff539a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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. diff --git a/Cargo.toml b/Cargo.toml index 5faac1d990..b22ad3cece 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/bin/wasm-node/javascript/prepare.js b/bin/wasm-node/javascript/prepare.js index c37ad8c4ef..a743661901 100755 --- a/bin/wasm-node/javascript/prepare.js +++ b/bin/wasm-node/javascript/prepare.js @@ -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. @@ -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' } ); @@ -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' } );