diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-05-04 17:02:25 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-05-18 17:37:02 +0100 |
| commit | 37a9a4e0f16c1df8de3a4add3a9566b24f024a95 (patch) | |
| tree | 0fc8f1fc15193e8e3c3ccd5e97408cef7372f394 /src/libs | |
| parent | d32829e053af2a0f382d4d692ede85c176c9f803 (diff) | |
| download | zig-37a9a4e0f16c1df8de3a4add3a9566b24f024a95.tar.gz zig-37a9a4e0f16c1df8de3a4add3a9566b24f024a95.zip | |
compiler: refactor `Zcu.File` and path representation
This commit makes some big changes to how we track state for Zig source
files. In particular, it changes:
* How `File` tracks its path on-disk
* How AstGen discovers files
* How file-level errors are tracked
* How `builtin.zig` files and modules are created
The original motivation here was to address incremental compilation bugs
with the handling of files, such as #22696. To fix this, a few changes
are necessary.
Just like declarations may become unreferenced on an incremental update,
meaning we suppress analysis errors associated with them, it is also
possible for all imports of a file to be removed on an incremental
update, in which case file-level errors for that file should be
suppressed. As such, after AstGen, the compiler must traverse files
(starting from analysis roots) and discover the set of "live files" for
this update.
Additionally, the compiler's previous handling of retryable file errors
was not very good; the source location the error was reported as was
based only on the first discovered import of that file. This source
location also disappeared on future incremental updates. So, as a part
of the file traversal above, we also need to figure out the source
locations of imports which errors should be reported against.
Another observation I made is that the "file exists in multiple modules"
error was not implemented in a particularly good way (I get to say that
because I wrote it!). It was subject to races, where the order in which
different imports of a file were discovered affects both how errors are
printed, and which module the file is arbitrarily assigned, with the
latter in turn affecting which other files are considered for import.
The thing I realised here is that while the AstGen worker pool is
running, we cannot know for sure which module(s) a file is in; we could
always discover an import later which changes the answer.
So, here's how the AstGen workers have changed. We initially ensure that
`zcu.import_table` contains the root files for all modules in this Zcu,
even if we don't know any imports for them yet. Then, the AstGen
workers do not need to be aware of modules. Instead, they simply ignore
module imports, and only spin off more workers when they see a by-path
import.
During AstGen, we can't use module-root-relative paths, since we don't
know which modules files are in; but we don't want to unnecessarily use
absolute files either, because those are non-portable and can make
`error.NameTooLong` more likely. As such, I have introduced a new
abstraction, `Compilation.Path`. This type is a way of representing a
filesystem path which has a *canonical form*. The path is represented
relative to one of a few special directories: the lib directory, the
global cache directory, or the local cache directory. As a fallback, we
use absolute (or cwd-relative on WASI) paths. This is kind of similar to
`std.Build.Cache.Path` with a pre-defined list of possible
`std.Build.Cache.Directory`, but has stricter canonicalization rules
based on path resolution to make sure deduplicating files works
properly. A `Compilation.Path` can be trivially converted to a
`std.Build.Cache.Path` from a `Compilation`, but is smaller, has a
canonical form, and has a digest which will be consistent across
different compiler processes with the same lib and cache directories
(important when we serialize incremental compilation state in the
future). `Zcu.File` and `Zcu.EmbedFile` both contain a
`Compilation.Path`, which is used to access the file on-disk;
module-relative sub paths are used quite rarely (`EmbedFile` doesn't
even have one now for simplicity).
After the AstGen workers all complete, we know that any file which might
be imported is definitely in `import_table` and up-to-date. So, we
perform a single-threaded graph traversal; similar to what
`resolveReferences` plays for `AnalUnit`s, but for files instead. We
figure out which files are alive, and which module each file is in. If a
file turns out to be in multiple modules, we set a field on `Zcu` to
indicate this error. If a file is in a different module to a prior
update, we set a flag instructing `updateZirRefs` to invalidate all
dependencies on the file. This traversal also discovers "import errors";
these are errors associated with a specific `@import`. With Zig's
current design, there is only one possible error here: "import outside
of module root". This must be identified during this traversal instead
of during AstGen, because it depends on which module the file is in. I
tried also representing "module not found" errors in this same way, but
it turns out to be much more useful to report those in Sema, because of
use cases like optional dependencies where a module import is behind a
comptime-known build option.
For simplicity, `failed_files` now just maps to `?[]u8`, since the
source location is always the whole file. In fact, this allows removing
`LazySrcLoc.Offset.entire_file` completely, slightly simplifying some
error reporting logic. File-level errors are now directly built in the
`std.zig.ErrorBundle.Wip`. If the payload is not `null`, it is the
message for a retryable error (i.e. an error loading the source file),
and will be reported with a "file imported here" note pointing to the
import site discovered during the single-threaded file traversal.
The last piece of fallout here is how `Builtin` works. Rather than
constructing "builtin" modules when creating `Package.Module`s, they are
now constructed on-the-fly by `Zcu`. The map `Zcu.builtin_modules` maps
from digests to `*Package.Module`s. These digests are abstract hashes of
the `Builtin` value; i.e. all of the options which are placed into
"builtin.zig". During the file traversal, we populate `builtin_modules`
as needed, so that when we see this imports in Sema, we just grab the
relevant entry from this map. This eliminates a bunch of awkward state
tracking during construction of the module graph. It's also now clearer
exactly what options the builtin module has, since previously it
inherited some options arbitrarily from the first-created module with
that "builtin" module!
The user-visible effects of this commit are:
* retryable file errors are now consistently reported against the whole
file, with a note pointing to a live import of that file
* some theoretical bugs where imports are wrongly considered distinct
(when the import path moves out of the cwd and then back in) are fixed
* some consistency issues with how file-level errors are reported are
fixed; these errors will now always be printed in the same order
regardless of how the AstGen pass assigns file indices
* incremental updates do not print retryable file errors differently
between updates or depending on file structure/contents
* incremental updates support files changing modules
* incremental updates support files becoming unreferenced
Resolves: #22696
Diffstat (limited to 'src/libs')
| -rw-r--r-- | src/libs/freebsd.zig | 38 | ||||
| -rw-r--r-- | src/libs/glibc.zig | 48 | ||||
| -rw-r--r-- | src/libs/libcxx.zig | 36 | ||||
| -rw-r--r-- | src/libs/libtsan.zig | 32 | ||||
| -rw-r--r-- | src/libs/libunwind.zig | 13 | ||||
| -rw-r--r-- | src/libs/mingw.zig | 46 | ||||
| -rw-r--r-- | src/libs/musl.zig | 37 | ||||
| -rw-r--r-- | src/libs/wasi_libc.zig | 54 |
8 files changed, 130 insertions, 174 deletions
diff --git a/src/libs/freebsd.zig b/src/libs/freebsd.zig index c7365ede4a..07ad3ee857 100644 --- a/src/libs/freebsd.zig +++ b/src/libs/freebsd.zig @@ -34,7 +34,7 @@ pub fn needsCrt0(output_mode: std.builtin.OutputMode) ?CrtFile { fn includePath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { return path.join(arena, &.{ - comp.zig_lib_directory.path.?, + comp.dirs.zig_lib.path.?, "libc" ++ path.sep_str ++ "include", sub_path, }); @@ -42,7 +42,7 @@ fn includePath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]co fn csuPath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { return path.join(arena, &.{ - comp.zig_lib_directory.path.?, + comp.dirs.zig_lib.path.?, "libc" ++ path.sep_str ++ "freebsd" ++ path.sep_str ++ "lib" ++ path.sep_str ++ "csu", sub_path, }); @@ -50,7 +50,7 @@ fn csuPath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const fn libcPath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { return path.join(arena, &.{ - comp.zig_lib_directory.path.?, + comp.dirs.zig_lib.path.?, "libc" ++ path.sep_str ++ "freebsd" ++ path.sep_str ++ "lib" ++ path.sep_str ++ "libc", sub_path, }); @@ -438,11 +438,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye // Use the global cache directory. var cache: Cache = .{ .gpa = gpa, - .manifest_dir = try comp.global_cache_directory.handle.makeOpenPath("h", .{}), + .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}), }; cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); - cache.addPrefix(comp.zig_lib_directory); - cache.addPrefix(comp.global_cache_directory); + cache.addPrefix(comp.dirs.zig_lib); + cache.addPrefix(comp.dirs.global_cache); defer cache.manifest_dir.close(); var man = cache.obtain(); @@ -452,7 +452,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye man.hash.add(target.abi); man.hash.add(target_version); - const full_abilists_path = try comp.zig_lib_directory.join(arena, &.{abilists_path}); + const full_abilists_path = try comp.dirs.zig_lib.join(arena, &.{abilists_path}); const abilists_index = try man.addFile(full_abilists_path, abilists_max_size); if (try man.hit()) { @@ -461,7 +461,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest), }, }); @@ -470,9 +470,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye const digest = man.final(); const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); - var o_directory: Compilation.Directory = .{ - .handle = try comp.global_cache_directory.handle.makeOpenPath(o_sub_path, .{}), - .path = try comp.global_cache_directory.join(arena, &.{o_sub_path}), + var o_directory: Cache.Directory = .{ + .handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}), + .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}), }; defer o_directory.handle.close(); @@ -974,7 +974,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "stdthreads", etc. const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable; try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items }); - try buildSharedLib(comp, arena, comp.global_cache_directory, o_directory, asm_file_basename, lib, prog_node); + try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node); } man.writeManifest() catch |err| { @@ -984,7 +984,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest), }, }); @@ -1023,8 +1023,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { fn buildSharedLib( comp: *Compilation, arena: Allocator, - zig_cache_directory: Compilation.Directory, - bin_directory: Compilation.Directory, + bin_directory: Cache.Directory, asm_file_basename: []const u8, lib: Lib, prog_node: std.Progress.Node, @@ -1057,9 +1056,8 @@ fn buildSharedLib( }); const root_mod = try Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -1079,8 +1077,6 @@ fn buildSharedLib( .global = config, .cc_argv = &.{}, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }); const c_source_files = [1]Compilation.CSourceFile{ @@ -1091,9 +1087,7 @@ fn buildSharedLib( }; const sub_compilation = try Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = zig_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .thread_pool = comp.thread_pool, .self_exe_path = comp.self_exe_path, .cache_mode = .incremental, diff --git a/src/libs/glibc.zig b/src/libs/glibc.zig index 5d1c6f420b..541cf5d168 100644 --- a/src/libs/glibc.zig +++ b/src/libs/glibc.zig @@ -365,7 +365,7 @@ fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![ const s = path.sep_str; var result = std.ArrayList(u8).init(arena); - try result.appendSlice(comp.zig_lib_directory.path.?); + try result.appendSlice(comp.dirs.zig_lib.path orelse "."); try result.appendSlice(s ++ "libc" ++ s ++ "glibc" ++ s ++ "sysdeps" ++ s); if (is_sparc) { if (is_64) { @@ -439,7 +439,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([ } if (opt_nptl) |nptl| { try args.append("-I"); - try args.append(try path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, lib_libc_glibc ++ "sysdeps", nptl })); + try args.append(try path.join(arena, &.{ comp.dirs.zig_lib.path orelse ".", lib_libc_glibc ++ "sysdeps", nptl })); } try args.append("-I"); @@ -459,11 +459,11 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([ try args.append(try lib_path(comp, arena, lib_libc_glibc ++ "sysdeps" ++ s ++ "generic")); try args.append("-I"); - try args.append(try path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, lib_libc ++ "glibc" })); + try args.append(try path.join(arena, &[_][]const u8{ comp.dirs.zig_lib.path orelse ".", lib_libc ++ "glibc" })); try args.append("-I"); try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", .{ - comp.zig_lib_directory.path.?, @tagName(target.cpu.arch), @tagName(target.os.tag), @tagName(target.abi), + comp.dirs.zig_lib.path orelse ".", @tagName(target.cpu.arch), @tagName(target.os.tag), @tagName(target.abi), })); try args.append("-I"); @@ -472,7 +472,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([ const arch_name = std.zig.target.osArchName(target); try args.append("-I"); try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-linux-any", .{ - comp.zig_lib_directory.path.?, arch_name, + comp.dirs.zig_lib.path orelse ".", arch_name, })); try args.append("-I"); @@ -626,15 +626,11 @@ fn add_include_dirs_arch( } } -fn path_from_lib(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { - return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); -} - const lib_libc = "libc" ++ path.sep_str; const lib_libc_glibc = lib_libc ++ "glibc" ++ path.sep_str; fn lib_path(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { - return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); + return path.join(arena, &.{ comp.dirs.zig_lib.path orelse ".", sub_path }); } pub const BuiltSharedObjects = struct { @@ -678,11 +674,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye // Use the global cache directory. var cache: Cache = .{ .gpa = gpa, - .manifest_dir = try comp.global_cache_directory.handle.makeOpenPath("h", .{}), + .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}), }; cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); - cache.addPrefix(comp.zig_lib_directory); - cache.addPrefix(comp.global_cache_directory); + cache.addPrefix(comp.dirs.zig_lib); + cache.addPrefix(comp.dirs.global_cache); defer cache.manifest_dir.close(); var man = cache.obtain(); @@ -692,7 +688,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye man.hash.add(target.abi); man.hash.add(target_version); - const full_abilists_path = try comp.zig_lib_directory.join(arena, &.{abilists_path}); + const full_abilists_path = try comp.dirs.zig_lib.join(arena, &.{abilists_path}); const abilists_index = try man.addFile(full_abilists_path, abilists_max_size); if (try man.hit()) { @@ -701,7 +697,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest), }, }); @@ -710,9 +706,9 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye const digest = man.final(); const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); - var o_directory: Compilation.Directory = .{ - .handle = try comp.global_cache_directory.handle.makeOpenPath(o_sub_path, .{}), - .path = try comp.global_cache_directory.join(arena, &.{o_sub_path}), + var o_directory: Cache.Directory = .{ + .handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}), + .path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}), }; defer o_directory.handle.close(); @@ -1112,7 +1108,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc. const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable; try o_directory.handle.writeFile(.{ .sub_path = asm_file_basename, .data = stubs_asm.items }); - try buildSharedLib(comp, arena, comp.global_cache_directory, o_directory, asm_file_basename, lib, prog_node); + try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node); } man.writeManifest() catch |err| { @@ -1122,7 +1118,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest), }, }); @@ -1174,8 +1170,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) void { fn buildSharedLib( comp: *Compilation, arena: Allocator, - zig_cache_directory: Compilation.Directory, - bin_directory: Compilation.Directory, + bin_directory: Cache.Directory, asm_file_basename: []const u8, lib: Lib, prog_node: std.Progress.Node, @@ -1208,9 +1203,8 @@ fn buildSharedLib( }); const root_mod = try Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -1230,8 +1224,6 @@ fn buildSharedLib( .global = config, .cc_argv = &.{}, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }); const c_source_files = [1]Compilation.CSourceFile{ @@ -1242,9 +1234,7 @@ fn buildSharedLib( }; const sub_compilation = try Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = zig_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .thread_pool = comp.thread_pool, .self_exe_path = comp.self_exe_path, .cache_mode = .incremental, diff --git a/src/libs/libcxx.zig b/src/libs/libcxx.zig index 1561a39949..43acb0e93a 100644 --- a/src/libs/libcxx.zig +++ b/src/libs/libcxx.zig @@ -134,10 +134,10 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! .basename = basename, }; - const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); - const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); - const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" }); - const cxx_libc_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "libc" }); + const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" }); + const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" }); + const cxx_src_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "src" }); + const cxx_libc_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "libc" }); const optimize_mode = comp.compilerRtOptMode(); const strip = comp.compilerRtStrip(); @@ -164,9 +164,8 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! }; const root_mod = Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -188,8 +187,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! .global = config, .cc_argv = &.{}, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }) catch |err| { comp.setMiscFailure( .libcxx, @@ -258,7 +255,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! try cache_exempt_flags.append(cxx_libc_include_path); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", cxx_src }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", cxx_src }), .extra_flags = cflags.items, .cache_exempt_flags = cache_exempt_flags.items, .owner = root_mod, @@ -266,9 +263,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! } const sub_compilation = Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = comp.global_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .self_exe_path = comp.self_exe_path, .cache_mode = .whole, .config = config, @@ -344,9 +339,9 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .basename = basename, }; - const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" }); - const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" }); - const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" }); + const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" }); + const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" }); + const cxx_src_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "src" }); const optimize_mode = comp.compilerRtOptMode(); const strip = comp.compilerRtStrip(); @@ -378,9 +373,8 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr }; const root_mod = Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -403,8 +397,6 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .global = config, .cc_argv = &.{}, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }) catch |err| { comp.setMiscFailure( .libcxxabi, @@ -459,7 +451,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr try cache_exempt_flags.append(cxx_src_include_path); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", cxxabi_src }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", cxxabi_src }), .extra_flags = cflags.items, .cache_exempt_flags = cache_exempt_flags.items, .owner = root_mod, @@ -467,9 +459,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr } const sub_compilation = Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = comp.global_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .self_exe_path = comp.self_exe_path, .cache_mode = .whole, .config = config, diff --git a/src/libs/libtsan.zig b/src/libs/libtsan.zig index af99a763e4..73c2c49f72 100644 --- a/src/libs/libtsan.zig +++ b/src/libs/libtsan.zig @@ -84,9 +84,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo }; const root_mod = Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -110,8 +109,6 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo .global = config, .cc_argv = &common_flags, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }) catch |err| { comp.setMiscFailure( .libtsan, @@ -124,7 +121,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena); try c_source_files.ensureUnusedCapacity(tsan_sources.len); - const tsan_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"libtsan"}); + const tsan_include_path = try comp.dirs.zig_lib.join(arena, &.{"libtsan"}); for (tsan_sources) |tsan_src| { var cflags = std.ArrayList([]const u8).init(arena); @@ -134,7 +131,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &.{ "libtsan", tsan_src }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", tsan_src }), .extra_flags = cflags.items, .owner = root_mod, }); @@ -155,7 +152,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libtsan", tsan_src }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", tsan_src }), .extra_flags = cflags.items, .owner = root_mod, }); @@ -179,14 +176,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-DNDEBUG"); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libtsan", asm_source }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", asm_source }), .extra_flags = cflags.items, .owner = root_mod, }); } try c_source_files.ensureUnusedCapacity(sanitizer_common_sources.len); - const sanitizer_common_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + const sanitizer_common_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", "sanitizer_common", }); for (sanitizer_common_sources) |common_src| { @@ -200,7 +197,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", "sanitizer_common", common_src, }), .extra_flags = cflags.items, @@ -224,7 +221,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", "sanitizer_common", c_src, }), .extra_flags = cflags.items, @@ -242,7 +239,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", "sanitizer_common", c_src, }), .extra_flags = cflags.items, @@ -250,10 +247,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo }); } - const interception_include_path = try comp.zig_lib_directory.join( - arena, - &[_][]const u8{"interception"}, - ); + const interception_include_path = try comp.dirs.zig_lib.join(arena, &.{"interception"}); try c_source_files.ensureUnusedCapacity(interception_sources.len); for (interception_sources) |c_src| { @@ -268,7 +262,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libtsan", "interception", c_src, }), .extra_flags = cflags.items, @@ -285,9 +279,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo // Workaround for https://github.com/llvm/llvm-project/issues/97627 const headerpad_size: ?u32 = if (target.os.tag.isDarwin()) 32 else null; const sub_compilation = Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = comp.global_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .thread_pool = comp.thread_pool, .self_exe_path = comp.self_exe_path, .cache_mode = .whole, diff --git a/src/libs/libunwind.zig b/src/libs/libunwind.zig index c453aca42c..3c2e14bfc5 100644 --- a/src/libs/libunwind.zig +++ b/src/libs/libunwind.zig @@ -50,9 +50,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr return error.SubCompilationFailed; }; const root_mod = Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -76,8 +75,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .global = config, .cc_argv = &.{}, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }) catch |err| { comp.setMiscFailure( .libunwind, @@ -118,7 +115,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr else => unreachable, // See `unwind_src_list`. } try cflags.append("-I"); - try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" })); + try cflags.append(try comp.dirs.zig_lib.join(arena, &.{ "libunwind", "include" })); try cflags.append("-D_LIBUNWIND_HIDE_SYMBOLS"); try cflags.append("-Wa,--noexecstack"); try cflags.append("-fvisibility=hidden"); @@ -148,16 +145,14 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr } c_source_files[i] = .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{unwind_src}), + .src_path = try comp.dirs.zig_lib.join(arena, &.{unwind_src}), .extra_flags = cflags.items, .owner = root_mod, }; } const sub_compilation = Compilation.create(comp.gpa, arena, .{ + .dirs = comp.dirs.withoutLocalCache(), .self_exe_path = comp.self_exe_path, - .local_cache_directory = comp.global_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, .config = config, .root_mod = root_mod, .cache_mode = .whole, diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig index 2049b0f6b7..640ed908f5 100644 --- a/src/libs/mingw.zig +++ b/src/libs/mingw.zig @@ -40,7 +40,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "crt", "crtexe.c", }), .extra_flags = args.items, @@ -57,7 +57,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre try addCrtCcArgs(comp, arena, &args); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "crt", "crtdll.c", }), .extra_flags = args.items, @@ -78,7 +78,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (mingw32_generic_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -88,7 +88,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre if (target.cpu.arch.isX86()) { for (mingw32_x86_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -98,7 +98,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre if (target.cpu.arch == .x86) { for (mingw32_x86_32_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -109,7 +109,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } else if (target.cpu.arch == .thumb) { for (mingw32_arm_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } for (mingw32_arm32_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -128,7 +128,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } else if (target.cpu.arch == .aarch64) { for (mingw32_arm_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -137,7 +137,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } for (mingw32_arm64_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = crt_args.items, @@ -164,7 +164,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (mingw32_winpthreads_src) |dep| { try c_source_files.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", dep, }), .extra_flags = winpthreads_args.items, @@ -192,7 +192,7 @@ fn addCcArgs( "-D__USE_MINGW_ANSI_STDIO=0", "-isystem", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "any-windows-any" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "any-windows-any" }), }); } @@ -219,7 +219,7 @@ fn addCrtCcArgs( "-DHAVE_CONFIG_H", "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "include" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "include" }), }); } @@ -232,7 +232,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { defer arena_allocator.deinit(); const arena = arena_allocator.allocator(); - const def_file_path = findDef(arena, comp.getTarget(), comp.zig_lib_directory, lib_name) catch |err| switch (err) { + const def_file_path = findDef(arena, comp.getTarget(), comp.dirs.zig_lib, lib_name) catch |err| switch (err) { error.FileNotFound => { log.debug("no {s}.def file available to make a DLL import {s}.lib", .{ lib_name, lib_name }); // In this case we will end up putting foo.lib onto the linker line and letting the linker @@ -247,15 +247,15 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { // Use the global cache directory. var cache: Cache = .{ .gpa = gpa, - .manifest_dir = try comp.global_cache_directory.handle.makeOpenPath("h", .{}), + .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}), }; cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); - cache.addPrefix(comp.zig_lib_directory); - cache.addPrefix(comp.global_cache_directory); + cache.addPrefix(comp.dirs.zig_lib); + cache.addPrefix(comp.dirs.global_cache); defer cache.manifest_dir.close(); cache.hash.addBytes(build_options.version); - cache.hash.addOptionalBytes(comp.zig_lib_directory.path); + cache.hash.addOptionalBytes(comp.dirs.zig_lib.path); cache.hash.add(target.cpu.arch); var man = cache.obtain(); @@ -276,7 +276,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { try comp.crt_files.ensureUnusedCapacity(gpa, 1); comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{ .full_object_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = sub_path, }, .lock = man.toOwnedLock(), @@ -286,11 +286,11 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { const digest = man.final(); const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest }); - var o_dir = try comp.global_cache_directory.handle.makeOpenPath(o_sub_path, .{}); + var o_dir = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}); defer o_dir.close(); const final_def_basename = try std.fmt.allocPrint(arena, "{s}.def", .{lib_name}); - const def_final_path = try comp.global_cache_directory.join(arena, &[_][]const u8{ + const def_final_path = try comp.dirs.global_cache.join(arena, &[_][]const u8{ "o", &digest, final_def_basename, }); @@ -306,7 +306,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { var aro_comp = aro.Compilation.init(gpa, std.fs.cwd()); defer aro_comp.deinit(); - const include_dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "mingw", "def-include" }); + const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" }); if (comp.verbose_cc) print: { std.debug.lockStdErr(); @@ -350,7 +350,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { if (!build_options.have_llvm) return error.ZigCompilerNotBuiltWithLLVMExtensions; const llvm_bindings = @import("../codegen/llvm/bindings.zig"); const def_final_path_z = try arena.dupeZ(u8, def_final_path); - const lib_final_path_z = try comp.global_cache_directory.joinZ(arena, &.{lib_final_path}); + const lib_final_path_z = try comp.dirs.global_cache.joinZ(arena, &.{lib_final_path}); if (llvm_bindings.WriteImportLibrary( def_final_path_z.ptr, @intFromEnum(target.toCoffMachine()), @@ -370,7 +370,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { defer comp.mutex.unlock(); try comp.crt_files.putNoClobber(gpa, final_lib_basename, .{ .full_object_path = .{ - .root_dir = comp.global_cache_directory, + .root_dir = comp.dirs.global_cache, .sub_path = lib_final_path, }, .lock = man.toOwnedLock(), diff --git a/src/libs/musl.zig b/src/libs/musl.zig index 6e48f3f49f..4ae86f0214 100644 --- a/src/libs/musl.zig +++ b/src/libs/musl.zig @@ -34,7 +34,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "crt", "crt1.c", }), .extra_flags = args.items, @@ -54,7 +54,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "crt", "rcrt1.c", }), .extra_flags = args.items, @@ -75,7 +75,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "crt", "Scrt1.c", }), .extra_flags = args.items, @@ -165,7 +165,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro try addCcArgs(comp, arena, &args, ext == .o3); const c_source_file = try c_source_files.addOne(); c_source_file.* = .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", src_file }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", src_file }), .extra_flags = args.items, .owner = undefined, }; @@ -220,9 +220,8 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro &.{ arch_define, family_define }; const root_mod = try Module.create(arena, .{ - .global_cache_directory = comp.global_cache_directory, .paths = .{ - .root = .{ .root_dir = comp.zig_lib_directory }, + .root = .zig_lib_root, .root_src_path = "", }, .fully_qualified_name = "root", @@ -242,14 +241,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .global = config, .cc_argv = cc_argv, .parent = null, - .builtin_mod = null, - .builtin_modules = null, // there is only one module in this compilation }); const sub_compilation = try Compilation.create(comp.gpa, arena, .{ - .local_cache_directory = comp.global_cache_directory, - .global_cache_directory = comp.global_cache_directory, - .zig_lib_directory = comp.zig_lib_directory, + .dirs = comp.dirs.withoutLocalCache(), .self_exe_path = comp.self_exe_path, .cache_mode = .whole, .config = config, @@ -266,9 +261,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .verbose_cimport = comp.verbose_cimport, .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, .clang_passthrough_mode = comp.clang_passthrough_mode, - .c_source_files = &[_]Compilation.CSourceFile{ + .c_source_files = &.{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &.{ "libc", "musl", "libc.S" }), + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "libc.S" }), .owner = root_mod, }, }, @@ -411,25 +406,25 @@ fn addCcArgs( "-D_XOPEN_SOURCE=700", "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "arch", arch_name }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "arch", arch_name }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "arch", "generic" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "arch", "generic" }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "src", "include" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", "include" }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "src", "internal" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", "internal" }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "include" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "include" }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", triple }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "generic-musl" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "generic-musl" }), o_arg, @@ -444,7 +439,7 @@ fn addCcArgs( fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { const target = comp.getTarget(); - return comp.zig_lib_directory.join(arena, &[_][]const u8{ + return comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "crt", std.zig.target.muslArchName(target.cpu.arch, target.abi), basename, }); } diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig index 2d345071ef..f718f39793 100644 --- a/src/libs/wasi_libc.zig +++ b/src/libs/wasi_libc.zig @@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre try addLibcBottomHalfIncludes(comp, arena, &args); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, crt1_reactor_src_file), }), .extra_flags = args.items, @@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre try addLibcBottomHalfIncludes(comp, arena, &args); var files = [_]Compilation.CSourceFile{ .{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, crt1_command_src_file), }), .extra_flags = args.items, @@ -114,7 +114,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre try addCCArgs(comp, arena, &args, .{ .want_O3 = true, .no_strict_aliasing = true }); for (emmalloc_src_files) |file_path| { try libc_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -131,7 +131,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (libc_bottom_half_src_files) |file_path| { try libc_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -148,7 +148,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (libc_top_half_src_files) |file_path| { try libc_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -168,7 +168,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre var emu_dl_sources = std.ArrayList(Compilation.CSourceFile).init(arena); for (emulated_dl_src_files) |file_path| { try emu_dl_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -186,7 +186,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena); for (emulated_process_clocks_src_files) |file_path| { try emu_clocks_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -203,7 +203,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena); for (emulated_getpid_src_files) |file_path| { try emu_getpid_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -220,7 +220,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena); for (emulated_mman_src_files) |file_path| { try emu_mman_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (emulated_signal_bottom_half_src_files) |file_path| { try emu_signal_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -255,7 +255,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre for (emulated_signal_top_half_src_files) |file_path| { try emu_signal_sources.append(.{ - .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ + .src_path = try comp.dirs.zig_lib.join(arena, &.{ "libc", try sanitize(arena, file_path), }), .extra_flags = args.items, @@ -316,10 +316,10 @@ fn addCCArgs( "/", "-iwithsysroot", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", triple }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }), "-iwithsysroot", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", "generic-musl" }), + try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "generic-musl" }), "-DBULK_MEMORY_THRESHOLD=32", }); @@ -336,7 +336,7 @@ fn addLibcBottomHalfIncludes( ) error{OutOfMemory}!void { try args.appendSlice(&[_][]const u8{ "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-bottom-half", @@ -345,7 +345,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-bottom-half", @@ -355,7 +355,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-bottom-half", @@ -364,7 +364,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", @@ -374,7 +374,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", @@ -382,7 +382,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", @@ -392,7 +392,7 @@ fn addLibcBottomHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", @@ -408,7 +408,7 @@ fn addLibcTopHalfIncludes( ) error{OutOfMemory}!void { try args.appendSlice(&[_][]const u8{ "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", @@ -418,7 +418,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", @@ -426,7 +426,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", @@ -436,7 +436,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "src", @@ -444,7 +444,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", @@ -454,7 +454,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "arch", @@ -462,7 +462,7 @@ fn addLibcTopHalfIncludes( }), "-I", - try comp.zig_lib_directory.join(arena, &[_][]const u8{ + try comp.dirs.zig_lib.join(arena, &.{ "libc", "wasi", "libc-top-half", |
