32 Commits

Author SHA1 Message Date
Andrew Kelley
b9f75a39d3 Package.Manifest: fix error message for paths
closes #17491
2023-10-12 10:47:22 -07:00
Andrew Kelley
1d1e5a8617 Package.Fetch: fix empty path and "." not including all
Related to #17491
2023-10-12 10:47:22 -07:00
Krzysztof Wolicki
8c6b0271cc Package.Fetch: wrap operations involving tmp_directory in a block
This makes tmp_directory close before calling renameTmpIntoCache which fixes occurences of those AccessDenied errors that aren't synonymous with PathAlreadyExists on Windows
2023-10-11 20:28:07 -07:00
Andrew Kelley
2ca7cc46c4 Package.Fetch: fix inclusions not working for directories
Oops, the loop was checking the wrong variable! Added a unit test.
2023-10-10 02:29:29 -07:00
Andrew Kelley
fa08e49f83 Package.Fetch: allow relative paths outside project root
Only for packages that come from the main package. Fetched packages
still cannot depend on paths outside their package root.
2023-10-09 22:01:18 -07:00
Andrew Kelley
95907cb795 restore progress reporting for package fetching 2023-10-08 21:14:30 -07:00
Andrew Kelley
5eb5d523b5 give modules friendly names for error reporting 2023-10-08 20:58:04 -07:00
Andrew Kelley
cd4397783f Package.Fetch: improved deletion algorithm
Instead of every file deletion being followed by a recursive attempt to
remove the parent directory, while walking the directory, every
directory that will have nonzero files deleted from it is tracked in an
array hash map.

After all the threads have finished deleting and hashing, the parent
thread sorts the "suspicious" directories by length, descending,
ensuring that children appear before parents, and then iterates over the
array hash map, attempting a rmdir operation on each. Any rmdir that
succeeds appends the parent directory to the map so that it will be
removed if empty.
2023-10-08 20:03:40 -07:00
Andrew Kelley
4a2cf38844 Package.Fetch: apply inclusion rules from build.zig.zon 2023-10-08 19:29:17 -07:00
Andrew Kelley
5e7c44a321 Package.Fetch: tighten up check for path outside root 2023-10-08 17:42:49 -07:00
Andrew Kelley
6d84caf727 move some package management related source files around 2023-10-08 17:29:55 -07:00
Andrew Kelley
7bae6d9064 fix dependencies.zig generation with no dependencies 2023-10-08 17:26:02 -07:00
Andrew Kelley
f0cc6f17a0 Package.Fetch: fix not making directory paths for symlinks 2023-10-08 17:21:08 -07:00
Andrew Kelley
1ad33f53fe give build.zig modules access to their dependencies' build.zig modules 2023-10-08 16:54:31 -07:00
Andrew Kelley
47a413361d Package.Fetch: fix handling of relative paths 2023-10-08 16:54:31 -07:00
Andrew Kelley
1fd95fc005 Package.Fetch: resolve instead of join relative paths
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-08 16:54:31 -07:00
Andrew Kelley
29156de120 CLI: fix only_core_functionality logic 2023-10-08 16:54:31 -07:00
Andrew Kelley
b2fefc8473 dependencies.zig: omit deps without hashes 2023-10-08 16:54:31 -07:00
Andrew Kelley
7b25d050e6 std.tar: fix creation of symlinks with omit_empty_directories 2023-10-08 16:54:31 -07:00
Andrew Kelley
e5c2a7dbca finish hooking up new dependency tree logic
* 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-08 16:54:31 -07:00
Andrew Kelley
a232f7e8ec finish implementing the auto-generated dependencies.zig module 2023-10-08 16:54:31 -07:00
Andrew Kelley
e86b7fcca3 fix detection of build.zig file inside packages 2023-10-08 16:54:31 -07:00
Andrew Kelley
4eb7b61daa package fetching: generate dependencies.zig file
Only problem is that it looks like `has_build_zig` is being false when
it should be true.

After that is fixed then main.zig needs to create the `@dependencies`
module from the generated source code.
2023-10-08 16:54:31 -07:00
Andrew Kelley
1ca4428324 fix recursive package fetching logic
For path-relative dependencies, they always need to be added to the hash
table at the end. For remote dependencies, they never need to be added.
2023-10-08 16:54:31 -07:00
Andrew Kelley
ddb7c40037 fix inverted logic for allowing/disallowing paths field 2023-10-08 16:54:31 -07:00
Andrew Kelley
aed6adb6e9 fix Fetch.JobQueue.consolidateErrors 2023-10-08 16:54:31 -07:00
Andrew Kelley
f708c5fafc CLI: finish updating module API usage
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-08 16:54:31 -07:00
Andrew Kelley
1c0d6f9c00 require inclusion directives in root manifest but not deps
see #14311
2023-10-08 16:54:31 -07:00
Andrew Kelley
d0bcc390e8 get zig fetch working with the new system
* 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-08 16:54:31 -07:00
Andrew Kelley
88bbec8f9b rework package manager
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-08 16:54:31 -07:00
Andrew Kelley
ef9966c985 introduce the 'zig fetch' command + symlink support
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-02 17:02:25 -07:00
Andrew Kelley
a4352982b3 compiler: extract package hashing logic to separate file
There are no functional changes in this commit.
2023-10-02 17:02:24 -07:00