Commit graph

255 commits

Author SHA1 Message Date
wooster0
a365971a33 std.meta.intToEnum -> std.enums.fromInt
Also use an optional as the return type instead of an error code.
2025-05-13 07:28:41 +02:00
Alex Rønne Petersen
bc3c50c21e
Merge pull request #23700 from sorairolake/rename-trims
chore(std.mem): Rename `trimLeft` and `trimRight` to `trimStart` and `trimEnd`
2025-05-12 17:11:52 +02:00
Alex Rønne Petersen
35f30558ad
std.Build: Rename --glibc-runtimes to --libc-runtimes and enable it for musl. 2025-05-06 01:52:47 +02:00
Alex Rønne Petersen
e7b46363ae std.Target: Remove Os.Tag.elfiamcu.
The last Intel Quark MCU was released in 2015. Quark was announced to be EOL in
2019, and stopped shipping entirely in 2022.

The OS tag was only meaningful for Intel's weird fork of Linux 3.8.7 with a
special ABI that differs from the regular i386 System V ABI; beyond that, the
CPU itself is just a plain old P54C (i586). We of course keep support for the
CPU itself, just not Intel's Linux fork.
2025-04-28 00:24:09 +02:00
Shun Sakai
5fc4448e45 chore(std.mem): Rename trimLeft and trimRight
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`.
`trimLeft` and `trimRight` functions remain as deprecated aliases for
these new names.
2025-04-27 18:03:59 +09:00
Alex Rønne Petersen
23440fbb99 std.Target: Remove Abi.gnuilp32.
* This has not seen meaningful development for about a decade.
* The Linux kernel port was never upstreamed.
* The glibc port was never upstreamed.
* GCC 15.1 recently deprecated support it.

It may still make sense to support an ILP32 ABI on AArch64 more broadly (which
we already have the Abi.ilp32 tag for), but, to the extent that it even existed
in any "official" sense, the *GNU* ILP32 ABI is certainly dead.
2025-04-26 22:12:31 +02:00
Andrew Kelley
f32a5d349d std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
Andrew Kelley
4e700fdf8e
Merge pull request #22516 from Jan200101/PR/build_id_option
std.Build: add build-id option
2025-04-11 16:37:46 -04:00
Alex Rønne Petersen
0132be7bf3 std.Target: Rename charSignedness() to cCharSignedness().
To be consistent with the other functions that answer C ABI questions.
2025-04-11 05:22:00 -04:00
Jan200101
1a5dcff8e4
std.Build: update build-id flag description
it now denotes:
- all supported styles
- what a given style outputs
- what formats a given style supports
2025-04-05 22:11:07 +02:00
Alex Rønne Petersen
8954e9748a
std.Target: Add Abi.muslf32 and Abi.muslsf. 2025-04-04 06:08:09 +02:00
Parker Liu
de62dc884e
translate-c: fix function prototype decalared inside a function
* If a function prototype is declarated inside a function, do not
  translate it to a top-level extern function declaration. Similar to
  extern local variable, just wrapped it into a block-local struct.

* Add a new extern_local_fn tag of aro_translate_c node for present
  extern local function declaration.

* When a function body has a C function prototype declaration, it adds
  an extern local function declaration. Subsequent function references
  will look for this function declaration.
2025-04-02 20:07:41 +00:00
Parker Liu
0bdc0bb534
translate-c: fix referencing extern locals from nested blocks 2025-03-31 20:22:03 +03:00
GalaxyShard
b5a5260546 std.Build: implement addEmbedPath for adding C #embed search directories 2025-03-27 09:47:42 +01:00
Андрей Краевский
aac800ec65
std.meta.FieldType -> @FieldType 2025-03-27 03:49:38 +00:00
Eric Joldasov
27c1f2b3a0 zig build: allow to choose "lazy mode" for fetching process
`--fetch` flag now has additional optional parameter, which specifies
how lazy dependencies should be fetched:
 * `needed` — lazy dependencies are fetched only if they are required
   for current build configuration to work. Default and works same
   as old `--fetch` flag.
 * `all` — lazy dependencies are always fetched. If `--system` flag
   is used after that, it's guaranteed that **any** build configuration
   will not require additional download of dependencies during build.
   Helpful for distro packagers and CI systems:
   https://www.github.com/ziglang/zig/issues/14597#issuecomment-1426827495

If none is passed, behaviour is same as if `needed` was passed.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-03-26 19:00:33 +01:00
Ryan Liptak
9c9d3931df Trick the meson build system into thinking zig rc is rc.exe
When determining the type of RC compiler, meson passes `/?` or `--version` and then reads from `stdout` looking for particular string(s) anywhere in the output.

So, by adding the string "Microsoft Resource Compiler" to the `/?` output, meson will recognize `zig rc` as rc.exe and give it the correct options, which works fine since `zig rc` is drop-in CLI compatible with rc.exe.

This allows using `zig rc` with meson for (cross-)compiling, by either:

- Setting WINDRES="zig rc" or putting windres = ['zig', 'rc'] in the cross-file
  + This will work like rc.exe, so it will output .res files. This will only link successfully if you are using a linker that can do .res -> .obj conversion (so something like zig cc, MSVC, lld)
- Setting WINDRES="zig rc /:output-format coff" or putting windres = ['zig', 'rc', '/:output-format', 'coff'] in the cross-file
  + This will make meson pass flags as if it were rc.exe, but it will cause the resulting .res file to actually be a COFF object file, meaning it will work with any linker that handles COFF object files

Example cross file that uses `zig cc` (which can link `.res` files, so `/:output-format coff` is not necessary) and `zig rc`:

```
[binaries]
c = ['zig', 'cc', '--target=x86_64-windows-gnu']
windres = ['zig', 'rc']

