Skip to content

Commit f5ade5e

Browse files
authored
Merge pull request #21862 from alexrp/llvm-19-api-break
Reduce our exposure to LLVM API breakage
2 parents ba2d006 + 16b87f7 commit f5ade5e

File tree

6 files changed

+89
-746
lines changed

6 files changed

+89
-746
lines changed

src/codegen/llvm.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,10 @@ pub const Object = struct {
13631363
.large => .Large,
13641364
};
13651365

1366-
const float_abi: llvm.ABIType = if (comp.root_mod.resolved_target.result.floatAbi() == .hard) .Hard else .Soft;
1366+
const float_abi: llvm.TargetMachine.FloatABI = if (comp.root_mod.resolved_target.result.floatAbi() == .hard)
1367+
.Hard
1368+
else
1369+
.Soft;
13671370

13681371
var target_machine = llvm.TargetMachine.create(
13691372
target,

src/codegen/llvm/bindings.zig

Lines changed: 20 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ pub const disposeMessage = LLVMDisposeMessage;
5757
extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;
5858

5959
pub const TargetMachine = opaque {
60+
pub const FloatABI = enum(c_int) {
61+
/// Target-specific (either soft or hard depending on triple, etc).
62+
Default,
63+
/// Soft float.
64+
Soft,
65+
// Hard float.
66+
Hard,
67+
};
68+
6069
pub const create = ZigLLVMCreateTargetMachine;
6170
extern fn ZigLLVMCreateTargetMachine(
6271
T: *Target,
@@ -68,7 +77,7 @@ pub const TargetMachine = opaque {
6877
CodeModel: CodeModel,
6978
function_sections: bool,
7079
data_sections: bool,
71-
float_abi: ABIType,
80+
float_abi: FloatABI,
7281
abi_name: ?[*:0]const u8,
7382
) *TargetMachine;
7483

@@ -108,7 +117,7 @@ pub const TargetMachine = opaque {
108117
TraceStores: bool,
109118
CollectControlFlow: bool,
110119

111-
pub const Type = enum(c_uint) {
120+
pub const Type = enum(c_int) {
112121
None = 0,
113122
Function,
114123
BB,
@@ -166,15 +175,6 @@ pub const RelocMode = enum(c_int) {
166175
ROPI_RWPI,
167176
};
168177

169-
pub const ABIType = enum(c_int) {
170-
/// Target-specific (either soft or hard depending on triple, etc).
171-
Default,
172-
/// Soft float.
173-
Soft,
174-
// Hard float.
175-
Hard,
176-
};
177-
178178
pub const Target = opaque {
179179
pub const getFromTriple = LLVMGetTargetFromTriple;
180180
extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: *[*:0]const u8) Bool;
@@ -303,142 +303,31 @@ pub const LinkCOFF = ZigLLDLinkCOFF;
303303
pub const LinkELF = ZigLLDLinkELF;
304304
pub const LinkWasm = ZigLLDLinkWasm;
305305

306-
pub const ObjectFormatType = enum(c_int) {
307-
Unknown,
306+
pub const ArchiveKind = enum(c_int) {
307+
GNU,
308+
GNU64,
309+
BSD,
310+
DARWIN,
311+
DARWIN64,
308312
COFF,
309-
DXContainer,
310-
ELF,
311-
GOFF,
312-
MachO,
313-
SPIRV,
314-
Wasm,
315-
XCOFF,
313+
AIXBIG,
316314
};
317315

318316
pub const WriteArchive = ZigLLVMWriteArchive;
319317
extern fn ZigLLVMWriteArchive(
320318
archive_name: [*:0]const u8,
321319
file_names_ptr: [*]const [*:0]const u8,
322320
file_names_len: usize,
323-
os_type: OSType,
321+
archive_kind: ArchiveKind,
324322
) bool;
325323

326-
pub const OSType = enum(c_int) {
327-
UnknownOS,
328-
Darwin,
329-
DragonFly,
330-
FreeBSD,
331-
Fuchsia,
332-
IOS,
333-
KFreeBSD,
334-
Linux,
335-
Lv2,
336-
MacOSX,
337-
NetBSD,
338-
OpenBSD,
339-
Solaris,
340-
UEFI,
341-
Win32,
342-
ZOS,
343-
Haiku,
344-
RTEMS,
345-
NaCl,
346-
AIX,
347-
CUDA,
348-
NVCL,
349-
AMDHSA,
350-
PS4,
351-
PS5,
352-
ELFIAMCU,
353-
TvOS,
354-
WatchOS,
355-
BridgeOS,
356-
DriverKit,
357-
XROS,
358-
Mesa3D,
359-
AMDPAL,
360-
HermitCore,
361-
Hurd,
362-
WASI,
363-
Emscripten,
364-
ShaderModel,
365-
LiteOS,
366-
Serenity,
367-
Vulkan,
368-
};
369-
370-
pub const ArchType = enum(c_int) {
371-
UnknownArch,
372-
arm,
373-
armeb,
374-
aarch64,
375-
aarch64_be,
376-
aarch64_32,
377-
arc,
378-
avr,
379-
bpfel,
380-
bpfeb,
381-
csky,
382-
dxil,
383-
hexagon,
384-
loongarch32,
385-
loongarch64,
386-
m68k,
387-
mips,
388-
mipsel,
389-
mips64,
390-
mips64el,
391-
msp430,
392-
ppc,
393-
ppcle,
394-
ppc64,
395-
ppc64le,
396-
r600,
397-
amdgcn,
398-
riscv32,
399-
riscv64,
400-
sparc,
401-
sparcv9,
402-
sparcel,
403-
systemz,
404-
tce,
405-
tcele,
406-
thumb,
407-
thumbeb,
408-
x86,
409-
x86_64,
410-
xcore,
411-
xtensa,
412-
nvptx,
413-
nvptx64,
414-
le32,
415-
le64,
416-
amdil,
417-
amdil64,
418-
hsail,
419-
hsail64,
420-
spir,
421-
spir64,
422-
spirv,
423-
spirv32,
424-
spirv64,
425-
kalimba,
426-
shave,
427-
lanai,
428-
wasm32,
429-
wasm64,
430-
renderscript32,
431-
renderscript64,
432-
ve,
433-
};
434-
435324
pub const ParseCommandLineOptions = ZigLLVMParseCommandLineOptions;
436325
extern fn ZigLLVMParseCommandLineOptions(argc: usize, argv: [*]const [*:0]const u8) void;
437326

438327
pub const WriteImportLibrary = ZigLLVMWriteImportLibrary;
439328
extern fn ZigLLVMWriteImportLibrary(
440329
def_path: [*:0]const u8,
441-
arch: ArchType,
330+
coff_machine: c_uint,
442331
output_lib_path: [*:0]const u8,
443332
kill_at: bool,
444333
) bool;

src/link.zig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,16 @@ pub const File = struct {
12091209
const llvm = @import("codegen/llvm.zig");
12101210
const target = comp.root_mod.resolved_target.result;
12111211
llvm.initializeLLVMTarget(target.cpu.arch);
1212-
const os_tag = llvm.targetOs(target.os.tag);
1213-
const bad = llvm_bindings.WriteArchive(full_out_path_z, object_files.items.ptr, object_files.items.len, os_tag);
1212+
const bad = llvm_bindings.WriteArchive(
1213+
full_out_path_z,
1214+
object_files.items.ptr,
1215+
object_files.items.len,
1216+
switch (target.os.tag) {
1217+
.aix => .AIXBIG,
1218+
.windows => .COFF,
1219+
else => if (target.os.tag.isDarwin()) .DARWIN else .GNU,
1220+
},
1221+
);
12141222
if (bad) return error.UnableToWriteArchive;
12151223

12161224
if (!base.disable_lld_caching) {

src/mingw.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,14 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
279279

280280
if (!build_options.have_llvm) return error.ZigCompilerNotBuiltWithLLVMExtensions;
281281
const llvm_bindings = @import("codegen/llvm/bindings.zig");
282-
const llvm = @import("codegen/llvm.zig");
283-
const arch_tag = llvm.targetArch(target.cpu.arch);
284282
const def_final_path_z = try arena.dupeZ(u8, def_final_path);
285283
const lib_final_path_z = try comp.global_cache_directory.joinZ(arena, &.{lib_final_path});
286-
if (llvm_bindings.WriteImportLibrary(def_final_path_z.ptr, arch_tag, lib_final_path_z.ptr, true)) {
284+
if (llvm_bindings.WriteImportLibrary(
285+
def_final_path_z.ptr,
286+
@intFromEnum(target.toCoffMachine()),
287+
lib_final_path_z.ptr,
288+
true,
289+
)) {
287290
// TODO surface a proper error here
288291
log.err("unable to turn {s}.def into {s}.lib", .{ lib_name, lib_name });
289292
return error.WritingImportLibFailed;

0 commit comments

Comments
 (0)