mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
std: add compile error when using std.os.getenv
on the wasi target
`std.process.getEnvMap` or `std.process.getEnvVarOwned` should be used instead, requiring allocation.
This commit is contained in:
parent
742030a8f2
commit
69982339ed
@ -1908,6 +1908,8 @@ pub fn getenv(key: []const u8) ?[:0]const u8 {
|
||||
}
|
||||
if (builtin.os.tag == .windows) {
|
||||
@compileError("std.os.getenv is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");
|
||||
} else if (builtin.os.tag == .wasi) {
|
||||
@compileError("std.os.getenv is unavailable for WASI. See std.process.getEnvMap or std.process.getEnvVarOwned for a cross-platform API.");
|
||||
}
|
||||
// The simplified start logic doesn't populate environ.
|
||||
if (std.start.simplified_logic) return null;
|
||||
|
@ -660,6 +660,11 @@ test "mmap" {
|
||||
}
|
||||
|
||||
test "getenv" {
|
||||
if (native_os == .wasi and !builtin.link_libc) {
|
||||
// std.os.getenv is not supported on WASI due to the need of allocation
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
if (native_os == .windows) {
|
||||
try expect(os.getenvW(&[_:0]u16{ 'B', 'O', 'G', 'U', 'S', 0x11, 0x22, 0x33, 0x44, 0x55 }) == null);
|
||||
} else {
|
||||
|
@ -100,7 +100,7 @@ pub fn detect(arena: Allocator, native_info: NativeTargetInfo) !NativePaths {
|
||||
return self;
|
||||
}
|
||||
|
||||
if (builtin.os.tag != .windows) {
|
||||
if (builtin.os.tag != .windows and builtin.os.tag != .wasi) {
|
||||
const triple = try native_target.linuxTriple(arena);
|
||||
|
||||
const qual = native_target.ptrBitWidth();
|
||||
|
Loading…
Reference in New Issue
Block a user