[target_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
```
2025-03-21 18:07:16 -04:00
Matthew Lugg
d0911786c9
Merge pull request #22397 from Techatrix/type-safe-ast
improve type safety of std.zig.Ast
2025-03-12 02:22:41 +00:00
Meghan Denny
0f6056903b std: Abi.default: only require an os tag 2025-03-09 09:44:11 +01:00
Techatrix
4129f7ff5a
std.zig.Ast: store lbrace and rbrace token in data of .error_set_decl
This makes the `.data` field the better choice over the `.main_token` for this tag.
2025-03-07 22:22:01 +01:00
Techatrix
ca6fb30e99
std.zig.Ast: improve type safety
This commits adds the following distinct integer types to std.zig.Ast:
- OptionalTokenIndex
- TokenOffset
- OptionalTokenOffset
- Node.OptionalIndex
- Node.Offset
- Node.OptionalOffset

The `Node.Index` type has also been converted to a distinct type while
`TokenIndex` remains unchanged.

`Ast.Node.Data` has also been changed to a (untagged) union to provide
safety checks.
2025-03-07 22:22:01 +01:00
Techatrix
6dcd8f4f75
std.zig.Ast: add blockStatements and builtinCallParams 2025-03-07 22:20:35 +01:00
Techatrix
de9c889a0e
aro_translate_c: fix ast lowering of continue node
fixes #22601
2025-03-07 22:20:35 +01:00
Jan200101
013a228960 std.Build: add build-id option 2025-03-07 10:59:02 +01:00
Linus Groh
79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Andrew Kelley
6b6c1b1b0e Revert "Merge pull request #22898 from kristoff-it/deprecated-proposal"
This reverts commit dea72d15da, reversing
changes made to ab381933c8.

The changeset does not work as advertised and does not have sufficient
test coverage.

Reopens #22822
2025-02-28 01:37:10 -08:00
Andrew Kelley
dea72d15da
Merge pull request #22898 from kristoff-it/deprecated-proposal
Implement `@deprecated`
2025-02-27 01:31:09 -05:00
Brad Olson
c031b62b83 compiler.build_runner: only build Fuzz on 64-bit platforms 2025-02-26 19:16:05 -05:00
Andrew Kelley
c5aa680c88 don't inherit allowed deprecation from parent modules
Inheriting allow-deprecation from parent modules doesn't make too much
sense, so instead make them default to disallow unless otherwise
specified. This allows build system to avoid redundant
`-fno-allow-deprecated` args.

This makes the generated CLIs smaller, and makes zig1.wasm update not
needed.

Also represented `is_root` differently (moved to field of graph).
2025-02-26 14:41:33 -05:00
Loris Cro
ba7cd8121d @deprecated: add build system support 2025-02-26 14:41:33 -05:00
Ali Cheraghi
181a89e728
build: add spirv to test matrix
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
2025-02-24 19:12:38 +01:00
Ryan Liptak
a502301b5e zig rc: Add COFF object file creation for CMake cross-compilation use case
In #22522 I said:

> RC="zig rc" will now work in combination with zig cc and CMake. Here's an example of cross-compiling a simple Windows GUI CMake project
>
>    $ RC="zig rc" CC="zig cc --target=x86_64-windows-gnu" cmake .. -DCMAKE_SYSTEM_NAME=Windows -G Ninja

However, I didn't realize that the time that this only works because of the `-G Ninja` part. When not using Ninja as the build tool, CMake adds a workaround for 'very long lists of object files' where it takes all object files and runs them through `ar` to combine them into one archive:

4a11fd8dde/Modules/Platform/Windows-GNU.cmake (L141-L158)

This is a problem for the Windows resource use-case, because `ar` doesn't know how to deal with `.res` files and so this object combining step fails with:

    unknown file type: foo.rc.res

Only the linker knows what to do with .res files (since it has its own `.res` -> `.obj` ('cvtres') conversion mechanism). So, when using Ninja, this object file combining step is skipped and the .res file gets passed to the linker and everyone is happy.

Note: When CMake thinks that its using `windres` as the Windows resource compiler, it will pass `-O coff` to windres which causes it to output a COFF object file instead of a `.res` file, which means that the `ar` step can succeed because it's only working on actual object files.

---

This commit gives `zig rc` the ability to output COFF object files directly when `/:output-format coff` is provided as an argument. This effectively matches what happens when CMake uses `windres` for resource compilation, but requires the argument to be provided explicitly.

So, after this change, the following CMake cross-compilation use case will work, even when not using Ninja as the generator:

    RC="zig rc /:output-format coff" CC="zig cc --target=x86_64-windows-gnu" cmake .. -DCMAKE_SYSTEM_NAME=Windows
2025-02-22 21:21:30 -05:00
Andrew Kelley
eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look
at multiple components of the target. But functions like isWasm(), isDarwin(),
isGnu(), etc only exist to save 4-8 characters. I don't think this is a good
enough reason to keep them, especially given that:

* It's not immediately obvious to a reader whether target.isDarwin() means the
  same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar
  functions *do* look at multiple components.
* It's not clear where we would draw the line. The logical conclusion before
  this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(),
  Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand.
* It's nice to just have a single correct way of doing something.
2025-02-17 19:18:19 +01:00
Alex Rønne Petersen
b541a7af11
std.Target: Remove Cpu.Arch.spu_2.
This was for a hobby project that appears to be dormant for now. This can be
added back if the project is resumed in the future.
2025-02-17 19:17:55 +01:00
Andrew Kelley
d789f1e5cf fuzzer: write inputs to shared memory before running
breaking change to the fuzz testing API; it now passes a type-safe
context parameter to the fuzz function.

libfuzzer is reworked to select inputs from the entire corpus.

I tested that it's roughly as good as it was before in that it can find
the panics in the simple examples, as well as achieve decent coverage on
the tokenizer fuzz test.

however I think the next step here will be figuring out why so many
points of interest are missing from the tokenizer in both Debug and
ReleaseSafe modes.

does not quite close #20803 yet since there are some more important
things to be done, such as opening the previous corpus, continuing
fuzzing after finding bugs, storing the length of the inputs, etc.
2025-02-11 13:39:20 -08:00
Ryan Liptak
00316bfbf0 resinator: Fix some error message integration
Fixup for some of the changes in https://github.com/ziglang/zig/pull/22522
2025-02-10 01:37:04 -08:00
Meghan Denny
9142482372
std.ArrayList: popOrNull() -> pop() [v2] (#22720) 2025-02-10 04:21:31 +00:00
Mason Remaley
13c6eb0d71
compiler,std: implement ZON support
This commit allows using ZON (Zig Object Notation) in a few ways.

* `@import` can be used to load ZON at comptime and convert it to a
  normal Zig value. In this case, `@import` must have a result type.
* `std.zon.parse` can be used to parse ZON at runtime, akin to the
  parsing logic in `std.json`.
* `std.zon.stringify` can be used to convert arbitrary data structures
  to ZON at runtime, again akin to `std.json`.
2025-02-03 09:14:37 +00:00
Guillaume Wenzek
3348478fc3
Make -freference-trace work without colors
Currently -freference-trace only works when running from a terminal.
This is annoying if you're running in another environment or if you redirect the output.
But -freference-trace also works fine without the color, so change how the build runner is interpreting this option.
2025-01-30 13:02:06 +01:00
Ryan Liptak
289e9c3507 resinator: Sync with upstream
Note: This mostly matches resinator v0.1.0 rather than the latest master version, since the latest master version focuses on adding support for .res -> .obj conversion which is not necessary for the future planned relationship of zig and resinator (resinator will likely be moved out of the compiler and into the build system, a la translate-c).

So, ultimately the changes here consist mostly of bug fixes for obscure edge cases.
2025-01-17 23:10:41 -08:00
Ryan Liptak
4baa448335 resinator: Fix incorrect args being printed in cli diagnostics 2025-01-17 23:04:26 -08:00
mlugg
e9bd2d45d4
Sema: rewrite semantic analysis of function calls
This rewrite improves some error messages, hugely simplifies the logic,
and fixes several bugs. One of these bugs is technically a new rule
which Andrew and I agreed on: if a parameter has a comptime-only type
but is not declared `comptime`, then the corresponding call argument
should not be *evaluated* at comptime; only resolved. Implementing this
required changing how function types work a little, which in turn
required allowing a new kind of function coercion for some generic use
cases: function coercions are now allowed to implicitly *remove*
`comptime` annotations from parameters with comptime-only types. This is
okay because removing the annotation affects only the call site.

Resolves: #22262
2025-01-09 06:46:47 +00:00
Alex Rønne Petersen
f06ca14cb5
Merge pull request #22225 from alexrp/libc-linux-os-version
Attach minimum Linux versions to provided libcs + incorporate ABI in `VersionRange.default()`
2024-12-23 19:42:53 +01:00
mlugg
0bb93ca053
std.Build: simplify module dependency handling
At the expense of a slight special case in the build runner, we can make
the handling of dependencies between modules a little shorter and much
easier to follow.

When module and step graphs are being constructed during the "configure"
phase, we do not set up step dependencies triggered by modules. Instead,
after the configure phase, the build runner traverses the whole
step/module graph, starting from the root top-level steps, and
configures all step dependencies implied by modules. The "make" phase
then proceeds as normal. Also, the old `Module.dependencyIterator` logic
is replaced by two separate iterables. `Module.getGraph` takes the root
module of a compilation, and returns all modules in its graph; while
`Step.Compile.getCompileDependencies` takes a `*Step.Compile` and
returns all `*Step.Compile` it depends on, recursively, possibly
excluding dynamic libraries. The old `Module.dependencyIterator`
combined these two functions into one unintuitive iterator; they are now
separated, which in particular helps readability at the usage sites
which only need one or the other.
2024-12-18 01:47:51 +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
mlugg
3e9810266b
compiler: add some missing consts
The previous commit exposed some missing `const` qualifiers in a few
places. These mutable slices could have been used to store invalid
values into memory!
2024-12-16 14:53:54 +00:00
Alex Rønne Petersen
09b39f77b7
std.Target: Remove Os.Tag.bridgeos.
It doesn't appear that targeting bridgeOS is meaningfully supported by Apple.
Even LLVM/Clang appear to have incomplete support for it, suggesting that Apple
never bothered to upstream that support. So there's really no sense in us
pretending to support this.
2024-12-03 20:43:15 +01:00
mlugg
9ebce51e16 compiler: un-jit zig fmt
This command being JITed leads to a substantially worse first-time user
experience, since you have to wait for upwards of 20 seconds for
`fmt.zig` to build. This is especially bad when your editor is
configured to run `zig fmt` on save and does so in a blocking manner. As
such, it makes sense from a usability perspective to not JIT this
particular command.
2024-11-12 21:55:46 -08:00
Daniel Hooper
560d6b99d5
Fix silent zig fmt errors (#21948) 2024-11-11 01:24:14 -08:00