Skip to content
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

Use Xargo for building Wasm contracts #32

Closed
Robbepop opened this issue Feb 4, 2020 · 2 comments · Fixed by #33
Closed

Use Xargo for building Wasm contracts #32

Robbepop opened this issue Feb 4, 2020 · 2 comments · Fixed by #33

Comments

@Robbepop
Copy link
Contributor

Robbepop commented Feb 4, 2020

This is a contender issue for: #22

It solves the same problems but with a different tool. For more details visit the linked issue.
Instead of invoking Cargo in order to build ink! smart contracts we should instead build them using Xargo (https://crates.io/crates/xargo).

This requires another Xargo.toml in the contract's root directory with the following contents:

[target.wasm32-unknown-unknown.dependencies]
core = {default-features=false, features=["panic_immediate_abort"]}
std = {default-features=false, features=["panic_immediate_abort"]}
alloc = {}

Also we have to remove the contents of the .cargo/config file to not override Xargo settings: (We demonstrate this here by simply commenting the line out.)

[target.wasm32-unknown-unknown]
rustflags = [
#	"-C", "link-args=-z stack-size=65536 --import-memory"
]

Another obstacle is that currently Cargo (or rustc) overrides profile settings given in Cargo.toml when rlib is specified as in:

[lib]
name = "erc20"
crate-type = [
	# Used for normal contract Wasm blobs.
	"cdylib",
	# Used for ABI generation.
	"rlib",
]

Unfortunately in ink! we use rlib for generating ink! metadata.
For automating this process we have to somehow get rid of this rlib field during compilation in order to NOT to override the following profile section in Cargo.toml:

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
codegen-units = 1

All these settings are very important to get all the important optimizations in the final Wasm binary.

After taking all these steps building a highly optimized ink! Wasm smart contract is just:

xargo build --no-default-features --target wasm32-unknown-unknown --release

So simply exchange cargo with xargo.
Also this still requires a pass by wasm-opt afterwards so this pass should be run before applying wasm-opt for final optimizations.

@ascjones
Copy link
Collaborator

ascjones commented Feb 4, 2020

Link for potential future cargo integration: https://github.com/rust-lang/wg-cargo-std-aware/ because of japaric/xargo#193

Possible alternative: https://github.com/rust-osdev/cargo-xbuild

@pepyakin
Copy link
Contributor

pepyakin commented Feb 4, 2020

Note that I haven't even tried to solve the issue with rustflags. I think it might be possible to workaround it by providing multiple -Clink-arg or somehow play with quotes.

@ascjones Good find! Didn't know that Xargo is in maintenance mode and I expected that this should be eventually be handled by cargo itself, especially in light of this announcment. However, the fact that the issue was created 20 Jan 2018 a bit discouraging... I hope for the best though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants