Skip to content

Commit

Permalink
Update CI conditional build
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Jul 17, 2024
1 parent c43e751 commit 7b72ed6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
swift --version
- name: Build
run: swift build -Xswiftc -DCLI_BUILD
run: CLI_BUILD=1 swift build
# - name: Run tests
# run: swift test -v

75 changes: 40 additions & 35 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,12 @@
import Foundation
import PackageDescription

// Get LLVM flags and version
#if CLI_BUILD
let (cFlags, linkFlags, _version) = try! getLLVMConfig()
let customSystemLibrary: Target = .systemLibrary(
name: "CLLVM",
path: "llvm-api/CLLVM"
)
let llvmTarget: Target = .target(
name: "LLVM",
dependencies: ["CLLVM"],
path: "llvm-api/LLVM",
cSettings: [
.unsafeFlags(cFlags),
],
linkerSettings: [
.unsafeFlags(linkFlags),
]
)
#else
let customSystemLibrary: Target = .systemLibrary(
name: "CLLVM",
path: "llvm-api/CLLVM",
pkgConfig: "cllvm"
)
let llvmTarget: Target = .target(
name: "LLVM",
dependencies: ["CLLVM"],
path: "llvm-api/LLVM"
)
#endif

let package = Package(
name: "llvm-api",
products: [
.library(name: "llvm-api", targets: ["LLVM"]),
],
targets: [
customSystemLibrary,
llvmTarget,
]
targets: getTargets()
)

/// Get LLVM config flags
Expand Down Expand Up @@ -109,3 +75,42 @@ extension String: Error {
return components.joined(separator: separator)
}
}

/// Check Environ,ent variable
func hasEnvironmentVariable(_ name: String) -> Bool {
ProcessInfo.processInfo.environment[name] != nil
}

func getTargets() -> [Target] {
if hasEnvironmentVariable("CLI_BUILD") {
let (cFlags, linkFlags, _) = try! getLLVMConfig()
let customSystemLibrary: Target = .systemLibrary(
name: "CLLVM",
path: "llvm-api/CLLVM"
)
let llvmTarget: Target = .target(
name: "LLVM",
dependencies: ["CLLVM"],
path: "llvm-api/LLVM",
cSettings: [
.unsafeFlags(cFlags),
],
linkerSettings: [
.unsafeFlags(linkFlags),
]
)
return [customSystemLibrary, llvmTarget]
} else {
let customSystemLibrary: Target = .systemLibrary(
name: "CLLVM",
path: "llvm-api/CLLVM",
pkgConfig: "cllvm"
)
let llvmTarget: Target = .target(
name: "LLVM",
dependencies: ["CLLVM"],
path: "llvm-api/LLVM"
)
return [customSystemLibrary, llvmTarget]
}
}

0 comments on commit 7b72ed6

Please sign in to comment.