Commit graph

10791 commits

Author SHA1 Message Date
mlugg
faafeb51af
std.Build.Step.Compile: change root_module field type to *Module
This commit changes the `root_module` field of `std.Build.Step.Compile`
to be a `*Module` rather than a `Module`. This is a breaking change, but
an incredibly minor one (the full potential extent of the breakage can
be seen in the modified standalone test).

This change will be necessary for an upcoming improvement, so it was
convenient to make it here.
2024-12-18 01:47:50 +05:00
Eric Joldasov
3d393dba6f
std.Build: remove deprecated APIs
These APIs were all deprecated prior to the release of 0.13.0, so can be
safety removed in the current release cycle.

`std.Build`:
* `host` -> `graph.host`

`std.Build.Step.Compile`:
* `setLinkerScriptPath` -> `setLinkerScript`
* `defineCMacro` -> `root_module.addCMacro`
* `linkFrameworkNeeded`-> `root_module.linkFramework`
* `linkFrameworkWeak`-> `root_module.linkFramework`

`std.Build.Step.ObjCopy`:
* `getOutputSource` -> `getOutput`

`std.Build.Step.Options`:
* `addOptionArtifact` -> `addOptionPath`
* `getSource` -> `getOutput`

`std.Build.Step.Run`:
* `extra_file_dependencies` -> `addFileInput`
* `addDirectorySourceArg` -> `addDirectoryArg`
* `addPrefixedDirectorySourceArg` -> `addPrefixedDirectoryArg`
2024-12-18 01:47:50 +05:00
Andrew Kelley
debba652a3
Merge pull request #22252 from jacobly0/dwarf-deduped-structs
Dwarf: preserve deduped struct navs
2024-12-17 01:26:09 -05:00
Alex Rønne Petersen
0ef01c5521
std.Target: Incorporate the Abi tag in VersionRange.default().
This is necessary to pick out the correct minimum OS version from the
std.zig.target.available_libcs list.
2024-12-17 05:04:16 +01:00
Alex Rønne Petersen
424f9ba532
std.zig.target: Check OS version for all targets in canBuildLibC().
The old logic only checked it for macOS, but we also need it to be checked for
Linux now.
2024-12-17 05:04:16 +01:00
Alex Rønne Petersen
df235f5163
std.zig.target: Attach a minimum Linux version to each glibc/musl libc entry.
(With the exception of x86 since that was available from the beginning.)

These were determined by analyzing the full, reconstructed Git history of the
Linux kernel here: https://landley.net/kdocs/fullhist
2024-12-17 05:04:14 +01:00
David Rubin
0c457fa7eb add m4 {pro,max} detection 2024-12-16 20:56:29 -05:00
Matthew Lugg
7e8be21363
Merge pull request #22250 from mlugg/zon-ast
compiler: introduce ZonGen and make `ast-check` run it for ZON inputs
2024-12-16 23:01:24 +00:00
Jacob Young
8c0628d0e2 Dwarf: include comptime-only values in debug info 2024-12-16 17:25:52 -05:00
mlugg
c7485d73ac
compiler: introduce ZonGen and make ast-check run it for ZON inputs
Currently, `zig ast-check` fails on ZON files, because it tries to
interpret the file as Zig source code. This commit introduces a new
verification pass, `std.zig.ZonGen`, which applies to an AST in ZON
mode.

Like `AstGen`, this pass also converts the AST into a more helpful
format. Rather than a sequence of instructions like `Zir`, the output
format of `ZonGen` is a new datastructure called `Zoir`. This type is
essentially a simpler form of AST, containing only the information
required for consumers of ZON. It is also far more compact than
`std.zig.Ast`, with the size generally being comparable to the size of
the well-formatted source file.

The emitted `Zoir` is currently not used aside from the `-t` option to
`ast-check` which causes it to be dumped to stdout. However, in future,
it can be used for comptime `@import` of ZON files, as well as for
simpler handling of files like `build.zig.zon`, and even by other parts
of the Zig Standard Library.

