如何在不清理整个项目的情况下强制 `build.rs` 再次运行? [英] How can I force `build.rs` to run again without cleaning my whole project?

查看:24
本文介绍了如何在不清理整个项目的情况下强制 `build.rs` 再次运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不清理整个项目的情况下强制 build.rs 再次运行?我检查了 cargo build --help,但找不到与 build.rs 相关的任何内容.

How can I force build.rs to run again without cleaning my whole project? I checked cargo build --help but I couldn't find anything related to build.rs.

推荐答案

如果打印

"cargo:rerun-if-changed=<FILE>"

每次文件更改时都会触发构建.

the build will be triggered every time the file has changed.

rerun-if-changed=PATH 是文件或目录的路径,表示构建脚本发生变化时应重新运行(由最近的最后修改时间戳检测)在文件上).通常,如果 crate 根目录中的任何文件发生更改,构建脚本会重新运行,但这可用于将更改范围限定为一小组文件.-- 来源

rerun-if-changed=PATH is a path to a file or directory which indicates that the build script should be re-run if it changes (detected by a more-recent last-modified timestamp on the file). Normally build scripts are re-run if any file inside the crate root changes, but this can be used to scope changes to just a small set of files. -- source

我不知道没有手动更改文件的解决方案(我只是在我的 build.rs 中的任何地方放了一个空格,但它会被 rustfmt 删除).

I'm not aware of a solution without changing a file manually (I just put a whitespace anywhere in my build.rs, it will be removed by rustfmt though).

我的项目中有几个构建脚本,主要是这两行给了我一个很好的解决方案:

I have several buildscripts in my projects, and mostly these two lines give me a nice solution:

println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=path/to/Cargo.lock");

但我猜你正在寻找一个命令 rustc/cargo 命令.无论如何,您可以放入一个小脚本,该脚本将编辑某个文件,从而触发构建过程.

but I guess you are looking for a command rustc/cargo command. Anyway, you can put in a small script, which will edit a certain file, which will trigger the build-process.

这篇关于如何在不清理整个项目的情况下强制 `build.rs` 再次运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