Rust - Error: Could not compile winapi

I tried the Windows OS in my Rust project and encountered an error during the build process.

Here are some highlights from the job log:

error: linking with `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\link.exe` failed: exit code: 1181

= note: LINK : fatal error LNK1181: cannot open input file 'advapi32.lib'

error: aborting due to previous error
error: Could not compile `winapi`.

Here’s the link to the full job log:

The winapi crate is a dependency of the rand crate that I’m using in this project. The rand crate is pretty popular, so I expect a lot of Rust projects failing to build/test on Windows as well given this issue.

1 Like

I don’t have any windows experience but it looks like the windows SDK is missing in the windows builds:

We’re also seeing the error in the Clippy CI build:

1 Like

For what it’s worth, this is what I use when creating Windows VM images for Servo’s CI:

$client = New-Object
$client.DownloadFile("", "C:\vs_buildtools.exe")
Start-Process C:\vs_buildtools.exe -ArgumentList (`
        "--passive --norestart --includeRecommended " +
        "--add Microsoft.VisualStudio.Workload.VCTools " +
        "--add Microsoft.VisualStudio.Component.VC.ATL " +
        "--add Microsoft.VisualStudio.Component.VC.ATLMFC"
) -Wait

(This is Powershell, but in case you use something else you get the idea.)

VCTools with recommended components should be enough to build and link Rust code with the x86_64-pc-windows-msvc toolchain. ATL is an additional dependency of SpiderMonkey.

1 Like

Seems like a problem related to using VS 2017 in the build image.

Rust currently knows about VS 2013 and 2015, and needs few env vars to be set up.
Look at for more details.


I added

if [ $TRAVIS_OS_NAME = windows ]; then
  choco install windows-sdk-10.0

to my setup script and it solved this issue


Hi Everyone

I changed our image to know include:

visualstudio2017buildtools --package-parameters "--allWorkloads --includeRecommended --includeOptional --quiet --norestart --locale en-US --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.ATLMFC"

I believe this has fixed the link.exe issue.

These packages might be overkill, all advice welcome.

Thank you for you help on this @danreeves and @SimonSapin


Thanks @josh. I was able to test this update by rerunning the Windows jobs and it worked on Rust stable. Unfortunately, the jobs for beta and nightly Rust failed. Here are the relevant parts of the log:

$ curl -sSf | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION -y
error: could not copy directory from 'C:\Users\travis\.rustup\tmp\vzp4uuxez717jya2_dir\rust- docs\share/doc/rust/html' to 'C:\Users\travis\.rustup\toolchains\beta-x86_64-pc-windows- msvc\share/doc/rust/html'
info: caused by: There is not enough space on the disk. (os error 112)

The command "curl -sSf | sh -s -- --default-toolchain=$TRAVIS_RUST_VERSION -y" failed and exited with 1 during .

I guess the additional items recently added to the image is making the disk almost full. Are you able to check how much disk space is available before any of the build specific tasks begin (before git clone)?.

Those are definitely overkill, I think they probably take up too much space for most projects to be able to build.

My guess is you should just need windows-sdk-10.1 and maybe microsoft-build-tools.

I was trying to to figure out the minimal packages you need, but ran into too many issues

Hopefully over the week, or Monday latest, we will increase the disk size to 60gb temporarily while we try to figure out what is best.

As for the job stalling when trying to install windows-sdk-10.1, I believe that is because that package tries to restart the VM using shutdown.exe. Could you try rerunning with --package-parameters "--quiet --wait --norestart"?

I tried to use choco optimize, which cleans up downloads and frees up space, but that is only for the licensed version.

Happy to try more ideas :slight_smile:


Hi All

I have released a new image which has more disk space available thanks to a choco package which helped me clean up some files.

For the time being I think we can class the winapi compile issue as resolved. If you have further issues with disk space could you please open a new topic (for better tracking).

Have a great weekend!

I had the same problem.
After installing two packages with Chocolatey as follows, it started to work.

choco install visualstudio2019buildtools
choco install visualstudio2019-workload-vctools