feature. See also
. The project being documented here (as the example) is the Zig library itself.
main.getIncludePaths
fn getIncludePaths(
arena: Allocator,
io: Io,
auto_includes_option: cli.Options.AutoIncludes,
zig_lib_dir: []const u8,
target_machine_type: std.coff.IMAGE.FILE.MACHINE,
environ_map: *const std.process.Environ.Map,
) ![]const []const u8
File
Code
fn getIncludePaths(
arena: Allocator,
io: Io,
auto_includes_option: cli.Options.AutoIncludes,
zig_lib_dir: []const u8,
target_machine_type: std.coff.IMAGE.FILE.MACHINE,
environ_map: *const std.process.Environ.Map,
) ![]const []const u8 {
if (auto_includes_option == .none) return &[_][]const u8{};
const includes_arch: std.Target.Cpu.Arch = switch (target_machine_type) {
.AMD64 => .x86_64,
.I386 => .x86,
.ARMNT => .thumb,
.ARM64 => .aarch64,
.ARM64EC => .aarch64,
.ARM64X => .aarch64,
.IA64, .EBC => {
return error.UnsupportedAutoIncludesMachineType;
},
// This is enforced by the argument parser in cli.zig.
else => unreachable,
};
var includes = auto_includes_option;
if (builtin.target.os.tag != .windows) {
switch (includes) {
.none => unreachable,
.msvc => return error.MsvcIncludesNotFound,
.any => includes = .gnu,
.gnu => {},
}
}
while (true) {
switch (includes) {
.none => unreachable,
.any, .msvc => {
// that .any and .msvc should be dealt with on non-Windows targets before this point,
// since getting MSVC include paths uses Windows-only APIs.
if (builtin.target.os.tag != .windows) unreachable;
const target_query: std.Target.Query = .{
.os_tag = .windows,
.cpu_arch = includes_arch,
.abi = .msvc,
};
const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(arena, io, .{ .root_dir = .cwd(), .sub_path = zig_lib_dir }, &target, is_native_abi, true, null, environ_map) catch {
if (includes == .any) {
includes = .gnu;
continue;
}
return error.MsvcIncludesNotFound;
};
if (detected_libc.libc_include_dir_list.len == 0) {
if (includes == .any) {
includes = .gnu;
continue;
}
return error.MsvcIncludesNotFound;
}
return detected_libc.libc_include_dir_list;
},
.gnu => {
const target_query: std.Target.Query = .{
.os_tag = .windows,
.cpu_arch = includes_arch,
.abi = .gnu,
};
const target = std.zig.resolveTargetQueryOrFatal(io, target_query);
const is_native_abi = target_query.isNativeAbi();
const detected_libc = std.zig.LibCDirs.detect(
arena,
io,
.{ .root_dir = .cwd(), .sub_path = zig_lib_dir },
&target,
is_native_abi,
true,
null,
environ_map,
) catch |err| switch (err) {
error.OutOfMemory => |e| return e,
else => return error.MingwIncludesNotFound,
};
return detected_libc.libc_include_dir_list;
},
}
}
}