Skip to content

Commit ccb1dc5

Browse files
authored
Merge pull request #75869 from compnerd/60foundations
utils: build Foundation macros for distribution
2 parents 026ffdd + 8bde819 commit ccb1dc5

File tree

2 files changed

+104
-11
lines changed

2 files changed

+104
-11
lines changed

utils/build-script-impl

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester"
12551255
XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest"
12561256
FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
12571257
FOUNDATION_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
1258+
FOUNDATION_MACROS_SOURCE_DIR="${WORKSPACE}/swift-foundation/Sources/FoundationMacros"
12581259
FOUNDATION_SWIFTFOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-foundation"
12591260
FOUNDATION_SWIFTFOUNDATIONICU_SOURCE_DIR="${WORKSPACE}/swift-foundation-icu"
12601261
LIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
@@ -1274,6 +1275,7 @@ SWIFT_SYNTAX_SOURCE_DIR="${WORKSPACE}/swift-syntax"
12741275
[[ "${SKIP_BUILD_STATIC_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch_static)
12751276
# llbuild and XCTest depend on Foundation, so Foundation must
12761277
# be added to the list of build products first.
1278+
[[ "${SKIP_BUILD_FOUNDATION}" ]] || PRODUCTS+=(foundation_macros)
12771279
[[ "${SKIP_BUILD_FOUNDATION}" ]] || PRODUCTS+=(foundation)
12781280
[[ "${SKIP_BUILD_STATIC_FOUNDATION}" ]] || PRODUCTS+=(foundation_static)
12791281
[[ "${SKIP_BUILD_LLBUILD}" ]] || PRODUCTS+=(llbuild)
@@ -1349,7 +1351,7 @@ function build_directory_bin() {
13491351
xctest)
13501352
echo "${root}/${XCTEST_BUILD_TYPE}/bin"
13511353
;;
1352-
foundation|foundation_static)
1354+
foundation|foundation_static|foundation_macros)
13531355
echo "${root}/${FOUNDATION_BUILD_TYPE}/bin"
13541356
;;
13551357
libdispatch|libdispatch_static)
@@ -1489,7 +1491,7 @@ function cmake_config_opt() {
14891491
xctest)
14901492
echo "--config ${XCTEST_BUILD_TYPE}"
14911493
;;
1492-
foundation|foundation_static)
1494+
foundation|foundation_static|foundation_macros)
14931495
echo "--config ${FOUNDATION_BUILD_TYPE}"
14941496
;;
14951497
libdispatch|libdispatch_static)
@@ -1680,7 +1682,7 @@ for host in "${ALL_HOSTS[@]}"; do
16801682
fi
16811683

16821684
for product in "${PRODUCTS[@]}"; do
1683-
[[ $(should_execute_action "${host}-${product/_static}-build") ]] || continue
1685+
[[ $(should_execute_action "${host}-${product%%_*}-build") ]] || continue
16841686

16851687
source_dir_var="$(toupper ${product})_SOURCE_DIR"
16861688
source_dir=${!source_dir_var}
@@ -1693,7 +1695,7 @@ for host in "${ALL_HOSTS[@]}"; do
16931695
module_cache="${build_dir}/module-cache"
16941696

16951697
# Add any specific cmake options specified by build-script
1696-
product_cmake_options_name=$(to_varname "${product/_static}")_CMAKE_OPTIONS
1698+
product_cmake_options_name=$(to_varname "${product%%_*}")_CMAKE_OPTIONS
16971699
product_cmake_options=(${!product_cmake_options_name}) # convert to array
16981700
cmake_options+=("${product_cmake_options[@]}")
16991701

@@ -2408,6 +2410,41 @@ for host in "${ALL_HOSTS[@]}"; do
24082410
;;
24092411
esac
24102412

