Skip to content

Commit a7e1eff

Browse files
committed
Use Windows_SDK.json from UE to determine what VS components to install
1 parent d7d4092 commit a7e1eff

File tree

8 files changed

+94
-179
lines changed

8 files changed

+94
-179
lines changed

docs/ue4-docker-build.adoc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ Use Linux containers under Windows hosts (useful when testing Docker Desktop or
147147
*--random-memory*::
148148
Use a random memory limit for Windows containers
149149

150-
*--visual-studio {2017,2019,2022}*::
151-
Specify Visual Studio Build Tools version.
152-
+
153-
By default, ue4-docker uses Visual Studio Build Tools 2017 to build Unreal Engine.
154-
Starting with Unreal Engine 4.25, you may choose to use Visual Studio Build Tools 2019 instead.
155-
+
156-
Unreal Engine 5.0 adds support for VS2022 but removes support for VS2017.
157-
158150
== Environment
159151

160152
This section describes several environment variables that affect how `ue4-docker build` operates.

src/ue4docker/build.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ def build():
200200
"Detected max image size: {:.0f}GB".format(DockerUtils.maxsize()),
201201
False,
202202
)
203-
logger.info(
204-
"Visual Studio: {}".format(config.visualStudio), False
205-
)
206203

207204
# Verify that the host OS is not a release that is blacklisted due to critical bugs
208205
if (
@@ -405,9 +402,6 @@ def build():
405402
prereqsArgs = prereqsArgs + [
406403
"--build-arg",
407404
"DLLSRCIMAGE=" + config.dllSrcImage,
408-
"--build-arg",
409-
"VISUAL_STUDIO_BUILD_NUMBER="
410-
+ config.visualStudio.build_number,
411405
]
412406

413407
custom_prerequisites_dockerfile = config.args.prerequisites_dockerfile

src/ue4docker/dockerfiles/ue4-build-prerequisites/windows/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ LABEL com.adamrehn.ue4-docker.sentinel="1"
5656
RUN reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
5757

5858
# Install Chocolatey
59-
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "$env:chocolateyVersion = '1.4.0'; Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
59+
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
6060

6161
# Install the rest of our build prerequisites and clean up afterwards to minimise image size
6262
COPY install-prerequisites.ps1 C:\
63-
ARG VISUAL_STUDIO_BUILD_NUMBER
64-
RUN powershell -ExecutionPolicy Bypass -File C:\install-prerequisites.ps1 %VISUAL_STUDIO_BUILD_NUMBER%
63+
RUN powershell -ExecutionPolicy Bypass -File C:\install-prerequisites.ps1

src/ue4docker/dockerfiles/ue4-build-prerequisites/windows/install-prerequisites.ps1

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -54,69 +54,12 @@ Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/1.4.304.0/windows/Vu
5454
Expand-Archive -Path "$env:TEMP\vulkan-runtime-components.zip" -DestinationPath "$env:TEMP"
5555
Copy-Item -Path "*\x64\vulkan-1.dll" -Destination C:\Windows\System32\
5656

57-
$visual_studio_build = $args[0]
58-
59-
if ($visual_studio_build -eq "15")
60-
{
61-
$windows_sdk_version = 18362
62-
}
63-
else
64-
{
65-
$windows_sdk_version = 20348
66-
}
67-
68-
# NOTE: We use the Visual Studio 2022 installer even for Visual Studio 2019 and 2017 here because the old (2017) installer now breaks
69-
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vs_buildtools.exe" -OutFile "$env:TEMP\vs_buildtools.exe"
70-
71-
# NOTE: Microsoft.NetCore.Component.SDK only exists for VS2019+. And it is actually *needed* only for UE5
72-
# NOTE: .NET 4.5 is required for some programs even in UE5, for example https://github.com/EpicGames/UnrealEngine/blob/5.0.1-release/Engine/Source/Programs/UnrealSwarm/SwarmCoordinator/SwarmCoordinator.csproj#L26
73-
# NOTE: Microsoft.NetCore.Component.Runtime.3.1 is required by the AutomationTool tool and does not come installed with VS2022 so it needs targetting here.
74-
$vs_args = @(
75-
"--quiet",
76-
"--wait",
77-
"--norestart",
78-
"--nocache",
79-
"--installPath", "C:\BuildTools",
80-
"--channelUri", "https://aka.ms/vs/$visual_studio_build/release/channel",
81-
"--installChannelUri", "https://aka.ms/vs/$visual_studio_build/release/channel",
82-
"--channelId", "VisualStudio.$visual_studio_build.Release",
83-
"--productId", "Microsoft.VisualStudio.Product.BuildTools",
84-
"--locale", "en-US",
85-
"--add", "Microsoft.VisualStudio.Workload.VCTools",
86-
"--add", "Microsoft.VisualStudio.Workload.MSBuildTools",
87-
"--add", "Microsoft.VisualStudio.Component.NuGet",
88-
"--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
89-
"--add", "Microsoft.VisualStudio.Component.Windows10SDK.$windows_sdk_version",
90-
"--add", "Microsoft.Net.Component.4.5.TargetingPack",
91-
"--add", "Microsoft.Net.Component.4.6.2.TargetingPack",
92-
"--add", "Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
93-
"--add", "Microsoft.NetCore.Component.SDK",
94-
"--add", "Microsoft.NetCore.Component.Runtime.3.1"
95-
)
96-
97-
# Install the Visual Studio Build Tools workloads and components we need
98-
RunProcessChecked "$env:TEMP\vs_buildtools.exe" $vs_args
99-
100-
# NOTE: Install the .Net 4.5 Framework Pack via NuGet as it is no longer available via Visual Studio, but still needed
101-
# NOTE: some programs even in UE5, for example https://github.com/EpicGames/UnrealEngine/blob/5.0.1-release/Engine/Source/Programs/UnrealSwarm/SwarmCoordinator/SwarmCoordinator.csproj#L26
102-
Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/package/Microsoft.NETFramework.ReferenceAssemblies.net45/1.0.3" -OutFile "$env:TEMP\DotNet45.zip"
103-
Expand-Archive -Path "$env:TEMP\DotNet45.zip" -DestinationPath "$env:TEMP"
104-
Copy-Item -Path "$env:TEMP\build\.NETFramework\v4.5\*" -Destination "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\" -Recurse -Force
105-
10657
# Clean up any temp files generated during prerequisite installation
10758
Remove-Item -LiteralPath "$env:TEMP" -Recurse -Force
10859
New-Item -Type directory -Path "$env:TEMP"
10960

11061
# This shaves off ~300MB as of 2021-08-31
11162
RunProcessChecked "choco-cleaner" @("--dummy")
11263

113-
# Something that gets installed in ue4-build-prerequisites creates a bogus NuGet config file
114-
# Just remove it, so a proper one will be generated on next NuGet run
115-
# See https://github.com/adamrehn/ue4-docker/issues/171#issuecomment-852136034
116-
if (Test-Path "$env:APPDATA\NuGet")
117-
{
118-
Remove-Item -LiteralPath "$env:APPDATA\NuGet" -Recurse -Force
119-
}
120-
12164
# Display a human-readable completion message
12265
Write-Output "Finished installing build prerequisites and cleaning up temporary files."

src/ue4docker/dockerfiles/ue4-source/windows/Dockerfile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# escape=`
22
{% if combine %}
3-
FROM prerequisites as source
3+
FROM prerequisites as source-prep
44
{% else %}
55
ARG NAMESPACE
66
ARG PREREQS_TAG
7-
FROM ${NAMESPACE}/ue4-build-prerequisites:${PREREQS_TAG}
7+
FROM ${NAMESPACE}/ue4-build-prerequisites:${PREREQS_TAG} as source-prep
88
{% endif %}
99

1010
{% if source_mode == "copy" %}
@@ -79,3 +79,19 @@ RUN Setup.bat -no-cache {{ gitdependencies_args }}
7979
ARG CHANGELIST
8080
COPY set-changelist.py C:\set-changelist.py
8181
RUN python C:\set-changelist.py C:\UnrealEngine\Engine\Build\Build.version %CHANGELIST%
82+
83+
{% if combine %}
84+
FROM prerequisites as source
85+
{% else %}
86+
ARG NAMESPACE
87+
ARG PREREQS_TAG
88+
FROM ${NAMESPACE}/ue4-build-prerequisites:${PREREQS_TAG} as source
89+
{% endif %}
90+
91+
# Only copy files required to determine Visual Studio version to avoid reinstalling it when minor engine changes happen
92+
COPY --from=source-prep C:\UnrealEngine\Engine\Config\Windows\Windows_SDK.json C:\UnrealEngine\Engine\Config\Windows\Windows_SDK.json
93+
94+
COPY install-vs.py C:\install-vs.py
95+
RUN python C:\install-vs.py C:\UnrealEngine\Engine\Config\Windows\Windows_SDK.json
96+
97+
COPY --from=source-prep C:\UnrealEngine C:\UnrealEngine
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import json
2+
import subprocess
3+
import sys
4+
from typing import Any
5+
from urllib import request
6+
7+
8+
class VisualStudio:
9+
def __init__(self, json_config: Any):
10+
self.version = json_config["MinimumVisualStudio2022Version"]
11+
self.components = sorted(set(
12+
[
13+
"Microsoft.VisualStudio.Workload.VCTools",
14+
"Microsoft.VisualStudio.Workload.MSBuildTools",
15+
"Microsoft.VisualStudio.Component.NuGet",
16+
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
17+
"Microsoft.NetCore.Component.SDK",
18+
]
19+
+ json_config["VisualStudioSuggestedComponents"]
20+
+ json_config["VisualStudio2022SuggestedComponents"]
21+
))
22+
23+
def download_installer(self, installer_path: str):
24+
print(f"Downloading Visual Studio {self.version}...")
25+
vs_installer_url = (
26+
f"https://aka.ms/vs/17/release.ltsc.{self.version}/vs_buildtools.exe"
27+
)
28+
request.urlretrieve(vs_installer_url, installer_path)
29+
30+
def install(self, installer_path: str):
31+
argv = [
32+
installer_path,
33+
"--quiet",
34+
"--wait",
35+
"--norestart",
36+
"--nocache",
37+
"--installPath",
38+
"C:/BuildTools",
39+
"--locale",
40+
"en-US",
41+
]
42+
43+
print(f"Installing Visual Studio {self.version}...")
44+
print("Components:")
45+
for component in self.components:
46+
argv.append("--add")
47+
argv.append(component)
48+
print(f" * {component}")
49+
50+
sys.stdout.flush()
51+
52+
subprocess.run(argv, check=True)
53+
54+
55+
if __name__ == "__main__":
56+
with open(sys.argv[1]) as windows_sdk_file:
57+
windows_sdk_json = json.load(windows_sdk_file)
58+
59+
vs = VisualStudio(windows_sdk_json)
60+
61+
vs_installer_path = "C:/vs_buildtools.exe"
62+
vs.download_installer(vs_installer_path)
63+
vs.install(vs_installer_path)

src/ue4docker/infrastructure/BuildConfiguration.py

Lines changed: 2 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import platform
33
import random
4-
from typing import Optional
54

65
import humanfriendly
76
from packaging.version import Version, InvalidVersion
@@ -40,53 +39,6 @@
4039
}
4140

