zig/test/standalone
Stephen Gregoratto 6216922a9d Linux: Nuke Stat bits in favour of statx
Maintaining the POSIX `stat` bits for Zig is a pain. The order and
bit-length of members differ between all architectures, and int types
can be signed or unsigned. The libcs deal with this by introducing the
own version of `struct stat` and copying the kernel structure members to
it. In the case of glibc, they did it twice thanks to the largefile
transition!

In practice, the project needs to maintain three versions of `struct
stat`:
- What the kernel defines.
- What musl wants for `struct stat`.
- What glibc wants for `struct stat64`. Make sure to use `fstatat64`!

This isn't as simple as running `zig translate-c`. In #21440 I had to:
- Compile toolchains for each arch+glibc/musl combo.
- Create a test `fstat` program with/without `FILE_OFFSET_BITS=64`.
- Dump the value for `struct stat`.
- Stare at `std.os.linux`/`std.c` and cry.
- Add some missing padding.

The fact that so many target checks in the `linux` and `posix` tests
exist is most likely due to writing to padding bits and failing later.

The solution to this madness is `statx(2)`:
- It takes a single structure that is the same for all arches AND libcs.
- It uses a custom timestamp format, but it is 64-bit ready.
- It gives the same info as `fstatat(2)` and more!
- Unlike `fstatat(2)`, you can request a subset of the info required
  based on passing a mask.

It's so good that modern Linux arches (e.g. riscv) don't even implement
`stat`, with the libcs using a generic `struct stat` and copying from
`struct statx`.

Therefore, this commit rips out all the `stat` bits from `std.os.linux`
and `std.c`. `std.posix.Stat` is now `void`, and calling
`std.posix.*stat` is an compile-time error. A wrapper around `statx` has
been added to `std.os.linux`, and callers have been upgraded to use it.
Tests have also been updated to use `statx` where possible.

While I was here, I converted the mask and file attributes to be packed
struct bitfields. A nice side effect is checking that you actually
recieved the members you asked for via `Statx.mask`, which I have used
by adding `assert`s at specific callsites.
2025-12-14 01:41:47 +01:00
..
c_compiler test: remove complex arithmetic testing from c_compiler standalone test 2025-11-19 01:42:45 +01:00
c_embed_path Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
child_process std.Io.Threaded: add ioBasic which disables networking 2025-10-29 06:20:51 -07:00
cmakedefine update tools and other miscellaneous things to new APIs 2025-08-30 00:48:50 -07:00
coff_dwarf test: disable coff_dwarf on FreeBSD 2025-11-23 07:10:35 +01:00
compile_asm test: rename issue_8550 standalone test to compile_asm 2025-09-16 14:51:29 +02:00
compiler_rt_panic test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
config_header std: Remove a handful of things deprecated during the 0.15 release cycle 2025-11-27 20:17:04 +00:00
dep_diamond test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_duplicate_module std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
dep_lazypath test: remove -Dskip-translate-c from test-standalone 2025-09-26 01:33:26 +02:00
dep_mutually_recursive test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_recursive tests: remove incorrect import 2025-05-18 17:10:04 +01:00
dep_shared_builtin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dep_triangle test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
depend_on_main_mod test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
dependency_options build: fix error in standalone test when using --release 2025-07-28 08:10:23 +01:00
dependencyFromBuildZig Update test build.zig.zon files to conform to the new manifest rules 2025-07-20 18:28:36 +02:00
dirname tests: do not require absolute paths from the build system 2025-06-13 15:46:43 +01:00
embed_generated_file test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_asm_and_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_asm_no_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
emit_llvm_no_bin test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
empty_env std.Build: don't force all children to inherit color option 2025-11-14 21:50:24 +01:00
empty_global_error_set x86_64: fix @errorName data 2025-01-05 17:15:56 -05:00
entry_point update tools and other miscellaneous things to new APIs 2025-08-30 00:48:50 -07:00
env_vars Add standalone test for environment variables 2025-03-22 15:44:27 -07:00
extern Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
glibc_compat Linux: Nuke Stat bits in favour of statx 2025-12-14 01:41:47 +01:00
global_linkage std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
install_headers std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
install_raw_hex Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
ios replace @panic with b.addFail in standalone test build.zig 2025-11-17 17:02:53 +01:00
issue_339 test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
issue_794 test: remove -Dskip-translate-c from test-standalone 2025-09-26 01:33:26 +02:00
issue_5825 Move std.Target.SubSystem to std.zig.Subsystem 2025-11-05 01:31:26 +01:00
issue_11595 test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
issue_12706 Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
libcxx test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
libfuzzer update some tests and tools for new Io APIs 2025-10-29 06:20:50 -07:00
load_dynamic_library Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
mix_c_files tests: extern threadlocals require LLVM 2025-06-06 23:42:15 -07:00
mix_o_files test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
pkg_import test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
posix Linux: Nuke Stat bits in favour of statx 2025-12-14 01:41:47 +01:00
run_cwd std.Build.Step.Run: prefix relative path arguments with './' 2025-06-18 22:45:05 +01:00
run_output_caching tests: do not require absolute paths from the build system 2025-06-13 15:46:43 +01:00
run_output_paths update more to avoid GenericWriter 2025-08-28 18:30:57 -07:00
self_exe_symlink tests: do not require absolute paths from the build system 2025-06-13 15:46:43 +01:00
shared_library std.Build: add addLibrary function (#22554) 2025-01-22 02:29:21 +00:00
simple all: replace all @Type usages 2025-11-22 22:42:38 +00:00
static_c_lib test: remove unnecessary @cImport usage in some standalone tests 2025-09-18 12:42:24 +02:00
strip_empty_loop test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
strip_struct_init test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
test_obj_link_run std: Remove a handful of things deprecated during the 0.15 release cycle 2025-11-27 20:17:04 +00:00
test_runner_module_imports std.Build: extend test_runner option to specify whether runner uses std.zig.Server 2025-01-20 00:14:58 +00:00
test_runner_path std.Build: extend test_runner option to specify whether runner uses std.zig.Server 2025-01-20 00:14:58 +00:00
tsan test: enable tsan standalone test for x86_64-freebsd and aarch64-freebsd 2025-10-26 11:12:46 +01:00
windows_argv std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
windows_bat_args windows_bat_args: fix path handling 2025-09-30 13:44:54 +01:00
windows_entry_points Let CRT take care of the entry point for wWinMain if libc is linked 2025-11-08 17:11:12 -08:00
windows_paths Teach fs.path about the wonderful world of Windows paths 2025-11-21 00:03:44 -08:00
windows_resources test-standalone: migrate from deprecated std.Build APIs 2024-12-18 01:49:13 +05:00
windows_spawn update standalone tests for ws2_32 dependency 2025-10-29 06:20:51 -07:00
zerolength_check test: add tests for @memmove 2025-04-26 13:34:17 +10:00
build.zig test: remove -Dskip-translate-c from test-standalone 2025-09-26 01:33:26 +02:00
build.zig.zon Teach fs.path about the wonderful world of Windows paths 2025-11-21 00:03:44 -08:00