This commit is contained in:
David Gonzalez Martin 2024-06-15 21:25:06 -05:00
parent 5c6b050a94
commit 21af15ac3a
2 changed files with 59 additions and 43 deletions

View File

@ -5714,37 +5714,38 @@ fn compile_c_source_files(thread: *Thread, arguments: []const []const u8) void {
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include", "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
}, },
.linux => switch (@import("builtin").abi) { .linux => configuration.include_paths,
.gnu => if (@import("configuration").ci) &.{ // .gnu => if (@import("configuration").ci) &.{
"/usr/include/c++/11", // "/usr/include/c++/11",
"/usr/include/x86_64-linux-gnu/c++/11", // "/usr/include/x86_64-linux-gnu/c++/11",
"/usr/lib/clang/17/include", // "/usr/lib/clang/17/include",
"/usr/include", // "/usr/include",
"/usr/include/x86_64-linux-gnu", // "/usr/include/x86_64-linux-gnu",
} else switch (@import("builtin").cpu.arch) { // } else switch (@import("builtin").cpu.arch) {
.x86_64 => &.{ // .x86_64 => &.{
"/usr/include/c++/14", // "/usr/include/c++/14",
"/usr/include/c++/14/x86_64-pc-linux-gnu", // "/usr/include/c++/14/x86_64-pc-linux-gnu",
"/usr/lib/clang/17/include", // "/usr/lib/clang/17/include",
"/usr/include", // "/usr/include",
"/usr/include/linux", // "/usr/include/linux",
}, // },
.aarch64 => &.{ // .aarch64 => &.{
"/usr/include/c++/14", // "/usr/include/c++/14",
"/usr/include/c++/14/aarch64-redhat-linux", // "/usr/include/c++/14/aarch64-redhat-linux",
"/usr/lib/clang/18/include", // "/usr/lib/clang/18/include",
"/usr/include", // "/usr/include",
"/usr/include/linux", // "/usr/include/linux",
}, // },
else => unreachable, // else => unreachable,
}, // },
else => unreachable, //@compileError("ABI not supported"), // else => unreachable, //@compileError("ABI not supported"),
}, // },
.windows => &.{}, .windows => &.{},
else => @compileError("OS not supported"), else => @compileError("OS not supported"),
}; };
for (libc_include_dirs) |include_dir| { for (libc_include_dirs) |include_dir| {
std.debug.print("Include path: {s}\n", .{include_dir});
argv.appendSliceAssumeCapacity(&.{ "-isystem", include_dir }); argv.appendSliceAssumeCapacity(&.{ "-isystem", include_dir });
} }

View File

