aboutsummaryrefslogtreecommitdiff
path: root/src/Package.zig
AgeCommit message (Collapse)Author
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-06-06Package.Hash.toSlice: consistent pointerAndrew Kelley
Makes the returned pointer always point inside `Hash.bytes` even when it is length zero.
2025-06-06Handle empty hashes in build.zig.zonfardragon
2025-02-26rename "nonce" to "fingerprint"Andrew Kelley
2025-02-26bump package id component to 32 bitsAndrew Kelley
and to make the base64 round even, bump sha256 to 200 bits (up from 192)
2025-02-26switch from "id" to "nonce"Andrew Kelley
mainly this addresses the following use case: 1. Someone creates a template with build.zig.zon, id field included (note that zig init does not create this problem since it generates fresh id every time it runs). 2. User A uses the template, changing package name to "example" but not id field. 3. User B uses the same template, changing package name also to "example", also not changing the id field. Here, both packages have unintentional conflicting logical ids. By making the field a combination of name checksum + random id, this accident is avoided. "nonce" is an OK name for this. Also relaxes errors on remote packages when using `zig fetch`.
2025-02-26Package: update unit tests to new APIAndrew Kelley
2025-02-26introduce package id and redo hash format againAndrew Kelley
Introduces the `id` field to `build.zig.zon`. Together with name, this represents a globally unique package identifier. This field should be initialized with a 16-bit random number when the package is first created, and then *never change*. This allows Zig to unambiguously detect when one package is an updated version of another. When forking a Zig project, this id should be regenerated with a new random number if the upstream project is still maintained. Otherwise, the fork is *hostile*, attempting to take control over the original project's identity. `0x0000` is invalid because it obviously means a random number wasn't used. `0xffff` is reserved to represent "naked" packages. Tracking issue #14288 Additionally: * Fix bad path in error messages regarding build.zig.zon file. * Manifest validates that `name` and `version` field of build.zig.zon are maximum 32 bytes. * Introduce error for root package to not switch to enum literal for name. * Introduce error for root package to omit `id`. * Update init template to generate `id` * Update init template to populate `minimum_zig_version`. * New package hash format changes: - name and version limited to 32 bytes via error rather than truncation - truncate sha256 to 192 bits rather than 40 bits - include the package id This means that, given only the package hashes for a complete dependency tree, it is possible to perform version selection and know the final size on disk, without doing any fetching whatsoever. This prevents wasted bandwidth since package versions not selected do not need to be fetched.
2025-02-26fix generated hash of by-path dependenciesAndrew Kelley
This branch regressed from master by switching to binary rather than hex digest, allowing null bytes to end up in identifiers in the zig file. This commit fixes it by changing the "hash" to be literally equal to the sub_path (with a prefix '/' to indicate "global") if it can fit. If it is too long then it is actually hashed, and that value used instead.
2025-02-26Package: new hash formatAndrew Kelley
legacy format is also supported. closes #20178
2024-04-09fetch: filter unpack errorsIgor Anić
Report only errors which are not filtered by paths in build.zig.zon.
2024-03-21move Package.Path to std.Build.Cache.PathAndrew Kelley
2024-02-26rearrange std.zigAndrew Kelley
This frees up std.zig.fmt to be used for the implementation of `zig fmt`.
2024-01-01compiler: fix UAF when writing builtin.zigAndrew Kelley
2024-01-01fix population of builtin.zig not making the parent dirAndrew Kelley
2023-10-10Package: Fix path separator not being escaped between root_dir and sub_pathRyan Liptak
Fixes a package fetching regression on Windows. Closes #17477
2023-10-08move some package management related source files aroundAndrew Kelley
2023-10-08Package.Fetch: resolve instead of join relative pathsAndrew Kelley
This prevents bogus "error: file exists in multiple modules" errors due to file paths looking like: ``` note: root of module foo/freetype/ note: root of module foo/fontconfig/../freetype/ ``` It also enables checking for dependency paths outside the root package.
2023-10-08finish hooking up new dependency tree logicAndrew Kelley
* add Module instances for each package's build.zig and attach it to the dependencies.zig module with the hash digest hex string as the name. * fix incorrectly skipping the wrong packages for creating dependencies.zig * a couple more renaming of "package" to "module"
2023-10-08fix detection of build.zig file inside packagesAndrew Kelley
2023-10-08make Package.Path support string escape formattingAndrew Kelley
2023-10-08CLI: finish updating module API usageAndrew Kelley
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731. Now the compiler compiles again. Wire up dependency tree fetching code in the CLI for `zig build`. Everything is hooked up except for `createDependenciesModule` is not yet implemented.
2023-10-08get `zig fetch` working with the new systemAndrew Kelley
* start renaming "package" to "module" (see #14307) - build system gains `main_mod_path` and `main_pkg_path` is still there but it is deprecated. * eliminate the object-oriented memory management style of what was previously `*Package`. Now it is `*Package.Module` and all pointers point to externally managed memory. * fixes to get the new Fetch.zig code working. The previous commit was work-in-progress. There are still two commented out code paths, the one that leads to `Compilation.create` and the one for `zig build` that fetches the entire dependency tree and creates the required modules for the build runner.
2023-10-08rework package managerAndrew Kelley
Organize everything around a Fetch task which does a bunch of stuff in a worker thread without touching any shared state, and then queues up Fetch tasks for its dependencies. This isn't the theoretical optimal package fetching performance because CPU cores don't necessarily map 1:1 with I/O tasks, and each fetch task contains a mixture of computations and I/O. However, it is expected for this to significantly outperform master branch, which fetches everything recursively with only one thread. The logic is now a lot more linear and easy to follow. Everything that is embarassingly parallel is done on the thread pool, and then after everything is fetched, the worker threads are joined and the main thread does the finishing touches of stitching together the dependencies.zig import files. There is only one tiny little critical section and it does not even have any error handling in it. This also lays the groundwork for #14281 because in system mode, all this fetching logic will be skipped, but the "finishing touches" mentioned above still need to be done. With this branch, that logic is separated out and no longer recursively tangled with fetching stuff. Additionally, this branch: * Implements inclusion directives in `build.zig.zon` for deciding which files belong the package (#14311). * Adds basic documentation for `build.zig.zon` files. * Adds support for fetching dependencies with the `file://` protocol scheme (#17364). * Adds a workaround for a Linux/btrfs file system bug (#17282). This commit is a work-in-progress. Still todo: 1. Hook up the CLI to the new system. 2. Restore the module table creation logic after all the fetching is done. 3. Fix compilation errors, get the tests passing, and regression test against real world projects.
2023-10-02Support symlinks for git+http(s) dependenciesIan Johnson
2023-10-02zig fetch: enhanced error reportingAndrew Kelley
* Package: use std.tar diagnostics to give detailed error messages * std.tar: add diagnostic for unsupported file type
2023-10-02introduce the 'zig fetch' command + symlink supportAndrew Kelley
zig fetch [options] <url> zig fetch [options] <path> Fetches a package which is found at <url> or <path> into the global cache directory, printing the package hash to stdout. Closes #16972 Related to #14280 Additionally, this commit: * Adds uncompressed .tar support to package fetching * Introduces symlink support to package fetching
2023-10-02compiler: extract package hashing logic to separate fileAndrew Kelley
There are no functional changes in this commit.
2023-09-30Support fetching dependencies over git+http(s)Ian Johnson
Closes #14298 This commit adds support for fetching dependencies over git+http(s) using a minimal implementation of the Git protocols and formats relevant to fetching repository data. Git URLs can be specified in `build.zig.zon` as follows: ```zig .xml = .{ .url = "git+https://github.com/ianprime0509/zig-xml#7380d59d50f1cd8460fd748b5f6f179306679e2f", .hash = "122085c1e4045fa9cb69632ff771c56acdb6760f34ca5177e80f70b0b92cd80da3e9", }, ``` The fragment part of the URL may specify a commit ID (SHA1 hash), branch name, or tag. It is an error to omit the fragment: if this happens, the compiler will prompt the user to add it, using the commit ID of the HEAD commit of the repository (that is, the latest commit of the default branch): ``` Fetch Packages... xml... /var/home/ian/src/zig-gobject/build.zig.zon:6:20: error: url field is missing an explicit ref .url = "git+https://github.com/ianprime0509/zig-xml", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ note: try .url = "git+https://github.com/ianprime0509/zig-xml#dfdc044f3271641c7d428dc8ec8cd46423d8b8b6", ``` This implementation currently supports only version 2 of Git's wire protocol (documented in [protocol-v2](https://git-scm.com/docs/protocol-v2)), which was first introduced in Git 2.19 (2018) and made the default in 2.26 (2020). The wire protocol behaves similarly when used over other transports, such as SSH and the "Git protocol" (git:// URLs), so it should be reasonably straightforward to support fetching dependencies from such URLs if the necessary transports are implemented (e.g. #14295).
2023-09-29Extract logic for directory packagesAdam Goertz
In addition to improving readability, this also fixes a subtle bug where the Progress node could display the wrong total number of packages to fetch.
2023-09-29Fix diamond dependencies with directory packagesAdamGoertz
2023-09-29Purge absolute paths and remove unneeded path processingAdamGoertz
No need to create paths with windows-specific path separators
2023-09-29Allow only relative paths.Adam Goertz
This commit makes the following changes: * Disallow file:/// URIs * Allow only relative paths in the .path field of build.zig.zon * Remote now-unneeded shlwapi dependency
2023-09-29Support file:/// URIs and relative pathsAdam Goertz
2023-09-28std.http: introduce options to http client to allow for raw urisEmil Lerch
Addresses #17015 by introducing a new startWithOptions. The only option is currently is a flag to use the provided URI as is, without modification when passed to the server. Normally, this is not needed nor desired. However, some REST APIs may have requirements that cannot be satisfied with the default handling.
2023-09-24Support non zig dependenciesantlilja
Dependencies no longer require a build.zig file. Adds path function to Dependency struct which returns a LazyPath into a dependency.
2023-09-15package manager: write deps in a flat format, eliminating the FQN conceptmlugg
The new `@depedencies` module contains generated code like the following (where strings like "abc123" represent hashes): ```zig pub const root_deps = [_]struct { []const u8, []const u8 }{ .{ "foo", "abc123" }, }; pub const packages = struct { pub const abc123 = struct { pub const build_root = "/home/mlugg/.cache/zig/blah/abc123"; pub const build_zig = @import("abc123"); pub const deps = [_]struct { []const u8, []const u8 }{ .{ "bar", "abc123" }, .{ "name", "ghi789" }, }; }; }; ``` Each package contains a build root string, the build.zig import, and a mapping from dependency names to package hashes. There is also such a mapping for the root package dependencies. In theory, we could now remove the `dep_prefix` field from `std.Build`, since its main purpose is now handled differently. I believe this is a desirable goal, as it doesn't really make sense to assign a single FQN to any package (because it may appear in many different places in the package hierarchy). This commit does not remove that field, as it's used non-trivially in a few places in the build runner and compiler tests: this will be a future enhancement. Resolves: #16354 Resolves: #17135
2023-08-27std: Rename `TailQueue` to `DoublyLinkedList`Jay Petacat
`TailQueue` was implemented as a doubly-linked list, but named after an abstract data type. This was inconsistent with `SinglyLinkedList`, which can be used to implement an abstract data type, but is still named after the implementation. Renaming `TailQueue` to `DoublyLinkedList` improves consistency between the two type names, and should help discoverability. `TailQueue` is now a deprecated alias of `DoublyLinkedList`. Related to issues #1629 and #8233.
2023-07-25Package: add progress indicator for package fetchingmlugg
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-03fix missing insertion of module to all_modules on first downloadDraagrenKirneh
2023-05-25std.fs.file: Rename File.Kind enum values to snake caseLinus Groh
2023-05-24Improve Content-Disposition filename detection (#15844)DraagrenKirneh
2023-05-23std.sort: add pdqsort and heapsortAli Chraghi
2023-05-18Only add build.zig module dependencies oncemlugg
2023-05-18Deduplicate uses of the same package across dependenciesmlugg
2023-05-15Package: support gitlab tarball urlsTravis Staloch
Allows the package manager to download gitlab tarballs from urls such as https://gitlab.com/<namespace>/<project>/-/archive/<sha>/<project>-<sha>.tar.gz Such http requests have headers Content-Type=application/octet-stream and Content-Disposition='attachment; filename="<project>-<sha>.tar.gz"'. The package manager doesn't yet support these headers. This patch doesn't attempt to properly parse the content-disposition header. Instead it checks that it starts with 'attachment;' and ends with '.tar.gz"'.
2023-05-13Improve error handling on dependency download (#15661)DraagrenKirneh
verify ok status on response. improve error messages
2023-05-13add application/tar+gzip unblocking sr.ht packagesSimon A. Nielsen Knights