-
Notifications
You must be signed in to change notification settings - Fork 120
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
Reduce wasm binary size with cargo-xbuild
& removing rlib
crate-type
#33
Conversation
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.
Very nice! All in all the code looks clean.
Worked for Flipper and ERC20 but not so well for Delegator.
(File not found error.)
robrob@t460p~/p/i/e/delegator> ./build-all.sh
~/projects/ink/examples/delegator/accumulator ~/projects/ink/examples/delegator
[1/4] Collecting crate metadata
[2/4] Building cargo project
[3/4] Post processing wasm file
ERROR: Can't read from the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }
~/projects/ink/examples/delegator
~/projects/ink/examples/delegator/adder ~/projects/ink/examples/delegator
[1/4] Collecting crate metadata
[2/4] Building cargo project
[3/4] Post processing wasm file
ERROR: Can't read from the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }
~/projects/ink/examples/delegator
~/projects/ink/examples/delegator/subber ~/projects/ink/examples/delegator
[1/4] Collecting crate metadata
[2/4] Building cargo project
[3/4] Post processing wasm file
ERROR: Can't read from the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }
~/projects/ink/examples/delegator
[1/4] Collecting crate metadata
[2/4] Building cargo project
[3/4] Post processing wasm file
[4/4] Optimizing wasm file
Original wasm size: 34K, Optimized: 14K
Your contract is ready. You can find it here:
/home/robrob/projects/ink/examples/delegator/target/delegator.wasm
Using Since I've also opened a PR to make it work with workspace configs (as our contract configs are): rust-osdev/cargo-xbuild#57 |
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.
LGTM!
You might want to write some release notes (for example into RELEASES.md
) for the 0.4
release since it is kinda ... big. :)
&tmp_manifest_path.cargo_arg(), | ||
&target_dir_arg, | ||
"--release", | ||
// "--no-default-features", // Breaks builds for MacOS (linker errors), we should investigate this issue asap! |
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.
I think --no-default-features
is wrong anyway because this tool performs IO, so for example cannot be no_std
.
pub fn directory(&self) -> Option<&Path> { | ||
let just_a_file_name = | ||
self.path.iter().collect::<Vec<_>>() == vec![Path::new(MANIFEST_FILE)]; | ||
if !just_a_file_name { |
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.
lol
Closes #32.
This PR significantly reduces the final wasm binary size by custom building rust
libcore
with thepanic_immediate_abort
feature which prevents panic strings and formatting code being included in the final executable.This is achieved using
cargo-xbuild
.rlib
crate-typerlib
is required to generate the metadata and also forink-as-dependency
. However it also causes bloat in the final Wasm blob so it will be automatically removed if enabled when runningcargo contract build
.Likewise if the
Cargo.toml
doesn't have therlib
incrate-types
and the user runsgenerate-metadata
, then that will also be added temporarily in order for build to succeed.A copy of the users
Cargo.toml
is made, amended as necessary and written to a temporary directory. Relative paths are rewritten to absolute paths.todo
User option to restore original Cargo.toml if process terminated(superseded)xbuild
cargo clean
(file not found)generate-metadata
to work.cargo/config
linkargsAddSee Add default[profile.release]
section, use provided values by default?[profile.release]
values to Cargo.toml if not present #40--verbose
and--quiet
args,quiet
by default