aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2025-10-03compiler: control the s390x backchain feature through the frame pointer optionAlex Rønne Petersen
This is a little different from how C/C++ compilers do this, but I think it's justified because it's what users actually *mean* when the use frame pointer options. This is another one of those LLVM "CPU" features that have nothing to do with CPU at all and should really be a TargetMachine option or something. One day we'll figure out a better way of dealing with these...
2025-10-02Coff: deleteJacob Young
2025-10-02Coff2: create a new linker from scratchJacob Young
2025-09-26Merge pull request #25342 from ziglang/fuzz-limitAndrew Kelley
fuzzing: implement limited fuzzing
2025-09-25Compilation: --debug-rt always DebugAndrew Kelley
--debug-rt previously would make rt libs match the root module. Now they are always debug when --debug-rt is passed. This includes compiler-rt, fuzzer lib, and others.
2025-09-24aro does not have -mmacos version flags or -Wno-overriding-optionAndrew Kelley
2025-09-24aro does not have a pragma-pack warningAndrew Kelley
2025-09-24`@cImport`: don't pass args to Aro it doesn't understandAndrew Kelley
2025-09-24Compilation: use renameTmpIntoCacheAndrew Kelley
solves several problems with this pattern
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-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-10Merge pull request #24968 from ifreund/dequeAndrew Kelley
std: add a Deque data structure
2025-09-06Compilation: fix buildGlibcSharedObjects error handlingAndrew Kelley
Oops, this was supposed to be only a temporary troubleshooting patch.
2025-08-31std.fmt: delete deprecated APIsAndrew Kelley
std.fmt.Formatter -> std.fmt.Alt std.fmt.format -> std.Io.Writer.print
2025-08-30Merge pull request #25077 from ziglang/GenericReaderAndrew Kelley
std.Io: delete GenericReader, AnyReader, FixedBufferStream; and related API breakage
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-30zig cc: pass -mthumb to the assembler as necessaryAlex Rønne Petersen
2025-08-30zig cc: pass CPU features to Clang using the new -Xclangas when assemblingAlex Rønne Petersen
Unfortunately, we cannot yet remove the special-casing for RISC-V CPU features, so that code stays. Closes #10411.
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28fix not discarding delimiterAndrew Kelley
perhaps these APIs have the defaults backwards, eh?
2025-08-27delete some vestigal dead codeAndrew Kelley
2025-08-26Compilation: use std.DequeIsaac Freund
And delete DeprecatedLinearFifo from the source tree.
2025-08-26std.Target: add vita osMaciej 'vesim' Kuliński
Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-08-25zig cc: don't pass -mcmodel for assembly filesAlex Rønne Petersen
It does nothing but generate a warning for these.
2025-08-25Merge pull request #24995 from alexrp/ubsan-rt-hiddenAlex Rønne Petersen
ubsan-rt: export symbols with hidden visibility
2025-08-25start adding big endian RISC-V supportAlex Rønne Petersen
The big endian RISC-V effort is mostly driven by MIPS (the company) which is pivoting to RISC-V, and presumably needs a big endian variant to fill the niche that big endian MIPS (the ISA) did. GCC already supports these targets, but LLVM support will only appear in 22; this commit just adds the necessary target knowledge and checks on our end.
2025-08-25Compilation: avoid ZCU strategy for ubsan-rt in Windows DLLsAlex Rønne Petersen
2025-08-22feat(std.Target): add 3ds osGasInfinity
2025-08-20wasi-libc: update to c89896107d7b57aef69dcadede47409ee4f702eeAlex Rønne Petersen
2025-08-18Compilation: fix compiler_rt and ubsan_rt strategy logicmlugg
It doesn't really make sense for `target_util.canBuildLibCompilerRt` (and its ubsan-rt friend) to take in `use_llvm`, because the caller doesn't control that: they're just going to queue a sub-compilation for the runtime. The only exception to that is the ZCU strategy, where we effectively embed `_ = @import("compiler_rt")` into the Zig compilation: there, the question does matter. Rather than trying to do multiple weird calls to model this, just have `canBuildLibCompilerRt` return not just a boolean, but also differentiate the self-hosted backend being capable of building the library vs only LLVM being capable. Logic in `Compilation` uses that difference to decide whether to use the ZCU strategy, and also to disable the library if the compiler does not support LLVM and it is required. Also, remove a redundant check later on, when actually queuing jobs. We've already checked that we can build `compiler_rt`, and `compiler_rt_strat` is set accordingly. I'm guessing this was there to work around a bug I saw in the old strategy assignment, where support was ignored in some cases. Resolves: #24623
2025-08-16Compilation: remove last instance of deprecatedReaderAndrew Kelley
This also makes initStreaming preemptively disable file size checking.
2025-08-16Compilation: retain ZCU object when emitting unstripped Mach-O binarymlugg
On macOS, when using the LLVM backend, the output binary retains a reference to this object file's debug info (as opposed to self-hosted backends which instead emit a dSYM bundle). As such, we need to retain this object file in such cases. This object does unfortunately "leak", in that it won't be reused and will just sit in the cache forever (or until GC'd in the future). But that's no worse than the cache behavior prior to the rework that caused this, and it will become less of a problem over time as the self-hosted backend gains usability for debug builds and eventually becomes the default. Resolves: #24369
2025-08-15Zcu: don't tell linkers about exports if there are compile errorsmlugg
In the best case, this is redundant work, because we aren't actually going to emit a working binary this update. In the worst case, it causes bugs because the linker may not have *seen* the thing being exported due to the compile errors. Resolves: #24417
2025-08-14Merge pull request #24825 from alexrp/freebsd-fixesAlex Rønne Petersen
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-13freebsd: correctly define __FreeBSD_version to the first stable releaseAlex Rønne Petersen
See: https://docs.freebsd.org/en/books/porters-handbook/versions Closes #24819.
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-06link: prevent deadlock when prelink tasks failmlugg
If an error occured which prevented a prelink task from being queued, then `pending_prelink_tasks` would never be decremented, which could cause deadlocks in some cases. So, instead of calculating ahead of time the number of prelink tasks to expect, we use a simpler strategy which is much like a wait group: we add 1 to a value when we spawn a worker, and in the worker function, `defer` decrementing the value. The initial value is 1, and there's a decrement after all of the workers are spawned, so once it hits 0, prelink is done (be it with a failure or a success).
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-05std: remove BoundedArrayAndrew Kelley
This use case is handled by ArrayListUnmanaged via the "...Bounded" method variants, and it's more optimal to share machine code, versus generating multiple versions of each function for differing array lengths.
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-26aarch64: implement some safety checksJacob Young
Closes #24553
2025-07-24Autodoc: fix sources.tar generationIan Johnson
Closes #24565
2025-07-23std.Io.poll: update to new I/O APIAndrew Kelley
2025-07-23Merge pull request #24523 from ziglang/fifnoAndrew Kelley
std.tar: update to new I/O API