Skip to content

Commit 33bd6be

Browse files
committed
feat: Add -Zdetect-antivirus flag
1 parent 8ce3636 commit 33bd6be

File tree

5 files changed

+59
-35
lines changed

5 files changed

+59
-35
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub struct BuildConfig {
5252
pub sbom: bool,
5353
/// Build compile time dependencies only, e.g., build scripts and proc macros
5454
pub compile_time_deps_only: bool,
55+
/// Whether we should try to detect and notify the user when antivirus
56+
/// software might make newly created binaries slow to launch.
57+
pub detect_antivirus: bool,
5558
}
5659

5760
fn default_parallelism() -> CargoResult<u32> {
@@ -127,6 +130,9 @@ impl BuildConfig {
127130
_ => Vec::new(),
128131
};
129132

133+
// Enabled by default (for now only when the unstable flag is set).
134+
let detect_antivirus = gctx.cli_unstable().detect_antivirus;
135+
130136
Ok(BuildConfig {
131137
requested_kinds,
132138
jobs,
@@ -145,6 +151,7 @@ impl BuildConfig {
145151
timing_outputs,
146152
sbom,
147153
compile_time_deps_only: false,
154+
detect_antivirus,
148155
})
149156
}
150157

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +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"),
857858
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
858859
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
859860
feature_unification: bool = ("Enable new feature unification modes in workspaces"),
@@ -1373,6 +1374,7 @@ impl CliUnstable {
13731374
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
13741375
"config-include" => self.config_include = parse_empty(k, v)?,
13751376
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
1377+
"detect-antivirus" => self.detect_antivirus = parse_empty(k, v)?,
13761378
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
13771379
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
13781380
"fix-edition" => {

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ where `<compatible-ver>` is the latest version supporting rustc {rustc_version}"
556556
}
557557
}
558558

559+
if build_config.detect_antivirus {
560+
// TODO(madsmtm): Actually implement the check.
561+
}
562+
559563
let bcx = BuildContext::new(
560564
ws,
561565
pkg_set,

src/doc/src/reference/unstable.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ Each new feature described below should explain how to use it.
131131
* [Package message format](#package-message-format) --- Message format for `cargo package`.
132132
* [`fix-edition`](#fix-edition) --- A permanently unstable edition migration helper.
133133
* [Plumbing subcommands](https://github.com/crate-ci/cargo-plumbing) --- Low, level commands that act as APIs for Cargo, like `cargo metadata`
134+
* [Detect antivirus](#detect-antivirus) --- Detect whether newly created binaries may be slow to launch due to antivirus.
134135

135136
## allow-features
136137

@@ -1947,6 +1948,14 @@ enabled = true
19471948
Enables the new build-dir filesystem layout.
19481949
This layout change unblocks work towards caching and locking improvements.
19491950

1951+
## Detect Antivirus
1952+
1953+
* Tracking Issue: [#0](https://github.com/rust-lang/cargo/issues/0)
1954+
1955+
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.
1956+
1957+
This feature will be enabled by default in the future.
1958+
19501959

19511960
# Stabilized and removed features
19521961

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

Lines changed: 37 additions & 35 deletions
Loading

0 commit comments

Comments
 (0)