Skip to content

Commit 1c2c004

Browse files
authored
Merge pull request #90 from lorentey/fix-c++-interop
Avoid C atomic operations in Swift 5.9+
2 parents 6d3d340 + 1698b26 commit 1c2c004

25 files changed

+110
-86
lines changed

Package-@swift-5.6.swift

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// swift-tools-version:5.6
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the Swift.org open source project
5+
//
6+
// Copyright (c) 2020 - 2023 Apple Inc. and the Swift project authors
7+
// Licensed under Apache License v2.0 with Runtime Library Exception
8+
//
9+
// See https://swift.org/LICENSE.txt for license information
10+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
import PackageDescription
15+
16+
var _cSettings: [CSetting] = []
17+
var _swiftSettings: [SwiftSetting] = []
18+
19+
// Note: ATOMICS_NATIVE_BUILTINS works via the BuiltinModule language feature,
20+
// so it is not usable in language versions below 5.9.
21+
22+
let package = Package(
23+
name: "swift-atomics",
24+
products: [
25+
.library(
26+
name: "Atomics",
27+
targets: ["Atomics"]),
28+
],
29+
targets: [
30+
.target(
31+
name: "_AtomicsShims",
32+
exclude: [
33+
"CMakeLists.txt"
34+
]
35+
),
36+
.target(
37+
name: "Atomics",
38+
dependencies: ["_AtomicsShims"],
39+
exclude: [
40+
"CMakeLists.txt",
41+
"AtomicBool.swift.gyb",
42+
"AtomicLazyReference.swift.gyb",
43+
"HighLevelTypes.swift.gyb",
44+
"IntegerConformances.swift.gyb",
45+
"PointerConformances.swift.gyb",
46+
"Primitives.native.swift.gyb",
47+
"Primitives.shims.swift.gyb",
48+
],
49+
cSettings: _cSettings,
50+
swiftSettings: _swiftSettings
51+
),
52+
.testTarget(
53+
name: "AtomicsTests",
54+
dependencies: ["Atomics"],
55+
exclude: [
56+
"main.swift",
57+
"Basics/BasicTests.gyb-template",
58+
"Basics/BasicAtomicBoolTests.swift.gyb",
59+
"Basics/BasicAtomicDoubleWordTests.swift.gyb",
60+
"Basics/BasicAtomicInt16Tests.swift.gyb",
61+
"Basics/BasicAtomicInt32Tests.swift.gyb",
62+
"Basics/BasicAtomicInt64Tests.swift.gyb",
63+
"Basics/BasicAtomicInt8Tests.swift.gyb",
64+
"Basics/BasicAtomicIntTests.swift.gyb",
65+
"Basics/BasicAtomicMutablePointerTests.swift.gyb",
66+
"Basics/BasicAtomicMutableRawPointerTests.swift.gyb",
67+
"Basics/BasicAtomicOptionalMutablePointerTests.swift.gyb",
68+
"Basics/BasicAtomicOptionalMutableRawPointerTests.swift.gyb",
69+
"Basics/BasicAtomicOptionalPointerTests.swift.gyb",
70+
"Basics/BasicAtomicOptionalRawPointerTests.swift.gyb",
71+
"Basics/BasicAtomicOptionalRawRepresentableTests.swift.gyb",
72+
"Basics/BasicAtomicOptionalReferenceTests.swift.gyb",
73+
"Basics/BasicAtomicOptionalUnmanagedTests.swift.gyb",
74+
"Basics/BasicAtomicPointerTests.swift.gyb",
75+
"Basics/BasicAtomicRawPointerTests.swift.gyb",
76+
"Basics/BasicAtomicRawRepresentableTests.swift.gyb",
77+
"Basics/BasicAtomicReferenceTests.swift.gyb",
78+
"Basics/BasicAtomicUInt16Tests.swift.gyb",
79+
"Basics/BasicAtomicUInt32Tests.swift.gyb",
80+
"Basics/BasicAtomicUInt64Tests.swift.gyb",
81+
"Basics/BasicAtomicUInt8Tests.swift.gyb",
82+
"Basics/BasicAtomicUIntTests.swift.gyb",
83+
"Basics/BasicAtomicUnmanagedTests.swift.gyb",
84+
]
85+
),
86+
]
87+
)

Package.swift

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.9
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the Swift.org open source project
@@ -13,23 +13,17 @@
1313

1414
import PackageDescription
1515

16-
// Enables the use of native Swift compiler builtins instead of C atomics.
17-
// This requires the use of an unsafe compiler flag, so it cannot currently
18-
// be enabled when this package is built as a regular SwiftPM dependency.
19-
let useNativeBuiltins = false
20-
2116
var _cSettings: [CSetting] = []
2217
var _swiftSettings: [SwiftSetting] = []
2318

24-
if useNativeBuiltins {
25-
_cSettings += [
26-
.define("ATOMICS_NATIVE_BUILTINS"),
27-
]
28-
_swiftSettings += [
29-
.define("ATOMICS_NATIVE_BUILTINS"),
30-
.unsafeFlags(["-Xfrontend", "-parse-stdlib"]),
31-
]
32-
}
19+
// Enable the use of native Swift compiler builtins instead of C atomics.
20+
_cSettings += [
21+
.define("ATOMICS_NATIVE_BUILTINS"),
22+
]
23+
_swiftSettings += [
24+
.define("ATOMICS_NATIVE_BUILTINS"),
25+
.enableExperimentalFeature("BuiltinModule")
26+
]
3327

3428
let package = Package(
3529
name: "swift-atomics",

Sources/Atomics/AtomicBool.swift.gyb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
}%
1717
${autogenerated_warning()}
1818

19-
#if ATOMICS_NATIVE_BUILTINS
20-
import Swift
21-
#else
19+
#if !ATOMICS_NATIVE_BUILTINS
2220
import _AtomicsShims
2321
#endif
2422

Sources/Atomics/AtomicInteger.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#endif
16-
1713
/// A type that supports atomic integer operations through a separate
1814
/// atomic storage representation.
1915
///

Sources/Atomics/AtomicLazyReference.swift.gyb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
}%
1515
${autogenerated_warning()}
1616

17-
#if ATOMICS_NATIVE_BUILTINS
18-
import Swift
19-
#endif
20-
2117
/// An unsafe reference type holding a lazily initializable atomic
2218
/// strong reference, requiring manual memory management of the
2319
/// underlying storage representation.

Sources/Atomics/AtomicMemoryOrderings.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#endif
16-
1713
/// Specifies the memory ordering semantics of an atomic load operation.
1814
@frozen
1915
public struct AtomicLoadOrdering {

Sources/Atomics/AtomicOptional.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#endif
16-
1713
/// An atomic value that also supports atomic operations when wrapped
1814
/// in an `Optional`. Atomic optional wrappable types come with a
1915
/// standalone atomic representation for their optional-wrapped

Sources/Atomics/AtomicOptionalRawRepresentable.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#endif
16-
1713
extension RawRepresentable
1814
where
1915
Self: AtomicOptionalWrappable,

Sources/Atomics/AtomicRawRepresentable.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#endif
16-
1713
extension RawRepresentable
1814
where
1915
Self: AtomicValue,

Sources/Atomics/AtomicStrongReference.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
14-
import Swift
15-
#else
13+
#if !ATOMICS_NATIVE_BUILTINS
1614
import _AtomicsShims
1715
#endif
1816

0 commit comments

Comments
 (0)