Resolves: #22078
2024-12-16 17:02:35 +00:00
mlugg
512cb22d83
std.c.darwin.posix_spawn: fix signature
And change corresponding signature in `DarwinPosixSpawn`.
2024-12-16 14:53:54 +00:00
Andrew Kelley
d12c0bf909
Merge pull request #22242 from Rexicon226/moar-branch-hint
utilize `@branchHint` more
2024-12-16 07:27:20 -05:00
Matthew Lugg
3a0a9aa9b8
Merge pull request #22245 from mlugg/zir-no-doc-comments
compiler: remove doc comments from Zir
2024-12-16 02:48:28 +00:00
David Rubin
0fe17ea12a
hashmap: remove inline from getIndex now that we have @branchHint 2024-12-15 17:20:08 -08:00
mlugg
847c34ac66
compiler: remove doc comments from Zir
This code was left over from the legacy Autodoc implementation. No
component of the compiler pipeline actually requires doc comments, so it
is a waste of time and space to store them in ZIR.
2024-12-15 16:32:55 +00:00
David Rubin
b58916bb7c
correct the hint in XxHash3 2024-12-15 03:40:20 -08:00
Alex Rønne Petersen
6066e7bfd1
std.zig.target: Remove wasm32-freestanding-musl.
This is, at least today, a very broken target: It doesn't actually build either
musl or wasi-libc even if you use -lc. It does give you musl headers, but that's
it. Those headers are not terribly useful, however, without any implementation
code. You can sort of call some math functions because they just so happen to
have implementations in compiler-rt. But that's only true for a small subset,
and I don't think users should be relying on the ABI surface of a library that
is an implementation detail of the compiler.

Clearly, a freestanding-capable libc of sorts is a useful thing as evidenced by
newlib, picolibc, etc existing. However, calling it "musl" is misleading when it
isn't actually musl-compatible, nor can it ever be because the musl API surface
is inextricably tied to the Linux kernel. In the discussion on #20690, there was
agreement that once we split up the API and ABI components in the target string,
the API component should be about compatibility, not whether you literally get a
particular implementation of it. Also, we decided that Linux musl and wasi-libc
musl shouldn't use the same API tag precisely because they're not actually
compatible.

(And besides, how would any syscall even be implemented in freestanding? Who or
what would we be calling?)

