Skip to content

Commit 2b57f6b

Browse files
authored
Merge pull request #23378 from alexrp/build-zig-cleanup
2 parents cc9634a + f71590d commit 2b57f6b

File tree

1 file changed

+56
-12
lines changed

1 file changed

+56
-12
lines changed

build.zig

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,6 @@ pub fn build(b: *std.Build) !void {
214214

215215
test_step.dependOn(&exe.step);
216216

217-
if (target.result.os.tag == .windows and target.result.abi == .gnu) {
218-
// LTO is currently broken on mingw, this can be removed when it's fixed.
219-
exe.want_lto = false;
220-
}
221-
222217
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
223218
exe.use_llvm = use_llvm;
224219
exe.use_lld = use_llvm;
@@ -331,7 +326,12 @@ pub fn build(b: *std.Build) !void {
331326
try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
332327
} else {
333328
// Here we are -Denable-llvm but no cmake integration.
334-
try addStaticLlvmOptionsToModule(exe.root_module);
329+
try addStaticLlvmOptionsToModule(exe.root_module, .{
330+
.llvm_has_m68k = llvm_has_m68k,
331+
.llvm_has_csky = llvm_has_csky,
332+
.llvm_has_arc = llvm_has_arc,
333+
.llvm_has_xtensa = llvm_has_xtensa,
334+
});
335335
}
336336
if (target.result.os.tag == .windows) {
337337
// LLVM depends on networking as of version 18.
@@ -359,11 +359,7 @@ pub fn build(b: *std.Build) !void {
359359
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
360360
);
361361

362-
// On mingw, we need to opt into windows 7+ to get some features required by tracy.
363-
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
364-
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
365-
else
366-
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
362+
const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
367363

368364
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
369365
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
@@ -818,7 +814,12 @@ fn addCmakeCfgOptionsToExe(
818814
}
819815
}
820816

821-
fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
817+
fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
818+
llvm_has_m68k: bool,
819+
llvm_has_csky: bool,
820+
llvm_has_arc: bool,
821+
llvm_has_xtensa: bool,
822+
}) !void {
822823
// Adds the Zig C++ sources which both stage1 and stage2 need.
823824
//
824825
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
@@ -842,6 +843,22 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
842843
mod.linkSystemLibrary(lib_name, .{});
843844
}
844845

846+
if (options.llvm_has_m68k) for (llvm_libs_m68k) |lib_name| {
847+
mod.linkSystemLibrary(lib_name, .{});
848+
};
849+
850+
if (options.llvm_has_csky) for (llvm_libs_csky) |lib_name| {
851+
mod.linkSystemLibrary(lib_name, .{});
852+
};
853+
854+
if (options.llvm_has_arc) for (llvm_libs_arc) |lib_name| {
855+
mod.linkSystemLibrary(lib_name, .{});
856+
};
857+
858+
if (options.llvm_has_xtensa) for (llvm_libs_xtensa) |lib_name| {
859+
mod.linkSystemLibrary(lib_name, .{});
860+
};
861+
845862
mod.linkSystemLibrary("z", .{});
846863
mod.linkSystemLibrary("zstd", .{});
847864

@@ -1330,6 +1347,33 @@ const llvm_libs = [_][]const u8{
13301347
"LLVMSupport",
13311348
"LLVMDemangle",
13321349
};
1350+
const llvm_libs_m68k = [_][]const u8{
1351+
"LLVMM68kDisassembler",
1352+
"LLVMM68kAsmParser",
1353+
"LLVMM68kCodeGen",
1354+
"LLVMM68kDesc",
1355+
"LLVMM68kInfo",
1356+
};
1357+
const llvm_libs_csky = [_][]const u8{
1358+
"LLVMCSKYDisassembler",
1359+
"LLVMCSKYAsmParser",
1360+
"LLVMCSKYCodeGen",
1361+
"LLVMCSKYDesc",
1362+
"LLVMCSKYInfo",
1363+
};
1364+
const llvm_libs_arc = [_][]const u8{
1365+
"LLVMARCDisassembler",
1366+
"LLVMARCCodeGen",
1367+
"LLVMARCDesc",
1368+
"LLVMARCInfo",
1369+
};
1370+
const llvm_libs_xtensa = [_][]const u8{
1371+
"LLVMXtensaDisassembler",
1372+
"LLVMXtensaAsmParser",
1373+
"LLVMXtensaCodeGen",
1374+
"LLVMXtensaDesc",
1375+
"LLVMXtensaInfo",
1376+
};
13331377

13341378
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
13351379
const doctest_exe = b.addExecutable(.{

0 commit comments

Comments
 (0)