Skip to content

Commit 7b72ed6

Browse files
committed
Update CI conditional build
1 parent c43e751 commit 7b72ed6

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

.github/workflows/swift.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
swift --version
3030
3131
- name: Build
32-
run: swift build -Xswiftc -DCLI_BUILD
32+
run: CLI_BUILD=1 swift build
3333
# - name: Run tests
3434
# run: swift test -v
3535

Package.swift

+40-35
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,12 @@
44
import Foundation
55
import PackageDescription
66

7-
// Get LLVM flags and version
8-
#if CLI_BUILD
9-
let (cFlags, linkFlags, _version) = try! getLLVMConfig()
10-
let customSystemLibrary: Target = .systemLibrary(
11-
name: "CLLVM",
12-
path: "llvm-api/CLLVM"
13-
)
14-
let llvmTarget: Target = .target(
15-
name: "LLVM",
16-
dependencies: ["CLLVM"],
17-
path: "llvm-api/LLVM",
18-
cSettings: [
19-
.unsafeFlags(cFlags),
20-
],
21-
linkerSettings: [
22-
.unsafeFlags(linkFlags),
23-
]
24-
)
25-
#else
26-
let customSystemLibrary: Target = .systemLibrary(
27-
name: "CLLVM",
28-
path: "llvm-api/CLLVM",
29-
pkgConfig: "cllvm"
30-
)
31-
let llvmTarget: Target = .target(
32-
name: "LLVM",
33-
dependencies: ["CLLVM"],
34-
path: "llvm-api/LLVM"
35-
)
36-
#endif
37-
387
let package = Package(
398
name: "llvm-api",
409
products: [
4110
.library(name: "llvm-api", targets: ["LLVM"]),
4211
],
43-
targets: [
44-
customSystemLibrary,
45-
llvmTarget,
46-
]
12+
targets: getTargets()
4713
)
4814

4915
/// Get LLVM config flags
@@ -109,3 +75,42 @@ extension String: Error {
10975
return components.joined(separator: separator)
11076
}
11177
}
78+
79+
/// Check Environ,ent variable
80+
func hasEnvironmentVariable(_ name: String) -> Bool {
81+
ProcessInfo.processInfo.environment[name] != nil
82+
}
83+
84+
func getTargets() -> [Target] {
85+
if hasEnvironmentVariable("CLI_BUILD") {
86+
let (cFlags, linkFlags, _) = try! getLLVMConfig()
87+
let customSystemLibrary: Target = .systemLibrary(
88+
name: "CLLVM",
89+
path: "llvm-api/CLLVM"
90+
)
91+
let llvmTarget: Target = .target(
92+
name: "LLVM",
93+
dependencies: ["CLLVM"],
94+
path: "llvm-api/LLVM",
95+
cSettings: [
96+
.unsafeFlags(cFlags),
97+
],
98+
linkerSettings: [
99+
.unsafeFlags(linkFlags),
100+
]
101+
)
102+
return [customSystemLibrary, llvmTarget]
103+
} else {
104+
let customSystemLibrary: Target = .systemLibrary(
105+
name: "CLLVM",
106+
path: "llvm-api/CLLVM",
107+
pkgConfig: "cllvm"
108+
)
109+
let llvmTarget: Target = .target(
110+
name: "LLVM",
111+
dependencies: ["CLLVM"],
112+
path: "llvm-api/LLVM"
113+
)
114+
return [customSystemLibrary, llvmTarget]
115+
}
116+
}

0 commit comments

Comments
 (0)