Skip to content

Commit 403ccd4

Browse files
authored
Extend freestanding to support targeting Darwin platforms (swiftlang#40202)
* add an option to add freestanding to the Darwin platform, so that to get expected compile behaviours (e.g. setting the install name) * rework testing configuration to relax assumptions about freestanding * add a preset to test such configuration (at least for PR testing) Addresses rdar://85465396
1 parent 3f16d69 commit 403ccd4

File tree

12 files changed

+101
-14
lines changed

12 files changed

+101
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHO
669669
set(SWIFT_APPLE_PLATFORMS ${SWIFT_DARWIN_PLATFORMS})
670670
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
671671
list(APPEND SWIFT_APPLE_PLATFORMS "FREESTANDING")
672+
if(SWIFT_FREESTANDING_IS_DARWIN)
673+
list(APPEND SWIFT_DARWIN_PLATFORMS "FREESTANDING")
674+
endif()
672675
endif()
673676

674677
# Configuration flags passed to all of our invocations of gyb. Try to

stdlib/public/Platform/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(SWIFT_ENABLE_REFLECTION)
1717
endif()
1818

1919
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS)
20-
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
20+
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple" AND NOT SWIFT_FREESTANDING_IS_DARWIN)
2121
set(swiftDarwin_target_sdks ALL_APPLE_PLATFORMS FREESTANDING)
2222
endif()
2323

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ normalize_boolean_spelling(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS)
203203
normalize_boolean_spelling(SWIFT_HAVE_LIBXML2)
204204
normalize_boolean_spelling(SWIFT_INCLUDE_TOOLS)
205205
normalize_boolean_spelling(SWIFT_STDLIB_STATIC_PRINT)
206+
normalize_boolean_spelling(SWIFT_ENABLE_DISPATCH)
207+
normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
206208
is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED)
207209

208210
set(profdata_merge_worker

test/lit.cfg

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,18 +938,24 @@ if run_vendor == 'apple':
938938
# The "freestanding" tests will link against the static libswiftCore.a and
939939
# cannot use any of Obj-C / Dispatch / Foundation.
940940
if "-freestanding" in config.variant_suffix:
941-
config.target_runtime = "native"
942-
config.available_features.remove('libdispatch')
943-
config.available_features.remove('foundation')
944-
config.available_features.remove('objc_interop')
941+
if not config.swift_freestanding_is_darwin:
942+
config.target_runtime = "native"
943+
if not config.swift_enable_dispatch:
944+
config.available_features.remove('libdispatch')
945+
if not config.swift_freestanding_is_darwin:
946+
config.available_features.remove('foundation')
947+
if not config.swift_stdlib_enable_objc_interop:
948+
config.available_features.remove('objc_interop')
945949
config.available_features.add('freestanding')
946950

947951
# Build all "freestanding" tests with -disable-objc-interop
948-
swift_execution_tests_extra_flags += ' -Xfrontend -disable-objc-interop'
952+
if not config.swift_stdlib_enable_objc_interop:
953+
swift_execution_tests_extra_flags += ' -Xfrontend -disable-objc-interop'
949954

950955
# The Concurrency module is not available in "freestanding" mode.
951-
swift_execution_tests_extra_flags += \
952-
' -Xfrontend -disable-implicit-concurrency-module-import'
956+
if not 'concurrency' in config.available_features:
957+
swift_execution_tests_extra_flags += \
958+
' -Xfrontend -disable-implicit-concurrency-module-import'
953959

954960
# To have visible references from symbolic manglings
955961
swift_execution_tests_extra_flags += \
@@ -958,9 +964,11 @@ if run_vendor == 'apple':
958964
# Link all "freestanding" tests with -dead_strip, which can effectively
959965
# even remove parts of the stdlib and runtime, if it's not needed. Since
960966
# it's a very desired behavior, let's enable it for all executable tests.
961-
swift_execution_tests_extra_flags += ' -Xlinker -dead_strip'
967+
if not config.swift_freestanding_is_darwin:
968+
swift_execution_tests_extra_flags += ' -Xlinker -dead_strip'
962969

963-
swift_execution_tests_extra_flags += ' -experimental-hermetic-seal-at-link -lto=llvm-full'
970+
if not config.swift_freestanding_is_darwin:
971+
swift_execution_tests_extra_flags += ' -experimental-hermetic-seal-at-link -lto=llvm-full'
964972

965973
# Build a resource dir for freestanding tests.
966974
new_resource_dir = os.path.join(config.test_exec_root, "resource_dir")
@@ -972,6 +980,8 @@ if run_vendor == 'apple':
972980
symlink_if_not_exists("clang", "clang")
973981
symlink_if_not_exists("shims", "shims")
974982
symlink_if_not_exists("freestanding", "macosx")
983+
if config.swift_freestanding_is_darwin:
984+
symlink_if_not_exists("apinotes", "apinotes")
975985
config.resource_dir_opt = "-resource-dir %s" % new_resource_dir
976986
lit_config.note('Using freestanding resource dir: ' + new_resource_dir)
977987

@@ -1160,7 +1170,13 @@ if run_vendor == 'apple':
11601170
'Running tests on %s version %s (%s)' %
11611171
(sw_vers_name, sw_vers_vers, sw_vers_build))
11621172

