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:

https://api.travis-ci.org/v3/job/440473144/log.txt

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: https://users.rust-lang.org/t/problems-with-installing-rust-on-windows/9349

We’re also seeing the error in the Clippy CI build: https://travis-ci.org/rust-lang-nursery/rust-clippy/jobs/440485576#L325

1 Like

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

$client = New-Object system.net.WebClient
$client.DownloadFile("https://aka.ms/vs/15/release/vs_buildtools.exe", "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 https://github.com/rust-lang/rust/issues/52683 for more details.

2 Likes

I added

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

to my setup script and it solved this issue

4 Likes

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"
visualstudio2017-workload-netcorebuildtools
visualstudio2017-workload-vctools
visualstudio2017-workload-webbuildtools
windows-sdk-10.0
microsoft-build-tools
vcredist2017

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

2 Likes

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 https://sh.rustup.rs | 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 https://sh.rustup.rs | 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)?.

@josh
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:

2 Likes

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