2413+
;;
2414+
foundation_macros)
2415+
if [[ ${host} == "macosx"* ]]; then
2416+
echo "Skipping Foundation Macros on OS X -- Foundation is part of the OS on this platform"
2417+
continue
2418+
fi
2419+
2420+
if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]]
2421+
then
2422+
# The Swift project might have been changed, but CMake might
2423+
# not be aware and will not rebuild.
2424+
echo "Cleaning the Foundation Macros build directory"
2425+
call rm -rf "${build_dir}"
2426+
fi
2427+
2428+
cmake_options=(
2429+
${cmake_options[@]}
2430+
-DCMAKE_BUILD_TYPE:STRING=${FOUNDATION_BUILD_TYPE}
2431+
-DCMAKE_C_COMPILER:PATH=${CLANG_BIN}/clang
2432+
-DCMAKE_CXX_COMPILER:PATH=${CLANG_BIN}/clang++
2433+
-DCMAKE_SWIFT_COMPILER:PATH=${SWIFTC_BIN}
2434+
-DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN}
2435+
-DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)"
2436+
-DCMAKE_INSTALL_PREFIX:PATH=$(get_host_install_prefix ${host})
2437+
2438+
-DSwiftSyntax_DIR=$(build_directory ${host} swift)/cmake/modules
2439+
2440+
-DBUILD_SHARED_LIBS=YES
2441+
-DCMAKE_C_FLAGS="$(swift_c_flags ${host}) $(maybe_lfts ${host})"
2442+
)
2443+
2444+
if [[ $(is_cross_tools_host ${host}) ]] ; then
2445+
cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
2446+
fi
2447+
24112448
;;
24122449
foundation|foundation_static)
24132450
# The configuration script requires knowing about XCTest's
@@ -2416,7 +2453,7 @@ for host in "${ALL_HOSTS[@]}"; do
24162453
XCTEST_BUILD_DIR=$(build_directory ${host} xctest)
24172454

24182455
if [[ ${host} == "macosx"* ]]; then
2419-
echo "Skipping Foundation on OS X -- use the Xcode project instead"
2456+
echo "Skipping Foundation on OS X -- Foundation is part of the OS on this platform"
24202457
continue
24212458
fi
24222459

@@ -2534,7 +2571,7 @@ for host in "${ALL_HOSTS[@]}"; do
25342571
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch)
25352572
-Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules
25362573

2537-
-DSwiftSyntax_DIR=$(build_directory ${host} swift)/cmake/modules
2574+
-DSwiftFoundation_MACROS=$(build_directory ${LOCAL_HOST} foundation_macros)/lib
25382575

25392576
-D_SwiftFoundation_SourceDIR=${FOUNDATION_SWIFTFOUNDATION_SOURCE_DIR}
25402577
-D_SwiftFoundationICU_SourceDIR=${FOUNDATION_SWIFTFOUNDATIONICU_SOURCE_DIR}
@@ -2914,7 +2951,7 @@ for host in "${ALL_HOSTS[@]}"; do
29142951
;;
29152952
esac
29162953
;;
2917-
foundation|foundation_static)
2954+
foundation|foundation_static|foundation_macros)
29182955
continue
29192956
;;
29202957
libdispatch)
@@ -3026,7 +3063,7 @@ for host in "${ALL_HOSTS[@]}"; do
30263063
set_build_options_for_host $host
30273064

30283065
for product in "${PRODUCTS[@]}"; do
3029-
[[ $(should_execute_action "${host}-${product/_static}-install") ]] || continue
3066+
[[ $(should_execute_action "${host}-${product%%_*}-install") ]] || continue
30303067
if [[ -z "${INSTALL_DESTDIR}" ]] ; then
30313068
echo "--install-destdir is required to install products."
30323069
exit 1
@@ -3074,10 +3111,10 @@ for host in "${ALL_HOSTS[@]}"; do
30743111
esac
30753112

