From ed72e75799786e26b4a244aa612f303b9668c668 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Wed, 10 Nov 2021 21:03:20 +0200 Subject: [PATCH 1/3] `-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/3] 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 From 14835b32d39491e727b9e530410bccb8b3767fd7 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Tue, 16 Nov 2021 16:20:57 +0200 Subject: [PATCH 3/3] Updated Unreleased section --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 439dfb4f..4ac96a65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Use of `-Clinker-plugin-lto` flag(reduces the size of the contract) if `lto` is enabled - [#358](https://github.com/paritytech/cargo-contract/pull/358) + ## [0.15.0] - 2021-10-18 ### Changed -- GitLab