Skip to content

Commit 8ac03f5

Browse files
Export environment from vcvars64.bat
Resolves #13. Some build scripts want to have the compiler and/or linker on the `PATH` (such as `blt.mond`). On Windows, this is usually achieved by running a Visual Studio `cmd` shell which sets the appropriate environment. However, I didn't see a simple way to do this in the `Dockerfile` for `powershell` (Windows has no equivalent of `source` in `bash`). Instead, we use a variant of a hack described on [Stack Overflow](https://stackoverflow.com/a/2124759). Note the call to `[Environment]::SetEnvironmentVariable`. Simply setting variables in `$env:` will not persist beyond a single `RUN` command.
1 parent 5e53c5a commit 8ac03f5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

windows/Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ RUN .\vcpkg-master\vcpkg install @(Get-Content C:\vc-packages.txt)
5353
# Tell the `vcpkg` crate to generate dynamically linked executables
5454
ENV VCPKGRS_DYNAMIC=1
5555

56+
# Export environment from `vcvars64.bat` in powershell. This puts `cl.exe` and
57+
# others on our `PATH`.
58+
#
59+
# Powershell doesn't have an equivalent of `source`, so we use `cmd` to run
60+
# `vcvars64.bat`, then parse each environment variable and set it manually.
61+
# See https://stackoverflow.com/a/2124759.
62+
RUN cd 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build'; `
63+
cmd /c 'vcvars64.bat & set' | `
64+
%{ if ($_ -match '=') { $v = $_.split('='); [System.Environment]::SetEnvironmentVariable($v[0], $v[1], [System.EnvironmentVariableTarget]::Machine) } }
65+
5666
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

0 commit comments

Comments
 (0)