Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: build Foundation macros for distribution #75869

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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[@]}")

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -2914,7 +2951,7 @@ for host in "${ALL_HOSTS[@]}"; do
;;
esac
;;
foundation|foundation_static)
foundation|foundation_static|foundation_macros)
continue
;;
libdispatch)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
58 changes: 57 additions & 1 deletion utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {

enum HostComponent {
Compilers = 5
System = 10
FoundationMacros = 10
System
ToolsSupportCore
LLBuild
Yams
Expand Down Expand Up @@ -323,6 +324,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {
enum BuildComponent {
BuildTools
Compilers
FoundationMacros
}

function Get-BuildProjectBinaryCache([BuildComponent]$Project) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down