1163-
config.target_sdk_name = xcrun_sdk_name
1173+
if "-freestanding" in config.variant_suffix and config.swift_freestanding_is_darwin:
1174+
# This will ensure we are able to find libraries
1175+
# and resource dir at the correct path in tests that require
1176+
# Foundation and ObjectiveC capabilities
1177+
config.target_sdk_name = config.freestanding_sdk_name
1178+
else:
1179+
config.target_sdk_name = xcrun_sdk_name
11641180
config.target_ld = "%s ld -L%r" % (xcrun_prefix, make_path(test_resource_dir, config.target_sdk_name))
11651181

11661182
maccatalyst_extra_frameworks = ""

test/lit.site.cfg.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ if "@SWIFT_STDLIB_STATIC_PRINT@" == "TRUE":
142142
if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
143143
config.available_features.add('string_processing')
144144

145+
config.swift_freestanding_is_darwin = "@SWIFT_FREESTANDING_IS_DARWIN@" == "TRUE"
146+
config.swift_enable_dispatch = "@SWIFT_ENABLE_DISPATCH@" == "TRUE"
147+
config.swift_stdlib_enable_objc_interop = "@SWIFT_STDLIB_ENABLE_OBJC_INTEROP@" == "TRUE"
148+
# Configured in DarwinSDKs.cmake
149+
config.freestanding_sdk_name = "@SWIFT_SDK_FREESTANDING_LIB_SUBDIR@"
150+
145151
# Let the main config do the real work.
146152
if config.test_exec_root is None:
147153
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))

test/stdlib/symbols-depended-on-in-freestanding.darwin.test-sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
// REQUIRES: freestanding
77
// REQUIRES: executable_test
8+
// UNSUPPORTED: objc_interop
89

910
// RUN: %{python} %utils/check_freestanding_dependencies.py --vendor %target-vendor --library %test-resource-dir/freestanding/libswiftCore.a --nm-path %llvm-nm

utils/build-presets.ini

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,30 @@ mixin-preset=stdlib_S_standalone_minimal_macho_x86_64,build
25642564
test
25652565
validation-test
25662566

2567+
[preset: stdlib_S_standalone_darwin_x86_64,build]
2568+
mixin-preset=
2569+
stdlib_S_standalone,build
2570+
2571+
build-subdir=stdlib_S_standalone_darwin
2572+
enable-experimental-differentiable-programming=0
2573+
enable-experimental-concurrency=0
2574+
enable-experimental-distributed=0
2575+
2576+
stdlib-deployment-targets=freestanding-x86_64
2577+
swift-primary-variant-sdk=FREESTANDING
2578+
swift-primary-variant-arch=x86_64
2579+
swift-freestanding-flavor=apple
2580+
swift-freestanding-sdk=macosx
2581+
swift-freestanding-is-darwin=1
2582+
swift-freestanding-triple-name=macosx11.0
2583+
swift-freestanding-module-name=macos
2584+
swift-freestanding-archs=x86_64
2585+
2586+
[preset: stdlib_S_standalone_darwin_x86_64,build,test]
2587+
mixin-preset=stdlib_S_standalone_darwin_x86_64,build
2588+
2589+
test
2590+
validation-test
25672591

25682592
#===----------------------------------------------------------------------===#
25692593
# Preset for Source Compatibility Suite

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ def create_argument_parser():
589589
'module-only targets on Darwin platforms. These targets are '
590590
'in addition to the full library targets.')
591591

592+
option('--swift-freestanding-is-darwin', toggle_true,
593+
help='True if the freestanding platform is a Darwin one.')
594+
592595
# -------------------------------------------------------------------------
593596
in_group('Options to select projects')
594597

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
'swift_disable_dead_stripping': False,
219219
'swift_darwin_module_archs': None,
220220
'swift_darwin_supported_archs': None,
221+
'swift_freestanding_is_darwin': False,
221222
'swift_stdlib_assertions': True,
222223
'swift_stdlib_build_variant': 'Debug',
223224
'swift_tools_max_parallel_lto_link_jobs':
@@ -681,6 +682,7 @@ class BuildScriptImplOption(_BaseOption):
681682
StrOption('--stdlib-deployment-targets'),
682683
StrOption('--swift-darwin-module-archs'),
683684
StrOption('--swift-darwin-supported-archs'),
685+
SetTrueOption('--swift-freestanding-is-darwin'),
684686

685687
PathOption('--android-deploy-device-path'),
686688
PathOption('--android-icu-i18n'),

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
6262
# Add experimental string processing flag.
6363
self.cmake_options.extend(self._enable_experimental_string_processing)
6464

65+
# Add freestanding related flags.
66+
self.cmake_options.extend(self._freestanding_is_darwin)
67+
6568
@classmethod
6669
def is_build_script_impl_product(cls):
6770
"""is_build_script_impl_product -> bool
@@ -171,6 +174,11 @@ def _enable_experimental_string_processing(self):
171174
return [('SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING:BOOL',
172175
self.args.enable_experimental_string_processing)]
173176

177+
@property
178+
def _freestanding_is_darwin(self):
179+
return [('SWIFT_FREESTANDING_IS_DARWIN:BOOL',
180+
self.args.swift_freestanding_is_darwin)]
181+
174182
@classmethod
175183
def get_dependencies(cls):
176184
return [cmark.CMark,

0 commit comments

Comments
 (0)