为什么我的货物依赖性不影响字节码的大小?

发布于 2025-01-23 06:52:37 字数 563 浏览 3 评论 0原文

我有一个准骨头生锈项目(特别是宇宙智能合约,不确定这是否重要)。当我运行货物构建时 - 释放-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-30 06:52:37

为什么字节码的大小仍然相同?我是否需要实际使用库,以使货物将库包括在字节码中?

是的。通常,只有使用使用的代码才会出现在编译器的最终输出中。 (在正常情况下)没有理由包含未使用的物品 -  它们会以无益的利益来扩大二进制文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文