35 Commits

Author SHA1 Message Date
Benjamin Jurk
4b5351bc0d
update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Alex Rønne Petersen
8817fc8958
incr-check: read/write messages as little endian 2025-11-19 01:42:45 +01:00
Ryan Liptak
5358af7ba4
incr-check: Kill child process on error
Since the child process is spawned with the tmp directory as its CWD, the child process opens it without DELETE access. On error, the child process would still be alive while the tmp directory is attempting to be deleted, so it would fail with `.SHARING_VIOLATION => return error.FileBusy`.

Fixes arguably the least important part of #22510, since it's only the directory itself that would fail to get deleted, all the files inside would get deleted just fine.
2025-11-09 07:45:31 +00:00
Matthew Lugg
74931fe25c
std.debug.lockStderrWriter: also return ttyconf
`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-30 09:31:28 +00:00
Andrew Kelley
89bb58e5a3 incr-check: windows source files depend on ws2_32 2025-10-29 06:20:51 -07:00
Andrew Kelley
10b1eef2d3 std: fix compilation errors on Windows 2025-10-29 06:20:50 -07:00
kcbanner
8b6cdc3d82 - Rework common translate-c and cImport logic into Compilation.translateC
- Add std.zig.Server.allocErrorBundle, replace duplicates
2025-10-09 01:06:09 -04:00
Andrew Kelley
9adcc31ca3 update tools and other miscellaneous things to new APIs 2025-08-30 00:48:50 -07:00
Andrew Kelley
b8955a2e0a std.Io.poll: update to new I/O API 2025-07-23 21:25:34 -07:00
Jacob Young
917640810e Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it
consistently shows up in profiles of the compiler.
2025-06-19 11:45:06 -04:00
mlugg
b5f73f8a7b
compiler: rework emit paths and cache modes
Previously, various doc comments heavily disagreed with the
implementation on both what lives where on the filesystem at what time,
and how that was represented in code. Notably, the combination of emit
paths outside the cache and `disable_lld_caching` created a kind of
ad-hoc "cache disable" mechanism -- which didn't actually *work* very
well, 'most everything still ended up in this cache. There was also a
long-standing issue where building using the LLVM backend would put a
random object file in your cwd.

This commit reworks how emit paths are specified in
`Compilation.CreateOptions`, how they are represented internally, and
how the cache usage is specified.

There are now 3 options for `Compilation.CacheMode`:
* `.none`: do not use the cache. The paths we have to emit to are
  relative to the compiler cwd (they're either user-specified, or
  defaults inferred from the root name). If we create any temporary
  files (e.g. the ZCU object when using the LLVM backend) they are
  emitted to a directory in `local_cache/tmp/`, which is deleted once
  the update finishes.
* `.whole`: cache the compilation based on all inputs, including file
  contents. All emit paths are computed by the compiler (and will be
  stored as relative to the local cache directory); it is a CLI error to
  specify an explicit emit path. Artifacts (including temporary files)
  are written to a directory under `local_cache/tmp/`, which is later
  renamed to an appropriate `local_cache/o/`. The caller (who is using
  `--listen`; e.g. the build system) learns the name of this directory,
  and can get the artifacts from it.
* `.incremental`: similar to `.whole`, but Zig source file contents, and
  anything else which incremental compilation can handle changes for, is
  not included in the cache manifest. We don't need to do the dance
  where the output directory is initially in `tmp/`, because our digest
  is computed entirely from CLI inputs.

To be clear, the difference between `CacheMode.whole` and
`CacheMode.incremental` is unchanged. `CacheMode.none` is new
(previously it was sort of poorly imitated with `CacheMode.whole`). The
defined behavior for temporary/intermediate files is new.

`.none` is used for direct CLI invocations like `zig build-exe foo.zig`.
The other cache modes are reserved for `--listen`, and the cache mode in
use is currently just based on the presence of the `-fincremental` flag.

There are two cases in which `CacheMode.whole` is used despite there
being no `--listen` flag: `zig test` and `zig run`. Unless an explicit
`-femit-bin=xxx` argument is passed on the CLI, these subcommands will
use `CacheMode.whole`, so that they can put the output somewhere without
polluting the cwd (plus, caching is potentially more useful for direct
usage of these subcommands).

Users of `--listen` (such as the build system) can now use
`std.zig.EmitArtifact.cacheName` to find out what an output will be
named. This avoids having to synchronize logic between the compiler and
all users of `--listen`.
2025-06-12 13:55:40 +01:00
mlugg
a0792e743f
incr-check: normalize path separators in file names in errors 2025-05-18 17:10:04 +01:00
mlugg
ed7335ce57
incr-check: support basic modules
Allow specifying modules which the root module depends on. More complex
graphs cannot currently be specified.
2025-05-18 17:10:04 +01: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
mlugg
8c9c24e09b
compiler: integrate @compileLog with incremental compilation
Compile log output is now separated based on the `AnalUnit` which
perfomred the `@compileLog` call, so that we can omit the output for
unreferenced ("dead") units. The units are also sorted when collecting
the `ErrorBundle`, so that compile logs are always printed in a
consistent order, like compile errors are. This is important not only
for incremental compilation, but also for parallel analysis.

Resolves: #23609
2025-04-20 18:11:53 +01:00
David Rubin
35b9db3b15 correct some bugs 2025-02-25 11:22:33 -08:00
mlugg
fcf8d5ada2
incr-check: check compile errors against expected
Also modifies all incremental cases using `#expect_error` to include the
errors and notes which are expected.
2025-01-25 09:32:40 +00:00
mlugg
7ef345f342
incr-check: deal with Windows stupidity
The real problem here is that Git for Windows has horrendous defaults
which convert LF to CRLF. However, rather than changing this
configuration on the CI runners, it's worth supporting inexplicable CRLF
in these files so that anyone else cloning Zig on Windows doesn't get
unexpected test failures.
2025-01-25 08:57:20 +00:00
mlugg
f47b8de2ad
incremental: handle @embedFile
Uses of `@embedFile` register dependencies on the corresponding
`Zcu.EmbedFile`. At the start of every update, we iterate all embedded
files and update them if necessary, and invalidate the dependencies if
they changed.

