Rust inside Windows containers

I created msbuild:ltsc2016 docker image using the following dockerfile:

# escape=`


# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

# Download the Build Tools bootstrapper.
ADD C:\TEMP\vs_buildtools.exe

# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
    --installPath C:\BuildTools `
    --includeRecommended `
    --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools `
    --add Microsoft.VisualStudio.Workload.MSBuildTools `
    --add Microsoft.VisualStudio.Workload.VCTools `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
RUN del C:\TEMP\vs_buildtools.exe

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
# ENTRYPOINT ["C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

And then I created an image for Rust MSVC:

# escape=`

FROM msbuild:ltsc2016

ADD C:\TEMP\rustup-init.exe

RUN C:\TEMP\rustup-init.exe -y -v --default-toolchain stable-x86_64-pc-windows-msvc
RUN del C:\TEMP\rustup-init.exe

Both dockerfiles build just fine. But there's a problem: when I try to build anything using rust-msvc, Rust errors about link.exe not being found. So it find out, Rust cannot find VS Build Tools, even though they are installed.

I tried to workaround this by adding the following file to C:\Users\ContainerAdministrator\.cargo\config:

linker = "C:\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\Hostx64\\x64\\link.exe"

And now Rust can find the linker. But unfortunately it can't find advapi32.lib instead.

My question is:

  • Is there a sane way to set the MSVC path for Rust?
  • If not, how do I make it work anyway?

Hmm... you could try running the vcvarsall.bat before invoking Rust. I think it should be here:


I think this will set the right environment variables.

This doesn't seem to help unfortunately.

Adding Microsoft.Component.VC.Runtime.UCRTSDK and Microsoft.VisualStudio.Component.Windows10SDK to install options fixed the issue with link.exe.

But instead I have got a new problem:

    Compiling typenum v1.12.0
    Compiling byteorder v1.3.4
      Running `rustc --crate-name build_script_main C:\Users\ContainerAdministrator\.cargo\registry\src\\typenum-1.12.0\build/ --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=52e7ed0d2e9d1000 -C extra-filename=-52e7ed0d2e9d1000 --out-dir C:\drone\src\target\debug\build\typenum-52e7ed0d2e9d1000 -L dependency=C:\drone\src\target\debug\deps --cap-lints allow`
      Running `rustc --crate-name build_script_build C:\Users\ContainerAdministrator\.cargo\registry\src\\byteorder-1.3.4\ --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1856c3fc328eff2c -C extra-filename=-1856c3fc328eff2c --out-dir C:\drone\src\target\debug\build\byteorder-1856c3fc328eff2c -L dependency=C:\drone\src\target\debug\deps --cap-lints allow`
 error: could not parse/generate dep info at: C:\drone\src\target\debug\build\typenum-52e7ed0d2e9d1000\build_script_main-52e7ed0d2e9d1000.d

 Caused by:
   The system cannot find the file specified. (os error 2)
 warning: build failed, waiting for other jobs to finish...
 error: could not parse/generate dep info at: C:\drone\src\target\debug\build\byteorder-1856c3fc328eff2c\build_script_build-1856c3fc328eff2c.d

UPDATE: this may be related to

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.