authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-27 17:12:17+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-03-27 17:12:17+01:00
log2b57f6b717e1c0f54ed73a66dfd5cceb79cb2e87
treea8e5a6091cd8fcfe56aa8af2ab7f0e5c8bc43c23
parentcc9634a2d3ac3ee7ec36e16ab9117aad6e2da625
parentf71590d4c49493b533da81a55962c7429f5b5151
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23378 from alexrp/build-zig-cleanup


1 files changed, 56 insertions(+), 12 deletions(-)

build.zig+56-12
......@@ -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
821fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
817fn 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};
1350const llvm_libs_m68k = [_][]const u8{
1351 "LLVMM68kDisassembler",
1352 "LLVMM68kAsmParser",
1353 "LLVMM68kCodeGen",
1354 "LLVMM68kDesc",
1355 "LLVMM68kInfo",
1356};
1357const llvm_libs_csky = [_][]const u8{
1358 "LLVMCSKYDisassembler",
1359 "LLVMCSKYAsmParser",
1360 "LLVMCSKYCodeGen",
1361 "LLVMCSKYDesc",
1362 "LLVMCSKYInfo",
1363};
1364const llvm_libs_arc = [_][]const u8{
1365 "LLVMARCDisassembler",
1366 "LLVMARCCodeGen",
1367 "LLVMARCDesc",
1368 "LLVMARCInfo",
1369};
1370const llvm_libs_xtensa = [_][]const u8{
1371 "LLVMXtensaDisassembler",
1372 "LLVMXtensaAsmParser",
1373 "LLVMXtensaCodeGen",
1374 "LLVMXtensaDesc",
1375 "LLVMXtensaInfo",
1376};
13331377
13341378fn generateLangRef(b: *std.Build) std.Build.LazyPath {
13351379 const doctest_exe = b.addExecutable(.{