aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
AgeCommit message (Collapse)Author
2025-10-30Merge pull request #25558 from jacobly0/elfv2-load-objJacob Young
Elf2: start implementing input object loading
2025-10-30std.debug.lockStderrWriter: also return ttyconfMatthew Lugg
`std.Io.tty.Config.detect` may be an expensive check (e.g. involving syscalls), and doing it every time we need to print isn't really necessary; under normal usage, we can compute the value once and cache it for the whole program's execution. Since anyone outputting to stderr may reasonably want this information (in fact they are very likely to), it makes sense to cache it and return it from `lockStderrWriter`. Call sites who do not need it will experience no significant overhead, and can just ignore the TTY config with a `const w, _` destructure.
2025-10-29Elf2: start implementing dynamic linkingJacob Young
2025-10-29std: move DNS record enum to a better namespaceAndrew Kelley
2025-10-29compiler: update for introduction of std.IoAndrew Kelley
only thing remaining is using libc dns resolution when linking libc
2025-10-29progress towards compiler building againAndrew Kelley
2025-10-29std.zig.system: upgrade to std.Io.ReaderAndrew Kelley
2025-10-09- Rework common translate-c and cImport logic into `Compilation.translateC`kcbanner
- Add std.zig.Server.allocErrorBundle, replace duplicates
2025-10-09- aro: fixup `toErrorBundle` not emitting the last error if it was followed ↵kcbanner
by .off or .warning - translate-c: emit `file_system_inputs` even in the case of failure, if available - translate-c: fixup emitting zero-length `file_system_inputs`
2025-10-09- Rework translate-c to integrate with the build system (by outputing error ↵kcbanner
bundles on stdout) via --zig-integration - Revive some of the removed cache integration logic in `cmdTranslateC` now that `translate-c` can return error bundles - Fixup inconsistent path separators (on Windows) when building the aro include path - Move some error bundle logic from resinator into aro.Diagnostics - Add `ErrorBundle.addRootErrorMessageWithNotes` (extracted from resinator)
2025-09-30compiler: better crash handlermlugg
Far simpler, because everything which `crash_report.zig` did is now handled pretty well by `std.debug` anyway. All we want is to print some context around panics and segfaults. Using the new ability to override the default segfault handler while still having std handle the target-specific bits for us, that's really simple.
2025-09-26Update descriptions of -f[no-]error-tracing to match the actual behaviorRyan Liptak
Before https://github.com/ziglang/zig/pull/18160, error tracing defaulted to true in ReleaseSafe, but that is no longer the case. These option descriptions were never updating accordingly.
2025-09-26Merge pull request #25351 from ziglang/chompAndrew Kelley
std.mem: introduce cut functions; rename "index of" to "find"
2025-09-25std.mem: add cutLast and cutScalarLastAndrew Kelley
2025-09-25std.mem: add cut and cutScalar and example usageAndrew Kelley
2025-09-25std.mem: rename chomp to cutAndrew Kelley
2025-09-25CLI: simpler semantics for prefixed integer argsAndrew Kelley
2025-09-25CLI: exploit std.mem.chompPrefixAndrew Kelley
fixes a bug in how -fstructured-cfg and -fno-structured-cfg are handled.
2025-09-24Compilation: re-implement cImportAndrew Kelley
2025-09-24fix rebase conflictsAndrew Kelley
2025-09-24Compilation: avoid passing Clang specific options to AroVeikka Tuominen
2025-09-24add translate-c CLI argsAndrew Kelley
2025-09-24delete enough aro to make it compileAndrew Kelley
2025-09-24compiler: update aro and translate-c to latest; delete clang translate-cAndrew Kelley
2025-09-21Elf2: create a new linker from scratchJacob Young
This iteration already has significantly better incremental support. Closes #24110
2025-09-19Fix duplicate LC_RPATH entries on macOS TahoeFrank Denis
When building on macOS Tahoe, binaries were getting duplicate LC_RPATH load commands which caused dyld to refuse to run them with a "duplicate LC_RPATH" error that has become a hard error. The duplicates occurred when library directories were being added to rpath_list twice: - from lib_directories - from native system paths detection which includes the same dirs
2025-08-31Fix `-M` and `--dep` splitting on every = instead of just the firstRyan Liptak
Before this commit, -Mfoo=bar=baz would be incorrectly split into mod_name: `foo` and root_src_orig: `bar` After this commit, -Mfoo=bar=baz will be correctly split into mod_name: `foo` and root_src_orig: `bar=baz` Closes #25059
2025-08-30upgrade more old API usesAndrew Kelley
2025-08-30rework std.Io.Writer.Allocating to support runtime-known alignmentAndrew Kelley
Also, breaking API changes to: * std.fs.Dir.readFileAlloc * std.fs.Dir.readFileAllocOptions
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28std.Io: delete GenericWriterAndrew Kelley
2025-08-27delete some vestigal dead codeAndrew Kelley
2025-08-24Add `test-obj` to the help messageArnau Camprubí
2025-08-20std.c.darwin: cleanup, expose everything in std.cJustus Klausecker
This mainly just moves stuff around. Justifications for other changes: * `KEVENT.FLAGS` is backed by `c_uint` because that's what the `kevent64` flags param takes (according to the 'latest' manpage from 2008) * `MACH_RCV_NOTIFY` is a legacy name and `MACH_RCV_OVERWRITE` is deprecated (xnu/osfmk/mach/message.h), so I removed them. They were 0 anyway and thus couldn't be represented as a packed struct field. * `MACH.RCV` and `MACH.SEND` are technically the same 'type' because they can both be supplied at the same time to `mach_msg`. I decided to still keep them separate because naming works out better that way and all flags except for `MACH_MSG_STRICT_REPLY` aren't shared anyway. Both are part of a packed union `mach_msg_option_t` which supplies a helper function to combine the two types. * `PT` is backed by `c_int` because that's what `ptrace` takes as a request arg (according to the latest manpage from 2015)
2025-08-15zig translate-c: don't forget to flushAndrew Kelley
fixes #24672
2025-08-13std.io.Writer.Allocating: rename getWritten() to written()Isaac Freund
This "get" is useless noise and was copied from FixedBufferWriter. Since this API has not yet landed in a release, now is a good time to make the breaking change to fix this.
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-08-08compiler: improve error reportingmlugg
The functions `Compilation.create` and `Compilation.update` previously returned inferred error sets, which had built up a lot of crap over time. This meant that certain error conditions -- particularly certain filesystem errors -- were not being reported properly (at best the CLI would just print the error name). This was also a problem in sub-compilations, where at times only the error name -- which might just be something like `LinkFailed` -- would be visible. This commit makes the error handling here more disciplined by introducing concrete error sets to these functions (and a few more as a consequence). These error sets are small: errors in `update` are almost all reported via compile errors, and errors in `create` are reported through a new `Compilation.CreateDiagnostic` type, a tagged union of possible error cases. This allows for better error reporting. Sub-compilations also report errors more correctly in several cases, leading to more informative errors in the case of compiler bugs. Also fixes some race conditions in library building by replacing calls to `setMiscFailure` with calls to `lockAndSetMiscFailure`. Compilation of libraries such as libc happens on the thread pool, so the logic must synchronize its access to shared `Compilation` state.
2025-08-06Revert "Sema: Stop adding Windows implib link inputs for `extern "..."` syntax."Alex Rønne Petersen
This reverts commit b461d07a5464aec86c533434dab0b58edfffb331. After some discussion in the team, we've decided that this is too disruptive, especially because the linker errors are less than helpful. That's a fixable problem, so we might reconsider this in the future, but revert it for now.
2025-08-04Merge pull request #24689 from mlugg/build-no-watch-regressionMatthew Lugg
build runner: fix FTBFS on targets without `--watch` implementation
2025-08-04init: small fix to zig init templateLoris Cro
it was placing the current zig version in the wrong field
2025-08-04cli: add `--debug-libc` to `zig build`mlugg
This option is similar to `--debug-target` in letting us override details of the build runner target when debugging the build system. While `--debug-target` lets us override the target query, this option lets us override the libc installation. This option is only usable in a compiler built with debug extensions. I am using this to (try to) test the build runner targeting SerenityOS.
2025-08-01build system: replace fuzzing UI with build UI, add time reportmlugg
This commit replaces the "fuzzer" UI, previously accessed with the `--fuzz` and `--port` flags, with a more interesting web UI which allows more interactions with the Zig build system. Most notably, it allows accessing the data emitted by a new "time report" system, which allows users to see which parts of Zig programs take the longest to compile. The option to expose the web UI is `--webui`. By default, it will listen on `[::1]` on a random port, but any IPv6 or IPv4 address can be specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`. The options `--fuzz` and `--time-report` both imply `--webui` if not given. Currently, `--webui` is incompatible with `--watch`; specifying both will cause `zig build` to exit with a fatal error. When the web UI is enabled, the build runner spawns the web server as soon as the configure phase completes. The frontend code consists of one HTML file, one JavaScript file, two CSS files, and a few Zig source files which are built into a WASM blob on-demand -- this is all very similar to the old fuzzer UI. Also inherited from the fuzzer UI is that the build system communicates with web clients over a WebSocket connection. When the build finishes, if `--webui` was passed (i.e. if the web server is running), the build runner does not terminate; it continues running to serve web requests, allowing interactive control of the build system. In the web interface is an overall "status" indicating whether a build is currently running, and also a list of all steps in this build. There are visual indicators (colors and spinners) for in-progress, succeeded, and failed steps. There is a "Rebuild" button which will cause the build system to reset the state of every step (note that this does not affect caching) and evaluate the step graph again. If `--time-report` is passed to `zig build`, a new section of the interface becomes visible, which associates every build step with a "time report". For most steps, this is just a simple "time taken" value. However, for `Compile` steps, the compiler communicates with the build system to provide it with much more interesting information: time taken for various pipeline phases, with a per-declaration and per-file breakdown, sorted by slowest declarations/files first. This feature is still in its early stages: the data can be a little tricky to understand, and there is no way to, for instance, sort by different properties, or filter to certain files. However, it has already given us some interesting statistics, and can be useful for spotting, for instance, particularly complex and slow compile-time logic. Additionally, if a compilation uses LLVM, its time report includes the "LLVM pass timing" information, which was previously accessible with the (now removed) `-ftime-report` compiler flag. To make time reports more useful, ZIR and compilation caches are ignored by the Zig compiler when they are enabled -- in other words, `Compile` steps *always* run, even if their result should be cached. This means that the flag can be used to analyze a project's compile time without having to repeatedly clear cache directory, for instance. However, when using `-fincremental`, updates other than the first will only show you the statistics for what changed on that particular update. Notably, this gives us a fairly nice way to see exactly which declarations were re-analyzed by an incremental update. If `--fuzz` is passed to `zig build`, another section of the web interface becomes visible, this time exposing the fuzzer. This is quite similar to the fuzzer UI this commit replaces, with only a few cosmetic tweaks. The interface is closer than before to supporting multiple fuzz steps at a time (in line with the overall strategy for this build UI, the goal will be for all of the fuzz steps to be accessible in the same interface), but still doesn't actually support it. The fuzzer UI looks quite different under the hood: as a result, various bugs are fixed, although other bugs remain. For instance, viewing the source code of any file other than the root of the main module is completely broken (as on master) due to some bogus file-to-module assignment logic in the fuzzer UI. Implementation notes: * The `lib/build-web/` directory holds the client side of the web UI. * The general server logic is in `std.Build.WebServer`. * Fuzzing-specific logic is in `std.Build.Fuzz`. * `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now relates to the build system web UI in general. * The build runner now has an **actual** general-purpose allocator, because thanks to `--watch` and `--webui`, the process can be arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the arena remains backed by `std.heap.page_allocator` for efficiency. I fixed several crashes caused by conflation of `gpa` and `arena` in the build runner and `std.Build`, but there may still be some I have missed. * The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a *lot* of threads involved. I anticipate this situation improving significantly once the `std.Io` interface (with concurrency support) is introduced.
2025-07-30update `zig env` to respect `ZIG_LIB_DIR` and support wasiTechatrix
2025-07-28Update `zig init` help with new `-m` argSilver
This was forgotten in #24555
2025-07-25init: replace '--strip' with '--minimal'mlugg
This option never worked properly (it emitted wrongly-formatted code), and it doesn't seem particularly *useful* -- someone who's proficient enough with `std.Build` to not need explanations probably just wants to write their own thing. Meanwhile, the use case of writing your own `build.zig` was extremely poorly served, because `build.zig.zon` *needs* to be generated programmatically for a correct `fingerprint`, but the only ways to do that were to a) do it wrong and get an error, or b) get the full init template and delete the vast majority of it. Both of these were pretty clunky, and `-s` didn't really help. So, replace this flag with a new one, `--minimal`/`-m`, which uses a different template. This template is trivial enough that I opted to just hardcode it into the compiler for simplicity. The main job of `zig init -m` is to generate a correct `build.zig.zon` (if it is unable to do this, it exits with a fatal error). In addition, it will *attempt* to generate a tiny stub `build.zig`, with only an `std` import and an empty `pub fn build`. However, if `build.zig` already exists, it will avoid overwriting it, and doesn't even complain. This serves the use case of writing `build.zig` manually and *then* running `zig init -m` to generate an appropriate `build.zig.zon`.
2025-07-22aarch64: add new from scratch self-hosted backendJacob Young
2025-07-21std.fs.File: delete writeFileAll and friendsAndrew Kelley
please use File.Writer for these use cases also breaking API changes to std.fs.AtomicFile
2025-07-20use stdout_buffer instead of stdio_buffer in main.zigantlilja
2025-07-20Merge pull request #24488 from ziglang/moreAndrew Kelley
std.zig: finish updating to new I/O API