Skip to content

Commit e23c079

Browse files
committed
feat: Add build.detect-antivirus config option
To allow disabling the warning.
1 parent ac13a9d commit e23c079

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,18 @@ impl BuildConfig {
130130
_ => Vec::new(),
131131
};
132132

133-
// Enabled by default (for now only when the unstable flag is set).
134-
let detect_antivirus = gctx.cli_unstable().detect_antivirus;
133+
let detect_antivirus = match (cfg.detect_antivirus, gctx.cli_unstable().detect_antivirus) {
134+
// Enabled by default (for now only when the flag is set).
135+
(None, unstable_flag) => unstable_flag,
136+
// But allow overriding with configuration option.
137+
(Some(cfg_option), true) => cfg_option,
138+
(Some(_), false) => {
139+
gctx.shell().warn(
140+
"ignoring 'build.detect-antivirus' config, pass `-Zdetect-antivirus` to enable it",
141+
)?;
142+
false
143+
}
144+
};
135145

136146
Ok(BuildConfig {
137147
requested_kinds,

src/cargo/core/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ unstable_cli_options!(
854854
checksum_freshness: bool = ("Use a checksum to determine if output is fresh rather than filesystem mtime"),
855855
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
856856
config_include: bool = ("Enable the `include` key in config files"),
857-
detect_antivirus: bool = ("Enable the experimental antivirus detection"),
857+
detect_antivirus: bool = ("Enable the experimental antivirus detection and the config option to disable it"),
858858
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
859859
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
860860
feature_unification: bool = ("Enable new feature unification modes in workspaces"),

src/cargo/util/context/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,8 @@ pub struct CargoBuildConfig {
27702770
pub sbom: Option<bool>,
27712771
/// Unstable feature `-Zbuild-analysis`.
27722772
pub analysis: Option<CargoBuildAnalysis>,
2773+
/// Unstable feature `-Zdetect-antivirus`.
2774+
pub detect_antivirus: Option<bool>,
27732775
}
27742776

27752777
/// Metrics collection for build analysis.

src/doc/src/reference/unstable.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,24 @@ This layout change unblocks work towards caching and locking improvements.
19541954

19551955
The `-Zdetect-antivirus` flag enables detection of antivirus software that might make launching a binary for the first time slower (which in turn makes Cargo's build scripts and tests slower), and outputs a notice to the user if this is the case.
19561956

1957-
This feature will be enabled by default in the future.
1957+
This feature will be enabled by default in the future (the flag acts as-if this future is now).
1958+
1959+
```toml
1960+
# Example ~/.cargo/config.toml
1961+
1962+
# Disable warning, e.g. if using a workplace-issued Mac that
1963+
# doesn't allow granting Developer Tool permissions.
1964+
[build]
1965+
detect-antivirus = false
1966+
```
1967+
1968+
### `build.detect-antivirus`
1969+
1970+
* Type: boolean
1971+
* Default: true (when `-Zdetect-antivirus` is enabled)
1972+
* Environment: CARGO_BUILD_DETECT_ANTIVIRUS
1973+
1974+
Allow opting out of antivirus detection.
19581975

19591976

19601977
# Stabilized and removed features

tests/testsuite/cargo/z_help/stdout.term.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)