mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-21 18:55:56 +03:00
Compare commits
1 Commits
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$
|
||||
Hello$
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$ cd Hello
|
||||
Hello$ ls -la
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$ cd Hello
|
||||
Hello$ ls -la
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$ cd Hello
|
||||
Hello$ ls -la
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$ cd Hello
|
||||
Hello$ ls -la
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
|
||||
@@ -3,7 +3,7 @@ Creating package: Hello
|
||||
Creating Package.swift
|
||||
Creating xtool.yml
|
||||
Creating .gitignore
|
||||
Creating .bsp/xtool.json
|
||||
Creating .sourcekit-lsp/config.json
|
||||
Creating Sources/Hello/HelloApp.swift
|
||||
Creating Sources/Hello/ContentView.swift
|
||||
|
||||
@@ -12,7 +12,7 @@ Finished generating project Hello.
|
||||
Developer$ cd Hello
|
||||
Hello$ ls -la
|
||||
-rw-rw-r-- 1 user user 187 .gitignore
|
||||
drwxrwxr-x 2 user user 4096 .bsp
|
||||
drwxrwxr-x 2 user user 4096 .sourcekit-lsp
|
||||
-rw-rw-r-- 1 user user 463 Package.swift
|
||||
drwxrwxr-x 3 user user 4096 Sources
|
||||
-rw-rw-r-- 1 user user 39 xtool.yml
|
||||
@@ -21,9 +21,5 @@ Hello$ cat xtool.yml
|
||||
version: 1
|
||||
bundleID: com.example.Hello
|
||||
|
||||
Hello$ cat .bsp/xtool.json
|
||||
{
|
||||
"name": "xtool",
|
||||
...
|
||||
"argv": ["/usr/bin/env", "xtool", "dev", "build-server"]
|
||||
}
|
||||
Hello$ cat .sourcekit-lsp/config.json
|
||||
{ "swiftPM": { "swiftSDK": "arm64-apple-ios" } }
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
}
|
||||
|
||||
@Step {
|
||||
Read `.bsp/xtool.json`.
|
||||
Read `.sourcekit-lsp/config.json`.
|
||||
|
||||
This file tells your IDE to ask xtool for build information (via the Build Server Protocol). It enables features like syntax highlighting and documentation lookup.
|
||||
This file tells SourceKit to build for the `arm64-apple-ios` system defined in `darwin.artifactbundle`. This is the [Swift SDK](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md) that we built during the setup process. It contains the necessary modules for building iOS apps, such as UIKit and SwiftUI, as well as tools for building and manipulating iOS binaries. Under the hood, xtool also calls `swift build` with `--swift-sdk arm64-apple-ios` for the same reason.
|
||||
|
||||
@Code(name: "Terminal", file: "template-4b.sh", previousFile: "template-4a.sh") {}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ Once you install WSL, you'll also need to set up USB passthrough. See Microsoft'
|
||||
|
||||
### Swift
|
||||
|
||||
Install the Swift 6.4 toolchain for your Linux distribution from <https://swift.org/install/linux>.
|
||||
Install the Swift 6.3 toolchain for your Linux distribution from <https://swift.org/install/linux>.
|
||||
|
||||
After following the steps there, confirm that Swift is installed correctly:
|
||||
|
||||
```bash
|
||||
swift --version
|
||||
# should say something like:
|
||||
# Swift version 6.4 (swift-6.4-RELEASE)
|
||||
# Swift version 6.3 (swift-6.3-RELEASE)
|
||||
```
|
||||
|
||||
### usbmuxd
|
||||
@@ -68,7 +68,7 @@ sudo apt-get install usbmuxd
|
||||
|
||||
### Xcode.xip
|
||||
|
||||
Download **Xcode 27** from <https://developer.apple.com/download/all/?q=Xcode>. Note the path where `Xcode.xip` is saved.
|
||||
Download **Xcode 26** from <https://developer.apple.com/download/all/?q=Xcode>. Note the path where `Xcode.xip` is saved.
|
||||
|
||||
> Note:
|
||||
>
|
||||
@@ -131,7 +131,7 @@ Choice (0-1): 0
|
||||
Path to Xcode.xip:
|
||||
```
|
||||
|
||||
Enter the path (for example `~/Downloads/Xcode_27.0.xip`) and hit enter. xtool will extract the Xcode XIP to generate and install an iOS Swift SDK for you.
|
||||
Enter the path (for example `~/Downloads/Xcode_16.3.xip`) and hit enter. xtool will extract the Xcode XIP to generate and install an iOS Swift SDK for you.
|
||||
|
||||
Confirm that it worked:
|
||||
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ let package = Package(
|
||||
"DeveloperAPI",
|
||||
"CXKit",
|
||||
"XUtils",
|
||||
.product(name: "XADI", package: "xadi", condition: .when(platforms: [.linux, .macOS])),
|
||||
.product(name: "XADI", package: "xadi", condition: .when(platforms: [.linux])),
|
||||
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
|
||||
.product(name: "Dependencies", package: "swift-dependencies"),
|
||||
.product(name: "SwiftyMobileDevice", package: "SwiftyMobileDevice"),
|
||||
|
||||
@@ -1,75 +1,37 @@
|
||||
import Foundation
|
||||
import Subprocess
|
||||
import XUtils
|
||||
import Superutils
|
||||
|
||||
public struct BuildSettings: Sendable {
|
||||
private static let customBinDir =
|
||||
// this is the same option used by SwiftPM itself for dev builds
|
||||
ProcessInfo.processInfo.environment["SWIFTPM_CUSTOM_BIN_DIR"].map { FilePath($0) }
|
||||
|
||||
public var packagePath: String
|
||||
private static let envURL = URL(fileURLWithPath: "/usr/bin/env")
|
||||
|
||||
public let packagePath: String
|
||||
public let configuration: BuildConfiguration
|
||||
public let triple: String
|
||||
public let buildSystem: BuildSystem
|
||||
public let customOptions: [String]
|
||||
|
||||
public var sdkOptions: [String]
|
||||
public var sdkEnvironment: [Environment.Key: String?]
|
||||
|
||||
private var configOptions: [String] {
|
||||
return [
|
||||
"--configuration", configuration.rawValue,
|
||||
"--build-system", buildSystem.pmName,
|
||||
"--package-path", packagePath,
|
||||
]
|
||||
}
|
||||
|
||||
private var resolvedBaseOptions: [String] {
|
||||
configOptions + sdkOptions + customOptions
|
||||
}
|
||||
public let sdkOptions: [String]
|
||||
public let options: [String]
|
||||
|
||||
public init(
|
||||
configuration: BuildConfiguration,
|
||||
triple: String,
|
||||
buildSystem: BuildSystem? = nil,
|
||||
packagePath: String = ".",
|
||||
options: [String] = []
|
||||
) async throws {
|
||||
self.packagePath = packagePath
|
||||
self.configuration = configuration
|
||||
self.customOptions = options
|
||||
self.options = options
|
||||
self.triple = triple
|
||||
self.buildSystem = if let buildSystem { buildSystem } else { try await .default() }
|
||||
|
||||
self.sdkEnvironment = [
|
||||
// xcrun passes an SDKROOT that messes with our sdk configuration
|
||||
"SDKROOT": nil,
|
||||
]
|
||||
|
||||
switch self.buildSystem {
|
||||
case .swiftPM:
|
||||
// on macOS we don't explicitly install a Swift SDK but
|
||||
// SwiftPM vends "implicit" Darwin SDKs as of Swift 6.1,
|
||||
// i.e. we can pass `--swift-sdk arm64-apple-ios` and it
|
||||
// just works. See:
|
||||
// https://github.com/swiftlang/swift-package-manager/pull/6828
|
||||
self.sdkOptions = ["--swift-sdk", triple]
|
||||
case .swiftBuild:
|
||||
self.sdkOptions = ["--triple", triple]
|
||||
#if !os(macOS)
|
||||
let darwinSDK = try DarwinSDK.current()
|
||||
.orThrow(StringError("No Darwin SDK configured. Please run `xtool setup`."))
|
||||
self.sdkOptions += [
|
||||
"--toolset", "\(darwinSDK.bundle.path)/toolset-swb.json",
|
||||
]
|
||||
self.sdkEnvironment.merge([
|
||||
"XCODE_EXTRA_PLATFORM_FOLDERS": "\(darwinSDK.bundle.path)/Developer/Platforms",
|
||||
// SWB looks for dsymutil in the PATH. Other stuff (lld, libtool) is handled by toolset-swb.json.
|
||||
"PATH": "\(darwinSDK.bundle.path)/toolset/bin:\(ProcessInfo.processInfo.environment["PATH"] ?? "")",
|
||||
]) { $1 }
|
||||
#endif
|
||||
}
|
||||
// on macOS we don't explicitly install a Swift SDK but
|
||||
// SwiftPM vends "implicit" Darwin SDKs as of Swift 6.1,
|
||||
// i.e. we can pass `--swift-sdk arm64-apple-ios` and it
|
||||
// just works. See:
|
||||
// https://github.com/swiftlang/swift-package-manager/pull/6828
|
||||
self.sdkOptions = ["--swift-sdk", triple]
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
@@ -82,40 +44,15 @@ public struct BuildSettings: Sendable {
|
||||
return result.standardOutput?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
}
|
||||
|
||||
private static let _swiftURL = Task {
|
||||
private static let swiftURL = Task {
|
||||
try await FilePath(xcrun(["-f", "swift"]))
|
||||
}
|
||||
|
||||
public static func swiftURL() async throws -> FilePath {
|
||||
try await _swiftURL.value
|
||||
}
|
||||
|
||||
private static let _swiftcURL = Task {
|
||||
try await FilePath(xcrun(["-f", "swiftc"]))
|
||||
}
|
||||
|
||||
public static func swiftcURL() async throws -> FilePath {
|
||||
try await _swiftcURL.value
|
||||
}
|
||||
#else
|
||||
public static func swiftURL() async throws -> FilePath {
|
||||
try await FilePath(ToolRegistry.locate("swift")).orThrow(StringError("Got bad path for swift executable"))
|
||||
}
|
||||
|
||||
public static func swiftcURL() async throws -> FilePath {
|
||||
try await FilePath(ToolRegistry.locate("swiftc")).orThrow(StringError("Got bad path for swiftc executable"))
|
||||
}
|
||||
#endif
|
||||
|
||||
public func withPackagePath(_ path: String) -> Self {
|
||||
var copy = self
|
||||
copy.packagePath = path
|
||||
return copy
|
||||
}
|
||||
|
||||
public func swiftPMInvocation(
|
||||
forTool tool: String,
|
||||
arguments: [String],
|
||||
packagePathOverride: String? = nil
|
||||
) async throws -> Subprocess.Configuration {
|
||||
let executable: Executable
|
||||
let baseArguments: [String]
|
||||
@@ -128,71 +65,35 @@ public struct BuildSettings: Sendable {
|
||||
// to add SDKROOT=.../MacOSX.sdk to our invocations. We avoid this by
|
||||
// 1) invoking the real swift executable (located with `xcrun -f`) and
|
||||
// 2) explicitly removing SDKROOT from the env, as it may be inherited
|
||||
// through a parent process (e.g. `swift run xtool`).
|
||||
executable = .path(try await Self.swiftURL())
|
||||
// through the `swift run pack` invocation.
|
||||
executable = .path(try await Self.swiftURL.value)
|
||||
#else
|
||||
executable = .name("swift")
|
||||
#endif
|
||||
baseArguments = [tool]
|
||||
}
|
||||
|
||||
let extraArguments: [String] = [
|
||||
"--package-path", packagePathOverride ?? packagePath,
|
||||
"--configuration", configuration.rawValue,
|
||||
]
|
||||
|
||||
var rawEnv = ProcessInfo.processInfo.environment
|
||||
rawEnv.removeValue(forKey: "SDKROOT")
|
||||
let env = Dictionary(uniqueKeysWithValues: rawEnv.map {
|
||||
(Environment.Key(rawValue: $0)!, $1)
|
||||
})
|
||||
|
||||
return Configuration(
|
||||
executable,
|
||||
arguments: .init(baseArguments + resolvedBaseOptions + arguments),
|
||||
environment: .inherit.updating(sdkEnvironment),
|
||||
arguments: .init(baseArguments + extraArguments + sdkOptions + options + arguments),
|
||||
environment: .custom(env),
|
||||
platformOptions: .withGracefulShutDown,
|
||||
)
|
||||
}
|
||||
|
||||
// loosely based on
|
||||
// https://github.com/swiftlang/sourcekit-lsp/blob/c55899a/Sources/BuildServerIntegration/ExternalBuildServerAdapter.swift#L92
|
||||
private var baseBuildServerArguments: [String] {
|
||||
return [
|
||||
"experimental-build-server",
|
||||
"--disable-automatic-resolution",
|
||||
"--scratch-path", ".build/index-build",
|
||||
// this requires Swift 6.4 but we need 6.4 on Linux anyway, for the platform toolset fixes
|
||||
"--experimental-skip-acquiring-lock",
|
||||
]
|
||||
}
|
||||
|
||||
public var buildServerArguments: [String] {
|
||||
["package"] + baseBuildServerArguments + resolvedBaseOptions
|
||||
}
|
||||
|
||||
public func buildServerInvocation() async throws -> Subprocess.Configuration {
|
||||
try await swiftPMInvocation(forTool: "package", arguments: baseBuildServerArguments)
|
||||
}
|
||||
}
|
||||
|
||||
public enum BuildConfiguration: String, CaseIterable, Sendable {
|
||||
case debug
|
||||
case release
|
||||
|
||||
var swiftBuildValue: String {
|
||||
switch self {
|
||||
case .debug: "Debug"
|
||||
case .release: "Release"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum BuildSystem: Sendable {
|
||||
case swiftPM
|
||||
case swiftBuild
|
||||
|
||||
public static func `default`() async throws -> Self {
|
||||
if try await SwiftVersion.current.supportsSwiftBuild {
|
||||
return .swiftBuild
|
||||
} else {
|
||||
return .swiftPM
|
||||
}
|
||||
}
|
||||
|
||||
var pmName: String {
|
||||
switch self {
|
||||
case .swiftPM: "native"
|
||||
case .swiftBuild: "swiftbuild"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,23 +98,14 @@ public struct DarwinSDK {
|
||||
}
|
||||
|
||||
private static func addHostClangResourceDir(to sdk: URL) async throws {
|
||||
struct SwiftTargetInfo: Decodable {
|
||||
struct Paths: Decodable {
|
||||
let runtimeResourcePath: String
|
||||
}
|
||||
let paths: Paths
|
||||
}
|
||||
|
||||
let clangURL = try await ToolRegistry.locate("clang")
|
||||
let process = try await Subprocess.run(
|
||||
.path(try await BuildSettings.swiftcURL()),
|
||||
arguments: ["-print-target-info"],
|
||||
output: .data(limit: .max)
|
||||
.path(FilePath(clangURL.path)),
|
||||
arguments: ["-print-resource-dir"],
|
||||
output: .string(limit: .max)
|
||||
).checkSuccess()
|
||||
let targetInfo = try JSONDecoder().decode(
|
||||
SwiftTargetInfo.self,
|
||||
from: process.standardOutput
|
||||
)
|
||||
let hostClangResources = URL(filePath: targetInfo.paths.runtimeResourcePath).appending(path: "clang")
|
||||
let output = process.standardOutput ?? ""
|
||||
let hostClangResources = URL(filePath: output.trimmingCharacters(in: .whitespacesAndNewlines))
|
||||
let hostInclude = hostClangResources.appending(path: "include")
|
||||
let sdkInclude = sdk.appending(path: "Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include")
|
||||
try await FileManager.default.copyItem(at: hostInclude, to: sdkInclude, preserveOwner: false)
|
||||
|
||||
@@ -22,9 +22,6 @@ public struct PackSchemaBase: Codable, Sendable {
|
||||
|
||||
public var extensions: [Extension]?
|
||||
|
||||
/// Skip auto-creating the LSP support file if it's missing.
|
||||
public var skipLSP: Bool?
|
||||
|
||||
public struct Extension: Codable, Sendable {
|
||||
public var product: String
|
||||
public var bundleID: String?
|
||||
|
||||
@@ -55,21 +55,20 @@ public struct Packer: Sendable {
|
||||
try Data().write(to: sources.appendingPathComponent("stub.c", isDirectory: false))
|
||||
}
|
||||
|
||||
let buildConfig = try await buildSettings
|
||||
.withPackagePath(packageDir.path)
|
||||
.swiftPMInvocation(
|
||||
forTool: "build",
|
||||
arguments: [
|
||||
"--scratch-path", ".build",
|
||||
// resolving can cause SwiftPM to overwrite the root package deps
|
||||
// with just the deps needed for the builder package (which is to
|
||||
// say, any "dev dependencies" of the root package may be removed.)
|
||||
// fortunately we've already resolved the root package by this point
|
||||
// in order to dump the plan, so we can skip resolution here to skirt
|
||||
// the issue.
|
||||
"--disable-automatic-resolution",
|
||||
],
|
||||
)
|
||||
let buildConfig = try await buildSettings.swiftPMInvocation(
|
||||
forTool: "build",
|
||||
arguments: [
|
||||
"--package-path", packageDir.path,
|
||||
"--scratch-path", ".build",
|
||||
// resolving can cause SwiftPM to overwrite the root package deps
|
||||
// with just the deps needed for the builder package (which is to
|
||||
// say, any "dev dependencies" of the root package may be removed.)
|
||||
// fortunately we've already resolved the root package by this point
|
||||
// in order to dump the plan, so we can skip resolution here to skirt
|
||||
// the issue.
|
||||
"--disable-automatic-resolution",
|
||||
]
|
||||
)
|
||||
try await Subprocess.run(
|
||||
buildConfig,
|
||||
output: .currentStandardOutput,
|
||||
@@ -85,16 +84,8 @@ public struct Packer: Sendable {
|
||||
|
||||
let outputURL = output.url
|
||||
|
||||
let binPath: String
|
||||
switch buildSettings.buildSystem {
|
||||
case .swiftPM:
|
||||
binPath = "\(buildSettings.triple)/\(buildSettings.configuration.rawValue)"
|
||||
case .swiftBuild:
|
||||
let platformName = buildSettings.triple.contains("simulator") ? "iphonesimulator" : "iphoneos"
|
||||
binPath = "out/Products/\(buildSettings.configuration.swiftBuildValue)-\(platformName)"
|
||||
}
|
||||
let binDir = URL(
|
||||
fileURLWithPath: ".build/\(binPath)",
|
||||
fileURLWithPath: ".build/\(buildSettings.triple)/\(buildSettings.configuration.rawValue)",
|
||||
isDirectory: true
|
||||
)
|
||||
|
||||
|
||||
@@ -244,9 +244,10 @@ public struct Planner: Sendable {
|
||||
}
|
||||
|
||||
private func _dumpAction(arguments: [String], path: String) async throws -> Data {
|
||||
let dumpConfig = try await buildSettings.withPackagePath(path).swiftPMInvocation(
|
||||
let dumpConfig = try await buildSettings.swiftPMInvocation(
|
||||
forTool: "package",
|
||||
arguments: arguments,
|
||||
packagePathOverride: path
|
||||
)
|
||||
return try await Subprocess.run(
|
||||
dumpConfig,
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import Subprocess
|
||||
import Version
|
||||
import XUtils
|
||||
|
||||
public struct SwiftVersion: Sendable {
|
||||
public var version: Version
|
||||
|
||||
public var supportsSwiftBuild: Bool {
|
||||
version >= Version(6, 4, 0)
|
||||
}
|
||||
}
|
||||
|
||||
extension SwiftVersion {
|
||||
private static let cached = Task<Self, Error> {
|
||||
let outputString: String?
|
||||
do {
|
||||
outputString = try await Subprocess.run(
|
||||
.path(try await BuildSettings.swiftURL()),
|
||||
arguments: ["--version"],
|
||||
output: .string(limit: .max)
|
||||
)
|
||||
.checkSuccess()
|
||||
.standardOutput
|
||||
} catch {
|
||||
throw StringError("Failed to obtain Swift version")
|
||||
}
|
||||
var output = outputString?[...] ?? ""
|
||||
if output.hasPrefix("Apple ") {
|
||||
output = output.dropFirst("Apple ".count)
|
||||
}
|
||||
guard output.hasPrefix("Swift version ") else {
|
||||
throw StringError("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
output = output.dropFirst("Swift version ".count)
|
||||
guard let space = output.firstIndex(of: " ") else {
|
||||
throw StringError("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
output = output[..<space]
|
||||
guard let version = Version(tolerant: output) else {
|
||||
throw StringError("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
return SwiftVersion(version: version)
|
||||
}
|
||||
|
||||
public static var current: Self {
|
||||
get async throws {
|
||||
try await cached.value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,10 +92,13 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
|
||||
private let _clientInfo = LockIsolated<String?>(nil)
|
||||
|
||||
public init() {
|
||||
public init(provisioningData: ProvisioningData? = nil) {
|
||||
@Dependency(\.keyValueStorage) var storage
|
||||
|
||||
if let localUserUIDString = try? storage.string(forKey: Self.localUserUIDKey),
|
||||
if let provisioningData {
|
||||
self.localUserUID = provisioningData.localUserUID
|
||||
try? storage.setData(provisioningData.adiPb, forKey: Self.provisioningKey)
|
||||
try? storage.setString("\(provisioningData.routingInfo)", forKey: Self.routingInfoKey)
|
||||
} else if let localUserUIDString = try? storage.string(forKey: Self.localUserUIDKey),
|
||||
let localUserUID = UUID(uuidString: localUserUIDString) {
|
||||
self.localUserUID = localUserUID
|
||||
} else {
|
||||
@@ -107,15 +110,9 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
self.localUserID = SHA256.hash(data: Data(localUserUID.uuidString.utf8))
|
||||
.map { String(format: "%02X", $0) }
|
||||
.joined()
|
||||
|
||||
if (try? storage.string(forKey: Self.providerIDKey)) != Self.providerID {
|
||||
self.resetProvisioning()
|
||||
try? storage.setString(Self.providerID, forKey: Self.providerIDKey)
|
||||
}
|
||||
}
|
||||
|
||||
private static let localUserUIDKey = "XTLLocalUserUID"
|
||||
private static let providerIDKey = "XTLADIProviderID"
|
||||
private static let provisioningKey = "XTLProvisioningInfo"
|
||||
private static let routingInfoKey = "XTLRoutingInfo"
|
||||
|
||||
@@ -248,16 +245,6 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
try? storage.setString(nil, forKey: Self.routingInfoKey)
|
||||
}
|
||||
|
||||
private static var providerID: String? {
|
||||
#if os(macOS)
|
||||
return "1"
|
||||
#else
|
||||
return nil
|
||||
#endif
|
||||
}
|
||||
|
||||
public var providerID: String? { Self.providerID }
|
||||
|
||||
public func provisioningData() -> ProvisioningData? {
|
||||
guard let provisioningInfo = try? storage.data(forKey: Self.provisioningKey),
|
||||
let routingInfoString = try? storage.string(forKey: Self.routingInfoKey),
|
||||
@@ -293,23 +280,6 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
|
||||
}
|
||||
|
||||
public struct ADIError: Error, CustomStringConvertible {
|
||||
public struct ADIError: Error {
|
||||
public var code: Int
|
||||
|
||||
public var description: String {
|
||||
switch code {
|
||||
case -45061:
|
||||
return """
|
||||
You were logged out. Please log in again with `xtool auth`.
|
||||
|
||||
If you see this repeatedly, please file an issue at https://github.com/xtool-org/xtool/issues/new/choose
|
||||
"""
|
||||
default:
|
||||
return """
|
||||
Apple Anisette library returned error \(code). Please try logging in again with `xtool auth`.
|
||||
|
||||
If this problem persists, file an issue at https://github.com/xtool-org/xtool/issues/new/choose
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,6 @@ import Foundation
|
||||
import Dependencies
|
||||
|
||||
public protocol AnisetteDataProvider: Sendable {
|
||||
/// Stored alongside login data. If the provider reports a new ID, we log out.
|
||||
///
|
||||
/// This is useful when switching Anisette provider implementations if the old
|
||||
/// implementation's provisioning data won't work with the new implementation.
|
||||
///
|
||||
/// The default implementation returns `nil`.
|
||||
var providerID: String? { get }
|
||||
|
||||
// This is a suggestion and not a requirement.
|
||||
func resetProvisioning() async
|
||||
func provisioningData() -> ProvisioningData?
|
||||
@@ -32,7 +24,6 @@ public struct ProvisioningData: Hashable, Codable, Sendable {
|
||||
}
|
||||
|
||||
extension AnisetteDataProvider {
|
||||
public var providerID: String? { nil }
|
||||
public func provisioningData() -> ProvisioningData? { nil }
|
||||
public func resetProvisioning() async {}
|
||||
}
|
||||
|
||||
@@ -111,15 +111,12 @@ struct AuthOperation {
|
||||
}
|
||||
)
|
||||
|
||||
@Dependency(\.anisetteDataProvider) var anisetteProvider
|
||||
|
||||
return AuthToken.xcode(.init(
|
||||
appleID: username,
|
||||
adsid: token.adsid,
|
||||
token: token.token,
|
||||
expiry: token.expiry,
|
||||
teamID: team.id.rawValue,
|
||||
anisetteProviderID: anisetteProvider.providerID
|
||||
teamID: team.id.rawValue
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ enum AuthToken: Codable, CustomStringConvertible {
|
||||
var token: String
|
||||
var expiry: Date
|
||||
var teamID: String
|
||||
var anisetteProviderID: String?
|
||||
}
|
||||
|
||||
struct AppStoreConnect: Codable {
|
||||
@@ -59,18 +58,7 @@ extension AuthToken {
|
||||
guard let data = try storage.data(forKey: "XTLAuthToken") else {
|
||||
return nil
|
||||
}
|
||||
let decoded = try decoder.decode(AuthToken.self, from: data)
|
||||
switch decoded {
|
||||
case .xcode(let xcode):
|
||||
@Dependency(\.anisetteDataProvider) var anisetteProvider
|
||||
guard xcode.anisetteProviderID == anisetteProvider.providerID else {
|
||||
try? clear()
|
||||
return nil
|
||||
}
|
||||
case .appStoreConnect:
|
||||
break
|
||||
}
|
||||
return decoded
|
||||
return try decoder.decode(AuthToken.self, from: data)
|
||||
}
|
||||
|
||||
static func clear() throws {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import XKit
|
||||
import PackLib
|
||||
import Subprocess
|
||||
|
||||
struct DevBSPCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "build-server",
|
||||
abstract: "Run build server",
|
||||
)
|
||||
|
||||
@Option
|
||||
var triple: String?
|
||||
|
||||
func run() async throws {
|
||||
guard try await SwiftVersion.current.supportsSwiftBuild else {
|
||||
throw Console.Error("`xtool dev build-server` requires Swift 6.4 or later")
|
||||
}
|
||||
let settings = try await BuildSettings(
|
||||
configuration: .debug,
|
||||
triple: triple ?? PackOperation.defaultTriple
|
||||
)
|
||||
try await Subprocess.run(
|
||||
settings.buildServerInvocation(),
|
||||
input: .standardInput,
|
||||
output: .currentStandardOutput,
|
||||
error: .currentStandardError,
|
||||
)
|
||||
.checkSuccess()
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,6 @@ struct PackOperation {
|
||||
|
||||
@discardableResult
|
||||
func run() async throws -> URL {
|
||||
// TODO: support running inside a child directory
|
||||
|
||||
let contents = try FileManager.default.contentsOfDirectory(atPath: ".")
|
||||
guard contents.contains("Package.swift")
|
||||
|| contents.contains(where: { $0.hasPrefix("Package@") && $0.hasSuffix(".swift") })
|
||||
else {
|
||||
throw Console.Error("Could not find Package.swift in this directory.")
|
||||
}
|
||||
|
||||
try await EnsureSDKOperation(quiet: true).run()
|
||||
|
||||
print("Planning...")
|
||||
@@ -52,8 +43,6 @@ struct PackOperation {
|
||||
""")
|
||||
}
|
||||
|
||||
await LSPConfig.tryEnsure(using: schema)
|
||||
|
||||
let buildSettings = try await BuildSettings(
|
||||
configuration: buildOptions.configuration,
|
||||
triple: triple ?? Self.defaultTriple,
|
||||
@@ -287,7 +276,6 @@ struct DevCommand: AsyncParsableCommand {
|
||||
DevXcodeCommand.self,
|
||||
DevBuildCommand.self,
|
||||
DevRunCommand.self,
|
||||
DevBSPCommand.self,
|
||||
],
|
||||
defaultSubcommand: DevRunCommand.self
|
||||
)
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
import Foundation
|
||||
import PackLib
|
||||
|
||||
enum LSPConfig {
|
||||
static let bsp: (String, String) = (
|
||||
".bsp/xtool.json",
|
||||
"""
|
||||
{
|
||||
"name": "xtool",
|
||||
"version": "1.0",
|
||||
"bspVersion": "2.2.0",
|
||||
"languages": ["c", "cpp", "objective-c", "objective-cpp", "swift"],
|
||||
"argv": ["/usr/bin/env", "xtool", "dev", "build-server"]
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
static let legacyLSP: (String, String) = (
|
||||
".sourcekit-lsp/config.json",
|
||||
"""
|
||||
{
|
||||
"swiftPM": {
|
||||
"swiftSDK": "arm64-apple-ios"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
nonisolated(nonsending) static func tryEnsure(
|
||||
using schema: PackSchema,
|
||||
quiet: Bool = false,
|
||||
currentDirectory directory: URL = URL(filePath: FileManager.default.currentDirectoryPath)
|
||||
) async {
|
||||
do {
|
||||
try await ensure(using: schema, quiet: quiet, currentDirectory: directory)
|
||||
} catch {
|
||||
print("warning: failed to validate LSP configuration: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated(nonsending) static func ensure(
|
||||
using schema: PackSchema,
|
||||
quiet: Bool = false,
|
||||
currentDirectory directory: URL = URL(filePath: FileManager.default.currentDirectoryPath)
|
||||
) async throws {
|
||||
if schema.skipLSP == true {
|
||||
return
|
||||
}
|
||||
|
||||
if try await SwiftVersion.current.supportsSwiftBuild {
|
||||
try await ensure(primary: bsp, secondary: legacyLSP, quiet: quiet, currentDirectory: directory)
|
||||
} else {
|
||||
try await ensure(primary: legacyLSP, secondary: bsp, quiet: quiet, currentDirectory: directory)
|
||||
}
|
||||
}
|
||||
|
||||
// creates the primary LSP-support file if it doesn't exist, and cleans up old files
|
||||
private nonisolated(nonsending) static func ensure(
|
||||
primary: (String, String),
|
||||
secondary: (String, String),
|
||||
quiet: Bool,
|
||||
currentDirectory directory: URL
|
||||
) async throws {
|
||||
let primaryURL = directory.appendingPathComponent(primary.0)
|
||||
if FileManager.default.fileExists(atPath: primaryURL.path) {
|
||||
return
|
||||
}
|
||||
|
||||
try? FileManager.default.createDirectory(
|
||||
at: primaryURL.deletingLastPathComponent(),
|
||||
withIntermediateDirectories: true
|
||||
)
|
||||
try Data((primary.1 + "\n").utf8).write(to: primaryURL)
|
||||
|
||||
let secondaryURL = directory.appendingPathComponent(secondary.0)
|
||||
if let secondaryData = try? await Data(reading: secondaryURL),
|
||||
let secondaryString = String(data: secondaryData, encoding: .utf8),
|
||||
secondaryString.trimmingCharacters(in: .whitespacesAndNewlines) == secondary.1 {
|
||||
try? FileManager.default.removeItem(at: secondaryURL)
|
||||
}
|
||||
|
||||
if !quiet {
|
||||
print("""
|
||||
[LSP] Created \(primary.0) for enhanced IDE support. You may
|
||||
need to restart your editor for the change to take effect.
|
||||
You can disable this with `skipLSP: true` in xtool.yml.
|
||||
""")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,17 @@ struct NewCommand: AsyncParsableCommand {
|
||||
"""
|
||||
),
|
||||
|
||||
(
|
||||
".sourcekit-lsp/config.json",
|
||||
"""
|
||||
{
|
||||
"swiftPM": {
|
||||
"swiftSDK": "arm64-apple-ios"
|
||||
}
|
||||
}
|
||||
"""
|
||||
),
|
||||
|
||||
(
|
||||
"Sources/\(moduleName)/\(moduleName)App.swift",
|
||||
"""
|
||||
@@ -166,12 +177,6 @@ struct NewCommand: AsyncParsableCommand {
|
||||
try "\(contents)\n".write(to: url, atomically: true, encoding: .utf8)
|
||||
}
|
||||
|
||||
await LSPConfig.tryEnsure(
|
||||
using: .default,
|
||||
quiet: true,
|
||||
currentDirectory: baseURL,
|
||||
)
|
||||
|
||||
print("\nFinished generating project \(name). Next steps:")
|
||||
print("- Enter the directory with `cd \(name)`")
|
||||
print("- Build and run with `xtool dev`")
|
||||
|
||||
@@ -5,7 +5,6 @@ import Subprocess
|
||||
import XKit // HTTPClient, stdoutSafe
|
||||
import XUtils // System.File{Path,Descriptor}
|
||||
|
||||
// swiftlint:disable:next type_body_length
|
||||
struct SDKBuilder {
|
||||
enum Arch: String {
|
||||
case x86_64
|
||||
@@ -76,15 +75,14 @@ struct SDKBuilder {
|
||||
let mode: Mode
|
||||
|
||||
// bump this when the sdk builder logic changes
|
||||
static let sdkEpoch = 2
|
||||
static let sdkEpoch = 1
|
||||
|
||||
// tag from https://github.com/xtool-org/darwin-tools-linux-llvm
|
||||
static let darwinToolsVersion = "1.1.0"
|
||||
static let darwinToolsVersion = "1.0.1"
|
||||
|
||||
// tag from https://github.com/xtool-org/OpenAppleMacros
|
||||
static let oamVersion = "1.3.0"
|
||||
static let oamVersion = "1.2.0"
|
||||
static let oamLibraries: [String] = [
|
||||
"FoundationModelsMacros",
|
||||
"PreviewsMacros",
|
||||
"SwiftUIMacros",
|
||||
]
|
||||
@@ -95,7 +93,6 @@ struct SDKBuilder {
|
||||
"""
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func buildSDK() async throws {
|
||||
let sdkVersion = Self.currentSDKVersion
|
||||
|
||||
@@ -177,9 +174,6 @@ struct SDKBuilder {
|
||||
"linker": {
|
||||
"path": "ld64.lld"
|
||||
},
|
||||
"librarian": {
|
||||
"path": "llvm-lib"
|
||||
},
|
||||
"swiftCompiler": {
|
||||
"extraCLIOptions": [
|
||||
"-Xfrontend", "-enable-cross-import-overlays",
|
||||
@@ -193,26 +187,6 @@ struct SDKBuilder {
|
||||
encoding: .utf8
|
||||
)
|
||||
|
||||
// this toolset works with the swiftbuild system on Linux
|
||||
// note that we need Swift 6.4+ because 6.3 has bugs in
|
||||
// resolving the librarian and linker paths.
|
||||
try """
|
||||
{
|
||||
"schemaVersion": "1.0",
|
||||
"rootPath": "toolset/bin",
|
||||
"linker": {
|
||||
"path": "ld64.lld"
|
||||
},
|
||||
"librarian": {
|
||||
"path": "llvm-lib"
|
||||
}
|
||||
}
|
||||
""".write(
|
||||
to: output.appendingPathComponent("toolset-swb.json"),
|
||||
atomically: false,
|
||||
encoding: .utf8
|
||||
)
|
||||
|
||||
let sdkDefinition = SDKDefinition(
|
||||
schemaVersion: "4.0",
|
||||
targetTriples: [
|
||||
@@ -233,7 +207,6 @@ struct SDKBuilder {
|
||||
.write(to: output.appendingPathComponent("darwin-sdk-version.txt"))
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
private func installToolset(in output: URL) async throws {
|
||||
let toolsetDir = output.appendingPathComponent("toolset")
|
||||
|
||||
@@ -280,109 +253,6 @@ struct SDKBuilder {
|
||||
try await execution.standardInputWriter.finish()
|
||||
}
|
||||
.checkSuccess()
|
||||
|
||||
// swift-build assumes we have an Apple-flavored librarian for Apple platforms
|
||||
// (https://github.com/swiftlang/swift-build/blob/b2433e74e/Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift#L1735)
|
||||
// but allows us to override this assumption if we explicitly provide the name llvm-lib (look a few lines above in that file)
|
||||
try FileManager.default.moveItem(
|
||||
at: toolsetDir.appending(path: "bin/libtool"),
|
||||
to: toolsetDir.appending(path: "bin/llvm-lib")
|
||||
)
|
||||
|
||||
let ld64 = toolsetDir.appending(path: "bin/ld64.lld")
|
||||
let origBins = toolsetDir.appending(path: "bin/orig")
|
||||
let origLD64 = origBins.appending(path: "ld64.lld")
|
||||
try FileManager.default.createDirectory(at: origBins, withIntermediateDirectories: false)
|
||||
try FileManager.default.moveItem(at: ld64, to: origLD64)
|
||||
|
||||
// this terrible hack works around the fact that lld doesn't support the -r option,
|
||||
// which merges multiple object files into one (used by SPM's SWB backend to combine
|
||||
// per-file MachOs into a single one for the module, on Darwin).
|
||||
//
|
||||
// so instead, we write a trampoline that intercepts `ld64.lld -r` and instead runs
|
||||
// libtool to build a static archive.
|
||||
try """
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
case "$0" in
|
||||
*/*) script_path="$0" ;;
|
||||
*) script_path="$(command -v "$0")" ;;
|
||||
esac
|
||||
case "$script_path" in
|
||||
/*) script_dir="${script_path%/*}"; [ -n "$script_dir" ] || script_dir="/" ;;
|
||||
*/*) script_dir="${script_path%/*}" ;;
|
||||
*) script_dir="." ;;
|
||||
esac
|
||||
bin_dir="$(CDPATH= cd -P "$script_dir" && pwd -P)"
|
||||
|
||||
find_argument_value() {
|
||||
argument_name="$1"
|
||||
shift
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
if [ "$1" = "$argument_name" ]; then
|
||||
shift
|
||||
if [ "$#" -gt 0 ]; then
|
||||
argument_value="$1"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
relocatable=
|
||||
for argument do
|
||||
if [ "$argument" = "-r" ]; then
|
||||
relocatable=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$relocatable" ]; then
|
||||
missing_argument=
|
||||
|
||||
if find_argument_value -filelist "$@"; then
|
||||
filelist="$argument_value"
|
||||
else
|
||||
missing_argument=1
|
||||
fi
|
||||
if find_argument_value -dependency_info "$@"; then
|
||||
dependency_info="$argument_value"
|
||||
else
|
||||
missing_argument=1
|
||||
fi
|
||||
if find_argument_value -o "$@"; then
|
||||
output="$argument_value"
|
||||
else
|
||||
missing_argument=1
|
||||
fi
|
||||
|
||||
if [ -n "$missing_argument" ]; then
|
||||
echo "ld64.lld trampoline could not process arguments." >&2
|
||||
echo "Please file an issue at https://github.com/xtool-org/xtool/issues" >&2
|
||||
echo " Arguments: $@" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
exec "$bin_dir/llvm-lib" -static \
|
||||
-filelist "$filelist" \
|
||||
-dependency_info "$dependency_info" \
|
||||
-o "$output"
|
||||
fi
|
||||
|
||||
exec "$bin_dir/orig/ld64.lld" "$@"
|
||||
""".write(
|
||||
to: ld64,
|
||||
atomically: false,
|
||||
encoding: .utf8
|
||||
)
|
||||
// set -x
|
||||
try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: ld64.path)
|
||||
}
|
||||
|
||||
private func installMacros(in output: URL) async throws {
|
||||
@@ -548,8 +418,6 @@ struct SDKBuilder {
|
||||
let lib = "../../../../../Library"
|
||||
let platformDir = dev.appending(path: "Platforms/\(platform).platform")
|
||||
|
||||
try patchPlatformManifest(path: platformDir.appending(path: "Info.plist"))
|
||||
|
||||
/*
|
||||
XCTest and Testing.framework are located in *.platform/Developer/{Library/Frameworks,usr/lib} rather than inside
|
||||
the SDK. These search paths are explicitly included when building tests, which presumably ensures that normal
|
||||
@@ -639,26 +507,6 @@ struct SDKBuilder {
|
||||
}.value
|
||||
}
|
||||
|
||||
private func patchPlatformManifest(path: URL) throws {
|
||||
let data = try Data(contentsOf: path)
|
||||
guard var plist = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any] else {
|
||||
throw Console.Error("Could not read '\(path.path)'")
|
||||
}
|
||||
|
||||
var defaultProperties = (plist["DefaultProperties"] as? [String: Any]) ?? [:]
|
||||
defaultProperties["SWIFT_RESOURCE_DIR"] = "$(PLATFORM_DIR)/../../Toolchains/XcodeDefault.xctoolchain/usr/lib/swift"
|
||||
defaultProperties["CLANG_RESOURCE_DIR"] = "$(SWIFT_RESOURCE_DIR)/clang"
|
||||
defaultProperties["ALTERNATE_LINKER"] = "lld"
|
||||
// stub out codesign as /bin/true (SwiftBuild often emits CodeSign tasks, e.g. when
|
||||
// building for sim). we sign post-build.
|
||||
defaultProperties["CODESIGN"] = "true"
|
||||
plist["DefaultProperties"] = defaultProperties
|
||||
|
||||
let newData = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)
|
||||
// a non-atomic write would modify the shared inode that's hard-linked from Xcode.app
|
||||
try newData.write(to: path, options: .atomic)
|
||||
}
|
||||
|
||||
// returns the number of files we actually want to keep,
|
||||
// useful for computing progress % during fs traversal
|
||||
private func _extractXIP(inputPath: String, outDir: String) async throws -> Int {
|
||||
@@ -802,16 +650,13 @@ struct SDKEntry {
|
||||
E("clang"),
|
||||
]),
|
||||
E("Platforms", ["iPhoneOS", "MacOSX", "iPhoneSimulator"].map {
|
||||
E("\($0).platform", [
|
||||
E("Info.plist"),
|
||||
E("Developer", [
|
||||
E("SDKs"),
|
||||
E("Library", [
|
||||
E("Frameworks"),
|
||||
E("PrivateFrameworks"),
|
||||
]),
|
||||
E("usr/lib"),
|
||||
])
|
||||
E("\($0).platform/Developer", [
|
||||
E("SDKs"),
|
||||
E("Library", [
|
||||
E("Frameworks"),
|
||||
E("PrivateFrameworks"),
|
||||
]),
|
||||
E("usr/lib"),
|
||||
])
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -151,6 +151,40 @@ extension DarwinSDK {
|
||||
}
|
||||
}
|
||||
|
||||
private enum SwiftVersion {}
|
||||
extension SwiftVersion {
|
||||
static func current() async throws -> Version {
|
||||
let outputString: String?
|
||||
do {
|
||||
outputString = try await Subprocess.run(
|
||||
.name("swift"),
|
||||
arguments: ["--version"],
|
||||
output: .string(limit: .max)
|
||||
)
|
||||
.checkSuccess()
|
||||
.standardOutput
|
||||
} catch {
|
||||
throw Console.Error("Failed to obtain Swift version")
|
||||
}
|
||||
var output = outputString?[...] ?? ""
|
||||
if output.hasPrefix("Apple ") {
|
||||
output = output.dropFirst("Apple ".count)
|
||||
}
|
||||
guard output.hasPrefix("Swift version ") else {
|
||||
throw Console.Error("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
output = output.dropFirst("Swift version ".count)
|
||||
guard let space = output.firstIndex(of: " ") else {
|
||||
throw Console.Error("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
output = output[..<space]
|
||||
guard let version = Version(tolerant: output) else {
|
||||
throw Console.Error("Could not parse Swift version: '\(output)'")
|
||||
}
|
||||
return version
|
||||
}
|
||||
}
|
||||
|
||||
struct EnsureSDKOperation {
|
||||
let quiet: Bool
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||
<true/>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$(AppIdentifierPrefix)sh.xtool.keychain</string>
|
||||
|
||||
Reference in New Issue
Block a user