@ -36,11 +36,6 @@ pub fn build(b: *std.Build) !void {
.windows => true, .windows => true,
// .macos => true, // .macos => true,
}; };
const compiler_options = b.addOptions();
compiler_options.addOption(bool, "print_stack_trace", print_stack_trace);
compiler_options.addOption(bool, "ci", is_ci);
compiler_options.addOption(bool, "editor", use_editor);
compiler_options.addOption(bool, "sleep_on_thread_hot_loops", sleep_on_thread_hot_loops);
const fetcher = b.addExecutable(.{ const fetcher = b.addExecutable(.{
.name = "llvm_fetcher", .name = "llvm_fetcher",
@ -118,7 +113,6 @@ pub fn build(b: *std.Build) !void {
}, },
}); });
compiler.root_module.addOptions("configuration", compiler_options);
compiler.formatted_panics = print_stack_trace; compiler.formatted_panics = print_stack_trace;
compiler.root_module.unwind_tables = print_stack_trace or target.result.os.tag == .windows; compiler.root_module.unwind_tables = print_stack_trace or target.result.os.tag == .windows;
compiler.root_module.omit_frame_pointer = false; compiler.root_module.omit_frame_pointer = false;
@ -371,6 +365,8 @@ pub fn build(b: *std.Build) !void {
"libclangTransformer.a", "libclangTransformer.a",
}; };
var include_paths = std.ArrayList([]const u8).init(b.allocator);
if (static or target.result.os.tag == .windows) { if (static or target.result.os.tag == .windows) {
if (target.result.os.tag == .linux) compiler.linkage = .static; if (target.result.os.tag == .linux) compiler.linkage = .static;
compiler.linkLibCpp(); compiler.linkLibCpp();
@ -440,15 +436,18 @@ pub fn build(b: *std.Build) !void {
compiler.linkSystemLibrary(if (is_ci or builtin.os.tag == .macos) "z" else "zlib"); compiler.linkSystemLibrary(if (is_ci or builtin.os.tag == .macos) "z" else "zlib");
compiler.linkSystemLibrary("zstd"); compiler.linkSystemLibrary("zstd");
var llvm_prefix: []const u8 = "";
switch (target.result.os.tag) { switch (target.result.os.tag) {
.linux => { .linux => {
if (third_party_ci) { if (third_party_ci) {
compiler.addObjectFile(.{ .cwd_relative = "/lib/x86_64-linux-gnu/libstdc++.so.6" }); compiler.addObjectFile(.{ .cwd_relative = "/lib/x86_64-linux-gnu/libstdc++.so.6" });
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" }); try include_paths.append("/usr/include");
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" }); try include_paths.append("/usr/include" );
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/c++/11" }); try include_paths.append("/usr/include/x86_64-linux-gnu" );
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu/c++/11" }); try include_paths.append("/usr/include/c++/11" );
compiler.addIncludePath(.{ .cwd_relative = "/usr/lib/llvm-18/include" }); try include_paths.append("/usr/include/x86_64-linux-gnu/c++/11" );
try include_paths.append("/usr/lib/llvm-18/include" );
llvm_prefix = "/usr/lib/llvm-18";
compiler.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" }); compiler.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" });
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-18/lib" }); compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-18/lib" });
} else { } else {
@ -491,10 +490,11 @@ pub fn build(b: *std.Build) !void {
} }
}); });
compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" }); compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" });
compiler.addIncludePath(.{ .cwd_relative = if (use_debug) "../../local/llvm18-debug/include" else "../../local/llvm18-release/include" }); llvm_prefix = if (use_debug) "../../local/llvm18-debug/" else "../../local/llvm18-release";
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" }); try include_paths.append(try std.mem.concat(b.allocator, u8, &.{llvm_prefix, "/include"}));
compiler.addIncludePath(.{ .cwd_relative = cxx_include_base }); try include_paths.append("/usr/include");
compiler.addIncludePath(.{ .cwd_relative = cxx_include_arch }); try include_paths.append(cxx_include_base);
try include_paths.append(cxx_include_arch);
compiler.addLibraryPath(.{ .cwd_relative = if (use_debug) "../../local/llvm18-debug/lib" else "../../local/llvm18-release/lib" }); compiler.addLibraryPath(.{ .cwd_relative = if (use_debug) "../../local/llvm18-debug/lib" else "../../local/llvm18-release/lib" });
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" }); compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" });
} }
@ -502,10 +502,11 @@ pub fn build(b: *std.Build) !void {
.macos => { .macos => {
compiler.linkLibCpp(); compiler.linkLibCpp();
if (discover_brew_prefix(b, "llvm@18")) |llvm_prefix| { if (discover_brew_prefix(b, "llvm@18")) |prefix| {
llvm_prefix = prefix;
const llvm_include_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/include" }); const llvm_include_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/include" });
const llvm_lib_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/lib" }); const llvm_lib_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/lib" });
compiler.addIncludePath(.{ .cwd_relative = llvm_include_path }); try include_paths.append(llvm_include_path);
compiler.addLibraryPath(.{ .cwd_relative = llvm_lib_path }); compiler.addLibraryPath(.{ .cwd_relative = llvm_lib_path });
} else |err| { } else |err| {
return err; return err;
@ -529,6 +530,12 @@ pub fn build(b: *std.Build) !void {
else => |tag| @panic(@tagName(tag)), else => |tag| @panic(@tagName(tag)),
} }
for (include_paths.items) |include_path| {
compiler.addIncludePath(.{ .cwd_relative = include_path });
}
try include_paths.append(try std.mem.concat(b.allocator, u8, &.{llvm_prefix, "/lib/clang/18/include"}));
if (use_editor) { if (use_editor) {
compiler.linkSystemLibrary("glfw"); compiler.linkSystemLibrary("glfw");
compiler.linkSystemLibrary("GL"); compiler.linkSystemLibrary("GL");
@ -552,6 +559,14 @@ pub fn build(b: *std.Build) !void {
} }
} }
const compiler_options = b.addOptions();
compiler_options.addOption(bool, "print_stack_trace", print_stack_trace);
compiler_options.addOption(bool, "ci", is_ci);
compiler_options.addOption(bool, "editor", use_editor);
compiler_options.addOption(bool, "sleep_on_thread_hot_loops", sleep_on_thread_hot_loops);
compiler_options.addOption([]const []const u8, "include_paths", include_paths.items);
compiler.root_module.addOptions("configuration", compiler_options);
if (target.result.os.tag == .windows) { if (target.result.os.tag == .windows) {
compiler.linkSystemLibrary("ole32"); compiler.linkSystemLibrary("ole32");
compiler.linkSystemLibrary("version"); compiler.linkSystemLibrary("version");