In order to properly integrate with the lazy analysis model, failed
embed files are now reported by the `AnalUnit` which actually used
`@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`.

An incremental test is added covering incremental updates to embedded
files, and I have verified locally that dependency invalidation is
working correctly.
2025-01-25 06:07:08 +00:00
Jacob Young
dde3116e50
Dwarf: implement new incremental line number update API 2025-01-05 02:20:56 +00:00
mlugg
ada60616b3
incr-check: minor fixes
* fix inconsistency in global cache directory name
* don't error if spawning external executor fails
* handle CRLF correctly
2024-10-05 20:52:26 +01:00
mlugg
dfc0a27090
incr-check: clean up temporary directory by default
The new `--preserve-tmp` flag can be used to preserve the temporary
directory for debugging purposes.
2024-10-05 20:52:26 +01:00
mlugg
5ce962eb69
incr-check: better progress output, support external executors
If no external executor is available for a successful binary, its
execution is silently skipped. This allows the CI to test, to the
fullest extent possible, incremental cross-compilation to targets whose
binaries can't be executed on the host.
2024-10-05 20:52:25 +01:00
mlugg
f60c045cef
tests: add test-incremental step
This is contained in the `test` step, so is tested by CI.

This commit also includes some enhancements to the `incr-check` tool to
make this work correctly.
2024-10-05 20:52:25 +01:00
mlugg
054dbb6798
incr-check: specify backend in manifest, allow multiple targets/backends 2024-09-25 20:39:31 +01:00
Jakub Konka
1714b74edf incr-check: actually handle end message for a compiler update 2024-09-25 17:54:50 +02:00
Jakub Konka
1c2048ebcc incr-check: add --debug-link flag for verbose linker logging 2024-09-25 17:54:50 +02:00
Linus Groh
8588964972 Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
Robin Voetter
43f73af359
fix various issues related to Path handling in the compiler and std
A compilation build step for which the binary is not required could not
be compiled previously. There were 2 issues that caused this:

- The compiler communicated only the results of the emitted binary and
  did not properly communicate the result if the binary was not emitted.

  This is fixed by communicating the final hash of the artifact path (the
  hash of the corresponding /o/<hash> directory) and communicating this
  instead of the entire path. This changes the zig build --listen protocol
  to communicate hashes instead of paths, and emit_bin_path is accordingly
  renamed to emit_digest.

- There was an error related to the default llvm object path when
  CacheUse.Whole was selected. I'm not really sure why this didn't manifest
  when the binary is also emitted.

  This was fixed by improving the path handling related to flush() and
  emitLlvmObject().

In general, this commit also improves some of the path handling throughout
the compiler and standard library.
2024-08-19 19:09:11 +02:00
mlugg
65cbdefe4d tools: add CBE option to incr-check 2024-08-17 18:50:10 -04:00
mlugg
936a79f428 tools,test: improve incr-check and add new incremental tests 2024-08-17 18:50:10 -04:00
mlugg
b65865b027 tools: improve incr-check
And add a new incremental test to match!
2024-08-17 18:50:10 -04:00
Andrew Kelley
645ad1ef72 incr-check: support running the generated binary 2024-07-20 01:06:29 -07:00
Andrew Kelley
9f112ce868 incr-test: running an update 2024-07-20 01:06:29 -07:00
Andrew Kelley
ea2c45227a init incremental compilation check tool 2024-07-20 01:06:29 -07:00