Skip to content
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

Export system Foundation for Darwin platforms #406

Closed
Closed
Show file tree
Hide file tree
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
266 changes: 158 additions & 108 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,120 +4,170 @@
import PackageDescription
import CompilerPluginSupport

// Availability Macros
let availabilityMacros: [SwiftSetting] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parkera This might have to default to be true otherwise tests won't run on CI... or maybe we should set some special environment variables for testing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, how does the swift-crypto project do this? We should certainly resolve before merging because we don't want to effectively disable building for macOS in CI.

"FoundationPreview 0.1:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.1:macOS 14, iOS 17, tvOS 17, watchOS 10",
"FoundationPreview 0.2:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPreview 0.3:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.3:macOS 14, iOS 17, tvOS 17, watchOS 10",
"FoundationPreview 0.4:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.4:macOS 14, iOS 17, tvOS 17, watchOS 10",
].map { .enableExperimentalFeature("AvailabilityMacro=\($0)") }
// To develop this package on Apple platforms, set this to true
let developmentOnDarwin = false

let package = Package(
name: "FoundationPreview",
platforms: [.macOS("13.3"), .iOS("16.4"), .tvOS("16.4"), .watchOS("9.4")],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(name: "FoundationPreview", targets: ["FoundationPreview"]),
.library(name: "FoundationEssentials", targets: ["FoundationEssentials"]),
.library(name: "FoundationInternationalization", targets: ["FoundationInternationalization"]),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-collections",
revision: "d8003787efafa82f9805594bc51100be29ac6903"), // on release/1.1
.package(
url: "https://github.com/apple/swift-foundation-icu",
exact: "0.0.5"),
.package(
url: "https://github.com/apple/swift-syntax.git",
from: "509.0.2")
],
targets: [
// Foundation (umbrella)
.target(
name: "FoundationPreview",
dependencies: [
#if canImport(Darwin)
let useSystemFoundation = !developmentOnDarwin
#else
// On non Darwin platforms always use package
let useSystemFoundation = false
#endif
Comment on lines +10 to +15
Copy link
Member

@FranzBusch FranzBusch Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend doing it this way since this will break cross compilation from Darwin to another platform. swift-crypto just defines a variable isDevelopment = false here and package maintainers manually set that to true. Setting it to true allows to run the code in the package on Darwin platforms. In general using #if canImport in Package.swift is not a good idea cc @MaxDesiatov

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what Franz said, this check will just break all packages depending on swift-foundation when cross-compiling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that for some platforms one can only cross-compile, e.g. Wasm/WASI, embedded etc. Presence of #if canImport or #if os checks in Package.swift make this package and everything that depends on it unusable for such platforms.


let package: Package

if !useSystemFoundation {
// Availability Macros
let availabilityMacros: [SwiftSetting] = [
"FoundationPreview 0.1:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.1:macOS 14, iOS 17, tvOS 17, watchOS 10",
"FoundationPreview 0.2:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPreview 0.3:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.3:macOS 14, iOS 17, tvOS 17, watchOS 10",
"FoundationPreview 0.4:macOS 13.3, iOS 16.4, tvOS 16.4, watchOS 9.4",
"FoundationPredicate 0.4:macOS 14, iOS 17, tvOS 17, watchOS 10",
].map { .enableExperimentalFeature("AvailabilityMacro=\($0)") }

package = Package(
name: "FoundationPreview",
platforms: [.macOS("13.3"), .iOS("16.4"), .tvOS("16.4"), .watchOS("9.4")],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(name: "FoundationPreview", targets: ["FoundationPreview"]),
.library(name: "FoundationEssentials", targets: ["FoundationEssentials"]),
.library(name: "FoundationInternationalization", targets: ["FoundationInternationalization"]),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-collections",
revision: "d8003787efafa82f9805594bc51100be29ac6903"), // on release/1.1
.package(
url: "https://github.com/apple/swift-foundation-icu",
exact: "0.0.5"),
.package(
url: "https://github.com/apple/swift-syntax.git",
from: "509.0.2")
],
targets: [
// Foundation (umbrella)
.target(
name: "FoundationPreview",
dependencies: [
"FoundationEssentials",
"FoundationInternationalization",
],
path: "Sources/Foundation"),

// _CShims (Internal)
.target(
name: "_CShims",
cSettings: [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
]
),

// TestSupport (Internal)
.target(name: "TestSupport", dependencies: [
"FoundationEssentials",
"FoundationInternationalization",
],
path: "Sources/Foundation"),
], swiftSettings: availabilityMacros),

// _CShims (Internal)
.target(name: "_CShims",
cSettings: [.define("_CRT_SECURE_NO_WARNINGS",
.when(platforms: [.windows]))]),
// FoundationEssentials
.target(
name: "FoundationEssentials",
dependencies: [
"_CShims",
"FoundationMacros",
.product(name: "_RopeModule", package: "swift-collections"),
],
swiftSettings: [
.enableExperimentalFeature("VariadicGenerics"),
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),
.testTarget(name: "FoundationEssentialsTests", dependencies: [
"TestSupport",
"FoundationEssentials"
], swiftSettings: availabilityMacros),

// TestSupport (Internal)
.target(name: "TestSupport", dependencies: [
"FoundationEssentials",
"FoundationInternationalization",
], swiftSettings: availabilityMacros),

// FoundationEssentials
.target(
name: "FoundationEssentials",
dependencies: [
"_CShims",
"FoundationMacros",
.product(name: "_RopeModule", package: "swift-collections"),
],
swiftSettings: [
.enableExperimentalFeature("VariadicGenerics"),
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),
.testTarget(name: "FoundationEssentialsTests", dependencies: [
"TestSupport",
"FoundationEssentials"
], swiftSettings: availabilityMacros),
// FoundationInternationalization
.target(
name: "FoundationInternationalization",
dependencies: [
.target(name: "FoundationEssentials"),
.target(name: "_CShims"),
.product(name: "FoundationICU", package: "swift-foundation-icu")
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),

// FoundationInternationalization
.target(
name: "FoundationInternationalization",
dependencies: [
.target(name: "FoundationEssentials"),
.target(name: "_CShims"),
.product(name: "FoundationICU", package: "swift-foundation-icu")
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),

// FoundationMacros
.macro(
name: "FoundationMacros",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),
.testTarget(
name: "FoundationMacrosTests",
dependencies: [
"FoundationMacros",
"TestSupport"
],
swiftSettings: availabilityMacros
)
]
)
// FoundationMacros
.macro(
name: "FoundationMacros",
dependencies: [
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
] + availabilityMacros
),
.testTarget(
name: "FoundationMacrosTests",
dependencies: [
"FoundationMacros",
"TestSupport"
],
swiftSettings: availabilityMacros
)
]
)

#if canImport(RegexBuilder)
package.targets.append(contentsOf: [
.testTarget(name: "FoundationInternationalizationTests", dependencies: [
"TestSupport",
"FoundationInternationalization"
], swiftSettings: availabilityMacros),
])
package.targets.append(contentsOf: [
.testTarget(name: "FoundationInternationalizationTests", dependencies: [
"TestSupport",
"FoundationInternationalization"
], swiftSettings: availabilityMacros),
])
#endif
} else {
package = Package(
name: "FoundationPreview",
platforms: [.iOS(.v12), .macOS(.v10_13), .tvOS(.v12), .watchOS(.v4)],
products: [
.library(
name: "FoundationPreview",
targets: ["FoundationPreview"]
),
.library(
name: "FoundationEssentials",
targets: ["FoundationEssentials"]
),
.library(
name: "FoundationInternationalization",
targets: ["FoundationInternationalization"]
),
],
targets: [
.target(
name: "FoundationPreview",
path: "Sources/SystemFoundationExport/FoundationPreview"
),
.target(
name: "FoundationEssentials",
path: "Sources/SystemFoundationExport/FoundationEssentials"
),
.target(
name: "FoundationInternationalization",
path: "Sources/SystemFoundationExport/FoundationInternationalization"
),
]
)
}
83 changes: 0 additions & 83 deletions [email protected]

This file was deleted.

12 changes: 12 additions & 0 deletions Sources/SystemFoundationExport/FoundationEssentials/Export.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

@_exported import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

@_exported import Foundation
Loading