319 Commits
Author SHA1 Message Date
Ryan Liptak 723085b9bf Build: fetch pending lazy dependencies and retry when artifact/etc is not found
Before the changes in this commit, the intention was to gather all pending lazy dependencies of all package scripts, and then only handle fetching after the root package script exits. However, that's not always feasible, since it's possible for a lazy dependency to depend on a lazy dependency, which means that the first fetch-and-retry can only know about the root's lazy dependencies. Then, during the second attempt at configuring, the root package script will see its lazy dependency as available, but in reality that dependency's package script may return error.LazyDependencyNeeded, which won't matter until *after* the root package script has finished running. Therefore, the root package script will continue running as if its lazy dependency is fully available, when in reality it has requested a fetch-and-retry.

This means that something like an `artifact` call in the root package script that depends on a lazy dependency of a lazy dependency will fail after the first fetch-and-retry, because the necessary remaining pending lazy dependencies would only get fetched once the root script finished.

In case it's helpful, the reproduction looks something like this:

root
└─ child1 (.lazy = true, gotten in root's build.zig via either `dependency` or `try dependencyLazy`)
   └─ child2 (.lazy = true, gotten in child1's build.zig via `try dependencyLazy`)

To fix this, whenever an artifact/module/etc is looked up and not found while there are pending lazy dependencies, we now immediately exit, fetch, and retry, since that artifact/module/etc could only exist after one of those pending lazy dependencies is made available (i.e. the dependency's configuration stopped part-way due to a missing lazy dependency).

Before (fails):

> zig build
debug(fetch): FileNotFound: zig-pkg\zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN.tar.gz
debug: configuration cache incomplete_manifest
info: fetching lazy dependency zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: zig-pkg\zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN.tar.gz
debug(fetch): FileNotFound: zig-pkg\zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx.tar.gz
debug: configuration cache incomplete_manifest
panic: unable to find artifact "zig_test_repo1_lib"

After (succeeds):

> zig build
debug(fetch): FileNotFound: zig-pkg\zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN.tar.gz
debug: configuration cache incomplete_manifest
info: fetching lazy dependency zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: zig-pkg\zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo1-0.0.0-FuDjYawXAAAK0sFpnAa7IPMoTJpCs44sgfKP7ZBi3oAN.tar.gz
debug(fetch): FileNotFound: zig-pkg\zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx.tar.gz
debug: configuration cache incomplete_manifest
info: fetching lazy dependency zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx
debug(fetch): FileNotFound: zig-pkg\zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx
debug(fetch): FileNotFound: C:\Users\Ryan\AppData\Local\zig\p/zig_test_repo2-0.0.0-eVW_ihsPAAAmwffTitFedoK7HGHiRfQTshvARXs0-qJx.tar.gz
debug: configuration cache incomplete_manifest
2026-10-24 23:10:20 +02:00
Ryan Liptak be69013825 Build.declareDependency{Step}: only populate unlazy_deps when the package is not available
The logic in Maker expects unlazy_deps to only be populated for deps that need to be fetched. Without this check, declareDependency/declareDependencyStep could lead to an infinite fetch-and-retry loop.
2026-10-23 17:15:17 -07:00
Matthew Lugg 067f8dcb37 std.Build.Cache: support depending on nonexistent file/directory 2026-10-19 18:30:35 +01:00
Andrew Kelley 21141cb88a Revert "allow standardOptimizeOption to return null"
This reverts commit aa8c774e0f.

In retrospect, the breaking change is quite invasive and I don't think
we have fully considered the alternatives.
2026-10-17 12:25:32 -07:00
Isaac Freund f2f0d97a9b std.Build.Configuration: add $DESTDIR-relative LazyPaths
The new deployed_prefix and related paths exist to support the use-case
of embedding absolute paths to other build artifacts in the build
artifacts themselves. For example pkg-config files are artifacts which
must contain absolute paths to the other library/header artifacts they
describe. Note that this feature is only supported to faciliate
interoperability with such legacy systems. In general, embedding
absolute paths in build artifacts should be avoided.

This patch also fixes a bug: currently passing an absolute path to
e.g. --prefix-lib-dir will cause $DESTDIR to be ignored for build
artifacts installed to that path.

I'm not entirely satisfied with the new "deployed" naming convention,
I want to avoid the breaking change of renaming "installed" to something
else and this is the best option I came up with.

Closes: https://codeberg.org/ziglang/zig/issues/37124
2026-10-17 20:12:39 +02:00
Andrew Kelley 2c18bccf44 std.Build: lazy dependencies can associate with steps
and serialize the configuration
2026-10-15 16:00:57 -07:00
Kendall Condon aa8c774e0f allow standardOptimizeOption to return null
In order to allow the compiler to default to ReleaseSafe when compiling
for fuzzing, Build.standardOptimizeOption has been changed to return an
optional value.
2026-10-09 10:14:16 +02:00
Jacob Young 4dd645fddd Runner: add --libc-runtimes support 2026-09-26 19:08:50 -04:00
Jacob Young 11958a306f test: implement new runner 2026-09-26 19:08:50 -04:00
Andrew Kelley d142f63f89 std.Build.Cache: fix adding files
no longer adding unwanted padding bytes
2026-09-16 13:12:47 -07:00
Andrew Kelley ec7805b867 WIP: rework std.Build.Cache
- implement std.Build functions:
  - `dependOnDirectoryMetadata`
  - `dependOnDirectoryContents`
  - `dependOnFileMetadata`
  - `dependOnFileContents`
- switch cache manifest to binary format. saves about 25% of file size,
  which is not a ton, but this is in the really hot path, so any amount
  we can reduce file system cache pressure is going to help a lot.
  - also means saving and loading is simpler - just copying bytes in and
    out of memory plus a tiny bit of validation.
- batch cache manifest memory allocations together. one big allocation
  for the entire manifest file contents, with the files hash map only
  tracking starting offsets for each entry, and the input files as a
  simple array list with the extra information needed for input files
  (so they can be lazily loaded only on cache miss)
- remove the manifest file size limit
- input files that have requested content to be loaded is loaded
  together into one big allocation rather than separately tracked.
- each file entry in the cache now tracks two additional bits:
  - kind: file or directory
  - tracking mode: contents or metadata
    - when tracking a directory, "contents" are considered to be the
      sorted list of file names contained in the directory (non recursive)
- rename "hit" to "check" and make it return enum instead of bool
- merge most "add...File" function variants together into one that has
  an "options bag" parameter.
- take advantage of async I/O when checking for cache hit to compute
  hashes concurrently. Care is taken to never cancel useful work, and
  never wait for unnecessary work to complete.

bonus:
- build.zig: use std.log for printing log messages
2026-09-16 13:12:46 -07:00
K4 2c93c6e91b std.lang.OptimizeMode -> std.lang.Optimize migration progress 2026-08-23 14:30:48 +02:00
Andrew Kelley e0f7e43a54 build system: rework user input options
followups from 8e48a5c524 along with
other related changes.

- user input options should not be serialized into Configuration.
- more helpful log messages when invalid -D arguments are provided
- use array hash maps in various places, simplifying iteration and
  sorting.
- when creating a package instance, sort the user input options once,
  before the lookup, rather than creating a fresh hash map and sorting
  it on every call to hash (wtf!)
  - when sorting, don't use ascii case insensitivity (wtf!!)
- simplify the detection of invalid arguments passed to zig build
- use package hash rather than file system path in package instance key
2026-08-13 23:40:03 -07:00
hemisputnik 3d50222f9b std.Build.Configuration: reintroduce serialization of std.Build instances 2026-08-10 11:20:19 +03:00
Andrew Kelley 8380531aec Merge pull request 'Serialize packages and root dependencies into configuration file' (#36419) from hemisputnik/zig:work/36387-configuration-deps into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36419
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-08-08 21:48:00 +02:00
Andrew Kelley 8dfddf95fe std.meta: deprecate fieldInfo, fieldNames, fieldTypes
Technically there is one valid use case for `fieldNames` which is use
with an enum or union so that those types can be used interchangeably.
But in practice these functions are mainly abused, because the callsites
always know what kind of type it is.

This commit encourages Zig users to embrace using `@typeInfo` directly
when doing type reflection.
2026-08-08 19:15:10 +02:00
hemisputnik 0f332fd536 std.Build.Configuration: serialize packages and their dependencies
The serializer now traverses the builder's available_deps and their
dependencies recursively, and serializes them into Configuration.packages.
2026-08-08 09:02:31 +03:00
Andrew Kelley 8bf3941f6b std.Build: remove dead fields
These were originally intended to tell the configure script whether or
not those third party integrations were enabled.

This is now a problem because we want to produce a configuration file
that is indendent of whether such external integrations will be enabled,
so that the logic does not need to be re-executed when those flags are
changed on the command line.

If we wish to make this feature interact with the configure script, let
us consider carefully how to add it in a future enhancement, and not
leave these dead fields sitting around in the meantime.

closes #35607
2026-08-07 11:19:55 -07:00
Krzysztof Wolicki ab4028d579 Update usages of most deprecated APIs
In particular renames of `std.mem.indexOf` family to `std.mem.find`
and generic unmanaged containers
2026-08-05 03:40:30 +02:00
Andrew Kelley ae4e835a66 std.lang: rename OptimizeMode to Optimize
and remove "release" from the enum tag names.

no functional change, however, despite the addition of
backwards-compatibile declarations in this patch, it is breaking because
expressions that use `==` or `!=` operators will not able to use the
deprecated names.

I predict these names to survive until the 1.0 tag without any more
breakage.
2026-07-20 17:26:50 -07:00
Justus Klausecker 69a26976ed zig fmt
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the
new `@backingInt` and `@fromBackingInt` builtins.
2026-07-17 23:30:26 +02:00
John Benediktsson f2c9e7a5c9 std.Build: cache package_map to improve dependency resolution 2026-07-08 03:35:02 +02:00
Andrew Kelley 554172e625 std.Build: restore dependency function
Now it supports lazy dependencies and if it needs to be fetched then it
will serialize the configuration and early-exit.
2026-07-01 14:35:04 -07:00
Andrew Kelley dc5feb49eb std.Build.serializeConfigurationExiting: extract from configurer 2026-07-01 14:19:42 -07:00
Andrew Kelley 8923dd4ca2 move main configurer logic to std.Build.Serialize 2026-07-01 14:15:31 -07:00
Andrew Kelley ca948d62d0 std.Build: deprecate lazyDependency and dependency
in favor of dependencyLazy which has a different function signature and
will be eventually renamed to dependency

migrating to all dependencies being potentially lazy by setting the flag
in build.zig.zon and embracing error.LazyDependencyNeeded propagation as
the way to deal with discovered needed dependencies.

solves the problem that handling the `null` case from `lazyDependency`
was annoying.
2026-07-01 14:02:31 -07:00
Andrew Kelley a30f029d53 std.Build: ignore configuration failure when lazy deps exist 2026-07-01 13:36:54 -07:00
Andrew Kelley 23a4fc3db7 std.Build: recognize error.LazyDependencyNeeded
when running user build functions. This makes control flow a lot easier
to manage for lazy dependencies.
2026-07-01 13:20:56 -07:00
Ryan Liptak 28e367f446 Build: mark Windows resource compilation stuff as deprecated
In preparation for https://codeberg.org/ziglang/zig/issues/31951
2026-07-01 10:24:02 +02:00
Andrew Kelley 779b6cc63c Maker: partially implement configurer cache invalidation
progress towards #35473
2026-06-29 23:50:20 -07:00
Andrew Kelley 3b2af05df1 std.Build: prefer {q} over '{s}' 2026-06-29 23:50:20 -07:00
Andrew Kelley a04f90c35b introduce std.Build API for making configure script depend on fs 2026-06-29 23:50:18 -07:00
Andrew Kelley 6a052277c3 std.Build: document a handful of functions 2026-06-29 23:50:18 -07:00
Techatrix d95dcb2a62 std.Build.Step.Compile: remove setExecCmd
This function can be used to prepend a list of arguments when running a
test step. Instead, the additional arguments should be manually added to
the run step which can handle a broader set of use cases.
2026-06-24 20:57:36 +02:00
Carl Åstholm e636825f01 std.Build.Step.Fmt: dupe lazy path lists 2026-06-11 16:48:13 +02:00
Andrew Kelley b28460b499 Merge pull request 'Rename usages of all deprecated ArrayHashMapUnmanaged to array_hash_map' (#35470) from kada49/zig:array_hash_map_deprecation_rename into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35470
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-06-11 05:59:44 +02:00
David Senoner d23e22c416 Replace usages of StringArrayHashMapUnmanaged with array_hash_map.String 2026-06-10 16:14:53 +02:00
Ryan Liptak 1042cbe010 Build: fix tryFindProgram on Windows and reintroduce ref in test block
Also reduce the amount of unnecessary allocations, since one buffer can be used for appending all supported PATHEXT extensions

Fixes #35668
2026-06-07 23:27:01 -07:00
Ryan Liptak be07f95cd7 Configuration: fix loadBits/storeBits on big endian architectures
Fixes #35669
2026-06-07 23:27:00 -07:00
Alex Rønne Petersen 23f46bcd4d Partially revert "add missing param to mem.concat call"
This partially reverts commit af27e8d06f.

This broke two platforms:

* s390x-linux: It caused the `loadBits and storeBits` test to be analyzed and
  run, and that test looks to me to be bogus on big endian.
* x86_64-windows: `tryFindProgram` is not fallible, yet the Windows code uses
  `try`, so making it get analyzed exposed another compile error.

Reverting the analysis of `findProgram` for now to unbreak master and a number
of PRs, but we should still urgently fix both of these issues.
2026-06-07 18:37:18 +02:00
Kirk Scheibelhut af27e8d06f add missing param to mem.concat call
also ensure findProgram actually gets analyzed
2026-06-06 21:28:49 -07:00
mlugg 3f1dead2fc Merge pull request 'Use struct-of-arrays style for std.lang.Type' (#35234) from Der_Teufel/zig:soa-builtin-type into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35234
2026-05-28 09:45:54 +02:00
Techatrix ea044a4b82 std.Build: do not clobber properties of a package like named modules
Repeated calls to `addModule` with the same name will override the
module that is visible to dependants which is likely unintentional.
Instead it should assert that no existing module has already been added
with the given name.

The same issue applies to `addNamedWriteFiles` and `addNamedLazyPath`.
2026-05-27 18:54:08 +02:00
Krzysztof Wolicki 9e80795623 all: update to use new std.lang.Type definitions 2026-05-27 10:03:51 +01:00
pentuppup e4512531d5 fix some missed errors from build system rework 2026-05-27 02:18:25 +02:00
Sertonix 8455563ed8 Fix build script compilation when usize is u32
On 32-bit systems usize is not u64 but it was assumed in multiple places
of the build script.

Sometimes using u64 instead of usize since available and used memory can
exceed usize on 32-bit systems (just like totalSystemMemory)

Example errors:

lib/compiler/build_runner.zig:508:26: error: expected type 'usize', found 'u64'
        .available_rss = max_rss,
                         ^~~~~~~
lib/compiler/build_runner.zig:508:26: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values
referenced by:
    callMain [inlined]: lib/std/start.zig:699:88
    callMainWithArgs [inlined]: lib/std/start.zig:638:20
    posixCallMainAndExit: lib/std/start.zig:590:38
    2 reference(s) hidden; use '-freference-trace=5' to see all references
lib/std/Build/WebServer.zig:849:38: error: expected type 'usize', found 'u64'
    const buf = gpa.realloc(old_buf, new_len) catch @panic("out of memory");
                                     ^~~~~~~
lib/std/Build/WebServer.zig:849:38: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values
lib/std/mem/Allocator.zig:399:58: note: parameter type declared here
pub fn realloc(self: Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(old_mem) {
                                                         ^~~~~
build.zig:548:10: error: type 'usize' cannot represent integer value '9300000000'
        .max_rss = 9_300_000_000,
        ~^~~~~~~~~~~~~~~~~~~~~~~
build.zig:778:10: error: type 'usize' cannot represent integer value '8000000000'
        .max_rss = 8_000_000_000,
        ~^~~~~~~~~~~~~~~~~~~~~~~
2026-05-26 09:43:39 -07:00
Andrew Kelley 19c63406d4 LazyPath: store relative paths as actual strings 2026-05-25 18:54:37 -07:00
Andrew Kelley 9eb85c4e5e build system: track TODOs outside source code
related to #363
2026-05-25 18:54:36 -07:00
Andrew Kelley 9a788dccf8 std.Build.lazyImport: fix compilation errors 2026-05-25 18:54:36 -07:00
Andrew Kelley 92038675af zig build: implement findProgram (not lazy) 2026-05-25 18:54:36 -07:00