44import PackageDescription
55import Foundation
66
7- let ( cFlags, linkFlags) = try ! getLLVMConfig ( )
7+ // Get LLVM flags and version
8+ let ( cFlags, linkFlags, _version) = try ! getLLVMConfig ( )
89
910let package = Package (
1011 name: " llvm-api " ,
@@ -31,7 +32,7 @@ let package = Package(
3132)
3233
3334/// Get LLVM config flags
34- func getLLVMConfig( ) throws -> ( [ String ] , [ String ] ) {
35+ func getLLVMConfig( ) throws -> ( [ String ] , [ String ] , [ Int ] ) {
3536 let brewPrefix = {
3637 guard let brew = which ( " brew " ) else { return nil }
3738 return run ( brew, args: [ " --prefix " ] )
@@ -40,6 +41,12 @@ func getLLVMConfig() throws -> ([String], [String]) {
4041 guard let llvmConfig = which ( " llvm-config " ) ?? which ( " \( brewPrefix) /opt/llvm/bin/llvm-config " ) else {
4142 throw " Failed to find llvm-config. Ensure llvm-config is installed and in your PATH "
4243 }
44+ // Fetch LLVM version
45+ let versionStr = run ( llvmConfig, args: [ " --version " ] ) !
46+ . replacing ( charactersIn: . newlines, with: " " )
47+ . replacingOccurrences ( of: " svn " , with: " " )
48+ let versionComponents = versionStr. components ( separatedBy: " . " )
49+ . compactMap { Int ( $0) }
4350 // Get linkage (LD) flags
4451 let ldFlags = run ( llvmConfig, args: [ " --ldflags " , " --libs " , " all " , " --system-libs " ] ) !
4552 . replacing ( charactersIn: . newlines, with: " " )
@@ -50,7 +57,7 @@ func getLLVMConfig() throws -> ([String], [String]) {
5057 . replacing ( charactersIn: . newlines, with: " " )
5158 . components ( separatedBy: " " )
5259 . filter { $0. hasPrefix ( " -I " ) }
53- return ( cFlags, ldFlags)
60+ return ( cFlags, ldFlags, versionComponents )
5461}
5562
5663/// Runs the specified program at the provided path.
0 commit comments