Skip to content

[6.1] Suppress .unsafeFlags() in Package.swift when tagging for release. #993

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

Merged
Merged
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
38 changes: 29 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
import PackageDescription
import CompilerPluginSupport

/// Information about the current state of the package's git repository.
let git = Context.gitInformation

/// Whether or not this package is being built for development rather than
/// distribution as a package dependency.
let buildingForDevelopment = (git?.currentTag == nil)

let package = Package(
name: "swift-testing",

Expand Down Expand Up @@ -67,19 +74,21 @@ let package = Package(
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: .packageSettings + [
// When building as a package, the macro plugin always builds as an
// executable rather than a library.
.define("SWT_NO_LIBRARY_MACRO_PLUGINS"),
swiftSettings: .packageSettings + {
var result = [PackageDescription.SwiftSetting]()

// The only target which needs the ability to import this macro
// implementation target's module is its unit test target. Users of the
// macros this target implements use them via their declarations in the
// Testing module. This target's module is never distributed to users,
// but as an additional guard against accidental misuse, this specifies
// the unit test target as the only allowable client.
.unsafeFlags(["-Xfrontend", "-allowable-client", "-Xfrontend", "TestingMacrosTests"]),
]
if buildingForDevelopment {
result.append(.unsafeFlags(["-Xfrontend", "-allowable-client", "-Xfrontend", "TestingMacrosTests"]))
}

return result
}()
),

// "Support" targets: These contain C family code and are used exclusively
Expand Down Expand Up @@ -122,14 +131,23 @@ extension Array where Element == PackageDescription.SwiftSetting {
/// Settings intended to be applied to every Swift target in this package.
/// Analogous to project-level build settings in an Xcode project.
static var packageSettings: Self {
availabilityMacroSettings + [
.unsafeFlags(["-require-explicit-sendable"]),
var result = availabilityMacroSettings

if buildingForDevelopment {
result.append(.unsafeFlags(["-require-explicit-sendable"]))
}

result += [
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("SuppressedAssociatedTypes"),

.enableExperimentalFeature("AccessLevelOnImport"),
.enableUpcomingFeature("InternalImportsByDefault"),

// When building as a package, the macro plugin always builds as an
// executable rather than a library.
.define("SWT_NO_LIBRARY_MACRO_PLUGINS"),

.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),

.define("SWT_NO_EXIT_TESTS", .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android])),
Expand All @@ -138,6 +156,8 @@ extension Array where Element == PackageDescription.SwiftSetting {
.define("SWT_NO_DYNAMIC_LINKING", .when(platforms: [.wasi])),
.define("SWT_NO_PIPES", .when(platforms: [.wasi])),
]

return result
}

/// Settings which define commonly-used OS availability macros.
Expand Down Expand Up @@ -175,7 +195,7 @@ extension Array where Element == PackageDescription.CXXSetting {
]

// Capture the testing library's version as a C++ string constant.
if let git = Context.gitInformation {
if let git {
let testingLibraryVersion = if let tag = git.currentTag {
tag
} else if git.hasUncommittedChanges {
Expand Down