forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticBuildConfigPluginExecutable.swift
More file actions
60 lines (56 loc) · 1.78 KB
/
StaticBuildConfigPluginExecutable.swift
File metadata and controls
60 lines (56 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
import Subprocess
import SwiftIfConfig
@main struct StaticBuildConfigPluginExecutable {
static func main() async throws {
let args = CommandLine.arguments
guard args.count > 1 else {
print("Usage: \(args[0]) <destination_path>")
return
}
let dst = URL(fileURLWithPath: args[1])
let data = try await loadStaticBuildConfig()
try data.write(to: dst, options: .atomic)
}
static func loadStaticBuildConfig() async throws -> Data {
#if compiler(>=6.3)
let result = try await run(
.name("swift"),
arguments: ["frontend", "-print-static-build-config", "-target", "aarch64-unknown-linux-gnu"],
output: .data(limit: 65536),
error: .string(limit: 65536)
)
if let error = result.standardError, !error.isEmpty {
fatalError(error)
}
return result.standardOutput
#else
#if compiler(>=6.2)
let configuration = StaticBuildConfiguration(
languageVersion: .init(components: [5, 10]),
compilerVersion: .init(components: [6, 2])
)
#else
let configuration = StaticBuildConfiguration(
languageVersion: .init(components: [5, 10]),
compilerVersion: .init(components: [6, 1])
)
#endif
let encoder = JSONEncoder()
return try encoder.encode(configuration)
#endif
}
}