30763113
;;
3077-
foundation|foundation_static)
3114+
foundation|foundation_static|foundation_macros)
30783115
# FIXME: Foundation doesn't build from the script on OS X
30793116
if [[ ${host} == "macosx"* ]]; then
3080-
echo "Skipping Foundation on OS X -- use the Xcode project instead"
3117+
echo "Skipping Foundation on OS X -- Foundation does not build for this platform"
30813118
continue
30823119
fi
30833120

utils/build.ps1

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
292292

293293
enum HostComponent {
294294
Compilers = 5
295-
System = 10
295+
FoundationMacros = 10
296+
System
296297
ToolsSupportCore
297298
LLBuild
298299
Yams
@@ -323,6 +324,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {
323324
enum BuildComponent {
324325
BuildTools
325326
Compilers
327+
FoundationMacros
326328
}
327329

328330
function Get-BuildProjectBinaryCache([BuildComponent]$Project) {
@@ -1455,10 +1457,58 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
14551457
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
14561458
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
14571459
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections"
1460+
SwiftFoundation_MACRO = "$(Get-BuildProjectBinaryCache FoundationMacros)\bin"
14581461
} + $TestingDefines)
14591462
}
14601463
}
14611464

1465+
function Build-FoundationMacros() {
1466+
[CmdletBinding(PositionalBinding = $false)]
1467+
param
1468+
(
1469+
[Parameter(Position = 0, Mandatory = $true)]
1470+
[Platform]$Platform,
1471+
[Parameter(Position = 1, Mandatory = $true)]
1472+
[hashtable]$Arch,
1473+
[switch] $Build = $false
1474+
)
1475+
1476+
$FoundationMacrosBinaryCache = if ($Build) {
1477+
Get-BuildProjectBinaryCache FoundationMacros
1478+
} else {
1479+
Get-HostProjectBinaryCache FoundationMacros
1480+
}
1481+
1482+
$SwiftSDK = $null
1483+
if ($Build) {
1484+
$SwiftSDK = $HostArch.SDKInstallRoot
1485+
}
1486+
1487+
$Targets = if ($Build) {
1488+
@("default")
1489+
} else {
1490+
@("default", "install")
1491+
}
1492+
1493+
$InstallDir = $null
1494+
if (-not $Build) {
1495+
$InstallDir = "$($Arch.ToolchainInstallRoot)\usr"
1496+
}
1497+
1498+
Build-CMakeProject `
1499+
-Src $SourceCache\swift-foundation\Sources\FoundationMacros `
1500+
-Bin $FoundationMacrosBinaryCache `
1501+
-InstallTo:$InstallDir `
1502+
-Arch $Arch `
1503+
-Platform $Platform `
1504+
-UseBuiltCompilers Swift `
1505+
-SwiftSDK:$SwiftSDK `
1506+
-BuildTargets $Targets `
1507+
-Defines @{
1508+
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
1509+
}
1510+
}
1511+
14621512
function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
14631513
$DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch
14641514
$FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation
@@ -2057,11 +2107,17 @@ if (-not $SkipBuild) {
20572107
# Build platform: SDK, Redist and XCTest
20582108
Invoke-BuildStep Build-Runtime Windows $Arch
20592109
Invoke-BuildStep Build-Dispatch Windows $Arch
2110+
Invoke-BuildStep Build-FoundationMacros -Build Windows $BuildArch
20602111
Invoke-BuildStep Build-Foundation Windows $Arch
20612112
Invoke-BuildStep Build-XCTest Windows $Arch
20622113
}
20632114
}
20642115

2116+
if (-not $SkipBuild) {
2117+
# Build Macros for distribution
2118+
Invoke-BuildStep Build-FoundationMacros Windows $HostArch
2119+
}
2120+
20652121
if (-not $ToBatch) {
20662122
if ($HostArch -in $WindowsSDKArchs) {
20672123
$RuntimeInstallRoot = [IO.Path]::Combine((Get-InstallDir $HostArch), "Runtimes", $ProductVersion)

0 commit comments

Comments
 (0)