Hi all,
This is a request for comment, open for the next couple days. We're thinking of changing the recommended command used to build contracts to:
cargo rustc --crate-type cdylib --target wasm32-unknown-unknown --release --package [your-contract-crate]
Instead of:
cargo build --target wasm32-unknown-unknown --release --package [your-contract-crate]
If you have a soroban project, you can try the new command now. Please give it a try. Let us know if you run into problems. All feedback appreciated!
Why:
cargo build will create larger wasm files if your crate happens to also be used as a library to be imported into other crates, such is the case when adding fuzzing to your project, or importing contract crate into another crate. This is unfortunately an intended limitation of cargo, and not something that'll likely ever change.
cargo rustc allows you to build wasm files in all cases without losing the compiler optimizations.
More details and examples here:
What
Change command recommended for building .wasm files for deployment
Why
Cargo/rust has an feature (not a bug unfortunately) that if a crate has multiple crate-types, like cdylib (wasm file) and...