Skip to content

Commit 3cd92c8

Browse files
committed
Add support for MSVC toolchain on Windows Server Core
This dockerfile cannot be pushed to public hubs due to licensing restrictions, but we might as well provide the dockerfile for others and test against it. Please see the comment at the top of the MSVC template file for more information.
1 parent bbc7feb commit 3cd92c8

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# escape=`
2+
3+
# IMAGES BUILT FROM THIS DOCKERFILE ARE NOT TO BE SHARED ON PUBLIC DOCKER HUBs.
4+
#
5+
# WARNING: NON-FREE AND DISTRIBUTION RESTRICTED ENCUMBERED SOFTWARE IN IMAGE.
6+
#
7+
# The VS Build Tools are very encumbered.
8+
#
9+
# IMAGE SHOULD ONLY BE BUILT BY USERS WHO CAN FOLLOW THESE TERMS:
10+
# https://visualstudio.microsoft.com/license-terms/mlt553512/
11+
#
12+
# See the fourth paragraph of this blog post for a warning from a Microsoftie:
13+
# https://blogs.msdn.microsoft.com/vcblog/2018/08/13/using-msvc-in-a-docker-container-for-your-c-projects/
14+
#
15+
# """
16+
# The VS Build Tools are licensed as a supplement to your existing Visual Studio license.
17+
# Any images built with these tools should be for your personal use or for use in your
18+
# organization in accordance with your existing Visual Studio and Windows licenses.
19+
# Please don’t share these images on a public Docker hub.
20+
# """
21+
#
22+
# That said, this Dockerfile will be built in a CI system for validation and testing in the project
23+
# but most definitely will skip deployment.
24+
25+
FROM mcr.microsoft.com/windows/servercore:1809
26+
27+
SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
28+
29+
RUN $url = 'https://download.visualstudio.microsoft.com/download/pr/20130c62-1bc8-43d6-b4f0-c20bb7c79113/7276a7355219f7988c480d198e23c2973bbb7ab971c4f0415c26cab2955344e5/vs_BuildTools.exe'; `
30+
$sha256 = '7276A7355219F7988C480D198E23C2973BBB7AB971C4F0415C26CAB2955344E5'; `
31+
Invoke-WebRequest -Uri $url -OutFile C:\vs_BuildTools.exe; `
32+
$actual256 = (Get-FileHash vs_BuildTools.exe -Algorithm sha256).Hash; `
33+
if ($actual256 -ne $sha256) { `
34+
Write-Host 'FAILED!'; `
35+
Write-Host ('expected: {0}' -f $sha256); `
36+
Write-Host ('got: {0}' -f $actual256); `
37+
exit 1; `
38+
}; `
39+
Start-Process -filepath C:\vs_BuildTools.exe -wait -argumentlist ' `
40+
--quiet --wait --norestart --nocache `
41+
--installPath C:\BuildTools `
42+
--add Microsoft.Component.MSBuild `
43+
--add Microsoft.VisualStudio.Component.Windows10SDK.17763 `
44+
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64'; `
45+
Remove-Item 'C:\\vs_BuildTools.exe'; `
46+
Remove-Item -Force -Recurse 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer'; `
47+
[Environment]::SetEnvironmentVariable('__VSCMD_ARG_NO_LOGO', '1', [EnvironmentVariableTarget]::Machine)
48+
49+
ENV RUSTUP_HOME=C:\rustup `
50+
CARGO_HOME=C:\cargo `
51+
RUST_VERSION=1.50.0
52+
53+
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; `
54+
$url = 'https://static.rust-lang.org/rustup/archive/1.23.1/x86_64-pc-windows-msvc/rustup-init.exe'; `
55+
$sha256 = 'a586cf9de3e4aa791fd5796b6a5f99ca05591ccef8bb94e53af5b69f0261fb03'; `
56+
Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; `
57+
$actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; `
58+
if ($actual256 -ne $sha256) { `
59+
Write-Host 'FAILED!'; `
60+
Write-Host ('expected: {0}' -f $sha256); `
61+
Write-Host ('got: {0}' -f $actual256); `
62+
exit 1; `
63+
}; `
64+
New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; `
65+
$newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); `
66+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); `
67+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); `
68+
C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-msvc; `
69+
Remove-Item C:\rustup-init.exe; `
70+
rustup -V; `
71+
cargo -V; `
72+
rustc -V

Dockerfile-windows-msvc.template

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# escape=`
2+
3+
# IMAGES BUILT FROM THIS DOCKERFILE ARE NOT TO BE SHARED ON PUBLIC DOCKER HUBs.
4+
#
5+
# WARNING: NON-FREE AND DISTRIBUTION RESTRICTED ENCUMBERED SOFTWARE IN IMAGE.
6+
#
7+
# The VS Build Tools are very encumbered.
8+
#
9+
# IMAGE SHOULD ONLY BE BUILT BY USERS WHO CAN FOLLOW THESE TERMS:
10+
# https://visualstudio.microsoft.com/license-terms/mlt553512/
11+
#
12+
# See the fourth paragraph of this blog post for a warning from a Microsoftie:
13+
# https://blogs.msdn.microsoft.com/vcblog/2018/08/13/using-msvc-in-a-docker-container-for-your-c-projects/
14+
#
15+
# """
16+
# The VS Build Tools are licensed as a supplement to your existing Visual Studio license.
17+
# Any images built with these tools should be for your personal use or for use in your
18+
# organization in accordance with your existing Visual Studio and Windows licenses.
19+
# Please don’t share these images on a public Docker hub.
20+
# """
21+
#
22+
# That said, this Dockerfile will be built in a CI system for validation and testing in the project
23+
# but most definitely will skip deployment.
24+
25+
FROM mcr.microsoft.com/windows/servercore:%%WINDOWS-VERSION%%
26+
27+
SHELL ["powershell.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
28+
29+
RUN $url = 'https://download.visualstudio.microsoft.com/download/pr/20130c62-1bc8-43d6-b4f0-c20bb7c79113/7276a7355219f7988c480d198e23c2973bbb7ab971c4f0415c26cab2955344e5/vs_BuildTools.exe'; `
30+
$sha256 = '7276A7355219F7988C480D198E23C2973BBB7AB971C4F0415C26CAB2955344E5'; `
31+
Invoke-WebRequest -Uri $url -OutFile C:\vs_BuildTools.exe; `
32+
$actual256 = (Get-FileHash vs_BuildTools.exe -Algorithm sha256).Hash; `
33+
if ($actual256 -ne $sha256) { `
34+
Write-Host 'FAILED!'; `
35+
Write-Host ('expected: {0}' -f $sha256); `
36+
Write-Host ('got: {0}' -f $actual256); `
37+
exit 1; `
38+
}; `
39+
Start-Process -filepath C:\vs_BuildTools.exe -wait -argumentlist ' `
40+
--quiet --wait --norestart --nocache `
41+
--installPath C:\BuildTools `
42+
--add Microsoft.Component.MSBuild `
43+
--add Microsoft.VisualStudio.Component.Windows10SDK.%%SDK-BUILD%% `
44+
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64'; `
45+
Remove-Item 'C:\\vs_BuildTools.exe'; `
46+
Remove-Item -Force -Recurse 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer'; `
47+
[Environment]::SetEnvironmentVariable('__VSCMD_ARG_NO_LOGO', '1', [EnvironmentVariableTarget]::Machine)
48+
49+
ENV RUSTUP_HOME=C:\rustup `
50+
CARGO_HOME=C:\cargo `
51+
RUST_VERSION=%%RUST-VERSION%%
52+
53+
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; `
54+
$url = 'https://static.rust-lang.org/rustup/archive/%%RUSTUP-VERSION%%/x86_64-pc-windows-msvc/rustup-init.exe'; `
55+
$sha256 = '%%RUSTUP-SHA256%%'; `
56+
Invoke-WebRequest -Uri $url -OutFile C:\rustup-init.exe; `
57+
$actual256 = (Get-FileHash rustup-init.exe -Algorithm sha256).Hash; `
58+
if ($actual256 -ne $sha256) { `
59+
Write-Host 'FAILED!'; `
60+
Write-Host ('expected: {0}' -f $sha256); `
61+
Write-Host ('got: {0}' -f $actual256); `
62+
exit 1; `
63+
}; `
64+
New-Item ${env:CARGO_HOME}\bin -type directory | Out-Null; `
65+
$newPath = ('{0}\bin;{1}' -f ${env:CARGO_HOME}, ${env:PATH}); `
66+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); `
67+
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Process); `
68+
C:\rustup-init.exe -y -v --no-modify-path --default-toolchain ${env:RUST_VERSION} --default-host x86_64-pc-windows-msvc; `
69+
Remove-Item C:\rustup-init.exe; `
70+
rustup -V; `
71+
cargo -V; `
72+
rustc -V

x.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,25 @@
3838

3939
default_alpine_version = "3.13"
4040

41+
# (Windows Server tag, Windows SDK build number)
42+
# The build number is specifically used to select the right Windows 10 SDK to
43+
# install from the Visual Studio Build Tools installer. See
44+
# https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019#c-build-tools
45+
# for the build version numbers.
46+
windows_servercore_versions = [
47+
("1809", "17763"),
48+
]
49+
4150
def rustup_hash(arch):
4251
url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch}/rustup-init.sha256"
4352
with request.urlopen(url) as f:
4453
return f.read().decode('utf-8').split()[0]
4554

55+
def rustup_hash_windows(arch):
56+
url = f"https://static.rust-lang.org/rustup/archive/{rustup_version}/{arch}/rustup-init.exe.sha256"
57+
with request.urlopen(url) as f:
58+
return f.read().decode('utf-8').split()[0]
59+
4660
def read_file(file):
4761
with open(file, "r") as f:
4862
return f.read()
@@ -100,6 +114,17 @@ def update_alpine():
100114
.replace("%%ARCH-CASE%%", arch_case)
101115
write_file(f"{rust_version}/alpine{version}/Dockerfile", rendered)
102116

117+
def update_windows():
118+
template = read_file("Dockerfile-windows-msvc.template")
119+
for version, build in windows_servercore_versions:
120+
rendered = template \
121+
.replace("%%RUST-VERSION%%", rust_version) \
122+
.replace("%%RUSTUP-VERSION%%", rustup_version) \
123+
.replace("%%WINDOWS-VERSION%%", version) \
124+
.replace("%%SDK-BUILD%%", build) \
125+
.replace("%%RUSTUP-SHA256%%", rustup_hash_windows("x86_64-pc-windows-msvc"))
126+
write_file(f"{rust_version}/windowsservercore-{version}/msvc/Dockerfile", rendered)
127+
103128
def update_travis():
104129
file = ".travis.yml"
105130
config = read_file(file)
@@ -209,6 +234,7 @@ def usage():
209234
update_debian()
210235
update_alpine()
211236
update_travis()
237+
update_windows()
212238
elif task == "generate-stackbrew-library":
213239
generate_stackbrew_library()
214240
else:

0 commit comments

Comments
 (0)