-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Apply runtime library workaround for snapshot toolchains on macOS #484
Changes from all commits
56e254e
2f9acd9
502ae93
46b6e2b
dcc8dec
861e5c7
d9fb1d2
8d7edd1
8835ffd
ad8f613
1a408ec
f254601
af42678
b398cfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,19 +135,30 @@ 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, | ||
scratchPath: scratchPath.path, | ||
extraArguments: extraArguments | ||
) | ||
|
||
var env: [String: String] = ProcessInfo.processInfo.environment | ||
if ToolchainSystem.isSnapshotVersion(swiftPath.verison), | ||
swiftPath.toolchain.extension == "xctoolchain" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mac環境かつsnapshotなら、 |
||
{ | ||
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 | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,16 @@ struct CommandTestRunner: TestRunner { | |
var arguments = [program, testFilePath.pathString] | ||
if listTestCases { | ||
arguments.append(contentsOf: ["--", "-l"]) | ||
} else if !testCases.isEmpty { | ||
arguments.append("--") | ||
arguments.append(contentsOf: testCases) | ||
} else { | ||
let programName = (program as NSString).lastPathComponent | ||
if programName == "wasmtime" { | ||
arguments += ["--dir", "."] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasmtimeのpreopenの問題の対応 |
||
} | ||
|
||
if !testCases.isEmpty { | ||
arguments.append("--") | ||
arguments.append(contentsOf: testCases) | ||
} | ||
} | ||
try await Process.run(arguments, parser: TestsParser(), terminal) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 6.0のsnapshotを追加します。 |
||
#elseif compiler(>=5.10) | ||
public let defaultToolchainVersion = "wasm-5.10.0-RELEASE" | ||
#else | ||
public let defaultToolchainVersion = "wasm-5.9.2-RELEASE" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,6 @@ extension Process { | |
|
||
switch result.map(\.exitStatus) { | ||
case .success(.terminated(code: EXIT_SUCCESS)): | ||
terminal.write("\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この改行が不要そうでした。 |
||
if let parser = parser { | ||
if parser.parsingConditions.contains(.success) { | ||
parser.parse(stdoutBuffer, terminal) | ||
|
@@ -103,7 +102,7 @@ extension Process { | |
terminal.write(stdoutBuffer) | ||
} | ||
terminal.write( | ||
"\n`\(processName)` process finished successfully\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この冒頭の改行も不要だと思いました。 |
||
"`\(processName)` process finished successfully\n", | ||
inColor: .green, | ||
bold: false | ||
) | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import CartonCore | ||
import CartonHelpers | ||
import Foundation | ||
|
||
|
@@ -65,6 +66,8 @@ extension ToolchainSystem { | |
stream: stdoutStream, | ||
header: "Downloading the archive" | ||
) | ||
defer { terminal.write("\n") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ダウンロードが完了した時 ここはターミナルがアニメーションするループがあるので、 |
||
|
||
var previouslyReceived = 0 | ||
for try await progress in fileDownload.progressStream { | ||
guard progress.receivedBytes - previouslyReceived >= (progress.totalOrEstimatedBytes / 100) | ||
|
@@ -109,6 +112,32 @@ extension ToolchainSystem { | |
terminal.logLookup("Unpacking the archive: ", arguments.joined(separator: " ")) | ||
try await Process.run(arguments, terminal) | ||
|
||
if ext == "pkg", Self.isSnapshotVersion(version) { | ||
try await patchSnapshotForMac(path: installationPath, terminal: terminal) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. インストール後にmacでsnapshotならパッチ(再署名)します。 |
||
} | ||
|
||
return installationPath | ||
} | ||
|
||
func patchSnapshotForMac(path: AbsolutePath, terminal: InteractiveWriter) async throws { | ||
let binDir = path.appending(components: ["usr", "bin"]) | ||
|
||
terminal.write( | ||
"To avoid issues with the snapshot, the toolchain will be re-signed.\n", | ||
inColor: .yellow | ||
) | ||
|
||
for file in try fileSystem.traverseRecursively(binDir) { | ||
guard fileSystem.isFile(file) else { continue } | ||
|
||
try Foundation.Process.checkRun( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 出力がスッキリするので |
||
URL(fileURLWithPath: "/usr/bin/codesign"), | ||
arguments: [ | ||
"--force", | ||
"--preserve-metadata=identifier,entitlements", | ||
"--sign", "-", file.pathString | ||
] | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,13 +235,19 @@ public class ToolchainSystem { | |
} | ||
} | ||
|
||
public struct SwiftPath { | ||
public var verison: String | ||
public var swift: AbsolutePath | ||
public var toolchain: AbsolutePath | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 従来、swiftとバージョンのタプルでしたが、 ついでにタプルをやめて型にすることで利用側のコードを読みやすくします。 |
||
|
||
/** 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] { | ||
|
@@ -311,4 +315,8 @@ public class ToolchainSystem { | |
|
||
return version | ||
} | ||
|
||
public static func isSnapshotVersion(_ version: String) -> Bool { | ||
version.contains("SNAPSHOT") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
環境変数を設定する口を開けました。
nil
をセットすると、継承するデフォルト挙動が消えるようなので、
nilの時はifで避けます。
参考:
https://developer.apple.com/documentation/foundation/process/1409412-environment