Skip to content

Commit 7bfd465

Browse files
authored
Support for LLVM 11 (#220)
* supporting LLVM11 * Bump package version in Readme * bump to 11 Co-authored-by: Alex Reilly <[email protected]>
1 parent 47b7fba commit 7bfd465

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ There are a couple annoying steps you need to accomplish before building
185185
LLVMSwift:
186186

187187
- Install LLVM 8.0+ using your favorite package manager. For example:
188-
- `brew install llvm`
188+
- `brew install llvm@11`
189189
- Ensure `llvm-config` is in your `PATH`
190190
- That will reside in the `/bin` folder wherever your package manager
191191
installed LLVM.
@@ -198,7 +198,7 @@ compiler projects!
198198
### Installation with Swift Package Manager
199199

200200
```swift
201-
.package(url: "https://github.com/llvm-swift/LLVMSwift.git", from: "0.4.0")
201+
.package(url: "https://github.com/llvm-swift/LLVMSwift.git", from: "0.8.0")
202202
```
203203

204204
### Installation without Swift Package Manager

Sources/LLVM/DIBuilder.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ extension DIBuilder {
197197
/// by third-party tools.
198198
/// - splitDWARFPath: The path to the split DWARF file.
199199
/// - identity: The identity of the tool that is compiling this source file.
200+
/// - sysRoot: The Clang system root (the value of the `-isysroot` that's passed to clang).
201+
/// - sdkRoot: The SDK root -- on Darwin platforms, this is the last component of the sysroot.
200202
/// - Returns: A value representing a compilation-unit level scope.
201203
public func buildCompileUnit(
202204
for language: DWARFSourceLanguage,
@@ -208,7 +210,9 @@ extension DIBuilder {
208210
flags: [String] = [],
209211
runtimeVersion: Int = 0,
210212
splitDWARFPath: String = "",
211-
identity: String = ""
213+
identity: String = "",
214+
sysRoot: String = "",
215+
sdkRoot: String = ""
212216
) -> CompileUnitMetadata {
213217
let allFlags = flags.joined(separator: " ")
214218
guard let cu = LLVMDIBuilderCreateCompileUnit(
@@ -220,7 +224,11 @@ extension DIBuilder {
220224
kind.llvm,
221225
/*DWOId*/0,
222226
splitDebugInlining.llvm,
223-
debugInfoForProfiling.llvm
227+
debugInfoForProfiling.llvm,
228+
sysRoot,
229+
sysRoot.count,
230+
sdkRoot,
231+
sdkRoot.count
224232
) else {
225233
fatalError()
226234
}
@@ -860,15 +868,22 @@ extension DIBuilder {
860868
/// - Parameters:
861869
/// - type: Original type.
862870
/// - name: Typedef name.
871+
/// - alignment: Alignment of the type
863872
/// - scope: The surrounding context for the typedef.
864873
/// - file: File where this type is defined.
865874
/// - line: Line number.
866875
public func buildTypedef(
867-
of type: DIType, name: String, scope: DIScope, file: FileMetadata, line: Int
876+
of type: DIType,
877+
name: String,
878+
alignment: Alignment = .one,
879+
scope: DIScope,
880+
file: FileMetadata,
881+
line: Int
868882
) -> DIType {
869883
guard let ty = LLVMDIBuilderCreateTypedef(
870884
self.llvm, type.asMetadata(), name, name.count,
871-
file.asMetadata(), UInt32(line), scope.asMetadata())
885+
file.asMetadata(), UInt32(line), scope.asMetadata(),
886+
alignment.rawValue * 8)
872887
else {
873888
fatalError("Failed to allocate metadata")
874889
}

Sources/LLVM/MetadataAttributes.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ public struct DIFlags : OptionSet {
455455
public static let forwardDeclaration = DIFlags(rawValue: LLVMDIFlagFwdDecl.rawValue)
456456
/// Denotes a block object.
457457
public static let appleBlock = DIFlags(rawValue: LLVMDIFlagAppleBlock.rawValue)
458-
/// Denotes the structure containing a variable captured by reference in a
459-
/// block object.
460-
public static let blockByrefStruct = DIFlags(rawValue: LLVMDIFlagBlockByrefStruct.rawValue)
461458
/// Denotes a virtual function or dynamic dispatch.
462459
public static let virtual = DIFlags(rawValue: LLVMDIFlagVirtual.rawValue)
463460
/// Denotes a compiler-generated declaration that may not appear in source.

Sources/LLVM/TargetMachine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class TargetMachine {
238238
}
239239
var err: UnsafeMutablePointer<Int8>?
240240
let status = path.withCString { cStr -> LLVMBool in
241-
var mutable = strdup(cStr)
241+
let mutable = strdup(cStr)
242242
defer { free(mutable) }
243243
return LLVMTargetMachineEmitToFile(llvm, module.llvm, mutable, type.asLLVM(), &err)
244244
}

utils/make-pkgconfig.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func makeFile() throws {
6363
}
6464

6565
/// Ensure we have llvm-config in the PATH
66-
guard let llvmConfig = which("llvm-config-9") ?? which("llvm-config") ?? brewLLVMConfig() else {
66+
guard let llvmConfig = which("llvm-config-11") ?? which("llvm-config") ?? brewLLVMConfig() else {
6767
throw "Failed to find llvm-config. Ensure llvm-config is installed and " +
6868
"in your PATH"
6969
}
@@ -84,8 +84,8 @@ func makeFile() throws {
8484

8585
let version = (components[0], components[1], components[2])
8686

87-
guard version >= (9, 0, 0) else {
88-
throw "LLVMSwift requires LLVM version >=9.0.0, but you have \(versionStr)"
87+
guard version >= (11, 0, 0) else {
88+
throw "LLVMSwift requires LLVM version >=11.0.0, but you have \(versionStr)"
8989
}
9090

9191
print("LLVM version is \(versionStr)")

0 commit comments

Comments
 (0)