From dcdb9b1e8b54b8ec3aa0349e32ade08083310db6 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 8 Aug 2024 14:34:10 -0700 Subject: [PATCH 1/2] utils: build Foundation macros for distribution This adds a build of the Foundation macros for distribution in the toolchain. --- utils/build.ps1 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index adf6176e5290b..e4ab86794061b 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -292,7 +292,8 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) { enum HostComponent { Compilers = 5 - System = 10 + FoundationMacros = 10 + System ToolsSupportCore LLBuild Yams @@ -323,6 +324,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) { enum BuildComponent { BuildTools Compilers + FoundationMacros } function Get-BuildProjectBinaryCache([BuildComponent]$Project) { @@ -1455,10 +1457,58 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) { _SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation"; _SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu"; _SwiftCollections_SourceDIR = "$SourceCache\swift-collections" + SwiftFoundation_MACRO = "$(Get-BuildProjectBinaryCache FoundationMacros)\bin" } + $TestingDefines) } } +function Build-FoundationMacros() { + [CmdletBinding(PositionalBinding = $false)] + param + ( + [Parameter(Position = 0, Mandatory = $true)] + [Platform]$Platform, + [Parameter(Position = 1, Mandatory = $true)] + [hashtable]$Arch, + [switch] $Build = $false + ) + + $FoundationMacrosBinaryCache = if ($Build) { + Get-BuildProjectBinaryCache FoundationMacros + } else { + Get-HostProjectBinaryCache FoundationMacros + } + + $SwiftSDK = $null + if ($Build) { + $SwiftSDK = $HostArch.SDKInstallRoot + } + + $Targets = if ($Build) { + @("default") + } else { + @("default", "install") + } + + $InstallDir = $null + if (-not $Build) { + $InstallDir = "$($Arch.ToolchainInstallRoot)\usr" + } + + Build-CMakeProject ` + -Src $SourceCache\swift-foundation\Sources\FoundationMacros ` + -Bin $FoundationMacrosBinaryCache ` + -InstallTo:$InstallDir ` + -Arch $Arch ` + -Platform $Platform ` + -UseBuiltCompilers Swift ` + -SwiftSDK:$SwiftSDK ` + -BuildTargets $Targets ` + -Defines @{ + SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers); + } +} + function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) { $DispatchBinaryCache = Get-TargetProjectBinaryCache $Arch Dispatch $FoundationBinaryCache = Get-TargetProjectBinaryCache $Arch Foundation @@ -2057,11 +2107,17 @@ if (-not $SkipBuild) { # Build platform: SDK, Redist and XCTest Invoke-BuildStep Build-Runtime Windows $Arch Invoke-BuildStep Build-Dispatch Windows $Arch + Invoke-BuildStep Build-FoundationMacros -Build Windows $BuildArch Invoke-BuildStep Build-Foundation Windows $Arch Invoke-BuildStep Build-XCTest Windows $Arch } } +if (-not $SkipBuild) { + # Build Macros for distribution + Invoke-BuildStep Build-FoundationMacros Windows $HostArch +} + if (-not $ToBatch) { if ($HostArch -in $WindowsSDKArchs) { $RuntimeInstallRoot = [IO.Path]::Combine((Get-InstallDir $HostArch), "Runtimes", $ProductVersion) From 8bde8198f3400f48d880d4a43cb47990ca6f205b Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld Date: Fri, 9 Aug 2024 16:23:40 -0700 Subject: [PATCH 2/2] Invoke Foundation macros build separately --- utils/build-script-impl | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/utils/build-script-impl b/utils/build-script-impl index 902fc8e7518c1..16e05052609f4 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -1255,6 +1255,7 @@ STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester" XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest" FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation" FOUNDATION_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation" +FOUNDATION_MACROS_SOURCE_DIR="${WORKSPACE}/swift-foundation/Sources/FoundationMacros" FOUNDATION_SWIFTFOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-foundation" FOUNDATION_SWIFTFOUNDATIONICU_SOURCE_DIR="${WORKSPACE}/swift-foundation-icu" LIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch" @@ -1274,6 +1275,7 @@ SWIFT_SYNTAX_SOURCE_DIR="${WORKSPACE}/swift-syntax" [[ "${SKIP_BUILD_STATIC_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch_static) # llbuild and XCTest depend on Foundation, so Foundation must # be added to the list of build products first. +[[ "${SKIP_BUILD_FOUNDATION}" ]] || PRODUCTS+=(foundation_macros) [[ "${SKIP_BUILD_FOUNDATION}" ]] || PRODUCTS+=(foundation) [[ "${SKIP_BUILD_STATIC_FOUNDATION}" ]] || PRODUCTS+=(foundation_static) [[ "${SKIP_BUILD_LLBUILD}" ]] || PRODUCTS+=(llbuild) @@ -1349,7 +1351,7 @@ function build_directory_bin() { xctest) echo "${root}/${XCTEST_BUILD_TYPE}/bin" ;; - foundation|foundation_static) + foundation|foundation_static|foundation_macros) echo "${root}/${FOUNDATION_BUILD_TYPE}/bin" ;; libdispatch|libdispatch_static) @@ -1489,7 +1491,7 @@ function cmake_config_opt() { xctest) echo "--config ${XCTEST_BUILD_TYPE}" ;; - foundation|foundation_static) + foundation|foundation_static|foundation_macros) echo "--config ${FOUNDATION_BUILD_TYPE}" ;; libdispatch|libdispatch_static) @@ -1680,7 +1682,7 @@ for host in "${ALL_HOSTS[@]}"; do fi for product in "${PRODUCTS[@]}"; do - [[ $(should_execute_action "${host}-${product/_static}-build") ]] || continue + [[ $(should_execute_action "${host}-${product%%_*}-build") ]] || continue source_dir_var="$(toupper ${product})_SOURCE_DIR" source_dir=${!source_dir_var} @@ -1693,7 +1695,7 @@ for host in "${ALL_HOSTS[@]}"; do module_cache="${build_dir}/module-cache" # Add any specific cmake options specified by build-script - product_cmake_options_name=$(to_varname "${product/_static}")_CMAKE_OPTIONS + product_cmake_options_name=$(to_varname "${product%%_*}")_CMAKE_OPTIONS product_cmake_options=(${!product_cmake_options_name}) # convert to array cmake_options+=("${product_cmake_options[@]}") @@ -2408,6 +2410,41 @@ for host in "${ALL_HOSTS[@]}"; do ;; esac + ;; + foundation_macros) + if [[ ${host} == "macosx"* ]]; then + echo "Skipping Foundation Macros on OS X -- Foundation is part of the OS on this platform" + continue + fi + + if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]] + then + # The Swift project might have been changed, but CMake might + # not be aware and will not rebuild. + echo "Cleaning the Foundation Macros build directory" + call rm -rf "${build_dir}" + fi + + cmake_options=( + ${cmake_options[@]} + -DCMAKE_BUILD_TYPE:STRING=${FOUNDATION_BUILD_TYPE} + -DCMAKE_C_COMPILER:PATH=${CLANG_BIN}/clang + -DCMAKE_CXX_COMPILER:PATH=${CLANG_BIN}/clang++ + -DCMAKE_SWIFT_COMPILER:PATH=${SWIFTC_BIN} + -DCMAKE_Swift_COMPILER:PATH=${SWIFTC_BIN} + -DCMAKE_Swift_FLAGS:STRING="$(common_swift_flags)" + -DCMAKE_INSTALL_PREFIX:PATH=$(get_host_install_prefix ${host}) + + -DSwiftSyntax_DIR=$(build_directory ${host} swift)/cmake/modules + + -DBUILD_SHARED_LIBS=YES + -DCMAKE_C_FLAGS="$(swift_c_flags ${host}) $(maybe_lfts ${host})" + ) + + if [[ $(is_cross_tools_host ${host}) ]] ; then + cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}") + fi + ;; foundation|foundation_static) # The configuration script requires knowing about XCTest's @@ -2416,7 +2453,7 @@ for host in "${ALL_HOSTS[@]}"; do XCTEST_BUILD_DIR=$(build_directory ${host} xctest) if [[ ${host} == "macosx"* ]]; then - echo "Skipping Foundation on OS X -- use the Xcode project instead" + echo "Skipping Foundation on OS X -- Foundation is part of the OS on this platform" continue fi @@ -2534,7 +2571,7 @@ for host in "${ALL_HOSTS[@]}"; do -DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch) -Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules - -DSwiftSyntax_DIR=$(build_directory ${host} swift)/cmake/modules + -DSwiftFoundation_MACROS=$(build_directory ${LOCAL_HOST} foundation_macros)/lib -D_SwiftFoundation_SourceDIR=${FOUNDATION_SWIFTFOUNDATION_SOURCE_DIR} -D_SwiftFoundationICU_SourceDIR=${FOUNDATION_SWIFTFOUNDATIONICU_SOURCE_DIR} @@ -2914,7 +2951,7 @@ for host in "${ALL_HOSTS[@]}"; do ;; esac ;; - foundation|foundation_static) + foundation|foundation_static|foundation_macros) continue ;; libdispatch) @@ -3026,7 +3063,7 @@ for host in "${ALL_HOSTS[@]}"; do set_build_options_for_host $host for product in "${PRODUCTS[@]}"; do - [[ $(should_execute_action "${host}-${product/_static}-install") ]] || continue + [[ $(should_execute_action "${host}-${product%%_*}-install") ]] || continue if [[ -z "${INSTALL_DESTDIR}" ]] ; then echo "--install-destdir is required to install products." exit 1 @@ -3074,10 +3111,10 @@ for host in "${ALL_HOSTS[@]}"; do esac ;; - foundation|foundation_static) + foundation|foundation_static|foundation_macros) # FIXME: Foundation doesn't build from the script on OS X if [[ ${host} == "macosx"* ]]; then - echo "Skipping Foundation on OS X -- use the Xcode project instead" + echo "Skipping Foundation on OS X -- Foundation does not build for this platform" continue fi