为什么我的货物依赖性不影响字节码的大小?
我有一个准骨头生锈项目(特别是宇宙智能合约,不确定这是否重要)。当我运行货物构建时 - 释放-target Wasm32未知
时,未压缩的WASM字节码约为1.7 MB。
然后,我添加以下依赖性: evm =“ 1.18.0”
,然后添加一个补丁:
[patch.crates-io]
evm = { path = "../../../evm" }
路径导致此项目: https://github.com/neonlabsorg/evm
然后,我重新运行货物构建-release -target wasm32-Ingnown-Ingnown-Ingnown
。我看到它确实正在构建EVM项目及其依赖性。但是,当我查看最终的未压缩WASM字节码时,它仍然是1.7 MB!为什么字节码的大小仍然相同?我是否需要实际使用该库,以使货物将库包括在字节码中?
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。通常,只有使用使用的代码才会出现在编译器的最终输出中。 (在正常情况下)没有理由包含未使用的物品 -  它们会以无益的利益来扩大二进制文件。
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.