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

Configurable wasm builds #148

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

CyberHoward
Copy link

@CyberHoward CyberHoward commented Mar 8, 2024

Updated version of #130

The need for featured contract compilation has been thoroughly discussed in issue #80. This PR upstreams the ability to optimize smart-contracts with different features, without hurting reproducibility.

Example

As an example let's say you have some functionality that should only be enabled on some specific chain. Currently it's extremely hard to do this without creating different contracts.

Our solution uses cargo's support for custom metadata fields to allow you to specify features that you want your contract to be built with.

I.e. if I want different logic when deploying to the cw-sdk then I add a feature in the contract's Cargo.toml like so:

[features]
cw-sdk = []

To trigger the optimizer into building the contract with this feature add the following to the same Cargo.toml:

[package.metadata.optimizer]
default-build = true
builds = [
  { name = "cw-sdk", features = [
    "cw-sdk",
  ] }
]

After running the optimizer image as usual you will be left with:

  • my_contract.wasm
  • my_contract-cw-sdk.wasm

When using the ARM image:

  • my_contract-aarch64.wasm
  • my_contract-cw-sdk-aarch64.wasm

Extra features

  • @apollo-sturdy requested the ability to disable WASM compilation with default features. This is solved by the default-build boolean. (defaults to true)
  • A suggestion was made in the previous PR to add WASM optimization configuration to this metadata. This currently can't be done as the optimization call is executed from the optimize.sh script which is not under control of the Rust code. This could be changed in a future PR.

Discussion

Some questions were raised about the additional caching layer that prevents re-build if the build settings are identical. I left this caching layer in place because we (Abstract) make extensive use of it. See here. However as mentioned re-building a previously built package shouldn't take much time.
Edit: We decided to remove this layer.

@apollo-sturdy
Copy link

@webmaster128 Any chance you have time to review and merge this? Would be very helpful for us.

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. This is great stuff, thanks a lot.

Some comments and an improvement PR here: https://github.com/CyberHoward/optimizer/pull/1/files

I will do another round looking into the caching and ask a collegue to give it another round. But happy to get this finally moving.

bob_the_builder/src/cargo_toml.rs Show resolved Hide resolved
bob_the_builder/src/cargo_toml.rs Outdated Show resolved Hide resolved
@CyberHoward
Copy link
Author

Applied feedback, thanks!

@apollo-sturdy for the default-build, do you want the ability to build without default features or does the current solution work for you?

@webmaster128
Copy link
Member

webmaster128 commented May 15, 2024

Not directly related but FYI I think we should get rid of the aarch64 suffixes at some point. I don't think they have value anymore. #151

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 this pull request may close these issues.

None yet

3 participants