Tro*_*els 7 rust rust-cargo pyo3
我正在使用cargo,maturin和pytest来构建一个混合的 Python/Rust 项目。在开发过程中,我经常循环使用命令:
$ cargo test -p mypkg --release
$ maturin develop --release
$ python -m pytest --failed-first my_pkg
Run Code Online (Sandbox Code Playgroud)
看起来,cargo 和 maturin 正在编译依赖项,而没有理由这样做。经过一些实验,我发现如果我运行
cargo ...maturin ...cargo ...maturin ...即使我没有手动更改任何源文件,第二次运行cargo和也会重新编译依赖项。maturin
我没有一个小例子来重现这个问题,所以我尝试用完整的系统来调试它。为此,我想知道 Cargo 和/或 Maturin 认为哪些文件已经过时。一旦我知道了这一点,完整的解决方案可能就会显而易见。
但是,似乎没有我可以传递的标志来向我提供该信息。 cargo -vv test ...产生大量关于正在编译的内容和方式的输出,但不包括原因。 maturin甚至似乎没有-v可用的标志。
我发现了cargo-outdated,但这似乎与依赖版本有关。
我有两个 Rust 包,每个包都有 5-10 个直接依赖项和大约 100 个总依赖项。
如何找出哪些文件导致cargo/maturin重建依赖关系?
She*_*ter 13
您可以要求 Cargo 输出与指纹相关的日志信息。对于 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
Run Code Online (Sandbox Code Playgroud)