使用 Cargo 时如何获得带有调试信息的发布版本?

2024-03-05

以下命令

$ cargo build

产生一个未优化 build with调试信息。相反,

$ cargo build --release

产生一个优化 build without调试信息。

有没有一种方法可以产生优化 build with调试信息?我需要它来获取有意义的分析信息。


As of 铁锈 1.57 https://github.com/rust-lang/rust/blob/1.57.0/RELEASES.md#cargo,货物现在允许自定义配置文件 https://doc.rust-lang.org/cargo/reference/profiles.html#custom-profiles。这允许您定义自己的配置文件来添加调试信息:

[profile.release-with-debug]
inherits = "release"
debug = true

然后您可以在构建时使用该配置文件:

% cargo build --profile=release-with-debug
   Compiling buggin v0.1.0 (/tmp/buggin)
    Finished release-with-debug [optimized + debuginfo] target(s) in 0.48s

在此版本之前,或者如果您always想要有调试信息,可以修改release profile https://doc.rust-lang.org/cargo/reference/profiles.html包含调试符号:

[profile.release]
debug = true

请注意,release简介和bench轮廓不同。

See also

  • 可以使用 Cargo 在发布模式下构建测试吗? https://stackoverflow.com/q/29818084/155423
  • 如何在启用溢出检查的情况下编译和运行优化的 Rust 程序 https://stackoverflow.com/q/34054669/155423
  • Cargo 是否支持自定义配置文件? https://stackoverflow.com/q/41920192/155423

或者基本上是“rust profiling”的任何热门搜索结果:

  • OSX 上使用 Instruments 和 FlameGraph 进行 Rust 分析:CPU/时间 http://carol-nichols.com/2015/12/09/rust-profiling-on-osx-cpu-time/
  • 在 Linux 上分析 Rust 应用程序 https://llogiq.github.io/2015/07/15/profiling.html
  • 使用 callgrind 分析 Rust 代码 https://web.archive.org/web/20170508162645/https://shunyata.github.io/2015/10/01/profiling-rust/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Cargo 时如何获得带有调试信息的发布版本? 的相关文章

随机推荐