From ed72e75799786e26b4a244aa612f303b9668c668 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Wed, 10 Nov 2021 21:03:20 +0200 Subject: [PATCH 1/2] `-Clinker-plugin-lto` reduced the size of my contract From: Original wasm size: 68.6K, Optimized: 31.9K To: Original wasm size: 67.2K, Optimized: 31.0K --- src/cmd/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 2a5fdf06..4ab069b0 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -249,7 +249,7 @@ fn exec_cargo_for_wasm_target( // Currently will override user defined RUSTFLAGS from .cargo/config. See https://github.com/paritytech/cargo-contract/issues/98. std::env::set_var( "RUSTFLAGS", - "-C link-arg=-zstack-size=65536 -C link-arg=--import-memory", + "-C link-arg=-zstack-size=65536 -C link-arg=--import-memory -Clto -Clinker-plugin-lto", ); let cargo_build = |manifest_path: &ManifestPath| { -- GitLab From 86a10caf1c6abcb05b4ab870ab1f2d541d067432 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Thu, 11 Nov 2021 18:43:18 +0200 Subject: [PATCH 2/2] Compiler will use `-Clinker-plugin-lto` if `lto` is enabled --- src/cmd/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 4ab069b0..0d32be54 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -249,7 +249,7 @@ fn exec_cargo_for_wasm_target( // Currently will override user defined RUSTFLAGS from .cargo/config. See https://github.com/paritytech/cargo-contract/issues/98. std::env::set_var( "RUSTFLAGS", - "-C link-arg=-zstack-size=65536 -C link-arg=--import-memory -Clto -Clinker-plugin-lto", + "-C link-arg=-zstack-size=65536 -C link-arg=--import-memory -Clinker-plugin-lto", ); let cargo_build = |manifest_path: &ManifestPath| { -- GitLab