Skip to content

Commit ac422bf

Browse files
authored
compilers: Compute the number of linker jobs (#984)
Best guesstimate puts the amount of RAM required per linker job at around 24 GiB. This allows us to remove the last differences betwen the upstream and downstream swift-toolchain workflow.
1 parent f1503d0 commit ac422bf

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

.github/workflows/swift-toolchain.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,19 @@ jobs:
10531053
10541054
$SwiftFlags += " -sdk `"${SDKROOT}`""
10551055
1056+
# Compute the number of parallel jobs to use for the build.
1057+
$RamBytes = if ($IsWindows) {
1058+
(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory
1059+
} elseif ($IsMacOS) {
1060+
[int64](sysctl -n hw.memsize)
1061+
} else {
1062+
throw "Unsupported OS"
1063+
}
1064+
$RamGB = [math]::Round($RamBytes / 1GB)
1065+
1066+
# Consider 24 GB per link job, to a minimum of 2 jobs.
1067+
$LinkJobs = [math]::Max(2, [math]::Floor($RamGB / 24))
1068+
10561069
# Output the context for the configure task.
10571070
$Context = @"
10581071
cc=${CC}
@@ -1066,6 +1079,7 @@ jobs:
10661079
python_include_dir=${PYTHON_INCLUDE_DIR}
10671080
python_binary=${PYTHON_BINARY}
10681081
sdkroot=${SDKROOT}
1082+
link_jobs=${LinkJobs}
10691083
"@
10701084
Write-Output $Context | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
10711085
@@ -1134,8 +1148,8 @@ jobs:
11341148
-D LLDB_LIBXML2_VERSION="${{ inputs.libxml2_version }}" `
11351149
-D PACKAGE_VENDOR=compnerd.org `
11361150
-D SWIFT_VENDOR=compnerd.org `
1137-
-D LLVM_PARALLEL_LINK_JOBS=2 `
1138-
-D SWIFT_PARALLEL_LINK_JOBS=2 `
1151+
-D LLVM_PARALLEL_LINK_JOBS=${{ steps.setup-context.outputs.link_jobs }} `
1152+
-D SWIFT_PARALLEL_LINK_JOBS=${{ steps.setup-context.outputs.link_jobs }} `
11391153
-D LLVM_APPEND_VC_REV=NO `
11401154
-D LLVM_VERSION_SUFFIX="" `
11411155
-D LLDB_PYTHON_EXE_RELATIVE_PATH=${{ steps.setup-context.outputs.python_binary }} `

0 commit comments

Comments
 (0)