我正在使用cargo、maturin和pytest来构建一个混合Python/Rust项目。在开发过程中,我经常循环执行以下命令:
$ cargo test -p mypkg --release
$ maturin develop --release
$ python -m pytest --failed-first my_pkg在没有理由这样做的情况下,货运和maturin似乎在编译依赖项。经过一些实验,我发现如果我跑
cargo ...maturin ...cargo ...maturin ...cargo和maturin的第二次运行将重新编译依赖项,即使我没有手动更改任何源文件。
我没有一个小的例子来重现这个例子,所以我尝试用整个系统来调试它。要做到这一点,我想知道哪些文件,货物和/或马图林认为是过时的。一旦我知道了,完整的解决方案可能是显而易见的。
然而,似乎没有标志,我可以传递给我的信息。cargo -vv test ...产生了大量关于它正在编译什么以及如何编译的输出,但没有提供原因。maturin甚至似乎没有可用的-v标志。
我找到了cargo-outdated,但这似乎是关于依赖型版本的。
我有两个锈蚀包,每一个有5-10个直接依赖项和大约100个总依赖项。
如何找出导致cargo/maturin重新构建依赖项的文件?
发布于 2021-11-30 18:16:05
您可以要求货物输出与指纹相关的日志信息。在Cargo 1.56.0中,适当的环境变量是CARGO_LOG=cargo::core::compiler::fingerprint=info。
例如:
% CARGO_LOG=cargo::core::compiler::fingerprint=info cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
% touch src/main.rs
% CARGO_LOG=cargo::core::compiler::fingerprint=info cargo build
[2021-11-30T18:13:54Z INFO cargo::core::compiler::fingerprint] stale: changed "/private/tmp/xxx/src/main.rs"
[2021-11-30T18:13:54Z INFO cargo::core::compiler::fingerprint] (vs) "/private/tmp/xxx/target/debug/.fingerprint/xxx-3af563e7d679143a/dep-bin-xxx"
[2021-11-30T18:13:54Z INFO cargo::core::compiler::fingerprint] FileTime { seconds: 1638295984, nanos: 344057437 } != FileTime { seconds: 1638296033, nanos: 750100000 }
[2021-11-30T18:13:54Z INFO cargo::core::compiler::fingerprint] fingerprint error for xxx v0.1.0 (/private/tmp/xxx)/Build/TargetInner { name: "xxx", doc: true, ..: with_path("/private/tmp/xxx/src/main.rs", Edition2021) }
[2021-11-30T18:13:54Z INFO cargo::core::compiler::fingerprint] err: current filesystem status shows we're outdated发布于 2021-12-03 21:14:11
这是针对下一个用户的具体问题的解决方案。
CARGO_LOG environment variable answer起作用了。它产生了大量的输出
[2021-11-30T18:29:06Z INFO cargo::core::compiler::fingerprint] err: RUSTFLAGS has changed: previously [], now ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]我确信maturin在构建由python导入的库时添加了这些标志。
有一次,我看到了一种修改Cargo.toml的方法,以便在使用cargo进行构建时添加这些内容。
我的解决方案更简单:我使用
cargo test -p mypkg # no --release这样,cargo就可以构建和测试调试代码以及maturin/pytest构建和测试发布代码。这些标志是不一致的,但在某种程度上并不重要。如果maturin更改了它添加的标志,我不需要更新我的标志。
这确实意味着,当依赖关系发生变化时,我会构建两次,但这比在每个周期构建它们两次要好得多。
https://stackoverflow.com/questions/70174147
复制相似问题