Reduce wasm binary size with `cargo-xbuild` & removing `rlib` crate-type

Sergej Kostjucenko requested to merge aj-xargo into master

Created by: ascjones

Closes #32 (closed).

This PR significantly reduces the final wasm binary size by custom building rust libcore with the panic_immediate_abort feature which prevents panic strings and formatting code being included in the final executable.

This is achieved using cargo-xbuild.

rlib crate-type

rlib is required to generate the metadata and also for ink-as-dependency. However it also causes bloat in the final Wasm blob so it will be automatically removed if enabled when running cargo contract build.

Likewise if the Cargo.toml doesn't have the rlib in crate-types and the user runs generate-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

  • For generate-metadata modify Cargo.toml to add "rlib" crate-type
  • User option to restore original Cargo.toml if process terminated (superseded)
  • Use tmp dir for amended manifests
  • Convert to xbuild
  • Test all happy and unhappy paths
  • Bug with building after build then cargo clean (file not found)
  • Figure out discrepancy of reported opt file size vs actual
  • Test all ink! examples work
  • Fix Delegator build
  • Get generate-metadata to work
  • Remove .cargo/config linkargs Add [profile.release] section, use provided values by default? See #40
  • Add --verbose and --quiet args, quiet by default

Merge request reports