Reputation: 595
I have a barebones Rust project (specifically a CosmWasm smart contract, not sure if that matters). When I run cargo build --release --target wasm32-unknown-unknown
, the uncompressed Wasm bytecode is about 1.7 MB.
Then I add the following dependency:
evm = "1.18.0"
and I add a patch:
[patch.crates-io]
evm = { path = "../../../evm" }
where the path leads to this project: https://github.com/neonlabsorg/evm
Then I re-run cargo build --release --target wasm32-unknown-unknown
. I see that it is indeed building the EVM project and its dependencies. But when I look at the final uncompressed Wasm bytecode, it is still 1.7 MB! Why is the size of the bytecode still the same? Do I need to actually use the library in order for cargo to include the library in the bytecode?
Thank you!
Upvotes: 0
Views: 224
Reputation: 43773
Why is the size of the bytecode still the same? Do I need to actually use the library in order for cargo to include the library in the bytecode?
Yes. In general, only code that is used will appear in the final output of the compiler. There is (in normal circumstances) no reason to include unused items — they would enlarge the binary for no benefit.
Upvotes: 3