@@ -43,7 +43,7 @@ use crate::core::compiler::UserIntent;
43
43
use crate :: core:: compiler:: unit_dependencies:: build_unit_dependencies;
44
44
use crate :: core:: compiler:: unit_graph:: { self , UnitDep , UnitGraph } ;
45
45
use crate :: core:: compiler:: { BuildConfig , BuildContext , BuildRunner , Compilation } ;
46
- use crate :: core:: compiler:: { CompileKind , CompileTarget , RustcTargetData , Unit } ;
46
+ use crate :: core:: compiler:: { CompileKind , CompileMode , CompileTarget , RustcTargetData , Unit } ;
47
47
use crate :: core:: compiler:: { CrateType , TargetInfo , apply_env_config, standard_lib} ;
48
48
use crate :: core:: compiler:: { DefaultExecutor , Executor , UnitInterner } ;
49
49
use crate :: core:: profiles:: Profiles ;
@@ -561,15 +561,34 @@ where `<compatible-ver>` is the latest version supporting rustc {rustc_version}"
561
561
}
562
562
563
563
if build_config. detect_antivirus {
564
- // TODO(madsmtm): Maybe only do this when we have above a certain
565
- // number of build scripts or test binaries to run?
564
+ // Count the number of test binaries and build scripts we'll need to
565
+ // run. This doesn't take into account the binary that will be run
566
+ // if `cargo run` was specified, and doesn't handle pre-2024 `rustdoc`
567
+ // tests, but that's fine, this is only a heuristic.
568
+ let num_binaries = unit_graph
569
+ . keys ( )
570
+ . filter ( |unit| {
571
+ matches ! (
572
+ unit. mode,
573
+ CompileMode :: Test | CompileMode :: Doctest | CompileMode :: RunCustomBuild
574
+ )
575
+ } )
576
+ . count ( ) ;
577
+
578
+ tracing:: debug!( "estimated {num_binaries} binaries that could be slowed down by antivirus" ) ;
566
579
567
580
// TODO(madsmtm): Consider only warning once every X days.
568
581
569
- // We don't want to do this check when installing, since there might
570
- // be `cargo install` users who are not necessarily developers (and so
571
- // the note will be irrelevant to them).
572
- if build_config. intent != UserIntent :: Install {
582
+ // Heuristic: Only do the check if we have to run more than a specific
583
+ // number of binaries. This makes it so that small beginner projects
584
+ // don't hit this.
585
+ //
586
+ // TODO(madsmtm): What should the threshold be?
587
+ //
588
+ // We also don't want to do this check when installing, since there
589
+ // might be `cargo install` users who are not necessarily developers
590
+ // (and so the note will be irrelevant to them).
591
+ if 10 < num_binaries && build_config. intent != UserIntent :: Install {
573
592
if let Err ( err) = detect_antivirus:: detect_and_report ( gctx) {
574
593
// Errors in this detection are not fatal.
575
594
tracing:: error!( "failed detecting whether binaries may be slow to run: {err}" ) ;
0 commit comments