Skip to content

Commit e2e6957

Browse files
authored
For the 'minimal' stdlib, disable Objective-C interop (swiftlang#33427)
1 parent 7378afd commit e2e6957

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ option(SWIFT_REPORT_STATISTICS
369369
"Create json files which contain internal compilation statistics"
370370
FALSE)
371371

372+
option(SWIFT_DISABLE_OBJC_INTEROP
373+
"Disable Objective-C interoperability even on platforms what would normally have it"
374+
FALSE)
375+
372376
#
373377
# User-configurable experimental options. Do not use in production builds.
374378
#

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ function(_add_target_variant_c_compile_flags)
329329
list(APPEND result "-D_WASI_EMULATED_MMAN")
330330
endif()
331331

332+
if(SWIFT_DISABLE_OBJC_INTEROP)
333+
list(APPEND result "-DSWIFT_OBJC_INTEROP=0")
334+
endif()
335+
332336
set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
333337
endfunction()
334338

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ function(_compile_swift_files
450450
list(APPEND swift_flags "-warn-swift3-objc-inference-complete")
451451
endif()
452452

453+
if(SWIFT_DISABLE_OBJC_INTEROP)
454+
list(APPEND swift_flags "-Xfrontend" "-disable-objc-interop")
455+
endif()
456+
453457
list(APPEND swift_flags ${SWIFT_EXPERIMENTAL_EXTRA_FLAGS})
454458

455459
if(SWIFTFILE_OPT_FLAGS)

stdlib/public/runtime/ImageInspectionMachO.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#if defined(__APPLE__) && defined(__MACH__)
2222

2323
#include "ImageInspection.h"
24+
#include "swift/Runtime/Config.h"
2425
#include <mach-o/dyld.h>
2526
#include <mach-o/getsect.h>
2627
#include <objc/runtime.h>
@@ -121,7 +122,7 @@ void addImageCallback2Sections(const mach_header *mh, intptr_t vmaddr_slide) {
121122

122123
} // end anonymous namespace
123124

124-
#if OBJC_ADDLOADIMAGEFUNC_DEFINED
125+
#if OBJC_ADDLOADIMAGEFUNC_DEFINED && SWIFT_OBJC_INTEROP
125126
#define REGISTER_FUNC(...) \
126127
if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)) { \
127128
objc_addLoadImageFunc(__VA_ARGS__); \

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,7 @@ enable-experimental-concurrency=0
23892389
build-swift-dynamic-sdk-overlay=0
23902390
build-swift-dynamic-stdlib=0
23912391
build-swift-static-stdlib=1
2392+
swift-objc-interop=0
23922393

23932394
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
23942395
mixin-preset=

utils/build-script-impl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ KNOWN_SETTINGS=(
192192
report-statistics "0" "set to 1 to generate compilation statistics files for swift libraries"
193193
sil-verify-all "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process"
194194
stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for"
195+
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Apple platfors, 0 otherwise"
195196

196197
## FREESTANDING Stdlib Options
197198
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
@@ -1816,6 +1817,13 @@ for host in "${ALL_HOSTS[@]}"; do
18161817
)
18171818
fi
18181819

1820+
if [[ "${SWIFT_OBJC_INTEROP}" == "0" ]] ; then
1821+
cmake_options=(
1822+
"${cmake_options[@]}"
1823+
-DSWIFT_DISABLE_OBJC_INTEROP:BOOL=True
1824+
)
1825+
fi
1826+
18191827
if [[ "${SWIFT_PRIMARY_VARIANT_SDK}" ]] ; then
18201828
cmake_options=(
18211829
"${cmake_options[@]}"

0 commit comments

Comments
 (0)