From 37ed08dc7b6f95acd5efd4dca310a27ece27801e Mon Sep 17 00:00:00 2001 From: Kuba Mracek Date: Mon, 17 Jun 2024 13:18:55 -0700 Subject: [PATCH] Add a build-script + CMake flag to enable/disable building the _Volatile module --- CMakeLists.txt | 5 +++++ stdlib/cmake/modules/SwiftSource.cmake | 4 ++++ stdlib/public/CMakeLists.txt | 4 +++- test/CMakeLists.txt | 5 +++++ test/lit.site.cfg.in | 2 ++ utils/build.ps1 | 2 ++ .../build_swift/build_swift/driver_arguments.py | 4 ++++ utils/build_swift/tests/expected_options.py | 2 ++ utils/swift-api-dump.py | 2 ++ .../swift_build_support/products/swift.py | 8 ++++++++ .../swift_build_support/products/wasmstdlib.py | 1 + .../tests/products/test_swift.py | 16 ++++++++++++++++ 12 files changed, 54 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffeeeafa079..1b7f7c5716e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -712,6 +712,10 @@ option(SWIFT_ENABLE_SYNCHRONIZATION "Enable build of the Swift Synchronization module" FALSE) +option(SWIFT_ENABLE_VOLATILE + "Enable build of the Swift Volatile module" + FALSE) + option(SWIFT_ENABLE_DISPATCH "Enable use of libdispatch" TRUE) @@ -1359,6 +1363,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY) message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}") message(STATUS "Observation Support: ${SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION}") message(STATUS "Synchronization Support: ${SWIFT_ENABLE_SYNCHRONIZATION}") + message(STATUS "Volatile Support: ${SWIFT_ENABLE_VOLATILE}") message(STATUS "") else() message(STATUS "Not building Swift standard library, SDK overlays, and runtime") diff --git a/stdlib/cmake/modules/SwiftSource.cmake b/stdlib/cmake/modules/SwiftSource.cmake index 03e525f48c3..87f63995de4 100644 --- a/stdlib/cmake/modules/SwiftSource.cmake +++ b/stdlib/cmake/modules/SwiftSource.cmake @@ -330,6 +330,10 @@ function(_add_target_variant_swift_compile_flags list(APPEND result "-D" "SWIFT_ENABLE_SYNCHRONIZATION") endif() + if(SWIFT_ENABLE_VOLATILE) + list(APPEND result "-D" "SWIFT_ENABLE_VOLATILE") + endif() + if(SWIFT_STDLIB_OS_VERSIONING) list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING") endif() diff --git a/stdlib/public/CMakeLists.txt b/stdlib/public/CMakeLists.txt index fb0bf678de5..475aec4e5d6 100644 --- a/stdlib/public/CMakeLists.txt +++ b/stdlib/public/CMakeLists.txt @@ -282,7 +282,9 @@ if(SWIFT_BUILD_STDLIB AND NOT SWIFT_STDLIB_BUILD_ONLY_CORE_MODULES) add_subdirectory(Synchronization) endif() - add_subdirectory(Volatile) + if(SWIFT_ENABLE_VOLATILE) + add_subdirectory(Volatile) + endif() endif() if(SWIFT_BUILD_REMOTE_MIRROR) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fc4ac867188..1e7f554ba4e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -215,6 +215,7 @@ normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_OBJC_INTEROP) normalize_boolean_spelling(SWIFT_ENABLE_BACKTRACING) normalize_boolean_spelling(SWIFT_BUILD_SWIFT_SYNTAX) normalize_boolean_spelling(SWIFT_ENABLE_SYNCHRONIZATION) +normalize_boolean_spelling(SWIFT_ENABLE_VOLATILE) normalize_boolean_spelling(SWIFT_BUILD_REMOTE_MIRROR) is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED) @@ -433,6 +434,10 @@ foreach(SDK ${SWIFT_SDKS}) list(APPEND LIT_ARGS "--param" "synchronization") endif() + if(SWIFT_ENABLE_VOLATILE) + list(APPEND LIT_ARGS "--param" "volatile") + endif() + if(SWIFT_BUILD_REMOTE_MIRROR) list(APPEND LIT_ARGS "--param" "remote_mirror") endif() diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index cff9e9690dc..2d31648867e 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -157,6 +157,8 @@ if "@SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE@" == "TRUE": config.available_features.add('swift_stdlib_debug_preconditions_in_release') if "@SWIFT_ENABLE_SYNCHRONIZATION@" == "TRUE": config.available_features.add('synchronization') +if "@SWIFT_ENABLE_VOLATILE@" == "TRUE": + config.available_features.add('volatile') if "@SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB@" == "TRUE": config.available_features.add('embedded_stdlib') diff --git a/utils/build.ps1 b/utils/build.ps1 index 09cdbb9a4e9..c0c564382bf 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1345,6 +1345,7 @@ function Build-Compilers() { SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES"; SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES"; SWIFT_ENABLE_SYNCHRONIZATION = "YES"; + SWIFT_ENABLE_VOLATILE = "YES"; SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch"; SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax"; SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing"; @@ -1594,6 +1595,7 @@ function Build-Runtime([Platform]$Platform, $Arch) { SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES"; # FIXME: re-enable after https://github.com/apple/swift/issues/74186 is fixed. SWIFT_ENABLE_SYNCHRONIZATION = if (($Platform -eq "Android") -and ($Arch -eq $AndroidARMv7)) { "NO" } else { "YES" }; + SWIFT_ENABLE_VOLATILE = "YES"; SWIFT_NATIVE_SWIFT_TOOLS_PATH = (Join-Path -Path $CompilersBinaryCache -ChildPath "bin"); SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch"; SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing"; diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index 7c5fa8ed337..e13b864a8e1 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -1465,6 +1465,10 @@ def create_argument_parser(): default=True, help='Enable Swift Synchronization.') + option('--enable-volatile', toggle_true, + default=True, + help='Enable Volatile module.') + option('--enable-experimental-parser-validation', toggle_true, default=False, help='Enable experimental Swift Parser validation by default.') diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index 89a141c0bb6..0bf27bcb50e 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -181,6 +181,7 @@ EXPECTED_DEFAULTS = { 'enable_experimental_parser_validation': False, 'swift_enable_backtracing': True, 'enable_synchronization': True, + 'enable_volatile': True, 'enable_lsan': False, 'enable_sanitize_coverage': False, 'disable_guaranteed_normal_arguments': False, @@ -622,6 +623,7 @@ EXPECTED_OPTIONS = [ EnableOption('--export-compile-commands'), EnableOption('--swift-enable-backtracing'), EnableOption('--enable-synchronization'), + EnableOption('--enable-volatile'), EnableOption('--foundation', dest='build_foundation'), EnableOption('--host-test'), EnableOption('--only-executable-test'), diff --git a/utils/swift-api-dump.py b/utils/swift-api-dump.py index fda705c9be2..4113ded32f4 100755 --- a/utils/swift-api-dump.py +++ b/utils/swift-api-dump.py @@ -108,6 +108,8 @@ def create_parser(): help='Enable experimental observation.') parser.add_argument('--enable-synchronization', action='store_true', help='Enable Synchronization.') + parser.add_argument('--enable-volatile', action='store_true', + help='Enable Volatile.') parser.add_argument('-swift-version', metavar='N', help='the Swift version to use') parser.add_argument('-show-overlay', action='store_true', diff --git a/utils/swift_build_support/swift_build_support/products/swift.py b/utils/swift_build_support/swift_build_support/products/swift.py index d791a292e9e..1ba2c51ec41 100644 --- a/utils/swift_build_support/swift_build_support/products/swift.py +++ b/utils/swift_build_support/swift_build_support/products/swift.py @@ -72,6 +72,9 @@ class Swift(product.Product): # Add synchronization flag. self.cmake_options.extend(self._enable_synchronization) + # Add volatile flag. + self.cmake_options.extend(self._enable_volatile) + # Add static vprintf flag self.cmake_options.extend(self._enable_stdlib_static_vprintf) @@ -219,6 +222,11 @@ updated without updating swift.py?") return [('SWIFT_ENABLE_SYNCHRONIZATION:BOOL', self.args.enable_synchronization)] + @property + def _enable_volatile(self): + return [('SWIFT_ENABLE_VOLATILE:BOOL', + self.args.enable_volatile)] + @property def _enable_stdlib_static_vprintf(self): return [('SWIFT_STDLIB_STATIC_PRINT', diff --git a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py index d6d932dd9af..b1e38a5c640 100644 --- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py +++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py @@ -110,6 +110,7 @@ class WasmStdlib(cmake_product.CMakeProduct): 'swift-experimental-string-processing')) self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP:BOOL', 'TRUE') self.cmake_options.define('SWIFT_ENABLE_SYNCHRONIZATION:BOOL', 'TRUE') + self.cmake_options.define('SWIFT_ENABLE_VOLATILE:BOOL', 'TRUE') self.cmake_options.define('SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL', 'TRUE') self.add_extra_cmake_options() diff --git a/utils/swift_build_support/tests/products/test_swift.py b/utils/swift_build_support/tests/products/test_swift.py index 5ed33959afe..6313966977f 100644 --- a/utils/swift_build_support/tests/products/test_swift.py +++ b/utils/swift_build_support/tests/products/test_swift.py @@ -63,6 +63,7 @@ class SwiftTestCase(unittest.TestCase): enable_experimental_parser_validation=False, swift_enable_backtracing=False, enable_synchronization=False, + enable_volatile=False, build_early_swiftsyntax=False, build_swift_stdlib_static_print=False, build_swift_stdlib_unicode_data=True, @@ -109,6 +110,7 @@ class SwiftTestCase(unittest.TestCase): '-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE', '-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE', '-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE', + '-DSWIFT_ENABLE_VOLATILE:BOOL=FALSE', '-DSWIFT_STDLIB_STATIC_PRINT=FALSE', '-DSWIFT_FREESTANDING_IS_DARWIN:BOOL=FALSE', '-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE', @@ -140,6 +142,7 @@ class SwiftTestCase(unittest.TestCase): '-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE', '-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE', '-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE', + '-DSWIFT_ENABLE_VOLATILE:BOOL=FALSE', '-DSWIFT_STDLIB_STATIC_PRINT=FALSE', '-DSWIFT_FREESTANDING_IS_DARWIN:BOOL=FALSE', '-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE', @@ -461,6 +464,19 @@ class SwiftTestCase(unittest.TestCase): [x for x in swift.cmake_options if 'DSWIFT_ENABLE_SYNCHRONIZATION' in x]) + def test_volatile_flags(self): + self.args.enable_volatile = True + swift = Swift( + args=self.args, + toolchain=self.toolchain, + source_dir='/path/to/src', + build_dir='/path/to/build') + self.assertEqual( + ['-DSWIFT_ENABLE_VOLATILE:BOOL=' + 'TRUE'], + [x for x in swift.cmake_options + if 'DSWIFT_ENABLE_VOLATILE' in x]) + def test_freestanding_is_darwin_flags(self): self.args.swift_freestanding_is_darwin = True swift = Swift(