Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ let package = Package(
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .openbsd, .android, .windows, .custom("freebsd")])),
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBCAS",
dependencies: ["SWBUtil", "SWBCSupport"],
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBAndroidPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public import SWBCore
import SWBMacro
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: PluginManager) {
@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
let plugin = AndroidPlugin()
manager.register(AndroidPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(AndroidEnvironmentExtension(plugin: plugin), type: EnvironmentExtensionPoint.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBAndroidPlatformPlugin/PluginMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import SWBAndroidPlatform

@_cdecl("initializePlugin")
@PluginExtensionSystemActor public func main(_ ptr: UnsafeRawPointer) {
initializePlugin(Unmanaged<PluginManager>.fromOpaque(ptr).takeUnretainedValue())
initializePlugin(Unmanaged<MutablePluginManager>.fromOpaque(ptr).takeUnretainedValue())
}
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SWBProtocol
import Foundation
import SWBTaskConstruction

@PluginExtensionSystemActor public func initializePlugin(_ manager: PluginManager) {
@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
manager.register(AppleDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
manager.register(ApplePlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(ActoolInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatformPlugin/PluginMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import SWBApplePlatform

@_cdecl("initializePlugin")
@PluginExtensionSystemActor public func main(_ ptr: UnsafeRawPointer) {
initializePlugin(Unmanaged<PluginManager>.fromOpaque(ptr).takeUnretainedValue())
initializePlugin(Unmanaged<MutablePluginManager>.fromOpaque(ptr).takeUnretainedValue())
}
2 changes: 1 addition & 1 deletion Sources/SWBBuildService/BuildServiceEntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension BuildService {
fileprivate static func run(inputFD: FileDescriptor, outputFD: FileDescriptor, connectionMode: ServiceHostConnectionMode, pluginsDirectory: URL?, arguments: [String], pluginLoadingFinished: () throws -> Void) async throws {
let pluginManager = try await { @PluginExtensionSystemActor () async throws in
// Create the plugin manager and load plugins.
let pluginManager = PluginManager(skipLoadingPluginIdentifiers: [])
let pluginManager = MutablePluginManager(skipLoadingPluginIdentifiers: [])

// Register plugin extension points.
pluginManager.registerExtensionPoint(ServiceExtensionPoint())
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBBuildSystem/BuildOperationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package struct BuildOperationExtensionPoint: ExtensionPoint {

// MARK: - actual extension point

package static func additionalEnvironmentVariables(pluginManager: PluginManager, fromEnvironment: @autoclosure () -> [String: String], parameters: @autoclosure () -> BuildParameters) throws -> [String: String] {
package static func additionalEnvironmentVariables(pluginManager: any PluginManager, fromEnvironment: @autoclosure () -> [String: String], parameters: @autoclosure () -> BuildParameters) throws -> [String: String] {
let (fromEnvironment, parameters) = (fromEnvironment(), parameters())
return try pluginManager.extensions(of: Self.self).reduce([:], { environment, ext in
try environment.addingContents(of: ext.additionalEnvironmentVariables(fromEnvironment: fromEnvironment, parameters: parameters))
Expand Down
5 changes: 5 additions & 0 deletions Sources/SWBCLibc/include/SWBCLibc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
//
//===----------------------------------------------------------------------===//

#include <stdio.h>

extern FILE * const swb_stdout();
extern FILE * const swb_stderr();

#if defined(__linux__) && !defined(__ANDROID__)
#include <fcntl.h>
#include <fnmatch.h>
Expand Down
13 changes: 13 additions & 0 deletions Sources/SWBCLibc/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ int swb_clibc_anchor(void);
int swb_clibc_anchor(void) {
return 0;
}

#include <stdio.h>

extern FILE * const swb_stdout();
extern FILE * const swb_stderr();

FILE * const swb_stdout() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this and swb_stderr() below need to be marked with __declspec(dllexport) on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

#751 might fix it, I'll run it on our CI to test.

return stdout;
}

FILE * const swb_stderr() {
return stderr;
}
20 changes: 10 additions & 10 deletions Sources/SWBCore/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public final class Core: Sendable {
/// Get a configured instance of the core.
///
/// - returns: An initialized Core instance on which all discovery and loading will have been completed. If there are errors during that process, they will be logged to `stderr` and no instance will be returned. Otherwise, the initialized object is returned.
public static func getInitializedCore(_ delegate: any CoreDelegate, pluginManager: PluginManager, developerPath: DeveloperPath? = nil, resourceSearchPaths: [Path] = [], inferiorProductsPath: Path? = nil, extraPluginRegistration: @PluginExtensionSystemActor (_ pluginPaths: [Path]) -> Void = { _ in }, additionalContentPaths: [Path] = [], environment: [String:String] = [:], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async -> Core? {
public static func getInitializedCore(_ delegate: any CoreDelegate, pluginManager: MutablePluginManager, developerPath: DeveloperPath? = nil, resourceSearchPaths: [Path] = [], inferiorProductsPath: Path? = nil, extraPluginRegistration: @PluginExtensionSystemActor (_ pluginManager: MutablePluginManager, _ pluginPaths: [Path]) -> Void = { _, _ in }, additionalContentPaths: [Path] = [], environment: [String:String] = [:], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async -> Core? {
// Enable macro expression interning during loading.
return await MacroNamespace.withExpressionInterningEnabled {
return await MacroNamespace.withExpressionInterningEnabled { () -> Core? in
let hostOperatingSystem: OperatingSystem
do {
hostOperatingSystem = try ProcessInfo.processInfo.hostOperatingSystem()
Expand All @@ -56,7 +56,7 @@ public final class Core: Sendable {
// Load specs from service plugins if requested since we don't have a Service in certain tests
// Here we don't have access to `core.pluginPaths` like we do in the call below,
// but it doesn't matter because it will return an empty array when USE_STATIC_PLUGIN_INITIALIZATION is defined.
await extraPluginRegistration([])
await extraPluginRegistration(pluginManager, [])
#endif

let resolvedDeveloperPath: DeveloperPath
Expand All @@ -83,20 +83,20 @@ public final class Core: Sendable {

let core: Core
do {
core = try await Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: pluginManager, developerPath: resolvedDeveloperPath, resourceSearchPaths: resourceSearchPaths, inferiorProductsPath: inferiorProductsPath, additionalContentPaths: additionalContentPaths, environment: environment, buildServiceModTime: buildServiceModTime, connectionMode: connectionMode)
core = try await Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: pluginManager.finalize(), developerPath: resolvedDeveloperPath, resourceSearchPaths: resourceSearchPaths, inferiorProductsPath: inferiorProductsPath, additionalContentPaths: additionalContentPaths, environment: environment, buildServiceModTime: buildServiceModTime, connectionMode: connectionMode)
} catch {
delegate.error("\(error)")
return nil
}

if UserDefaults.enablePluginManagerLogging {
let plugins = await core.pluginManager.pluginsByIdentifier
let plugins = core.pluginManager.pluginsByIdentifier
delegate.emit(Diagnostic(behavior: .note, location: .unknown, data: DiagnosticData("Loaded \(plugins.count) plugins"), childDiagnostics: plugins.sorted(byKey: <).map { (identifier, plugin) in
Diagnostic(behavior: .note, location: .path(plugin.path), data: DiagnosticData("Loaded plugin: \(identifier) from \(plugin.path.str)"))
}))
}

for diagnostic in await core.pluginManager.loadingDiagnostics {
for diagnostic in core.pluginManager.loadingDiagnostics {
// Only emit "severe" diagnostics (warning, error) from the plugin manager if the logging dwrite isn't set.
if UserDefaults.enablePluginManagerLogging || [.error, .warning].contains(diagnostic.behavior) {
delegate.emit(diagnostic)
Expand All @@ -106,7 +106,7 @@ public final class Core: Sendable {
#if !USE_STATIC_PLUGIN_INITIALIZATION
// In a package context, plugins are statically linked into the build system.
// Load specs from service plugins if requested since we don't have a Service in certain tests
await extraPluginRegistration(core.pluginPaths)
await extraPluginRegistration(core.pluginManager, core.pluginPaths)
#endif

await core.initializeSpecRegistry()
Expand Down Expand Up @@ -167,7 +167,7 @@ public final class Core: Sendable {
/// The host operating system.
public let hostOperatingSystem: OperatingSystem

public let pluginManager: PluginManager
public let pluginManager: any PluginManager

public enum DeveloperPath: Sendable, Hashable {
// A path to an Xcode install's "/Contents/Developer" directory
Expand Down Expand Up @@ -220,7 +220,7 @@ public final class Core: Sendable {

public let connectionMode: ServiceHostConnectionMode

@_spi(Testing) public init(delegate: any CoreDelegate, hostOperatingSystem: OperatingSystem, pluginManager: PluginManager, developerPath: DeveloperPath, resourceSearchPaths: [Path], inferiorProductsPath: Path?, additionalContentPaths: [Path], environment: [String:String], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async throws {
@_spi(Testing) public init(delegate: any CoreDelegate, hostOperatingSystem: OperatingSystem, pluginManager: any PluginManager, developerPath: DeveloperPath, resourceSearchPaths: [Path], inferiorProductsPath: Path?, additionalContentPaths: [Path], environment: [String:String], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async throws {
self.delegate = delegate
self.hostOperatingSystem = hostOperatingSystem
self.pluginManager = pluginManager
Expand Down Expand Up @@ -739,7 +739,7 @@ struct CoreRegistryDelegate : PlatformRegistryDelegate, SDKRegistryDelegate, Spe
return specRegistry.internalMacroNamespace
}

var pluginManager: PluginManager {
var pluginManager: any PluginManager {
core.pluginManager
}

Expand Down
5 changes: 1 addition & 4 deletions Sources/SWBCore/DependencyResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ struct SpecializationParameters: Hashable, CustomStringConvertible {
BuiltinMacros.TOOLCHAINS.name,
BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE.name,
]
@preconcurrency @PluginExtensionSystemActor func sdkVariantInfoExtensions() -> [any SDKVariantInfoExtensionPoint.ExtensionProtocol] {
core.pluginManager.extensions(of: SDKVariantInfoExtensionPoint.self)
}
for sdkVariantInfoExtension in sdkVariantInfoExtensions() {
for sdkVariantInfoExtension in core.pluginManager.extensions(of: SDKVariantInfoExtensionPoint.self) {
macros.formUnion(sdkVariantInfoExtension.supportsMacCatalystMacroNames)
}
return macros
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/Extensions/EnvironmentExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct EnvironmentExtensionPoint: ExtensionPoint {

// MARK: - actual extension point

public static func additionalEnvironmentVariables(pluginManager: PluginManager, context: any EnvironmentExtensionAdditionalEnvironmentVariablesContext) async throws -> [String: String] {
public static func additionalEnvironmentVariables(pluginManager: any PluginManager, context: any EnvironmentExtensionAdditionalEnvironmentVariablesContext) async throws -> [String: String] {
var env: [String: String] = [:]
for ext in pluginManager.extensions(of: Self.self) {
try await env.merge(ext.additionalEnvironmentVariables(context: context), uniquingKeysWith: { _, new in new })
Expand Down
8 changes: 4 additions & 4 deletions Sources/SWBCore/Extensions/SpecificationsExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public struct SpecificationsExtensionPoint: ExtensionPoint {

// MARK: - actual extension point

public static func specificationTypes(pluginManager: PluginManager) -> [any SpecType.Type] {
public static func specificationTypes(pluginManager: any PluginManager) -> [any SpecType.Type] {
return pluginManager.extensions(of: Self.self).reduce([]) { specs, ext in
specs.appending(contentsOf: ext.specificationTypes())
}
}

public static func specificationClasses(pluginManager: PluginManager) -> [any SpecIdentifierType.Type] {
public static func specificationClasses(pluginManager: any PluginManager) -> [any SpecIdentifierType.Type] {
return pluginManager.extensions(of: Self.self).reduce([]) { specs, ext in
specs.appending(contentsOf: ext.specificationClasses())
}
}

public static func specificationClassesClassic(pluginManager: PluginManager) -> [any SpecClassType.Type] {
public static func specificationClassesClassic(pluginManager: any PluginManager) -> [any SpecClassType.Type] {
return pluginManager.extensions(of: Self.self).reduce([]) { specs, ext in
specs.appending(contentsOf: ext.specificationClassesClassic())
}
}

public static func specificationImplementations(pluginManager: PluginManager) -> [any SpecImplementationType.Type] {
public static func specificationImplementations(pluginManager: any PluginManager) -> [any SpecImplementationType.Type] {
return pluginManager.extensions(of: Self.self).reduce([]) { specs, ext in
specs.appending(contentsOf: ext.specificationImplementations())
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SWBCore/PlatformRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public import SWBMacro

/// Delegate protocol used to access external information (such as specifications) and to report diagnostics.
@_spi(Testing) public protocol PlatformRegistryDelegate: DiagnosticProducingDelegate, SpecRegistryProvider {
var pluginManager: PluginManager { get }
var pluginManager: any PluginManager { get }

var developerPath: Core.DeveloperPath { get }
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public final class PlatformRegistry {
await registerPlatformsInDirectory(path, fs)
}

@preconcurrency @PluginExtensionSystemActor func platformInfoExtensions() async -> [any PlatformInfoExtensionPoint.ExtensionProtocol] {
@PluginExtensionSystemActor func platformInfoExtensions() async -> [any PlatformInfoExtensionPoint.ExtensionProtocol] {
return delegate.pluginManager.extensions(of: PlatformInfoExtensionPoint.self)
}

Expand Down Expand Up @@ -562,7 +562,7 @@ public final class PlatformRegistry {
return values.only
}()

@preconcurrency @PluginExtensionSystemActor func platformInfoExtensions() -> [any PlatformInfoExtensionPoint.ExtensionProtocol] {
@PluginExtensionSystemActor func platformInfoExtensions() -> [any PlatformInfoExtensionPoint.ExtensionProtocol] {
delegate.pluginManager.extensions(of: PlatformInfoExtensionPoint.self)
}

Expand Down
28 changes: 11 additions & 17 deletions Sources/SWBCore/SDKRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public import SWBMacro
/// The namespace to parse macros into.
var namespace: MacroNamespace { get }

var pluginManager: PluginManager { get }
var pluginManager: any PluginManager { get }

var platformRegistry: PlatformRegistry? { get }
}
Expand All @@ -32,23 +32,20 @@ public final class SDK: Sendable {
public let suffix: String?
}

private static func supportedSDKCanonicalNameSuffixes(pluginManager: PluginManager) -> Set<String> {
@preconcurrency @PluginExtensionSystemActor func extensions() -> [any SDKRegistryExtensionPoint.ExtensionProtocol] {
pluginManager.extensions(of: SDKRegistryExtensionPoint.self)
}
private static func supportedSDKCanonicalNameSuffixes(registry: SDKRegistry) -> Set<String> {
var suffixes: Set<String> = []
for `extension` in extensions() {
for `extension` in registry.extensions {
suffixes.formUnion(`extension`.supportedSDKCanonicalNameSuffixes)
}
return suffixes
}

/// Returns the component pieces of a given `canonicalName` for an SDK. Returns `nil` if the string is does not match the canonical name format.
@_spi(Testing) public static func parseSDKName(_ sdkCanonicalName: String, pluginManager: PluginManager) throws -> CanonicalNameComponents {
@_spi(Testing) public static func parseSDKName(_ sdkCanonicalName: String, registry: SDKRegistry) throws -> CanonicalNameComponents {
// Remove the suffix, if there is one.
var baseAndVersion = sdkCanonicalName
var suffix: String? = nil
for supportedSuffix in Self.supportedSDKCanonicalNameSuffixes(pluginManager: pluginManager).sorted() {
for supportedSuffix in Self.supportedSDKCanonicalNameSuffixes(registry: registry).sorted() {
// Some SDKs use the dot for suffixes and some do not, so both are supported.
if sdkCanonicalName.hasSuffix(".\(supportedSuffix)") {
baseAndVersion = sdkCanonicalName.withoutSuffix(".\(supportedSuffix)")
Expand Down Expand Up @@ -591,10 +588,12 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send

private func parseSDKName(_ canonicalName: String) throws -> SDK.CanonicalNameComponents {
try parsedSDKNames.getOrInsert(canonicalName) {
Result { try SDK.parseSDKName(canonicalName, pluginManager: delegate.pluginManager) }
Result { try SDK.parseSDKName(canonicalName, registry: self) }
}.get()
}

public let extensions: [any SDKRegistryExtension]

/// The boot system SDK.
//
// FIXME: This doesn't belong here.
Expand All @@ -607,6 +606,8 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send
self.type = type
self.hostOperatingSystem = hostOperatingSystem

extensions = delegate.pluginManager.extensions(of: SDKRegistryExtensionPoint.self)

for (path, platform) in searchPaths {
registerSDKsInDirectory(path, platform)
}
Expand Down Expand Up @@ -989,10 +990,6 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send
return nil
}

@preconcurrency @PluginExtensionSystemActor func extensions() -> [any SDKRegistryExtensionPoint.ExtensionProtocol] {
delegate.pluginManager.extensions(of: SDKRegistryExtensionPoint.self)
}

// Construct the SDK and add it to the registry.
let sdk = SDK(canonicalName, canonicalNameComponents: try? parseSDKName(canonicalName), aliases, cohortPlatforms, displayName, path, version, productBuildVersion, defaultSettings, overrideSettings, variants, defaultDeploymentTarget, defaultVariant, (headerSearchPaths, frameworkSearchPaths, librarySearchPaths), directoryMacros.elements, isBaseSDK, fallbackSettingConditionValues, toolchains, versionMap, maximumDeploymentTarget)
if let duplicate = sdksByCanonicalName[canonicalName] {
Expand Down Expand Up @@ -1237,11 +1234,8 @@ public final class SDKRegistry: SDKRegistryLookup, CustomStringConvertible, Send
}

func supportedSDKCanonicalNameSuffixes() -> Set<String> {
@preconcurrency @PluginExtensionSystemActor func extensions() -> [any SDKRegistryExtensionPoint.ExtensionProtocol] {
delegate.pluginManager.extensions(of: SDKRegistryExtensionPoint.self)
}
var suffixes: Set<String> = []
for `extension` in extensions() {
for `extension` in extensions {
suffixes.formUnion(`extension`.supportedSDKCanonicalNameSuffixes)
}
return suffixes
Expand Down
Loading