Closed CyberHoward closed 5 months ago
@webmaster128 Any chance you have time to review and merge this? Would be very helpful for us.
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?
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. https://github.com/CosmWasm/optimizer/issues/151
Cool!
Last question here: are we happy with the naming "default-features" and "default-build" to close to each other? Isn't this likely to cause confusion amongst contract devs who don't have a very clear understanding of how those things relate to each other? Should we rename one, e.g. "default-build" -> "standard-build"?
I'll merge this now and then change the terms to
in a separate PR. Feel free to disagree and let me know.
Thanks a lot for this contributions!
Follow-up work is here: https://github.com/CosmWasm/optimizer/pull/156
Great job @CyberHoward
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'sCargo.toml
like so:To trigger the optimizer into building the contract with this feature add the following to the same
Cargo.toml
: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
default
features. This is solved by thedefault-build
boolean. (defaults totrue
)optimize.sh
script which is not under control of the Rust code. This could be changed in a future PR.default-features = false
attribute.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.