So I think we should remove this triple for now. If we decide to reintroduce
something like this, especially once #2879 gets going, we should come up with a
bespoke name for it rather than using "musl".
2024-12-15 12:25:12 +01:00
Alex Rønne Petersen
7d4e8be0de
std.Target: Remove special case for wasm in Abi.default().
It'll still pick .musl for os.tag == .wasi.
2024-12-15 11:57:19 +01:00
Alex Rønne Petersen
d5c2f527b4
Merge pull request #22219 from alexrp/arm-big-endian
Add `armeb-linux-*`, `thumbeb-linux-*`, and `aarch64_be-linux-*` to CI
2024-12-15 01:41:46 +01:00
Techatrix
cc82620b2a fix std.zig.Ast.rootDecls on .zon mode Ast 2024-12-14 16:40:40 -05:00
Frank Denis
0fac47cf28
argon2: bail out if m < 8p (#22232)
Fixes #22231
2024-12-14 19:26:55 +00:00
Alex Rønne Petersen
70de2f3a76
Merge pull request #22156 from alexrp/mingw-update
Update MinGW-w64 to dcd7fefc703fb4b12187235386900d34cc13fdc5
2024-12-14 11:30:35 +01:00
Alex Rønne Petersen
13a9bf8629
std.zig.target: Update isLibCLibName() for MinGW dcd7fefc703fb4b12187235386900d34cc13fdc5. 2024-12-14 07:02:14 +01:00
gbaraldi
10282eae64 Also export mach_timebase_info_data from darwin 2024-12-14 03:16:34 +01:00
David Rubin
82f35c5186 add branchHint to std.Random.float 2024-12-13 13:24:38 +01:00
Alex Rønne Petersen
499ad89b41
std: Disable some vector-related tests on armeb.
https://github.com/ziglang/zig/issues/22060
2024-12-13 03:13:14 +01:00
Alex Rønne Petersen
130f7c2ed8
Merge pull request #22035 from alexrp/unwind-fixes
Better unwind table support + unwind protection in `_start()` and `clone()`
2024-12-13 03:09:24 +01:00
Alex Rønne Petersen
d48611ba67
Merge pull request #22090 from alexrp/glibc-runtime-triples
Add `std.zig.target.glibcRuntimeTriple()` and use it in `std.Build.Step.Run` and `process_headers.zig`
2024-12-12 18:55:15 +01:00
Techatrix
3f7b3daaa0 AstGen: fix analysis when encountering discard of error capture 2024-12-11 18:51:10 -05:00
Nico Elbers
4a3800d78f std.ArrayHashMap fix eql documentation
In cf88cf2657 the eql function provided in
The context of ArrayHashMap was changed to also include the key index,
but this wasn't properly updated in the documentation.

Since a flat `usize` is unintuitive, I've tried to explain the function
of the parameter as best I can based on the original commit.

Finally, I didn't do an extensive search if this eql definition is
incorrectly stated anywhere outside of these 2 spots. But I somewhat
doubt an file outside of `array_hash_map` would
2024-12-11 15:21:56 -05:00
Andrew Kelley
3670910f20
Merge pull request #22202 from ziglang/Cache.hit
std.Build.Cache.hit: more discipline in error handling
2024-12-11 14:57:11 -05:00
Andrew Kelley
7ff42eff91 std.Build.Cache.hit: work around macOS kernel bug
The previous commit cast doubt upon the initial report about macOS
kernel behavior, identifying another reason that ENOENT could be
returned from file creation.

However, it is demonstrable that ENOENT can be returned for both cases:
1. create file race
2. handle refers to deleted directory

This commit re-introduces the workaround for the file creation race on
macOS however it does not unconditionally retry - it first tries again
with O_EXCL to disambiguate the error condition that has occurred.
2024-12-11 11:56:44 -08:00
Frank Denis
295c5a64f5
Reinstantiates AEGIS-MAC with the final construction (#22205)
This reverts commit c9d6f8b505.
2024-12-11 18:52:43 +01:00
Andrew Kelley
d37ee79535 std.Build.Cache.hit: more discipline in error handling
Previous commits

2b0929929d
4ea2f441df

had this text:

> There are no dir components, so you would think that this was
> unreachable, however we have observed on macOS two processes racing to
> do openat() with O_CREAT manifest in ENOENT.

This appears to have been a misunderstanding based on the issue
report #12138 and corresponding PR #12139 in which the steps to
reproduce removed the cache directory in a loop which also executed
detached Zig compiler processes.

There is no evidence for the macOS kernel bug however the ENOENT is
easily explained by the removal of the cache directory.

This commit reverts those commits, ultimately reporting the ENOENT as an
error rather than repeating the create file operation. However this
commit also adds an explicit error set to `std.Build.Cache.hit` as well
as changing the `failed_file_index` to a proper diagnostic field that
fully communicates what failed, leading to more informative error
messages on failure to check the cache.

The equivalent failure when occuring for AstGen performs a fatal process
kill, reasoning being that the compiler has an invariant of the cache
directory not being yanked out from underneath it while executing. This
could be made a more granular error in the future but I suspect such
thing is not valuable to pursue.

Related to #18340 but does not solve it.
2024-12-10 18:11:12 -08:00
Alex Rønne Petersen
da018f9726
std.os.linux: Add unwinding protection in clone() implementations.
Whatever was in the frame pointer register prior to clone() will no longer be
valid in the child process, so zero it to protect FP-based unwinders. Similarly,
mark the link register as undefined to protect DWARF-based unwinders.

This is only zeroing the frame pointer(s) on Arm/Thumb because of an LLVM
assembler bug: https://github.com/llvm/llvm-project/issues/115891
2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
7d00877076
start: Extend DWARF unwinding protection to more architectures.
The function is not marked .cantunwind for Arm/Thumb because of an LLVM
assembler bug: https://github.com/llvm/llvm-project/issues/115891
2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
43b6bd4243
start: Zero the link and frame pointer registers on all architectures. 2024-12-11 00:10:17 +01:00
Alex Rønne Petersen
8af82621d7
compiler: Improve the handling of unwind table levels.
The goal here is to support both levels of unwind tables (sync and async) in
zig cc and zig build. Previously, the LLVM backend always used async tables
while zig cc was partially influenced by whatever was Clang's default.
2024-12-11 00:10:15 +01:00
saurabh
c172877b81
std.posix: map errno 6 (ENXIO) to error.NoDevice in write() (#22113)
Co-authored-by: Saurabh <saurabhm@proton.me>
2024-12-11 00:06:51 +01:00
Andrew Kelley
7575f21212
Merge pull request #22157 from mlugg/astgen-error-lazy
compiler: allow semantic analysis of files with AstGen errors
2024-12-09 18:32:23 -05:00
Andrew Kelley
8245d7fac0
Merge pull request #22164 from mlugg/astgen-ref-dedup
AstGen: correctly deduplicate `ref` of `param` and `alloc_inferred`
2024-12-09 18:04:26 -05:00
Alex Rønne Petersen
b94bb6f96f std.Target: Remove our broken support for the ancient and obsolete Arm OABI.
NetBSD has long since migrated to the EABI and doesn't officially support the
OABI anymore. The ABI selection logic in LLVM only actually picks OABI for
NetBSD as a last resort if the EABI isn't selected. That fallback is likely to
be removed in the future. So just remove this support in Zig entirely.

While here, I also removed some leftover 32-bit Arm and 32-bit x86 code for
Apple targets, which are long dead and unsupported by Zig.
2024-12-09 10:47:18 +01:00
Alex Rønne Petersen
7cd2c1ce87
Merge pull request #22191 from alexrp/wasi-libc-names
`std.zig.target`: Teach `isLibCLibName()` about emulated wasi-libc libraries
2024-12-09 10:46:56 +01:00
Alex Rønne Petersen
c9e74bb9aa
std.zig.target: Teach isLibCLibName() about emulated wasi-libc libraries. 2024-12-08 20:23:58 +01:00
Alex Rønne Petersen
92117d9bef
std.zig.target: Remove duplicate libc check for macOS in isLibCLibName(). 2024-12-08 20:18:01 +01:00
mlugg
03f5b967f0
AstGen: correctly deduplicate ref of param and alloc_inferred
Both of these instructions were previously under a special case in
`rvalue` which resulted in every reference to such an instruction adding
a new `ref` instruction. This had the effect that, for instance,
`&a != &a` for parameters. Deduplicating these `ref` instructions was
problematic for different reasons.

For `alloc_inferred`, the problem was that it's not valid to `ref` the
alloc until the allocation has been resolved (`resolve_inferred_alloc`),
but `AstGen.appendBodyWithFixups` would place the `ref` directly after
the `alloc_inferred`. This is solved by bringing
`resolve_inferred_alloc` in line with `make_ptr_const` by having it
*return* the final pointer, rather than modifying `sema.inst_map` of the
original `alloc_inferred`. That way, the `ref` refers to the
`resolve_inferred_alloc` instruction, so is placed immediately after it,
avoiding this issue.

For `param`, the problem is a bit trickier: `param` instructions live in
a body which must contain only `param` instructions, then a
`func{,_inferred,_fancy}`, then a `break_inline`. Moreover, `param`
instructions may be referenced not only by the function body, but also
by other parameters, the return type expression, etc. Each of these
bodies requires separate `ref` instructions. This is solved by pulling
entries out of `ref_table` after evaluating each component of the
function declaration, and appending the refs later on when actually
putting the bodies together. This gives way to another issue: if you
write `fn f(x: T) @TypeOf(x.foo())`, then since `x.foo()` takes a
reference to `x`, this `ref` instruction is now in a comptime context
(outside of the `@TypeOf` ZIR body), so emits a compile error. This is
solved by loosening the rules around `ref` instructions; because they
are not side-effecting, it is okay to allow `ref` of runtime values at
comptime, resulting in a runtime-known value in a comptime scope. We
already apply this mechanism in some cases; for instance, it's why
`runtime_array.len` works in a `comptime` context. In future, we will
want to give similar treatment to many operations in Sema: in general,
it's fine to apply runtime operations at comptime provided they don't
have side effects!

Resolves: #22140
2024-12-08 10:53:50 +00:00
Alex Rønne Petersen
ba37a4369b std.zig.WindowsSdk: Support cross-arch SDK lookups.
This makes e.g. cross-compiling for x86-windows-msvc on a x86_64-windows-msvc
system work properly.

Closes #11926.
2024-12-08 04:53:28 +01:00
Andrew Kelley
eb9c9a38f2
Merge pull request #22167 from alexrp/compiler-rt-names
compiler: Classify various compiler-rt and libunwind names accurately and satisfy them
2024-12-06 19:04:39 -05:00
Alex Rønne Petersen
ca069244b2 std.Target: Fix charSignedness() for hexagon. 2024-12-06 18:15:29 +01:00
Alex Rønne Petersen
65cfc91836
std.zig.target: Consider libsupc++ to be a libc++ library name.
This is, roughly, GCC's equivalent of libc++abi.
2024-12-06 15:08:43 +01:00