mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
fix compilation failures found by CI
This commit is contained in:
parent
6b2899df2a
commit
8c94950c24
28 changed files with 126 additions and 128 deletions
|
|
@ -26,7 +26,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
if (args.len < 2) {
|
if (args.len < 2) {
|
||||||
try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{});
|
try renderErrorMessage(stderr.writer(), stderr_config, .err, "expected zig lib dir as first argument", .{});
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
const zig_lib_dir = args[1];
|
const zig_lib_dir = args[1];
|
||||||
var cli_args = args[2..];
|
var cli_args = args[2..];
|
||||||
|
|
@ -62,7 +62,7 @@ pub fn main() !void {
|
||||||
var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) {
|
var options = cli.parse(allocator, cli_args, &cli_diagnostics) catch |err| switch (err) {
|
||||||
error.ParseError => {
|
error.ParseError => {
|
||||||
try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics);
|
try error_handler.emitCliDiagnostics(allocator, cli_args, &cli_diagnostics);
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
|
|
@ -117,7 +117,7 @@ pub fn main() !void {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{});
|
try error_handler.emitMessage(allocator, .note, "to disable auto includes, use the option /:auto-includes none", .{});
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -153,16 +153,16 @@ pub fn main() !void {
|
||||||
preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) {
|
preprocess.preprocess(&comp, preprocessed_buf.writer(), argv.items, maybe_dependencies_list) catch |err| switch (err) {
|
||||||
error.GeneratedSourceError => {
|
error.GeneratedSourceError => {
|
||||||
try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp);
|
try error_handler.emitAroDiagnostics(allocator, "failed during preprocessor setup (this is always a bug):", &comp);
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
// ArgError can occur if e.g. the .rc file is not found
|
// ArgError can occur if e.g. the .rc file is not found
|
||||||
error.ArgError, error.PreprocessError => {
|
error.ArgError, error.PreprocessError => {
|
||||||
try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp);
|
try error_handler.emitAroDiagnostics(allocator, "failed during preprocessing:", &comp);
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
error.StreamTooLong => {
|
error.StreamTooLong => {
|
||||||
try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{});
|
try error_handler.emitMessage(allocator, .err, "failed during preprocessing: maximum file size exceeded", .{});
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
error.OutOfMemory => |e| return e,
|
error.OutOfMemory => |e| return e,
|
||||||
};
|
};
|
||||||
|
|
@ -171,7 +171,7 @@ pub fn main() !void {
|
||||||
} else {
|
} else {
|
||||||
break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| {
|
break :full_input std.fs.cwd().readFileAlloc(allocator, options.input_filename, std.math.maxInt(usize)) catch |err| {
|
||||||
try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) });
|
try error_handler.emitMessage(allocator, .err, "unable to read input file path '{s}': {s}", .{ options.input_filename, @errorName(err) });
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -191,14 +191,14 @@ pub fn main() !void {
|
||||||
const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) {
|
const final_input = removeComments(mapping_results.result, mapping_results.result, &mapping_results.mappings) catch |err| switch (err) {
|
||||||
error.InvalidSourceMappingCollapse => {
|
error.InvalidSourceMappingCollapse => {
|
||||||
try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{});
|
try error_handler.emitMessage(allocator, .err, "failed during comment removal; this is a known bug", .{});
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
|
|
||||||
var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {
|
var output_file = std.fs.cwd().createFile(options.output_filename, .{}) catch |err| {
|
||||||
try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });
|
try error_handler.emitMessage(allocator, .err, "unable to create output file '{s}': {s}", .{ options.output_filename, @errorName(err) });
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
var output_file_closed = false;
|
var output_file_closed = false;
|
||||||
defer if (!output_file_closed) output_file.close();
|
defer if (!output_file_closed) output_file.close();
|
||||||
|
|
@ -231,7 +231,7 @@ pub fn main() !void {
|
||||||
output_file_closed = true;
|
output_file_closed = true;
|
||||||
// Failing to delete is not really a big deal, so swallow any errors
|
// Failing to delete is not really a big deal, so swallow any errors
|
||||||
std.fs.cwd().deleteFile(options.output_filename) catch {};
|
std.fs.cwd().deleteFile(options.output_filename) catch {};
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
|
|
@ -247,7 +247,7 @@ pub fn main() !void {
|
||||||
if (options.depfile_path) |depfile_path| {
|
if (options.depfile_path) |depfile_path| {
|
||||||
var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {
|
var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {
|
||||||
try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
|
try error_handler.emitMessage(allocator, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
defer depfile.close();
|
defer depfile.close();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ pub fn _errno() *c_int {
|
||||||
return &errno;
|
return &errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const PATH_MAX = 4096;
|
||||||
|
|
||||||
pub const mode_t = u32;
|
pub const mode_t = u32;
|
||||||
pub const time_t = i64;
|
pub const time_t = i64;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,12 @@ pub const MAX_PATH_BYTES = max_path_bytes;
|
||||||
/// * On other platforms, `[]u8` file paths are opaque sequences of bytes with
|
/// * On other platforms, `[]u8` file paths are opaque sequences of bytes with
|
||||||
/// no particular encoding.
|
/// no particular encoding.
|
||||||
pub const max_path_bytes = switch (native_os) {
|
pub const max_path_bytes = switch (native_os) {
|
||||||
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten => posix.PATH_MAX,
|
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9, .emscripten, .wasi => posix.PATH_MAX,
|
||||||
// Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes.
|
// Each WTF-16LE code unit may be expanded to 3 WTF-8 bytes.
|
||||||
// If it would require 4 WTF-8 bytes, then there would be a surrogate
|
// If it would require 4 WTF-8 bytes, then there would be a surrogate
|
||||||
// pair in the WTF-16LE, and we (over)account 3 bytes for it that way.
|
// pair in the WTF-16LE, and we (over)account 3 bytes for it that way.
|
||||||
// +1 for the null byte at the end, which can be encoded in 1 byte.
|
// +1 for the null byte at the end, which can be encoded in 1 byte.
|
||||||
.windows => windows.PATH_MAX_WIDE * 3 + 1,
|
.windows => windows.PATH_MAX_WIDE * 3 + 1,
|
||||||
// TODO work out what a reasonable value we should use here
|
|
||||||
.wasi => 4096,
|
|
||||||
else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX"))
|
else => if (@hasDecl(root, "os") and @hasDecl(root.os, "PATH_MAX"))
|
||||||
root.os.PATH_MAX
|
root.os.PATH_MAX
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -2555,7 +2555,7 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
|
||||||
return file.stat();
|
return file.stat();
|
||||||
}
|
}
|
||||||
if (native_os == .wasi and !builtin.link_libc) {
|
if (native_os == .wasi and !builtin.link_libc) {
|
||||||
const st = try posix.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
|
const st = try std.os.fstatat_wasi(self.fd, sub_path, .{ .SYMLINK_FOLLOW = true });
|
||||||
return Stat.fromWasi(st);
|
return Stat.fromWasi(st);
|
||||||
}
|
}
|
||||||
const st = try posix.fstatat(self.fd, sub_path, 0);
|
const st = try posix.fstatat(self.fd, sub_path, 0);
|
||||||
|
|
|
||||||
|
|
@ -457,7 +457,7 @@ pub fn stat(self: File) StatError!Stat {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||||
const st = try posix.fstat_wasi(self.handle);
|
const st = try std.os.fstat_wasi(self.handle);
|
||||||
return Stat.fromWasi(st);
|
return Stat.fromWasi(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1004,7 +1004,7 @@ pub fn metadata(self: File) MetadataError!Metadata {
|
||||||
.statx = stx,
|
.statx = stx,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
.wasi => .{ .stat = try posix.fstat_wasi(self.handle) },
|
.wasi => .{ .stat = try std.os.fstat_wasi(self.handle) },
|
||||||
else => .{ .stat = try posix.fstat(self.handle) },
|
else => .{ .stat = try posix.fstat(self.handle) },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const os = std.os;
|
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const math = std.math;
|
const math = std.math;
|
||||||
const fs = std.fs;
|
const fs = std.fs;
|
||||||
|
|
@ -14,10 +13,10 @@ pub const Preopens = struct {
|
||||||
// Indexed by file descriptor number.
|
// Indexed by file descriptor number.
|
||||||
names: []const []const u8,
|
names: []const []const u8,
|
||||||
|
|
||||||
pub fn find(p: Preopens, name: []const u8) ?os.fd_t {
|
pub fn find(p: Preopens, name: []const u8) ?std.posix.fd_t {
|
||||||
for (p.names, 0..) |elem_name, i| {
|
for (p.names, 0..) |elem_name, i| {
|
||||||
if (mem.eql(u8, elem_name, name)) {
|
if (mem.eql(u8, elem_name, name)) {
|
||||||
return @as(os.fd_t, @intCast(i));
|
return @intCast(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ const elf = std.elf;
|
||||||
const fs = std.fs;
|
const fs = std.fs;
|
||||||
const dl = @import("dynamic_library.zig");
|
const dl = @import("dynamic_library.zig");
|
||||||
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
||||||
|
const posix = std.posix;
|
||||||
|
|
||||||
pub const linux = @import("os/linux.zig");
|
pub const linux = @import("os/linux.zig");
|
||||||
pub const plan9 = @import("os/plan9.zig");
|
pub const plan9 = @import("os/plan9.zig");
|
||||||
|
|
@ -98,7 +99,6 @@ pub fn isGetFdPathSupportedOnTarget(os: std.Target.Os) bool {
|
||||||
///
|
///
|
||||||
/// Calling this function is usually a bug.
|
/// Calling this function is usually a bug.
|
||||||
pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 {
|
pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.RealPathError![]u8 {
|
||||||
const posix = std.posix;
|
|
||||||
if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
|
if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
|
||||||
@compileError("querying for canonical path of a handle is unsupported on this host");
|
@compileError("querying for canonical path of a handle is unsupported on this host");
|
||||||
}
|
}
|
||||||
|
|
@ -234,3 +234,37 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[MAX_PATH_BYTES]u8) std.posix.
|
||||||
else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above
|
else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// WASI-only. Same as `fstatat` but targeting WASI.
|
||||||
|
/// `pathname` should be encoded as valid UTF-8.
|
||||||
|
/// See also `fstatat`.
|
||||||
|
pub fn fstatat_wasi(dirfd: posix.fd_t, pathname: []const u8, flags: wasi.lookupflags_t) posix.FStatAtError!wasi.filestat_t {
|
||||||
|
var stat: wasi.filestat_t = undefined;
|
||||||
|
switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
|
||||||
|
.SUCCESS => return stat,
|
||||||
|
.INVAL => unreachable,
|
||||||
|
.BADF => unreachable, // Always a race condition.
|
||||||
|
.NOMEM => return error.SystemResources,
|
||||||
|
.ACCES => return error.AccessDenied,
|
||||||
|
.FAULT => unreachable,
|
||||||
|
.NAMETOOLONG => return error.NameTooLong,
|
||||||
|
.NOENT => return error.FileNotFound,
|
||||||
|
.NOTDIR => return error.FileNotFound,
|
||||||
|
.NOTCAPABLE => return error.AccessDenied,
|
||||||
|
.ILSEQ => return error.InvalidUtf8,
|
||||||
|
else => |err| return posix.unexpectedErrno(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fstat_wasi(fd: posix.fd_t) posix.FStatError!wasi.filestat_t {
|
||||||
|
var stat: wasi.filestat_t = undefined;
|
||||||
|
switch (wasi.fd_filestat_get(fd, &stat)) {
|
||||||
|
.SUCCESS => return stat,
|
||||||
|
.INVAL => unreachable,
|
||||||
|
.BADF => unreachable, // Always a race condition.
|
||||||
|
.NOMEM => return error.SystemResources,
|
||||||
|
.ACCES => return error.AccessDenied,
|
||||||
|
.NOTCAPABLE => return error.AccessDenied,
|
||||||
|
else => |err| return posix.unexpectedErrno(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ pub fn relocate(phdrs: []elf.Phdr) void {
|
||||||
break :base @intFromPtr(dynv) - phdr.p_vaddr;
|
break :base @intFromPtr(dynv) - phdr.p_vaddr;
|
||||||
}
|
}
|
||||||
// This is not supposed to happen for well-formed binaries.
|
// This is not supposed to happen for well-formed binaries.
|
||||||
std.os.abort();
|
@trap();
|
||||||
};
|
};
|
||||||
|
|
||||||
var rel_addr: usize = 0;
|
var rel_addr: usize = 0;
|
||||||
|
|
|
||||||
|
|
@ -1635,7 +1635,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE
|
||||||
errdefer close(fd);
|
errdefer close(fd);
|
||||||
|
|
||||||
if (flags.write) {
|
if (flags.write) {
|
||||||
const info = try fstat_wasi(fd);
|
const info = try std.os.fstat_wasi(fd);
|
||||||
if (info.filetype == .DIRECTORY)
|
if (info.filetype == .DIRECTORY)
|
||||||
return error.IsDir;
|
return error.IsDir;
|
||||||
}
|
}
|
||||||
|
|
@ -4282,7 +4282,7 @@ pub const FStatError = error{
|
||||||
/// Return information about a file descriptor.
|
/// Return information about a file descriptor.
|
||||||
pub fn fstat(fd: fd_t) FStatError!Stat {
|
pub fn fstat(fd: fd_t) FStatError!Stat {
|
||||||
if (native_os == .wasi and !builtin.link_libc) {
|
if (native_os == .wasi and !builtin.link_libc) {
|
||||||
return Stat.fromFilestat(try fstat_wasi(fd));
|
return Stat.fromFilestat(try std.os.fstat_wasi(fd));
|
||||||
}
|
}
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
@compileError("fstat is not yet implemented on Windows");
|
@compileError("fstat is not yet implemented on Windows");
|
||||||
|
|
@ -4300,19 +4300,6 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fstat_wasi(fd: fd_t) FStatError!wasi.filestat_t {
|
|
||||||
var stat: wasi.filestat_t = undefined;
|
|
||||||
switch (wasi.fd_filestat_get(fd, &stat)) {
|
|
||||||
.SUCCESS => return stat,
|
|
||||||
.INVAL => unreachable,
|
|
||||||
.BADF => unreachable, // Always a race condition.
|
|
||||||
.NOMEM => return error.SystemResources,
|
|
||||||
.ACCES => return error.AccessDenied,
|
|
||||||
.NOTCAPABLE => return error.AccessDenied,
|
|
||||||
else => |err| return unexpectedErrno(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const FStatAtError = FStatError || error{
|
pub const FStatAtError = FStatError || error{
|
||||||
NameTooLong,
|
NameTooLong,
|
||||||
FileNotFound,
|
FileNotFound,
|
||||||
|
|
@ -4325,10 +4312,10 @@ pub const FStatAtError = FStatError || error{
|
||||||
/// which is relative to `dirfd` handle.
|
/// which is relative to `dirfd` handle.
|
||||||
/// On WASI, `pathname` should be encoded as valid UTF-8.
|
/// On WASI, `pathname` should be encoded as valid UTF-8.
|
||||||
/// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding.
|
/// On other platforms, `pathname` is an opaque sequence of bytes with no particular encoding.
|
||||||
/// See also `fstatatZ` and `fstatat_wasi`.
|
/// See also `fstatatZ` and `std.os.fstatat_wasi`.
|
||||||
pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
|
pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat {
|
||||||
if (native_os == .wasi and !builtin.link_libc) {
|
if (native_os == .wasi and !builtin.link_libc) {
|
||||||
const filestat = try fstatat_wasi(dirfd, pathname, .{
|
const filestat = try std.os.fstatat_wasi(dirfd, pathname, .{
|
||||||
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
||||||
});
|
});
|
||||||
return Stat.fromFilestat(filestat);
|
return Stat.fromFilestat(filestat);
|
||||||
|
|
@ -4344,7 +4331,7 @@ pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!Stat
|
||||||
/// See also `fstatat`.
|
/// See also `fstatat`.
|
||||||
pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
|
pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
|
||||||
if (native_os == .wasi and !builtin.link_libc) {
|
if (native_os == .wasi and !builtin.link_libc) {
|
||||||
const filestat = try fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{
|
const filestat = try std.os.fstatat_wasi(dirfd, mem.sliceTo(pathname, 0), .{
|
||||||
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
||||||
});
|
});
|
||||||
return Stat.fromFilestat(filestat);
|
return Stat.fromFilestat(filestat);
|
||||||
|
|
@ -4372,27 +4359,6 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// WASI-only. Same as `fstatat` but targeting WASI.
|
|
||||||
/// `pathname` should be encoded as valid UTF-8.
|
|
||||||
/// See also `fstatat`.
|
|
||||||
fn fstatat_wasi(dirfd: fd_t, pathname: []const u8, flags: wasi.lookupflags_t) FStatAtError!wasi.filestat_t {
|
|
||||||
var stat: wasi.filestat_t = undefined;
|
|
||||||
switch (wasi.path_filestat_get(dirfd, flags, pathname.ptr, pathname.len, &stat)) {
|
|
||||||
.SUCCESS => return stat,
|
|
||||||
.INVAL => unreachable,
|
|
||||||
.BADF => unreachable, // Always a race condition.
|
|
||||||
.NOMEM => return error.SystemResources,
|
|
||||||
.ACCES => return error.AccessDenied,
|
|
||||||
.FAULT => unreachable,
|
|
||||||
.NAMETOOLONG => return error.NameTooLong,
|
|
||||||
.NOENT => return error.FileNotFound,
|
|
||||||
.NOTDIR => return error.FileNotFound,
|
|
||||||
.NOTCAPABLE => return error.AccessDenied,
|
|
||||||
.ILSEQ => return error.InvalidUtf8,
|
|
||||||
else => |err| return unexpectedErrno(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const KQueueError = error{
|
pub const KQueueError = error{
|
||||||
/// The per-process limit on the number of open file descriptors has been reached.
|
/// The per-process limit on the number of open file descriptors has been reached.
|
||||||
ProcessFdQuotaExceeded,
|
ProcessFdQuotaExceeded,
|
||||||
|
|
@ -4822,7 +4788,7 @@ pub fn faccessat(dirfd: fd_t, path: []const u8, mode: u32, flags: u32) AccessErr
|
||||||
const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path };
|
const resolved: RelativePathWasi = .{ .dir_fd = dirfd, .relative_path = path };
|
||||||
|
|
||||||
const st = blk: {
|
const st = blk: {
|
||||||
break :blk fstatat_wasi(dirfd, path, .{
|
break :blk std.os.fstatat_wasi(dirfd, path, .{
|
||||||
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
.SYMLINK_FOLLOW = (flags & AT.SYMLINK_NOFOLLOW) == 0,
|
||||||
});
|
});
|
||||||
} catch |err| switch (err) {
|
} catch |err| switch (err) {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ pub const Actions = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {
|
pub fn open(self: *Actions, fd: std.c.fd_t, path: []const u8, flags: u32, mode: std.c.mode_t) Error!void {
|
||||||
const posix_path = try std.os.toPosixPath(path);
|
const posix_path = try std.posix.toPosixPath(path);
|
||||||
return self.openZ(fd, &posix_path, flags, mode);
|
return self.openZ(fd, &posix_path, flags, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ pub const Actions = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chdir(self: *Actions, path: []const u8) Error!void {
|
pub fn chdir(self: *Actions, path: []const u8) Error!void {
|
||||||
const posix_path = try std.os.toPosixPath(path);
|
const posix_path = try std.posix.toPosixPath(path);
|
||||||
return self.chdirZ(&posix_path);
|
return self.chdirZ(&posix_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ pub fn spawn(
|
||||||
argv: [*:null]?[*:0]const u8,
|
argv: [*:null]?[*:0]const u8,
|
||||||
envp: [*:null]?[*:0]const u8,
|
envp: [*:null]?[*:0]const u8,
|
||||||
) Error!std.c.pid_t {
|
) Error!std.c.pid_t {
|
||||||
const posix_path = try std.os.toPosixPath(path);
|
const posix_path = try std.posix.toPosixPath(path);
|
||||||
return spawnZ(&posix_path, actions, attr, argv, envp);
|
return spawnZ(&posix_path, actions, attr, argv, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,12 +204,12 @@ pub fn spawnZ(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.os.WaitPidResult {
|
pub fn waitpid(pid: std.c.pid_t, flags: u32) Error!std.posix.WaitPidResult {
|
||||||
var status: c_int = undefined;
|
var status: c_int = undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
|
const rc = waitpid(pid, &status, @as(c_int, @intCast(flags)));
|
||||||
switch (errno(rc)) {
|
switch (errno(rc)) {
|
||||||
.SUCCESS => return std.os.WaitPidResult{
|
.SUCCESS => return std.posix.WaitPidResult{
|
||||||
.pid = @as(std.c.pid_t, @intCast(rc)),
|
.pid = @as(std.c.pid_t, @intCast(rc)),
|
||||||
.status = @as(u32, @bitCast(status)),
|
.status = @as(u32, @bitCast(status)),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -4136,10 +4136,10 @@ pub fn getDebugSymbols(self: *MachO) ?*DebugSymbols {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
|
pub fn ptraceAttach(self: *MachO, pid: std.posix.pid_t) !void {
|
||||||
if (!is_hot_update_compatible) return;
|
if (!is_hot_update_compatible) return;
|
||||||
|
|
||||||
const mach_task = try std.os.darwin.machTaskForPid(pid);
|
const mach_task = try std.c.machTaskForPid(pid);
|
||||||
log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });
|
log.debug("Mach task for pid {d}: {any}", .{ pid, mach_task });
|
||||||
self.hot_state.mach_task = mach_task;
|
self.hot_state.mach_task = mach_task;
|
||||||
|
|
||||||
|
|
@ -4149,7 +4149,7 @@ pub fn ptraceAttach(self: *MachO, pid: std.os.pid_t) !void {
|
||||||
// try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);
|
// try std.os.ptrace(std.os.darwin.PT.ATTACHEXC, pid, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ptraceDetach(self: *MachO, pid: std.os.pid_t) !void {
|
pub fn ptraceDetach(self: *MachO, pid: std.posix.pid_t) !void {
|
||||||
if (!is_hot_update_compatible) return;
|
if (!is_hot_update_compatible) return;
|
||||||
|
|
||||||
_ = pid;
|
_ = pid;
|
||||||
|
|
@ -4330,7 +4330,7 @@ const Section = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
const HotUpdateState = struct {
|
const HotUpdateState = struct {
|
||||||
mach_task: ?std.os.darwin.MachTask = null,
|
mach_task: ?std.c.MachTask = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DynamicRelocs = struct {
|
pub const DynamicRelocs = struct {
|
||||||
|
|
|
||||||
39
src/main.zig
39
src/main.zig
|
|
@ -12,6 +12,7 @@ const Color = std.zig.Color;
|
||||||
const warn = std.log.warn;
|
const warn = std.log.warn;
|
||||||
const ThreadPool = std.Thread.Pool;
|
const ThreadPool = std.Thread.Pool;
|
||||||
const cleanExit = std.process.cleanExit;
|
const cleanExit = std.process.cleanExit;
|
||||||
|
const native_os = builtin.os.tag;
|
||||||
|
|
||||||
const tracy = @import("tracy.zig");
|
const tracy = @import("tracy.zig");
|
||||||
const Compilation = @import("Compilation.zig");
|
const Compilation = @import("Compilation.zig");
|
||||||
|
|
@ -158,9 +159,9 @@ var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
crash_report.initialize();
|
crash_report.initialize();
|
||||||
|
|
||||||
const use_gpa = (build_options.force_gpa or !builtin.link_libc) and builtin.os.tag != .wasi;
|
const use_gpa = (build_options.force_gpa or !builtin.link_libc) and native_os != .wasi;
|
||||||
const gpa = gpa: {
|
const gpa = gpa: {
|
||||||
if (builtin.os.tag == .wasi) {
|
if (native_os == .wasi) {
|
||||||
break :gpa std.heap.wasm_allocator;
|
break :gpa std.heap.wasm_allocator;
|
||||||
}
|
}
|
||||||
if (use_gpa) {
|
if (use_gpa) {
|
||||||
|
|
@ -187,7 +188,7 @@ pub fn main() anyerror!void {
|
||||||
return mainArgs(gpa_tracy.allocator(), arena, args);
|
return mainArgs(gpa_tracy.allocator(), arena, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builtin.os.tag == .wasi) {
|
if (native_os == .wasi) {
|
||||||
wasi_preopens = try fs.wasi.preopensAlloc(arena);
|
wasi_preopens = try fs.wasi.preopensAlloc(arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -813,9 +814,9 @@ fn buildOutputType(
|
||||||
var no_builtin = false;
|
var no_builtin = false;
|
||||||
var listen: Listen = .none;
|
var listen: Listen = .none;
|
||||||
var debug_compile_errors = false;
|
var debug_compile_errors = false;
|
||||||
var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
|
var verbose_link = (native_os != .wasi or builtin.link_libc) and
|
||||||
EnvVar.ZIG_VERBOSE_LINK.isSet();
|
EnvVar.ZIG_VERBOSE_LINK.isSet();
|
||||||
var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
|
var verbose_cc = (native_os != .wasi or builtin.link_libc) and
|
||||||
EnvVar.ZIG_VERBOSE_CC.isSet();
|
EnvVar.ZIG_VERBOSE_CC.isSet();
|
||||||
var verbose_air = false;
|
var verbose_air = false;
|
||||||
var verbose_intern_pool = false;
|
var verbose_intern_pool = false;
|
||||||
|
|
@ -991,7 +992,7 @@ fn buildOutputType(
|
||||||
// if it exists, default the color setting to .off
|
// if it exists, default the color setting to .off
|
||||||
// explicit --color arguments will still override this setting.
|
// explicit --color arguments will still override this setting.
|
||||||
// Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
|
// Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
|
||||||
var color: Color = if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
|
var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
|
||||||
|
|
||||||
switch (arg_mode) {
|
switch (arg_mode) {
|
||||||
.build, .translate_c, .zig_test, .run => {
|
.build, .translate_c, .zig_test, .run => {
|
||||||
|
|
@ -2684,7 +2685,7 @@ fn buildOutputType(
|
||||||
fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
|
fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else if (builtin.os.tag == .wasi) {
|
} else if (native_os == .wasi) {
|
||||||
break :d getWasiPreopen("/lib");
|
break :d getWasiPreopen("/lib");
|
||||||
} else if (self_exe_path) |p| {
|
} else if (self_exe_path) |p| {
|
||||||
break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
|
break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
|
||||||
|
|
@ -2703,7 +2704,7 @@ fn buildOutputType(
|
||||||
.path = p,
|
.path = p,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (builtin.os.tag == .wasi) {
|
if (native_os == .wasi) {
|
||||||
break :l getWasiPreopen("/cache");
|
break :l getWasiPreopen("/cache");
|
||||||
}
|
}
|
||||||
const p = try introspect.resolveGlobalCacheDir(arena);
|
const p = try introspect.resolveGlobalCacheDir(arena);
|
||||||
|
|
@ -4368,7 +4369,7 @@ fn runOrTest(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const cmd = try std.mem.join(arena, " ", argv.items);
|
const cmd = try std.mem.join(arena, " ", argv.items);
|
||||||
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
|
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4747,9 +4748,9 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
||||||
var child_argv = std.ArrayList([]const u8).init(arena);
|
var child_argv = std.ArrayList([]const u8).init(arena);
|
||||||
var reference_trace: ?u32 = null;
|
var reference_trace: ?u32 = null;
|
||||||
var debug_compile_errors = false;
|
var debug_compile_errors = false;
|
||||||
var verbose_link = (builtin.os.tag != .wasi or builtin.link_libc) and
|
var verbose_link = (native_os != .wasi or builtin.link_libc) and
|
||||||
EnvVar.ZIG_VERBOSE_LINK.isSet();
|
EnvVar.ZIG_VERBOSE_LINK.isSet();
|
||||||
var verbose_cc = (builtin.os.tag != .wasi or builtin.link_libc) and
|
var verbose_cc = (native_os != .wasi or builtin.link_libc) and
|
||||||
EnvVar.ZIG_VERBOSE_CC.isSet();
|
EnvVar.ZIG_VERBOSE_CC.isSet();
|
||||||
var verbose_air = false;
|
var verbose_air = false;
|
||||||
var verbose_intern_pool = false;
|
var verbose_intern_pool = false;
|
||||||
|
|
@ -4894,7 +4895,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const work_around_btrfs_bug = builtin.os.tag == .linux and
|
const work_around_btrfs_bug = native_os == .linux and
|
||||||
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
|
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
|
||||||
const color: Color = .auto;
|
const color: Color = .auto;
|
||||||
|
|
||||||
|
|
@ -5311,7 +5312,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const cmd = try std.mem.join(arena, " ", child_argv.items);
|
const cmd = try std.mem.join(arena, " ", child_argv.items);
|
||||||
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(builtin.os.tag), cmd });
|
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{ @tagName(native_os), cmd });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5543,7 +5544,7 @@ fn jitCmd(
|
||||||
if (!process.can_spawn) {
|
if (!process.can_spawn) {
|
||||||
const cmd = try std.mem.join(arena, " ", child_argv.items);
|
const cmd = try std.mem.join(arena, " ", child_argv.items);
|
||||||
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{
|
fatal("the following command cannot be executed ({s} does not support spawning a child process):\n{s}", .{
|
||||||
@tagName(builtin.os.tag), cmd,
|
@tagName(native_os), cmd,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5655,7 +5656,7 @@ pub fn lldMain(
|
||||||
var count: usize = 0;
|
var count: usize = 0;
|
||||||
};
|
};
|
||||||
if (CallCounter.count == 1) { // Issue the warning on the first repeat call
|
if (CallCounter.count == 1) { // Issue the warning on the first repeat call
|
||||||
warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(builtin.os.tag)});
|
warn("invoking LLD for the second time within the same process because the host OS ({s}) does not support spawning child processes. This sometimes activates LLD bugs", .{@tagName(native_os)});
|
||||||
}
|
}
|
||||||
CallCounter.count += 1;
|
CallCounter.count += 1;
|
||||||
|
|
||||||
|
|
@ -5985,7 +5986,7 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
|
||||||
/// garbage collector to run concurrently to zig processes, and to allow multiple
|
/// garbage collector to run concurrently to zig processes, and to allow multiple
|
||||||
/// zig processes to run concurrently with each other, without clobbering each other.
|
/// zig processes to run concurrently with each other, without clobbering each other.
|
||||||
fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
|
fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
|
||||||
const have_rlimit = switch (builtin.os.tag) {
|
const have_rlimit = switch (native_os) {
|
||||||
.windows, .wasi => false,
|
.windows, .wasi => false,
|
||||||
else => true,
|
else => true,
|
||||||
};
|
};
|
||||||
|
|
@ -5993,13 +5994,13 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
|
||||||
const posix = std.posix;
|
const posix = std.posix;
|
||||||
|
|
||||||
var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
|
var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
|
||||||
if (comptime builtin.target.isDarwin()) {
|
if (native_os.isDarwin()) {
|
||||||
// On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
|
// On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`.
|
||||||
// According to the man pages for setrlimit():
|
// According to the man pages for setrlimit():
|
||||||
// setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
|
// setrlimit() now returns with errno set to EINVAL in places that historically succeeded.
|
||||||
// It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
|
// It no longer accepts "rlim_cur = RLIM.INFINITY" for RLIM.NOFILE.
|
||||||
// Use "rlim_cur = min(OPEN_MAX, rlim_max)".
|
// Use "rlim_cur = min(OPEN_MAX, rlim_max)".
|
||||||
lim.max = @min(std.os.darwin.OPEN_MAX, lim.max);
|
lim.max = @min(std.c.OPEN_MAX, lim.max);
|
||||||
}
|
}
|
||||||
if (lim.cur == lim.max) return;
|
if (lim.cur == lim.max) return;
|
||||||
|
|
||||||
|
|
@ -6770,7 +6771,7 @@ fn cmdFetch(
|
||||||
args: []const []const u8,
|
args: []const []const u8,
|
||||||
) !void {
|
) !void {
|
||||||
const color: Color = .auto;
|
const color: Color = .auto;
|
||||||
const work_around_btrfs_bug = builtin.os.tag == .linux and
|
const work_around_btrfs_bug = native_os == .linux and
|
||||||
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
|
EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
|
||||||
var opt_path_or_url: ?[]const u8 = null;
|
var opt_path_or_url: ?[]const u8 = null;
|
||||||
var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
|
var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn main() void {
|
||||||
fn print(a: u32, b: u32) void {
|
fn print(a: u32, b: u32) void {
|
||||||
const str = "123456789";
|
const str = "123456789";
|
||||||
const len = a + b;
|
const len = a + b;
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn main() void {
|
||||||
fn print(a: u32, b: u32) void {
|
fn print(a: u32, b: u32) void {
|
||||||
const str = "123456789";
|
const str = "123456789";
|
||||||
const len = a - b;
|
const len = a - b;
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn main() void {
|
||||||
fn print(a: u32, b: u32) void {
|
fn print(a: u32, b: u32) void {
|
||||||
const str = "123456789";
|
const str = "123456789";
|
||||||
const len = a & b;
|
const len = a & b;
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn main() void {
|
||||||
fn print(a: u32, b: u32) void {
|
fn print(a: u32, b: u32) void {
|
||||||
const str = "123456789";
|
const str = "123456789";
|
||||||
const len = a | b;
|
const len = a | b;
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn main() void {
|
||||||
fn print(a: u32, b: u32) void {
|
fn print(a: u32, b: u32) void {
|
||||||
const str = "123456789";
|
const str = "123456789";
|
||||||
const len = a ^ b;
|
const len = a ^ b;
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ pub fn main() void {
|
||||||
fn foo() anyerror!void {}
|
fn foo() anyerror!void {}
|
||||||
|
|
||||||
fn print() void {
|
fn print() void {
|
||||||
_ = std.os.write(1, "Hello, World!\n") catch {};
|
_ = std.posix.write(1, "Hello, World!\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ fn foo() anyerror!void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print() void {
|
fn print() void {
|
||||||
_ = std.os.write(1, "Hello, World!\n") catch {};
|
_ = std.posix.write(1, "Hello, World!\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ pub fn main() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stopSayingThat() void {
|
fn stopSayingThat() void {
|
||||||
_ = std.os.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};
|
_ = std.posix.write(1, "Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn moveEveryZig() void {
|
fn moveEveryZig() void {
|
||||||
_ = std.os.write(1, "All your codebase are belong to us\n") catch {};
|
_ = std.posix.write(1, "All your codebase are belong to us\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ fn id(x: u32) u32 {
|
||||||
|
|
||||||
fn print(len: u32) void {
|
fn print(len: u32) void {
|
||||||
const str = "Hello, World!\n";
|
const str = "Hello, World!\n";
|
||||||
_ = std.os.write(1, str[0..len]) catch {};
|
_ = std.posix.write(1, str[0..len]) catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ fn printNumberHex(x: u32) void {
|
||||||
var i: u5 = 28;
|
var i: u5 = 28;
|
||||||
while (true) : (i -= 4) {
|
while (true) : (i -= 4) {
|
||||||
const digit = (x >> i) & 0xf;
|
const digit = (x >> i) & 0xf;
|
||||||
_ = std.os.write(1, &.{digit_chars[digit]}) catch {};
|
_ = std.posix.write(1, &.{digit_chars[digit]}) catch {};
|
||||||
if (i == 0) break;
|
if (i == 0) break;
|
||||||
}
|
}
|
||||||
_ = std.os.write(1, "\n") catch {};
|
_ = std.posix.write(1, "\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// run
|
// run
|
||||||
|
|
|
||||||
|
|
@ -11,21 +11,21 @@ fn foo() void {
|
||||||
}
|
}
|
||||||
var f = async bar(@frame());
|
var f = async bar(@frame());
|
||||||
_ = &f;
|
_ = &f;
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar(frame: anyframe) void {
|
fn bar(frame: anyframe) void {
|
||||||
suspend {
|
suspend {
|
||||||
resume frame;
|
resume frame;
|
||||||
}
|
}
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var global_frame: anyframe = undefined;
|
var global_frame: anyframe = undefined;
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
_ = async foo();
|
_ = async foo();
|
||||||
resume global_frame;
|
resume global_frame;
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
// run
|
// run
|
||||||
// backend=stage1
|
// backend=stage1
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
|
||||||
fn foo() void {
|
fn foo() void {
|
||||||
var f = async bar(@frame());
|
var f = async bar(@frame());
|
||||||
_ = &f;
|
_ = &f;
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar(frame: anyframe) void {
|
fn bar(frame: anyframe) void {
|
||||||
suspend {
|
suspend {
|
||||||
resume frame;
|
resume frame;
|
||||||
}
|
}
|
||||||
std.os.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ fn checkStat() !void {
|
||||||
var stat = std.mem.zeroes(std.c.Stat);
|
var stat = std.mem.zeroes(std.c.Stat);
|
||||||
var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0);
|
var result = std.c.fstatat(cwdFd, "a_file_that_definitely_does_not_exist", &stat, 0);
|
||||||
assert(result == -1);
|
assert(result == -1);
|
||||||
assert(std.c.getErrno(result) == .NOENT);
|
assert(std.posix.errno(result) == .NOENT);
|
||||||
|
|
||||||
result = std.c.stat("a_file_that_definitely_does_not_exist", &stat);
|
result = std.c.stat("a_file_that_definitely_does_not_exist", &stat);
|
||||||
assert(result == -1);
|
assert(result == -1);
|
||||||
assert(std.c.getErrno(result) == .NOENT);
|
assert(std.posix.errno(result) == .NOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PR #17607 - reallocarray not visible in headers
|
// PR #17607 - reallocarray not visible in headers
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
|
|
||||||
pub usingnamespace if (build_options.keep_sigpipe) struct {
|
pub const std_options = .{
|
||||||
pub const std_options = .{
|
.keep_sigpipe = build_options.keep_sigpipe,
|
||||||
.keep_sigpipe = true,
|
};
|
||||||
};
|
|
||||||
} else struct {};
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const pipe = try std.os.pipe();
|
const pipe = try std.posix.pipe();
|
||||||
std.os.close(pipe[0]);
|
std.posix.close(pipe[0]);
|
||||||
_ = std.os.write(pipe[1], "a") catch |err| switch (err) {
|
_ = std.posix.write(pipe[1], "a") catch |err| switch (err) {
|
||||||
error.BrokenPipe => {
|
error.BrokenPipe => {
|
||||||
try std.io.getStdOut().writer().writeAll("BrokenPipe\n");
|
try std.io.getStdOut().writer().writeAll("BrokenPipe\n");
|
||||||
std.os.exit(123);
|
std.posix.exit(123);
|
||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const os = std.os;
|
const posix = std.posix;
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) !void {
|
pub fn build(b: *std.build.Builder) !void {
|
||||||
const test_step = b.step("test", "Test it");
|
const test_step = b.step("test", "Test it");
|
||||||
|
|
@ -16,12 +16,12 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
// This test runs "breakpipe" as a child process and that process
|
// This test runs "breakpipe" as a child process and that process
|
||||||
// depends on inheriting a SIGPIPE disposition of "default".
|
// depends on inheriting a SIGPIPE disposition of "default".
|
||||||
{
|
{
|
||||||
const act = os.Sigaction{
|
const act = posix.Sigaction{
|
||||||
.handler = .{ .handler = os.SIG.DFL },
|
.handler = .{ .handler = posix.SIG.DFL },
|
||||||
.mask = os.empty_sigset,
|
.mask = posix.empty_sigset,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
try os.sigaction(os.SIG.PIPE, &act, null);
|
try posix.sigaction(posix.SIG.PIPE, &act, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ([_]bool{ false, true }) |keep_sigpipe| {
|
for ([_]bool{ false, true }) |keep_sigpipe| {
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {
|
||||||
exe.addOptions("build_options", options);
|
exe.addOptions("build_options", options);
|
||||||
const run = b.addRunArtifact(exe);
|
const run = b.addRunArtifact(exe);
|
||||||
if (keep_sigpipe) {
|
if (keep_sigpipe) {
|
||||||
run.addCheck(.{ .expect_term = .{ .Signal = std.os.SIG.PIPE } });
|
run.addCheck(.{ .expect_term = .{ .Signal = std.posix.SIG.PIPE } });
|
||||||
} else {
|
} else {
|
||||||
run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });
|
run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });
|
||||||
run.addCheck(.{ .expect_term = .{ .Exited = 123 } });
|
run.addCheck(.{ .expect_term = .{ .Exited = 123 } });
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,13 @@ pub fn main() anyerror!void {
|
||||||
defer allocator.free(tmp_relative_path);
|
defer allocator.free(tmp_relative_path);
|
||||||
|
|
||||||
// Clear PATH
|
// Clear PATH
|
||||||
std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
|
std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
|
||||||
utf16Literal("PATH"),
|
utf16Literal("PATH"),
|
||||||
null,
|
null,
|
||||||
) == windows.TRUE);
|
) == windows.TRUE);
|
||||||
|
|
||||||
// Set PATHEXT to something predictable
|
// Set PATHEXT to something predictable
|
||||||
std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
|
std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
|
||||||
utf16Literal("PATHEXT"),
|
utf16Literal("PATHEXT"),
|
||||||
utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),
|
utf16Literal(".COM;.EXE;.BAT;.CMD;.JS"),
|
||||||
) == windows.TRUE);
|
) == windows.TRUE);
|
||||||
|
|
@ -39,7 +39,7 @@ pub fn main() anyerror!void {
|
||||||
// No PATH, so it should fail to find anything not in the cwd
|
// No PATH, so it should fail to find anything not in the cwd
|
||||||
try testExecError(error.FileNotFound, allocator, "something_missing");
|
try testExecError(error.FileNotFound, allocator, "something_missing");
|
||||||
|
|
||||||
std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
|
std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
|
||||||
utf16Literal("PATH"),
|
utf16Literal("PATH"),
|
||||||
tmp_absolute_path_w,
|
tmp_absolute_path_w,
|
||||||
) == windows.TRUE);
|
) == windows.TRUE);
|
||||||
|
|
@ -120,7 +120,7 @@ pub fn main() anyerror!void {
|
||||||
const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
|
const something_subdir_abs_path = try std.mem.concatWithSentinel(allocator, u16, &.{ tmp_absolute_path_w, utf16Literal("\\something") }, 0);
|
||||||
defer allocator.free(something_subdir_abs_path);
|
defer allocator.free(something_subdir_abs_path);
|
||||||
|
|
||||||
std.debug.assert(std.os.windows.kernel32.SetEnvironmentVariableW(
|
std.debug.assert(windows.kernel32.SetEnvironmentVariableW(
|
||||||
utf16Literal("PATH"),
|
utf16Literal("PATH"),
|
||||||
something_subdir_abs_path,
|
something_subdir_abs_path,
|
||||||
) == windows.TRUE);
|
) == windows.TRUE);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue