authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-08 18:27:39+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-08 18:27:39+02:00
log9bbac4288697f056f0cdb0c6ac597e9b1b18ea12
tree68a2e77e2fccf07774d8cc0fd51150fdd5ae1d2b
parent2d33cc2e42d40ce0ee798d4d56c2d7da93ead44a
parentc8631ec523bb9ae9ff04f00401cb7e0fe0ae3bf4
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23478 from alexrp/bsd-versions

`std.Target`: Bump some minimum OS versions for BSDs

4 files changed, 16 insertions(+), 58 deletions(-)

lib/std/Target.zig+4-4
......@@ -500,25 +500,25 @@ pub const Os = struct {
500500
501501 .dragonfly => .{
502502 .semver = .{
503 .min = .{ .major = 5, .minor = 8, .patch = 0 },
503 .min = .{ .major = 6, .minor = 0, .patch = 0 },
504504 .max = .{ .major = 6, .minor = 4, .patch = 0 },
505505 },
506506 },
507507 .freebsd => .{
508508 .semver = .{
509 .min = .{ .major = 12, .minor = 0, .patch = 0 },
509 .min = .{ .major = 13, .minor = 4, .patch = 0 },
510510 .max = .{ .major = 14, .minor = 2, .patch = 0 },
511511 },
512512 },
513513 .netbsd => .{
514514 .semver = .{
515 .min = .{ .major = 8, .minor = 0, .patch = 0 },
515 .min = .{ .major = 9, .minor = 4, .patch = 0 },
516516 .max = .{ .major = 10, .minor = 1, .patch = 0 },
517517 },
518518 },
519519 .openbsd => .{
520520 .semver = .{
521 .min = .{ .major = 7, .minor = 3, .patch = 0 },
521 .min = .{ .major = 7, .minor = 5, .patch = 0 },
522522 .max = .{ .major = 7, .minor = 6, .patch = 0 },
523523 },
524524 },
lib/std/os.zig+11-50
......@@ -158,57 +158,18 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
158158 return target;
159159 },
160160 .freebsd => {
161 if (builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) {
162 var kfile: std.c.kinfo_file = undefined;
163 kfile.structsize = std.c.KINFO_FILE_SIZE;
164 switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) {
165 .SUCCESS => {},
166 .BADF => return error.FileNotFound,
167 else => |err| return posix.unexpectedErrno(err),
168 }
169 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes;
170 if (len == 0) return error.NameTooLong;
171 const result = out_buffer[0..len];
172 @memcpy(result, kfile.path[0..len]);
173 return result;
174 } else {
175 // This fallback implementation reimplements libutil's `kinfo_getfile()`.
176 // The motivation is to avoid linking -lutil when building zig or general
177 // user executables.
178 var mib = [4]c_int{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_FILEDESC, std.c.getpid() };
179 var len: usize = undefined;
180 posix.sysctl(&mib, null, &len, null, 0) catch |err| switch (err) {
181 error.PermissionDenied => unreachable,
182 error.SystemResources => return error.SystemResources,
183 error.NameTooLong => unreachable,
184 error.UnknownName => unreachable,
185 else => return error.Unexpected,
186 };
187 len = len * 4 / 3;
188 const buf = std.heap.c_allocator.alloc(u8, len) catch return error.SystemResources;
189 defer std.heap.c_allocator.free(buf);
190 len = buf.len;
191 posix.sysctl(&mib, &buf[0], &len, null, 0) catch |err| switch (err) {
192 error.PermissionDenied => unreachable,
193 error.SystemResources => return error.SystemResources,
194 error.NameTooLong => unreachable,
195 error.UnknownName => unreachable,
196 else => return error.Unexpected,
197 };
198 var i: usize = 0;
199 while (i < len) {
200 const kf: *align(1) std.c.kinfo_file = @ptrCast(&buf[i]);
201 if (kf.fd == fd) {
202 len = mem.indexOfScalar(u8, &kf.path, 0) orelse max_path_bytes;
203 if (len == 0) return error.NameTooLong;
204 const result = out_buffer[0..len];
205 @memcpy(result, kf.path[0..len]);
206 return result;
207 }
208 i += @intCast(kf.structsize);
209 }
210 return error.FileNotFound;
161 var kfile: std.c.kinfo_file = undefined;
162 kfile.structsize = std.c.KINFO_FILE_SIZE;
163 switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) {
164 .SUCCESS => {},
165 .BADF => return error.FileNotFound,
166 else => |err| return posix.unexpectedErrno(err),
211167 }
168 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes;
169 if (len == 0) return error.NameTooLong;
170 const result = out_buffer[0..len];
171 @memcpy(result, kfile.path[0..len]);
172 return result;
212173 },
213174 .dragonfly => {
214175 @memset(out_buffer[0..max_path_bytes], 0);
lib/std/posix.zig+1-1
......@@ -6590,7 +6590,7 @@ pub const CopyFileRangeError = error{
65906590///
65916591/// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`.
65926592pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
6593 if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or
6593 if (builtin.os.tag == .freebsd or
65946594 (comptime builtin.os.tag == .linux and std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 })))
65956595 {
65966596 var off_in_copy: i64 = @bitCast(off_in);
test/llvm_targets.zig-3
......@@ -71,8 +71,6 @@ const targets = [_]std.Target.Query{
7171 // .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabi },
7272 // .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabihf },
7373
74 .{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabi },
75 .{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabihf },
7674 .{ .cpu_arch = .armeb, .os_tag = .freestanding, .abi = .eabi },
7775 .{ .cpu_arch = .armeb, .os_tag = .freestanding, .abi = .eabihf },
7876 .{ .cpu_arch = .armeb, .os_tag = .linux, .abi = .eabi },
......@@ -257,7 +255,6 @@ const targets = [_]std.Target.Query{
257255 // .{ .cpu_arch = .sparc, .os_tag = .rtems, .abi = .none },
258256 // .{ .cpu_arch = .sparc, .os_tag = .solaris, .abi = .none },
259257
260 .{ .cpu_arch = .sparc64, .os_tag = .freebsd, .abi = .none },
261258 .{ .cpu_arch = .sparc64, .os_tag = .freestanding, .abi = .none },
262259 .{ .cpu_arch = .sparc64, .os_tag = .haiku, .abi = .none },
263260 .{ .cpu_arch = .sparc64, .os_tag = .illumos, .abi = .none },