feature. See also
. The project being documented here (as the example) is the Zig library itself.
LibCDirs.detectFromInstallation
fn detectFromInstallation(arena: Allocator, target: *const std.Target, lci: *const LibCInstallation) !LibCDirs
File
Code
fn detectFromInstallation(arena: Allocator, target: *const std.Target, lci: *const LibCInstallation) !LibCDirs {
var list = try std.array_list.Managed([]const u8).initCapacity(arena, 5);
var framework_list = std.array_list.Managed([]const u8).init(arena);
list.appendAssumeCapacity(lci.include_dir.?);
const is_redundant = std.mem.eql(u8, lci.sys_include_dir.?, lci.include_dir.?);
if (!is_redundant) list.appendAssumeCapacity(lci.sys_include_dir.?);
if (target.os.tag == .windows) {
if (std.fs.path.dirname(lci.sys_include_dir.?)) |sys_include_dir_parent| {
// is installed. It contains headers, .rc files, and resources. It is especially
// necessary when working with Windows resources.
const atlmfc_dir = try std.fs.path.join(arena, &[_][]const u8{ sys_include_dir_parent, "atlmfc", "include" });
list.appendAssumeCapacity(atlmfc_dir);
}
if (std.fs.path.dirname(lci.include_dir.?)) |include_dir_parent| {
const um_dir = try std.fs.path.join(arena, &[_][]const u8{ include_dir_parent, "um" });
list.appendAssumeCapacity(um_dir);
const shared_dir = try std.fs.path.join(arena, &[_][]const u8{ include_dir_parent, "shared" });
list.appendAssumeCapacity(shared_dir);
}
}
if (target.os.tag == .haiku) {
const include_dir_path = lci.include_dir.?;
const subdirs = &[_][]const u8{
"os", "os/app", "os/device", "os/drivers",
"os/game", "os/interface", "os/kernel", "os/locale",
"os/mail", "os/media", "os/midi", "os/midi2",
"os/net", "os/opengl", "os/storage", "os/support",
"os/translation", "os/add-ons/graphics", "os/add-ons/input_server", "os/add-ons/mail_daemon",
"os/add-ons/registrar", "os/add-ons/screen_saver", "os/add-ons/tracker", "os/be_apps/NetPositive",
"os/be_apps/Tracker", "bsd", "glibc", "gnu",
};
for (subdirs) |subdir| {
const path = try std.fs.path.join(arena, &[_][]const u8{ include_dir_path, subdir });
try list.append(path);
}
}
var sysroot: ?[]const u8 = null;
if (target.os.tag.isDarwin()) d: {
const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
const down2 = std.fs.path.dirname(down1) orelse break :d;
try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
sysroot = down2;
}
return .{
.libc_include_dir_list = list.items,
.libc_installation = lci,
.libc_framework_dir_list = framework_list.items,
.sysroot = sysroot,
.darwin_sdk_layout = if (sysroot == null) null else .sdk,
};
}