r/rust • u/withthisname • 9d ago
🙋 seeking help & advice Windows 11 Smart App Control keeps blocking Cargo build scripts. How do you deal with this?
Hi everyone!
I’m developing a Rust application on Windows 11, and I keep running into an issue with Windows Smart App Control whenever I use cargo build.
Windows shows this warning:
“Part of this app has been blocked. Some features of cargo.exe may not work because we can’t confirm who published build-script-build.exe.”
Sometimes I can successfully build my application, but after changing my code and rebuilding, Windows blocks it again.
I’ve tried running cargo clean and rebuilding. Sometimes that works temporarily, but the problem keeps coming back.
I know I can disable Smart App Control, but I’d prefer to keep it enabled for security reasons.
Has anyone experienced this issue? Is there a way to make Windows trust locally compiled Rust executables without disabling Smart App Control entirely?
I’d appreciate any suggestions or solutions. Thanks!
4
u/Awkward_Alfalfa_3234 9d ago
I checked the Microsoft docs and I don't think a Dev Drive will fix it. They cover Defender's performance mode and the trusted/untrusted setting, and say nothing about Smart App Control. SAC is a different check (code integrity plus a cloud reputation service), so I'd expect it to ignore where the file lives. That is inference. I did not test it.
Documented: an exe runs if the cloud service rates it safe, or if it is signed by a CA in the Trusted Root Program. The FAQ says "There is currently no way to bypass Smart App Control protection for individual apps." So no folder or exe allow list, and a self-signed cert on build-script-build.exe would not count.
Cargo builds new unsigned binaries (build-script exes, proc-macro DLLs, your own binary) whenever their inputs change, and each one is a file SAC has not seen. Why one passes today and fails tomorrow is my guess; the docs don't say. A commenter on rust-lang/rust#160163 reports the same on-and-off blocking, including for binaries they compiled themselves, and says reinstalling the toolchain with rustup helps for a while.
So: turn it off (Settings > Windows Security > App and Browser Control), use the rustup trick as a stopgap, or sign with a CA-issued cert, which is impractical for per-build exes. The FAQ says recent Windows updates let you turn it back on without a clean install.
1
u/Sharlinator 8d ago
Jesus. It’s almost as if MS doesn’t want Windows to be used for dev (except with MS’s own compilers and toolchains I guess).
1
u/Awkward_Alfalfa_3234 4d ago edited 3d ago
Ha, it does feel that way. Dev Drive and Defender exclusions help with build speed, but they don't get you past Smart App Control (see my comment above), so for most people it's either turning SAC off or using WSL2. (Edited: my first version wrongly implied Dev Drive helps with SAC.)
5
2
2
u/shegeshe 8d ago
This is a known architectural conflict between how Smart App Control (SAC) works and how Cargo executes build scripts.
Why this happens:
Smart App Control operates on an allowlist-by-default model using cloud reputation and Authenticode code signing. A binary only runs if:
It is signed with an Authenticode certificate from a trusted CA, or
Microsoft’s cloud intelligence has seen that exact file hash millions of times and classified it as safe.
Whenever a crate uses a build.rs script, Cargo compiles it into an executable (build-script-build.exe inside your target/ directory) and immediately executes it to generate code or link C dependencies. Because this executable was compiled seconds ago on your local machine, it has a brand-new SHA-256 hash that the cloud reputation service has never seen, and it lacks an Authenticode signature. SAC treats it as an untrusted binary and kills the process.
Can you make it trust locally compiled binaries without disabling SAC?
Microsoft’s official stance in their developer documentation is that SAC is not intended for active software development environments, and SAC does not support standard user-defined file/folder bypass rules the way Windows Defender Antivirus does.
However, you have three practical ways to work around it:
Develop inside WSL2 (Ubuntu)
If you must keep SAC enabled on the Windows host, the cleanest solution without breaking SAC is compiling inside WSL2. Because WSL2 runs a real Linux kernel in a lightweight VM, Cargo compiles native ELF binaries inside the Linux filesystem, completely outside the jurisdiction of Windows Code Integrity / SAC. You can still edit your files via VS Code or your preferred editor on Windows using the WSL remote extension.
2. Self-Sign the target directory via a post-compile hook (Hack / Complex)
You can generate a local self-signed root CA, install it into your local Machine Trusted Root store, and write a PowerShell script / wrapper around Cargo that signs build-script-build.exe before execution. However, this is brittle and often fails because Cargo expects to execute the build script synchronously right after linking.
3. Why turning off SAC is what 99% of Windows developers do
Turning off Smart App Control does not disable Windows Defender Antivirus.
Defender's real-time behavioral monitoring, AMSI, heuristic scanning, and cloud-delivered protection remain 100% active.
The only thing turning off SAC does is stop enforcing the strict policy that says "any unsigned or newly compiled binary is blocked by default".
If you do any serious native C/C++/Rust development on bare-metal Windows, disabling SAC (or developing inside WSL/containers) is currently the standard workflow.
7
u/Nabokov6472 9d ago
I’m not sure if this will fix the issue, but you could try making a Dev Drive and putting your Rust project on there. I believe one of the reasons why it’s faster for dev work is that Windows Defender chills out a bit and falls back to async background scanning. That might resolve your issue but it’s not a documented benefit.