4241

43-
class VisualStudio(object):
44-
def __init__(
45-
self,
46-
name: str,
47-
build_number: str,
48-
supported_since: Version,
49-
unsupported_since: Optional[Version],
50-
pass_version_to_buildgraph: bool,
51-
):
52-
self.name = name
53-
self.build_number = build_number
54-
self.supported_since = supported_since
55-
self.unsupported_since = unsupported_since
56-
self.pass_version_to_buildgraph = pass_version_to_buildgraph
57-
58-
def __str__(self) -> str:
59-
return self.name
60-
61-
62-
DefaultVisualStudio = "2017"
63-
64-
VisualStudios = {
65-
"2017": VisualStudio(
66-
name="2017",
67-
build_number="15",
68-
# We do not support versions older than 4.27
69-
supported_since=Version("4.27"),
70-
unsupported_since=Version("5.0"),
71-
pass_version_to_buildgraph=False,
72-
),
73-
"2019": VisualStudio(
74-
name="2019",
75-
build_number="16",
76-
supported_since=Version("4.27"),
77-
unsupported_since=Version("5.4"),
78-
pass_version_to_buildgraph=True,
79-
),
80-
"2022": VisualStudio(
81-
name="2022",
82-
build_number="17",
83-
supported_since=Version("5.0"),
84-
unsupported_since=None,
85-
pass_version_to_buildgraph=True,
86-
),
87-
}
88-
89-
9042
class ExcludedComponent(object):
9143
"""
9244
The different components that we support excluding from the built images
@@ -196,12 +148,6 @@ def addArguments(parser):
196148
metavar="VERSION",
197149
help="Add CUDA support as well as OpenGL support when building Linux containers",
198150
)
199-
parser.add_argument(
200-
"--visual-studio",
201-
default=DefaultVisualStudio,
202-
choices=VisualStudios.keys(),
203-
help="Specify Visual Studio Build Tools version to use for Windows containers",
204-
)
205151
parser.add_argument(
206152
"-username",
207153
default=None,
@@ -476,7 +422,7 @@ def __init__(self, parser, argv, logger):
476422
self.platformArgs = ["--no-cache"] if self.args.no_cache == True else []
477423
self.excludedComponents = set(self.args.exclude)
478424
self.baseImage = None
479-
self.prereqsTag = None
425+
self.prereqsTag: str | None = None
480426
self.ignoreBlacklist = self.args.ignore_blacklist
481427
self.verbose = self.args.verbose
482428
self.layoutDir = self.args.layout
@@ -605,41 +551,6 @@ def describeExcludedComponents(self):
605551
)
606552

607553
def _generateWindowsConfig(self):
608-
self.visualStudio = VisualStudios.get(self.args.visual_studio)
609-
if self.visualStudio is None:
610-
raise RuntimeError(
611-
f"unknown Visual Studio version: {self.args.visual_studio}"
612-
)
613-
614-
if self.release is not None and not self.custom:
615-
# Check whether specified Unreal Engine release is compatible with specified Visual Studio
616-
if (
617-
self.visualStudio.supported_since is not None
618-
and Version(self.release) < self.visualStudio.supported_since
619-
):
620-
raise RuntimeError(
621-
f"specified version of Unreal Engine is too old for Visual Studio {self.visualStudio.name}"
622-
)
623-
624-
if (
625-
self.visualStudio.unsupported_since is not None
626-
and Version(self.release) >= self.visualStudio.unsupported_since
627-
):
628-
raise RuntimeError(
629-
"Visual Studio {} is too old for specified version of Unreal Engine".format(
630-
self.visualStudio
631-
)
632-
)
633-
634-
# See https://github.com/EpicGames/UnrealEngine/commit/72585138472785e2ee58aab9950a7260275ee2ac
635-
# Note: We must not pass VS2019 arg for older UE4 versions that didn't have VS2019 variable in their build graph xml.
636-
# Otherwise, UAT errors out with "Unknown argument: VS2019".
637-
if self.visualStudio.pass_version_to_buildgraph:
638-
self.opts["buildgraph_args"] = (
639-
self.opts.get("buildgraph_args", "")
640-
+ f" -set:VS{self.visualStudio.name}=true"
641-
)
642-
643554
# Determine base tag for the Windows release of the host system
644555
self.hostBasetag = WindowsUtils.getHostBaseTag()
645556

@@ -655,7 +566,7 @@ def _generateWindowsConfig(self):
655566

656567
self.baseImage = "mcr.microsoft.com/windows/servercore:" + self.basetag
657568
self.dllSrcImage = WindowsUtils.getDllSrcImage(self.basetag)
658-
self.prereqsTag = self.basetag + "-vs" + self.visualStudio.name
569+
self.prereqsTag = self.basetag
659570

660571
# If the user has explicitly specified an isolation mode then use it, otherwise auto-detect
661572
if self.args.isolation is not None:

test-suite/test-ue-releases.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
class UERelease:
1616
def __init__(
17-
self, name: str, tag: str, repo: str, vsVersion: int, ubuntuVersion: str | None
17+
self, name: str, tag: str, repo: str, ubuntuVersion: str | None
1818
) -> None:
1919
self.name = name
2020
self.tag = tag
2121
self.repo = repo
22-
self.vsVersion = vsVersion
2322
self.ubuntuVersion = ubuntuVersion
2423

2524

@@ -29,13 +28,13 @@ def __init__(
2928

3029
# The list of Unreal Engine releases that are currently supported by ue4-docker
3130
SUPPORTED_RELEASES = [
32-
UERelease("4.27", "4.27.2-fixed", COMMITDEPS_REPO, 2017, None),
33-
UERelease("5.0", "5.0.3-fixed", COMMITDEPS_REPO, 2019, "20.04"),
34-
UERelease("5.1", "5.1.1-fixed", COMMITDEPS_REPO, 2019, None),
35-
UERelease("5.2", "5.2.1-release", UPSTREAM_REPO, 2022, None),
36-
UERelease("5.3", "5.3.2-release", UPSTREAM_REPO, 2022, None),
37-
UERelease("5.4", "5.4.4-release", UPSTREAM_REPO, 2022, None),
38-
UERelease("5.5", "5.5.1-release", UPSTREAM_REPO, 2022, None),
31+
UERelease("4.27", "4.27.2-fixed", COMMITDEPS_REPO, None),
32+
UERelease("5.0", "5.0.3-fixed", COMMITDEPS_REPO, "20.04"),
33+
UERelease("5.1", "5.1.1-fixed", COMMITDEPS_REPO, None),
34+
UERelease("5.2", "5.2.1-release", UPSTREAM_REPO, None),
35+
UERelease("5.3", "5.3.2-release", UPSTREAM_REPO, None),
36+
UERelease("5.4", "5.4.4-release", UPSTREAM_REPO, None),
37+
UERelease("5.5", "5.5.1-release", UPSTREAM_REPO, None),
3938
]
4039

4140

@@ -82,9 +81,7 @@ def testRelease(
8281
]
8382

8483
# Apply any platform-specific flags
85-
if platform.system() == "Windows":
86-
command += ["--visual-studio", release.vsVersion]
87-
elif release.ubuntuVersion is not None:
84+
if release.ubuntuVersion is not None:
8885
command += ["-basetag", f"ubuntu{release.ubuntuVersion}"]
8986

9087
# Attempt to run the build

0 commit comments

Comments
 (0)