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

This commit is contained in:
Alex Rønne Petersen 2025-03-27 17:12:17 +01:00
parent ed6418544c
commit 1423b38c45
No known key found for this signature in database

View File

@ -214,11 +214,6 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
if (target.result.os.tag == .windows and target.result.abi == .gnu) {
// LTO is currently broken on mingw, this can be removed when it's fixed.
exe.want_lto = false;
}
const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend"); const use_llvm = b.option(bool, "use-llvm", "Use the llvm backend");
exe.use_llvm = use_llvm; exe.use_llvm = use_llvm;
exe.use_lld = use_llvm; exe.use_lld = use_llvm;
@ -331,7 +326,12 @@ pub fn build(b: *std.Build) !void {
try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
} else { } else {
// Here we are -Denable-llvm but no cmake integration. // Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToModule(exe.root_module); try addStaticLlvmOptionsToModule(exe.root_module, .{
.llvm_has_m68k = llvm_has_m68k,
.llvm_has_csky = llvm_has_csky,
.llvm_has_arc = llvm_has_arc,
.llvm_has_xtensa = llvm_has_xtensa,
});
} }
if (target.result.os.tag == .windows) { if (target.result.os.tag == .windows) {
// LLVM depends on networking as of version 18. // LLVM depends on networking as of version 18.
@ -359,11 +359,7 @@ pub fn build(b: *std.Build) !void {
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" }, &[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
); );
// On mingw, we need to opt into windows 7+ to get some features required by tracy. const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path }); exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path });
exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
@ -818,7 +814,12 @@ fn addCmakeCfgOptionsToExe(
} }
} }
fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void { fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
llvm_has_m68k: bool,
llvm_has_csky: bool,
llvm_has_arc: bool,
llvm_has_xtensa: bool,
}) !void {
// Adds the Zig C++ sources which both stage1 and stage2 need. // Adds the Zig C++ sources which both stage1 and stage2 need.
// //
// We need this because otherwise zig_clang_cc1_main.cpp ends up pulling // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
@ -842,6 +843,22 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void {
mod.linkSystemLibrary(lib_name, .{}); mod.linkSystemLibrary(lib_name, .{});
} }
if (options.llvm_has_m68k) for (llvm_libs_m68k) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_csky) for (llvm_libs_csky) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_arc) for (llvm_libs_arc) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
if (options.llvm_has_xtensa) for (llvm_libs_xtensa) |lib_name| {
mod.linkSystemLibrary(lib_name, .{});
};
mod.linkSystemLibrary("z", .{}); mod.linkSystemLibrary("z", .{});
mod.linkSystemLibrary("zstd", .{}); mod.linkSystemLibrary("zstd", .{});
@ -1330,6 +1347,33 @@ const llvm_libs = [_][]const u8{
"LLVMSupport", "LLVMSupport",
"LLVMDemangle", "LLVMDemangle",
}; };
const llvm_libs_m68k = [_][]const u8{
"LLVMM68kDisassembler",
"LLVMM68kAsmParser",
"LLVMM68kCodeGen",
"LLVMM68kDesc",
"LLVMM68kInfo",
};
const llvm_libs_csky = [_][]const u8{
"LLVMCSKYDisassembler",
"LLVMCSKYAsmParser",
"LLVMCSKYCodeGen",
"LLVMCSKYDesc",
"LLVMCSKYInfo",
};
const llvm_libs_arc = [_][]const u8{
"LLVMARCDisassembler",
"LLVMARCCodeGen",
"LLVMARCDesc",
"LLVMARCInfo",
};
const llvm_libs_xtensa = [_][]const u8{
"LLVMXtensaDisassembler",
"LLVMXtensaAsmParser",
"LLVMXtensaCodeGen",
"LLVMXtensaDesc",
"LLVMXtensaInfo",
};
fn generateLangRef(b: *std.Build) std.Build.LazyPath { fn generateLangRef(b: *std.Build) std.Build.LazyPath {
const doctest_exe = b.addExecutable(.{ const doctest_exe = b.addExecutable(.{