Skip to content
/ zig Public
forked from ziglang/zig

Commit

Permalink
std.Target: Add extra functions for determining libc from the target.
Browse files Browse the repository at this point in the history
Once ziglang#20690 is implemented, these will go away in favor of a simple api field.
But for now, they're convenient to have.
  • Loading branch information
alexrp committed Nov 4, 2024
1 parent 94d5672 commit 37cc6e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ pub const Os = struct {
};
}

pub inline fn isMinGW(tag: Os.Tag, abi: Abi) bool {
return tag == .windows and abi.isGnu();
}

pub inline fn isMuslLibC(tag: Os.Tag, abi: Abi) bool {
return tag == .linux and abi.isMusl();
}

pub inline fn isWasiLibC(tag: Os.Tag, abi: Abi) bool {
return tag == .wasi and abi.isMusl();
}

pub inline fn isGnuLibC(tag: Os.Tag, abi: Abi) bool {
return (tag == .hurd or tag == .linux) and abi.isGnu();
}
Expand Down Expand Up @@ -2032,7 +2044,15 @@ pub fn libPrefix(target: Target) [:0]const u8 {
}

pub inline fn isMinGW(target: Target) bool {
return target.os.tag == .windows and target.abi.isGnu();
return target.os.tag.isMinGW(target.abi);
}

pub inline fn isMuslLibC(target: Target) bool {
return target.os.tag.isMuslLibC(target.abi);
}

pub inline fn isWasiLibC(target: Target) bool {
return target.os.tag.isWasiLibC(target.abi);
}

pub inline fn isGnuLibC(target: Target) bool {
Expand Down
4 changes: 2 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
}
// Loads the libraries provided by `target_util.libcFullLinkFlags(target)`.
comp.link_task_queue.shared.appendAssumeCapacity(.load_host_libc);
} else if (target.isMusl() and !target.isWasm()) {
} else if (target.isMuslLibC()) {
if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;

if (musl.needsCrtiCrtn(target)) {
Expand Down Expand Up @@ -1802,7 +1802,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.{ .glibc_shared_objects = {} },
.{ .glibc_crt_file = .libc_nonshared_a },
});
} else if (target.isWasm() and target.os.tag == .wasi) {
} else if (target.isWasiLibC()) {
if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;

for (comp.wasi_emulated_libs) |crt_file| {
Expand Down

0 comments on commit 37cc6e6

Please sign in to comment.