rust - 如何在 CI 上出现警告时导致编译失败并在 .cargo/config 中设置额外的 rustflags?
问题描述
解决方案
您可以使用built::util::detect_ci()
来确定当前构建是否在 CI 下执行。然后你可以使用一个小的构建脚本来设置一个 cfg
货运.toml
[package]
build = true
[build-dependencies]
built = { version = "0.3", default_features = false }
构建.rs
fn main() {
if let Some(ci) = built::util::detect_ci() {
// There may be a better way to do this
println!("cargo:rustc-cfg=DENY_WARNINGS");
println!("cargo:warning=Denying warnings because we are in CI \"{}\"", ci);
}
}
请注意,构建脚本的结果是缓存的,所以一旦这个构建脚本运行并且 Cargo 决定我们是否在 CI 下运行,它会一直使用这个结果,直到您修改构建脚本或cargo clean
. 这对于本地开发或 CI 来说都不是问题,除非 Scotty 定期向您提供帮助。
main.rs或lib.rs
#![cfg_attr(DENY_WARNINGS, deny(warnings))]
fn main() {
// This will be a warning locally but fail to compile e.g. if built on Travis
Result::<(), ()>::Err(());
}
推荐阅读
- ruby-on-rails - rufus-scheduler 只用 puma 执行一次 rake 任务
- mysql - SQL 使用 csv 源路径创建表
- c++ - JsonCpp:如何将 unordered_map 转换为 Json::Value
- windows - 是否存在与 SID 1:1 映射的可读 Windows 用户帐户 ID?
- vue.js - Vuex - this.$store.commit 还是 state.commit?
- git - 您使用什么工具或技术来跨存储库同步配置?
- amazon-web-services - 如何将 api 网关(带有 api 密钥)添加到现有的 lambda cloudformation 模板?
- ios - cellForRowAtIndexPath 为不可见的单元格返回 nil
- ios - 在 XCode 11 中使用 FreeForm 作为模拟大小时,无法使 UIView 适合 UIViewController 的完整大小
- kubernetes - 在 OpenShift 上预填充持久卷