From fb2765851c5cb5b42f8d2d87bde7c85d269eb195 Mon Sep 17 00:00:00 2001 From: omochimetaru Date: Mon, 10 Jun 2024 12:23:51 +0900 Subject: [PATCH] set DYLD_LIBRARY_PATH if need --- Sources/CartonCore/FoundationProcessEx.swift | 2 ++ .../CartonDriver/CartonDriverCommand.swift | 22 ++++++++++++++----- Sources/CartonHelpers/DefaultToolchain.swift | 4 +++- .../SwiftToolchain/ToolchainManagement.swift | 18 +++++++++------ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Sources/CartonCore/FoundationProcessEx.swift b/Sources/CartonCore/FoundationProcessEx.swift index e49b9e41..7a99c87c 100644 --- a/Sources/CartonCore/FoundationProcessEx.swift +++ b/Sources/CartonCore/FoundationProcessEx.swift @@ -71,12 +71,14 @@ extension Foundation.Process { public static func checkRun( _ executableURL: URL, arguments: [String], + environment: [String: String]? = nil, printsLoadingMessage: Bool = true, forwardExit: Bool = false ) throws { let process = Foundation.Process() process.executableURL = executableURL process.arguments = arguments + process.environment = environment try process.checkRun( printsLoadingMessage: printsLoadingMessage, forwardExit: forwardExit diff --git a/Sources/CartonDriver/CartonDriverCommand.swift b/Sources/CartonDriver/CartonDriverCommand.swift index 04dc9845..603ec917 100644 --- a/Sources/CartonDriver/CartonDriverCommand.swift +++ b/Sources/CartonDriver/CartonDriverCommand.swift @@ -135,10 +135,10 @@ func pluginSubcommand(subcommand: String, argv0: String, arguments: [String]) as let terminal = InteractiveWriter.stdout let toolchainSystem = try ToolchainSystem(fileSystem: localFileSystem) - let (swiftPath, _) = try await toolchainSystem.inferSwiftPath(terminal) + let swiftPath = try await toolchainSystem.inferSwiftPath(terminal) let extraArguments = arguments - let swiftExec = URL(fileURLWithPath: swiftPath.pathString) + let swiftExec = URL(fileURLWithPath: swiftPath.swift.pathString) let pluginArguments = try derivePackageCommandArguments( swiftExec: swiftExec, subcommand: subcommand, @@ -146,8 +146,19 @@ func pluginSubcommand(subcommand: String, argv0: String, arguments: [String]) as extraArguments: extraArguments ) + var env: [String: String] = ProcessInfo.processInfo.environment + if ToolchainSystem.isSnapshotVersion(swiftPath.verison), + swiftPath.toolchain.extension == "xctoolchain" + { + env["DYLD_LIBRARY_PATH"] = swiftPath.toolchain.appending( + components: ["usr", "lib", "swift", "macosx"] + ).pathString + } + try Foundation.Process.checkRun( - swiftExec, arguments: pluginArguments, + swiftExec, + arguments: pluginArguments, + environment: env, forwardExit: true ) } @@ -175,9 +186,10 @@ public func main(arguments: [String]) async throws { case "package": let terminal = InteractiveWriter.stdout let toolchainSystem = try ToolchainSystem(fileSystem: localFileSystem) - let (swiftPath, _) = try await toolchainSystem.inferSwiftPath(terminal) + let swiftPath = try await toolchainSystem.inferSwiftPath(terminal) + try Foundation.Process.checkRun( - URL(fileURLWithPath: swiftPath.pathString), + URL(fileURLWithPath: swiftPath.swift.pathString), arguments: ["package"] + arguments.dropFirst(), forwardExit: true ) diff --git a/Sources/CartonHelpers/DefaultToolchain.swift b/Sources/CartonHelpers/DefaultToolchain.swift index 0d830311..fe6dc7e7 100644 --- a/Sources/CartonHelpers/DefaultToolchain.swift +++ b/Sources/CartonHelpers/DefaultToolchain.swift @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if compiler(>=5.10) +#if compiler(>=6.0) +public let defaultToolchainVersion = "wasm-6.0-SNAPSHOT-2024-06-08-a" +#elseif compiler(>=5.10) public let defaultToolchainVersion = "wasm-6.0-SNAPSHOT-2024-06-08-a" #else public let defaultToolchainVersion = "wasm-5.9.2-RELEASE" diff --git a/Sources/SwiftToolchain/ToolchainManagement.swift b/Sources/SwiftToolchain/ToolchainManagement.swift index cbb5209e..3071e6c6 100644 --- a/Sources/SwiftToolchain/ToolchainManagement.swift +++ b/Sources/SwiftToolchain/ToolchainManagement.swift @@ -235,13 +235,19 @@ public class ToolchainSystem { } } + public struct SwiftPath { + public var verison: String + public var swift: AbsolutePath + public var toolchain: AbsolutePath + } + /** Infer `swift` binary path matching a given version if any is present, or infer the version from the `.swift-version` file. If neither version is installed, download it. */ public func inferSwiftPath( from versionSpec: String? = nil, _ terminal: InteractiveWriter - ) async throws -> (AbsolutePath, String) { + ) async throws -> SwiftPath { let specURL = versionSpec.flatMap { (string: String) -> Foundation.URL? in guard let url = Foundation.URL(string: string), @@ -254,11 +260,9 @@ public class ToolchainSystem { let swiftVersion = try inferSwiftVersion(from: versionSpec, terminal) for resolver in resolvers { - if let path = try checkAndLog( - installationPath: resolver.toolchain(for: swiftVersion), - terminal - ) { - return (path, swiftVersion) + let toolchain = resolver.toolchain(for: swiftVersion) + if let path = try checkAndLog(installationPath: toolchain, terminal) { + return SwiftPath(verison: swiftVersion, swift: path, toolchain: toolchain) } } @@ -291,7 +295,7 @@ public class ToolchainSystem { throw ToolchainError.invalidInstallationArchive(installationPath) } - return (path, swiftVersion) + return SwiftPath(verison: swiftVersion, swift: path, toolchain: installationPath) } public func fetchAllSwiftVersions() throws -> [String] {