mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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
This commit is contained in:
parent
d32829e053
commit
37a9a4e0f1
49 changed files with 2755 additions and 2386 deletions
|
|
@ -19,6 +19,26 @@ code_model: std.builtin.CodeModel,
|
||||||
omit_frame_pointer: bool,
|
omit_frame_pointer: bool,
|
||||||
wasi_exec_model: std.builtin.WasiExecModel,
|
wasi_exec_model: std.builtin.WasiExecModel,
|
||||||
|
|
||||||
|
/// Compute an abstract hash representing this `Builtin`. This is *not* a hash
|
||||||
|
/// of the resulting file contents.
|
||||||
|
pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {
|
||||||
|
var h: Cache.Hasher = Cache.hasher_init;
|
||||||
|
inline for (@typeInfo(@This()).@"struct".fields) |f| {
|
||||||
|
if (comptime std.mem.eql(u8, f.name, "target")) {
|
||||||
|
// This needs special handling.
|
||||||
|
std.hash.autoHash(&h, opts.target.cpu);
|
||||||
|
std.hash.autoHash(&h, opts.target.os.tag);
|
||||||
|
std.hash.autoHash(&h, opts.target.os.versionRange());
|
||||||
|
std.hash.autoHash(&h, opts.target.abi);
|
||||||
|
std.hash.autoHash(&h, opts.target.ofmt);
|
||||||
|
std.hash.autoHash(&h, opts.target.dynamic_linker);
|
||||||
|
} else {
|
||||||
|
std.hash.autoHash(&h, @field(opts, f.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return h.finalResult();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate(opts: @This(), allocator: Allocator) Allocator.Error![:0]u8 {
|
pub fn generate(opts: @This(), allocator: Allocator) Allocator.Error![:0]u8 {
|
||||||
var buffer = std.ArrayList(u8).init(allocator);
|
var buffer = std.ArrayList(u8).init(allocator);
|
||||||
try append(opts, &buffer);
|
try append(opts, &buffer);
|
||||||
|
|
@ -263,50 +283,66 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn populateFile(comp: *Compilation, mod: *Module, file: *File) !void {
|
/// This essentially takes the place of `Zcu.PerThread.updateFile`, but for 'builtin' modules.
|
||||||
if (mod.root.statFile(mod.root_src_path)) |stat| {
|
/// Instead of reading the file from disk, its contents are generated in-memory.
|
||||||
|
pub fn populateFile(opts: @This(), gpa: Allocator, file: *File) Allocator.Error!void {
|
||||||
|
assert(file.is_builtin);
|
||||||
|
assert(file.status == .never_loaded);
|
||||||
|
assert(file.source == null);
|
||||||
|
assert(file.tree == null);
|
||||||
|
assert(file.zir == null);
|
||||||
|
|
||||||
|
file.source = try opts.generate(gpa);
|
||||||
|
|
||||||
|
log.debug("parsing and generating 'builtin.zig'", .{});
|
||||||
|
|
||||||
|
file.tree = try std.zig.Ast.parse(gpa, file.source.?, .zig);
|
||||||
|
assert(file.tree.?.errors.len == 0); // builtin.zig must parse
|
||||||
|
|
||||||
|
file.zir = try AstGen.generate(gpa, file.tree.?);
|
||||||
|
assert(!file.zir.?.hasCompileErrors()); // builtin.zig must not have astgen errors
|
||||||
|
file.status = .success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// After `populateFile` succeeds, call this function to write the generated file out to disk
|
||||||
|
/// if necessary. This is useful for external tooling such as debuggers.
|
||||||
|
/// Assumes that `file.mod` is correctly set to the builtin module.
|
||||||
|
pub fn updateFileOnDisk(file: *File, comp: *Compilation) !void {
|
||||||
|
assert(file.is_builtin);
|
||||||
|
assert(file.status == .success);
|
||||||
|
assert(file.source != null);
|
||||||
|
|
||||||
|
const root_dir, const sub_path = file.path.openInfo(comp.dirs);
|
||||||
|
|
||||||
|
if (root_dir.statFile(sub_path)) |stat| {
|
||||||
if (stat.size != file.source.?.len) {
|
if (stat.size != file.source.?.len) {
|
||||||
std.log.warn(
|
std.log.warn(
|
||||||
"the cached file '{}{s}' had the wrong size. Expected {d}, found {d}. " ++
|
"the cached file '{}' had the wrong size. Expected {d}, found {d}. " ++
|
||||||
"Overwriting with correct file contents now",
|
"Overwriting with correct file contents now",
|
||||||
.{ mod.root, mod.root_src_path, file.source.?.len, stat.size },
|
.{ file.path.fmt(comp), file.source.?.len, stat.size },
|
||||||
);
|
);
|
||||||
|
|
||||||
try writeFile(file, mod);
|
|
||||||
} else {
|
} else {
|
||||||
file.stat = .{
|
file.stat = .{
|
||||||
.size = stat.size,
|
.size = stat.size,
|
||||||
.inode = stat.inode,
|
.inode = stat.inode,
|
||||||
.mtime = stat.mtime,
|
.mtime = stat.mtime,
|
||||||
};
|
};
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else |err| switch (err) {
|
} else |err| switch (err) {
|
||||||
error.BadPathName => unreachable, // it's always "builtin.zig"
|
error.FileNotFound => {},
|
||||||
error.NameTooLong => unreachable, // it's always "builtin.zig"
|
|
||||||
error.PipeBusy => unreachable, // it's not a pipe
|
|
||||||
error.NoDevice => unreachable, // it's not a pipe
|
|
||||||
error.WouldBlock => unreachable, // not asking for non-blocking I/O
|
error.WouldBlock => unreachable, // not asking for non-blocking I/O
|
||||||
|
error.BadPathName => unreachable, // it's always "o/digest/builtin.zig"
|
||||||
|
error.NameTooLong => unreachable, // it's always "o/digest/builtin.zig"
|
||||||
|
|
||||||
error.FileNotFound => try writeFile(file, mod),
|
// We don't expect the file to be a pipe, but can't mark `error.PipeBusy` as `unreachable`,
|
||||||
|
// because the user could always replace the file on disk.
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("parsing and generating '{s}'", .{mod.root_src_path});
|
// `make_path` matters because the dir hasn't actually been created yet.
|
||||||
|
var af = try root_dir.atomicFile(sub_path, .{ .make_path = true });
|
||||||
file.tree = try std.zig.Ast.parse(comp.gpa, file.source.?, .zig);
|
|
||||||
assert(file.tree.?.errors.len == 0); // builtin.zig must parse
|
|
||||||
|
|
||||||
file.zir = try AstGen.generate(comp.gpa, file.tree.?);
|
|
||||||
assert(!file.zir.?.hasCompileErrors()); // builtin.zig must not have astgen errors
|
|
||||||
file.status = .success;
|
|
||||||
// Note that whilst we set `zir` here, we populated `path_digest`
|
|
||||||
// all the way back in `Package.Module.create`.
|
|
||||||
}
|
|
||||||
|
|
||||||
fn writeFile(file: *File, mod: *Module) !void {
|
|
||||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
|
||||||
var af = try mod.root.atomicFile(mod.root_src_path, .{ .make_path = true }, &buf);
|
|
||||||
defer af.deinit();
|
defer af.deinit();
|
||||||
try af.file.writeAll(file.source.?);
|
try af.file.writeAll(file.source.?);
|
||||||
af.finish() catch |err| switch (err) {
|
af.finish() catch |err| switch (err) {
|
||||||
|
|
@ -331,6 +367,7 @@ fn writeFile(file: *File, mod: *Module) !void {
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
const Cache = std.Build.Cache;
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const Module = @import("Package/Module.zig");
|
const Module = @import("Package/Module.zig");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
|
||||||
1403
src/Compilation.zig
1403
src/Compilation.zig
File diff suppressed because it is too large
Load diff
|
|
@ -1723,6 +1723,19 @@ pub const FileIndex = enum(u32) {
|
||||||
.index = @intFromEnum(file_index) & ip.getIndexMask(u32),
|
.index = @intFromEnum(file_index) & ip.getIndexMask(u32),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub fn toOptional(i: FileIndex) Optional {
|
||||||
|
return @enumFromInt(@intFromEnum(i));
|
||||||
|
}
|
||||||
|
pub const Optional = enum(u32) {
|
||||||
|
none = std.math.maxInt(u32),
|
||||||
|
_,
|
||||||
|
pub fn unwrap(opt: Optional) ?FileIndex {
|
||||||
|
return switch (opt) {
|
||||||
|
.none => null,
|
||||||
|
_ => @enumFromInt(@intFromEnum(opt)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const File = struct {
|
const File = struct {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
//! Corresponds to something that Zig source code can `@import`.
|
//! Corresponds to something that Zig source code can `@import`.
|
||||||
|
|
||||||
/// Only files inside this directory can be imported.
|
/// The root directory of the module. Only files inside this directory can be imported.
|
||||||
root: Cache.Path,
|
root: Compilation.Path,
|
||||||
/// Relative to `root`. May contain path separators.
|
/// Path to the root source file of this module. Relative to `root`. May contain path separators.
|
||||||
root_src_path: []const u8,
|
root_src_path: []const u8,
|
||||||
/// Name used in compile errors. Looks like "root.foo.bar".
|
/// Name used in compile errors. Looks like "root.foo.bar".
|
||||||
fully_qualified_name: []const u8,
|
fully_qualified_name: []const u8,
|
||||||
/// The dependency table of this module. Shared dependencies such as 'std',
|
/// The dependency table of this module. The shared dependencies 'std' and
|
||||||
/// 'builtin', and 'root' are not specified in every dependency table, but
|
/// 'root' are not specified in every module dependency table, but are stored
|
||||||
/// instead only in the table of `main_mod`. `Module.importFile` is
|
/// separately in `Zcu`. 'builtin' is also not stored here, although it is
|
||||||
/// responsible for detecting these names and using the correct package.
|
/// not necessarily the same between all modules. Handling of `@import` in
|
||||||
|
/// the rest of the compiler must detect these special names and use the
|
||||||
|
/// correct module instead of consulting `deps`.
|
||||||
deps: Deps = .{},
|
deps: Deps = .{},
|
||||||
|
|
||||||
resolved_target: ResolvedTarget,
|
resolved_target: ResolvedTarget,
|
||||||
|
|
@ -33,25 +35,14 @@ cc_argv: []const []const u8,
|
||||||
structured_cfg: bool,
|
structured_cfg: bool,
|
||||||
no_builtin: bool,
|
no_builtin: bool,
|
||||||
|
|
||||||
/// If the module is an `@import("builtin")` module, this is the `File` that
|
|
||||||
/// is preallocated for it. Otherwise this field is null.
|
|
||||||
builtin_file: ?*File,
|
|
||||||
|
|
||||||
pub const Deps = std.StringArrayHashMapUnmanaged(*Module);
|
pub const Deps = std.StringArrayHashMapUnmanaged(*Module);
|
||||||
|
|
||||||
pub fn isBuiltin(m: Module) bool {
|
|
||||||
return m.builtin_file != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const Tree = struct {
|
pub const Tree = struct {
|
||||||
/// Each `Package` exposes a `Module` with build.zig as its root source file.
|
/// Each `Package` exposes a `Module` with build.zig as its root source file.
|
||||||
build_module_table: std.AutoArrayHashMapUnmanaged(MultiHashHexDigest, *Module),
|
build_module_table: std.AutoArrayHashMapUnmanaged(MultiHashHexDigest, *Module),
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CreateOptions = struct {
|
pub const CreateOptions = struct {
|
||||||
/// Where to store builtin.zig. The global cache directory is used because
|
|
||||||
/// it is a pure function based on CLI flags.
|
|
||||||
global_cache_directory: Cache.Directory,
|
|
||||||
paths: Paths,
|
paths: Paths,
|
||||||
fully_qualified_name: []const u8,
|
fully_qualified_name: []const u8,
|
||||||
|
|
||||||
|
|
@ -61,15 +52,8 @@ pub const CreateOptions = struct {
|
||||||
/// If this is null then `resolved_target` must be non-null.
|
/// If this is null then `resolved_target` must be non-null.
|
||||||
parent: ?*Package.Module,
|
parent: ?*Package.Module,
|
||||||
|
|
||||||
builtin_mod: ?*Package.Module,
|
|
||||||
|
|
||||||
/// Allocated into the given `arena`. Should be shared across all module creations in a Compilation.
|
|
||||||
/// Ignored if `builtin_mod` is passed or if `!have_zcu`.
|
|
||||||
/// Otherwise, may be `null` only if this Compilation consists of a single module.
|
|
||||||
builtin_modules: ?*std.StringHashMapUnmanaged(*Module),
|
|
||||||
|
|
||||||
pub const Paths = struct {
|
pub const Paths = struct {
|
||||||
root: Cache.Path,
|
root: Compilation.Path,
|
||||||
/// Relative to `root`. May contain path separators.
|
/// Relative to `root`. May contain path separators.
|
||||||
root_src_path: []const u8,
|
root_src_path: []const u8,
|
||||||
};
|
};
|
||||||
|
|
@ -401,126 +385,13 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
|
||||||
.cc_argv = options.cc_argv,
|
.cc_argv = options.cc_argv,
|
||||||
.structured_cfg = structured_cfg,
|
.structured_cfg = structured_cfg,
|
||||||
.no_builtin = no_builtin,
|
.no_builtin = no_builtin,
|
||||||
.builtin_file = null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const opt_builtin_mod = options.builtin_mod orelse b: {
|
|
||||||
if (!options.global.have_zcu) break :b null;
|
|
||||||
|
|
||||||
const generated_builtin_source = try Builtin.generate(.{
|
|
||||||
.target = target,
|
|
||||||
.zig_backend = zig_backend,
|
|
||||||
.output_mode = options.global.output_mode,
|
|
||||||
.link_mode = options.global.link_mode,
|
|
||||||
.unwind_tables = unwind_tables,
|
|
||||||
.is_test = options.global.is_test,
|
|
||||||
.single_threaded = single_threaded,
|
|
||||||
.link_libc = options.global.link_libc,
|
|
||||||
.link_libcpp = options.global.link_libcpp,
|
|
||||||
.optimize_mode = optimize_mode,
|
|
||||||
.error_tracing = error_tracing,
|
|
||||||
.valgrind = valgrind,
|
|
||||||
.sanitize_thread = sanitize_thread,
|
|
||||||
.fuzz = fuzz,
|
|
||||||
.pic = pic,
|
|
||||||
.pie = options.global.pie,
|
|
||||||
.strip = strip,
|
|
||||||
.code_model = code_model,
|
|
||||||
.omit_frame_pointer = omit_frame_pointer,
|
|
||||||
.wasi_exec_model = options.global.wasi_exec_model,
|
|
||||||
}, arena);
|
|
||||||
|
|
||||||
const new = if (options.builtin_modules) |builtins| new: {
|
|
||||||
const gop = try builtins.getOrPut(arena, generated_builtin_source);
|
|
||||||
if (gop.found_existing) break :b gop.value_ptr.*;
|
|
||||||
errdefer builtins.removeByPtr(gop.key_ptr);
|
|
||||||
const new = try arena.create(Module);
|
|
||||||
gop.value_ptr.* = new;
|
|
||||||
break :new new;
|
|
||||||
} else try arena.create(Module);
|
|
||||||
errdefer if (options.builtin_modules) |builtins| assert(builtins.remove(generated_builtin_source));
|
|
||||||
|
|
||||||
const new_file = try arena.create(File);
|
|
||||||
|
|
||||||
const hex_digest = digest: {
|
|
||||||
var hasher: Cache.Hasher = Cache.hasher_init;
|
|
||||||
hasher.update(generated_builtin_source);
|
|
||||||
|
|
||||||
var bin_digest: Cache.BinDigest = undefined;
|
|
||||||
hasher.final(&bin_digest);
|
|
||||||
|
|
||||||
var hex_digest: Cache.HexDigest = undefined;
|
|
||||||
_ = std.fmt.bufPrint(
|
|
||||||
&hex_digest,
|
|
||||||
"{s}",
|
|
||||||
.{std.fmt.fmtSliceHexLower(&bin_digest)},
|
|
||||||
) catch unreachable;
|
|
||||||
|
|
||||||
break :digest hex_digest;
|
|
||||||
};
|
|
||||||
|
|
||||||
const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ hex_digest);
|
|
||||||
|
|
||||||
new.* = .{
|
|
||||||
.root = .{
|
|
||||||
.root_dir = options.global_cache_directory,
|
|
||||||
.sub_path = builtin_sub_path,
|
|
||||||
},
|
|
||||||
.root_src_path = "builtin.zig",
|
|
||||||
.fully_qualified_name = if (options.parent == null)
|
|
||||||
"builtin"
|
|
||||||
else
|
|
||||||
try std.fmt.allocPrint(arena, "{s}.builtin", .{options.fully_qualified_name}),
|
|
||||||
.resolved_target = .{
|
|
||||||
.result = target,
|
|
||||||
.is_native_os = resolved_target.is_native_os,
|
|
||||||
.is_native_abi = resolved_target.is_native_abi,
|
|
||||||
.llvm_cpu_features = llvm_cpu_features,
|
|
||||||
},
|
|
||||||
.optimize_mode = optimize_mode,
|
|
||||||
.single_threaded = single_threaded,
|
|
||||||
.error_tracing = error_tracing,
|
|
||||||
.valgrind = valgrind,
|
|
||||||
.pic = pic,
|
|
||||||
.strip = strip,
|
|
||||||
.omit_frame_pointer = omit_frame_pointer,
|
|
||||||
.stack_check = stack_check,
|
|
||||||
.stack_protector = stack_protector,
|
|
||||||
.code_model = code_model,
|
|
||||||
.red_zone = red_zone,
|
|
||||||
.sanitize_c = sanitize_c,
|
|
||||||
.sanitize_thread = sanitize_thread,
|
|
||||||
.fuzz = fuzz,
|
|
||||||
.unwind_tables = unwind_tables,
|
|
||||||
.cc_argv = &.{},
|
|
||||||
.structured_cfg = structured_cfg,
|
|
||||||
.no_builtin = no_builtin,
|
|
||||||
.builtin_file = new_file,
|
|
||||||
};
|
|
||||||
new_file.* = .{
|
|
||||||
.sub_file_path = "builtin.zig",
|
|
||||||
.stat = undefined,
|
|
||||||
.source = generated_builtin_source,
|
|
||||||
.tree = null,
|
|
||||||
.zir = null,
|
|
||||||
.zoir = null,
|
|
||||||
.status = .never_loaded,
|
|
||||||
.mod = new,
|
|
||||||
};
|
|
||||||
break :b new;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (opt_builtin_mod) |builtin_mod| {
|
|
||||||
try mod.deps.ensureUnusedCapacity(arena, 1);
|
|
||||||
mod.deps.putAssumeCapacityNoClobber("builtin", builtin_mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// All fields correspond to `CreateOptions`.
|
/// All fields correspond to `CreateOptions`.
|
||||||
pub const LimitedOptions = struct {
|
pub const LimitedOptions = struct {
|
||||||
root: Cache.Path,
|
root: Compilation.Path,
|
||||||
root_src_path: []const u8,
|
root_src_path: []const u8,
|
||||||
fully_qualified_name: []const u8,
|
fully_qualified_name: []const u8,
|
||||||
};
|
};
|
||||||
|
|
@ -553,18 +424,73 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P
|
||||||
.cc_argv = undefined,
|
.cc_argv = undefined,
|
||||||
.structured_cfg = undefined,
|
.structured_cfg = undefined,
|
||||||
.no_builtin = undefined,
|
.no_builtin = undefined,
|
||||||
.builtin_file = null,
|
|
||||||
};
|
};
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that the module has a builtin module, which is not true for non-zig
|
/// Does not ensure that the module's root directory exists on-disk; see `Builtin.updateFileOnDisk` for that task.
|
||||||
/// modules such as ones only used for `@embedFile`, or the root module when
|
pub fn createBuiltin(arena: Allocator, opts: Builtin, dirs: Compilation.Directories) Allocator.Error!*Module {
|
||||||
/// there is no Zig Compilation Unit.
|
const sub_path = "b" ++ Cache.binToHex(opts.hash());
|
||||||
pub fn getBuiltinDependency(m: Module) *Module {
|
const new = try arena.create(Module);
|
||||||
const result = m.deps.values()[0];
|
new.* = .{
|
||||||
assert(result.isBuiltin());
|
.root = try .fromRoot(arena, dirs, .global_cache, sub_path),
|
||||||
return result;
|
.root_src_path = "builtin.zig",
|
||||||
|
.fully_qualified_name = "builtin",
|
||||||
|
.resolved_target = .{
|
||||||
|
.result = opts.target,
|
||||||
|
// These values are not in `opts`, but do not matter because `builtin.zig` contains no runtime code.
|
||||||
|
.is_native_os = false,
|
||||||
|
.is_native_abi = false,
|
||||||
|
.llvm_cpu_features = null,
|
||||||
|
},
|
||||||
|
.optimize_mode = opts.optimize_mode,
|
||||||
|
.single_threaded = opts.single_threaded,
|
||||||
|
.error_tracing = opts.error_tracing,
|
||||||
|
.valgrind = opts.valgrind,
|
||||||
|
.pic = opts.pic,
|
||||||
|
.strip = opts.strip,
|
||||||
|
.omit_frame_pointer = opts.omit_frame_pointer,
|
||||||
|
.code_model = opts.code_model,
|
||||||
|
.sanitize_thread = opts.sanitize_thread,
|
||||||
|
.fuzz = opts.fuzz,
|
||||||
|
.unwind_tables = opts.unwind_tables,
|
||||||
|
.cc_argv = &.{},
|
||||||
|
// These values are not in `opts`, but do not matter because `builtin.zig` contains no runtime code.
|
||||||
|
.stack_check = false,
|
||||||
|
.stack_protector = 0,
|
||||||
|
.red_zone = false,
|
||||||
|
.sanitize_c = .off,
|
||||||
|
.structured_cfg = false,
|
||||||
|
.no_builtin = false,
|
||||||
|
};
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the `Builtin` which forms the contents of `@import("builtin")` for this module.
|
||||||
|
pub fn getBuiltinOptions(m: Module, global: Compilation.Config) Builtin {
|
||||||
|
assert(global.have_zcu);
|
||||||
|
return .{
|
||||||
|
.target = m.resolved_target.result,
|
||||||
|
.zig_backend = target_util.zigBackend(m.resolved_target.result, global.use_llvm),
|
||||||
|
.output_mode = global.output_mode,
|
||||||
|
.link_mode = global.link_mode,
|
||||||
|
.unwind_tables = m.unwind_tables,
|
||||||
|
.is_test = global.is_test,
|
||||||
|
.single_threaded = m.single_threaded,
|
||||||
|
.link_libc = global.link_libc,
|
||||||
|
.link_libcpp = global.link_libcpp,
|
||||||
|
.optimize_mode = m.optimize_mode,
|
||||||
|
.error_tracing = m.error_tracing,
|
||||||
|
.valgrind = m.valgrind,
|
||||||
|
.sanitize_thread = m.sanitize_thread,
|
||||||
|
.fuzz = m.fuzz,
|
||||||
|
.pic = m.pic,
|
||||||
|
.pie = global.pie,
|
||||||
|
.strip = m.strip,
|
||||||
|
.code_model = m.code_model,
|
||||||
|
.omit_frame_pointer = m.omit_frame_pointer,
|
||||||
|
.wasi_exec_model = global.wasi_exec_model,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Module = @This();
|
const Module = @This();
|
||||||
|
|
|
||||||
149
src/Sema.zig
149
src/Sema.zig
|
|
@ -829,7 +829,7 @@ pub const Block = struct {
|
||||||
|
|
||||||
pub fn ownerModule(block: Block) *Package.Module {
|
pub fn ownerModule(block: Block) *Package.Module {
|
||||||
const zcu = block.sema.pt.zcu;
|
const zcu = block.sema.pt.zcu;
|
||||||
return zcu.namespacePtr(block.namespace).fileScope(zcu).mod;
|
return zcu.namespacePtr(block.namespace).fileScope(zcu).mod.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trackZir(block: *Block, inst: Zir.Inst.Index) Allocator.Error!InternPool.TrackedInst.Index {
|
fn trackZir(block: *Block, inst: Zir.Inst.Index) Allocator.Error!InternPool.TrackedInst.Index {
|
||||||
|
|
@ -1127,10 +1127,10 @@ fn analyzeBodyInner(
|
||||||
|
|
||||||
// The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away.
|
// The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away.
|
||||||
if (build_options.enable_logging) {
|
if (build_options.enable_logging) {
|
||||||
std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
|
std.log.scoped(.sema_zir).debug("sema ZIR {} %{d}", .{ path: {
|
||||||
const file_index = block.src_base_inst.resolveFile(&zcu.intern_pool);
|
const file_index = block.src_base_inst.resolveFile(&zcu.intern_pool);
|
||||||
const file = zcu.fileByIndex(file_index);
|
const file = zcu.fileByIndex(file_index);
|
||||||
break :sub_file_path file.sub_file_path;
|
break :path file.path.fmt(zcu.comp);
|
||||||
}, inst });
|
}, inst });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6162,50 +6162,67 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
|
||||||
}
|
}
|
||||||
const parent_mod = parent_block.ownerModule();
|
const parent_mod = parent_block.ownerModule();
|
||||||
const digest = Cache.binToHex(c_import_res.digest);
|
const digest = Cache.binToHex(c_import_res.digest);
|
||||||
const c_import_zig_path = try comp.arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ digest);
|
|
||||||
const c_import_mod = Package.Module.create(comp.arena, .{
|
const new_file_index = file: {
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
const c_import_zig_path = try comp.arena.dupe(u8, "o" ++ std.fs.path.sep_str ++ digest);
|
||||||
.paths = .{
|
const c_import_mod = Package.Module.create(comp.arena, .{
|
||||||
.root = .{
|
.paths = .{
|
||||||
.root_dir = comp.local_cache_directory,
|
.root = try .fromRoot(comp.arena, comp.dirs, .local_cache, c_import_zig_path),
|
||||||
.sub_path = c_import_zig_path,
|
.root_src_path = "cimport.zig",
|
||||||
},
|
},
|
||||||
.root_src_path = "cimport.zig",
|
.fully_qualified_name = c_import_zig_path,
|
||||||
},
|
.cc_argv = parent_mod.cc_argv,
|
||||||
.fully_qualified_name = c_import_zig_path,
|
.inherited = .{},
|
||||||
.cc_argv = parent_mod.cc_argv,
|
.global = comp.config,
|
||||||
.inherited = .{},
|
.parent = parent_mod,
|
||||||
.global = comp.config,
|
}) catch |err| switch (err) {
|
||||||
.parent = parent_mod,
|
// None of these are possible because we are creating a package with
|
||||||
.builtin_mod = parent_mod.getBuiltinDependency(),
|
// the exact same configuration as the parent package, which already
|
||||||
.builtin_modules = null, // `builtin_mod` is set
|
// passed these checks.
|
||||||
}) catch |err| switch (err) {
|
error.ValgrindUnsupportedOnTarget => unreachable,
|
||||||
// None of these are possible because we are creating a package with
|
error.TargetRequiresSingleThreaded => unreachable,
|
||||||
// the exact same configuration as the parent package, which already
|
error.BackendRequiresSingleThreaded => unreachable,
|
||||||
// passed these checks.
|
error.TargetRequiresPic => unreachable,
|
||||||
error.ValgrindUnsupportedOnTarget => unreachable,
|
error.PieRequiresPic => unreachable,
|
||||||
error.TargetRequiresSingleThreaded => unreachable,
|
error.DynamicLinkingRequiresPic => unreachable,
|
||||||
error.BackendRequiresSingleThreaded => unreachable,
|
error.TargetHasNoRedZone => unreachable,
|
||||||
error.TargetRequiresPic => unreachable,
|
error.StackCheckUnsupportedByTarget => unreachable,
|
||||||
error.PieRequiresPic => unreachable,
|
error.StackProtectorUnsupportedByTarget => unreachable,
|
||||||
error.DynamicLinkingRequiresPic => unreachable,
|
error.StackProtectorUnavailableWithoutLibC => unreachable,
|
||||||
error.TargetHasNoRedZone => unreachable,
|
|
||||||
error.StackCheckUnsupportedByTarget => unreachable,
|
|
||||||
error.StackProtectorUnsupportedByTarget => unreachable,
|
|
||||||
error.StackProtectorUnavailableWithoutLibC => unreachable,
|
|
||||||
|
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
|
};
|
||||||
|
const c_import_file_path: Compilation.Path = try c_import_mod.root.join(gpa, comp.dirs, "cimport.zig");
|
||||||
|
errdefer c_import_file_path.deinit(gpa);
|
||||||
|
const c_import_file = try gpa.create(Zcu.File);
|
||||||
|
errdefer gpa.destroy(c_import_file);
|
||||||
|
const c_import_file_index = try zcu.intern_pool.createFile(gpa, pt.tid, .{
|
||||||
|
.bin_digest = c_import_file_path.digest(),
|
||||||
|
.file = c_import_file,
|
||||||
|
.root_type = .none,
|
||||||
|
});
|
||||||
|
c_import_file.* = .{
|
||||||
|
.status = .never_loaded,
|
||||||
|
.stat = undefined,
|
||||||
|
.is_builtin = false,
|
||||||
|
.path = c_import_file_path,
|
||||||
|
.source = null,
|
||||||
|
.tree = null,
|
||||||
|
.zir = null,
|
||||||
|
.zoir = null,
|
||||||
|
.mod = c_import_mod,
|
||||||
|
.sub_file_path = "cimport.zig",
|
||||||
|
.module_changed = false,
|
||||||
|
.prev_zir = null,
|
||||||
|
.zoir_invalidated = false,
|
||||||
|
};
|
||||||
|
break :file c_import_file_index;
|
||||||
};
|
};
|
||||||
|
pt.updateFile(new_file_index, zcu.fileByIndex(new_file_index)) catch |err|
|
||||||
const result = pt.importPkg(c_import_mod) catch |err|
|
|
||||||
return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
|
return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
|
||||||
|
|
||||||
const path_digest = zcu.filePathDigest(result.file_index);
|
try pt.ensureFileAnalyzed(new_file_index);
|
||||||
pt.updateFile(result.file, path_digest) catch |err|
|
const ty = zcu.fileRootType(new_file_index);
|
||||||
return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
|
|
||||||
|
|
||||||
try pt.ensureFileAnalyzed(result.file_index);
|
|
||||||
const ty = zcu.fileRootType(result.file_index);
|
|
||||||
try sema.declareDependency(.{ .interned = ty });
|
try sema.declareDependency(.{ .interned = ty });
|
||||||
try sema.addTypeReferenceEntry(src, ty);
|
try sema.addTypeReferenceEntry(src, ty);
|
||||||
return Air.internedToRef(ty);
|
return Air.internedToRef(ty);
|
||||||
|
|
@ -14097,25 +14114,19 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
|
||||||
const operand_src = block.tokenOffset(inst_data.src_tok);
|
const operand_src = block.tokenOffset(inst_data.src_tok);
|
||||||
const operand = sema.code.nullTerminatedString(extra.path);
|
const operand = sema.code.nullTerminatedString(extra.path);
|
||||||
|
|
||||||
const result = pt.importFile(block.getFileScope(zcu), operand) catch |err| switch (err) {
|
const result = pt.doImport(block.getFileScope(zcu), operand) catch |err| switch (err) {
|
||||||
error.ImportOutsideModulePath => {
|
error.ModuleNotFound => return sema.fail(block, operand_src, "no module named '{s}' available within module '{s}'", .{
|
||||||
return sema.fail(block, operand_src, "import of file outside module path: '{s}'", .{operand});
|
operand, block.getFileScope(zcu).mod.?.fully_qualified_name,
|
||||||
},
|
}),
|
||||||
error.ModuleNotFound => {
|
error.IllegalZigImport => unreachable, // caught before semantic analysis
|
||||||
return sema.fail(block, operand_src, "no module named '{s}' available within module {s}", .{
|
error.OutOfMemory => |e| return e,
|
||||||
operand, block.getFileScope(zcu).mod.fully_qualified_name,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
else => {
|
|
||||||
// TODO: these errors are file system errors; make sure an update() will
|
|
||||||
// retry this and not cache the file system error, which may be transient.
|
|
||||||
return sema.fail(block, operand_src, "unable to open '{s}': {s}", .{ operand, @errorName(err) });
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
switch (result.file.getMode()) {
|
const file_index = result.file;
|
||||||
|
const file = zcu.fileByIndex(file_index);
|
||||||
|
switch (file.getMode()) {
|
||||||
.zig => {
|
.zig => {
|
||||||
try pt.ensureFileAnalyzed(result.file_index);
|
try pt.ensureFileAnalyzed(file_index);
|
||||||
const ty = zcu.fileRootType(result.file_index);
|
const ty = zcu.fileRootType(file_index);
|
||||||
try sema.declareDependency(.{ .interned = ty });
|
try sema.declareDependency(.{ .interned = ty });
|
||||||
try sema.addTypeReferenceEntry(operand_src, ty);
|
try sema.addTypeReferenceEntry(operand_src, ty);
|
||||||
return Air.internedToRef(ty);
|
return Air.internedToRef(ty);
|
||||||
|
|
@ -14129,11 +14140,11 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
|
||||||
break :b res_ty.toIntern();
|
break :b res_ty.toIntern();
|
||||||
};
|
};
|
||||||
|
|
||||||
try sema.declareDependency(.{ .zon_file = result.file_index });
|
try sema.declareDependency(.{ .zon_file = file_index });
|
||||||
const interned = try LowerZon.run(
|
const interned = try LowerZon.run(
|
||||||
sema,
|
sema,
|
||||||
result.file,
|
file,
|
||||||
result.file_index,
|
file_index,
|
||||||
res_ty,
|
res_ty,
|
||||||
operand_src,
|
operand_src,
|
||||||
block,
|
block,
|
||||||
|
|
@ -17290,10 +17301,10 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
|
||||||
const name = name: {
|
const name = name: {
|
||||||
// TODO: we should probably store this name in the ZIR to avoid this complexity.
|
// TODO: we should probably store this name in the ZIR to avoid this complexity.
|
||||||
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
|
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
|
||||||
const tree = file.getTree(sema.gpa) catch |err| {
|
const tree = file.getTree(zcu) catch |err| {
|
||||||
// In this case we emit a warning + a less precise source location.
|
// In this case we emit a warning + a less precise source location.
|
||||||
log.warn("unable to load {s}: {s}", .{
|
log.warn("unable to load {}: {s}", .{
|
||||||
file.sub_file_path, @errorName(err),
|
file.path.fmt(zcu.comp), @errorName(err),
|
||||||
});
|
});
|
||||||
break :name null;
|
break :name null;
|
||||||
};
|
};
|
||||||
|
|
@ -17318,10 +17329,10 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
|
||||||
const msg = msg: {
|
const msg = msg: {
|
||||||
const name = name: {
|
const name = name: {
|
||||||
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
|
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
|
||||||
const tree = file.getTree(sema.gpa) catch |err| {
|
const tree = file.getTree(zcu) catch |err| {
|
||||||
// In this case we emit a warning + a less precise source location.
|
// In this case we emit a warning + a less precise source location.
|
||||||
log.warn("unable to load {s}: {s}", .{
|
log.warn("unable to load {}: {s}", .{
|
||||||
file.sub_file_path, @errorName(err),
|
file.path.fmt(zcu.comp), @errorName(err),
|
||||||
});
|
});
|
||||||
break :name null;
|
break :name null;
|
||||||
};
|
};
|
||||||
|
|
@ -17415,7 +17426,7 @@ fn zirBuiltinSrc(
|
||||||
};
|
};
|
||||||
|
|
||||||
const module_name_val = v: {
|
const module_name_val = v: {
|
||||||
const module_name = file_scope.mod.fully_qualified_name;
|
const module_name = file_scope.mod.?.fully_qualified_name;
|
||||||
const array_ty = try pt.intern(.{ .array_type = .{
|
const array_ty = try pt.intern(.{ .array_type = .{
|
||||||
.len = module_name.len,
|
.len = module_name.len,
|
||||||
.sentinel = .zero_u8,
|
.sentinel = .zero_u8,
|
||||||
|
|
|
||||||
707
src/Zcu.zig
707
src/Zcu.zig
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -333,7 +333,7 @@ pub fn generate(
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_type = Type.fromInterned(func.ty);
|
const fn_type = Type.fromInterned(func.ty);
|
||||||
const file_scope = zcu.navFileScope(func.owner_nav);
|
const file_scope = zcu.navFileScope(func.owner_nav);
|
||||||
const target = &file_scope.mod.resolved_target.result;
|
const target = &file_scope.mod.?.resolved_target.result;
|
||||||
|
|
||||||
var branch_stack = std.ArrayList(Branch).init(gpa);
|
var branch_stack = std.ArrayList(Branch).init(gpa);
|
||||||
defer {
|
defer {
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ pub fn generate(
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const func_ty = Type.fromInterned(func.ty);
|
const func_ty = Type.fromInterned(func.ty);
|
||||||
const file_scope = zcu.navFileScope(func.owner_nav);
|
const file_scope = zcu.navFileScope(func.owner_nav);
|
||||||
const target = &file_scope.mod.resolved_target.result;
|
const target = &file_scope.mod.?.resolved_target.result;
|
||||||
|
|
||||||
var branch_stack = std.ArrayList(Branch).init(gpa);
|
var branch_stack = std.ArrayList(Branch).init(gpa);
|
||||||
defer {
|
defer {
|
||||||
|
|
|
||||||
|
|
@ -767,7 +767,7 @@ pub fn generate(
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_type = Type.fromInterned(func.ty);
|
const fn_type = Type.fromInterned(func.ty);
|
||||||
const mod = zcu.navFileScope(func.owner_nav).mod;
|
const mod = zcu.navFileScope(func.owner_nav).mod.?;
|
||||||
|
|
||||||
var branch_stack = std.ArrayList(Branch).init(gpa);
|
var branch_stack = std.ArrayList(Branch).init(gpa);
|
||||||
defer {
|
defer {
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ pub fn generate(
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const func_ty = Type.fromInterned(func.ty);
|
const func_ty = Type.fromInterned(func.ty);
|
||||||
const file_scope = zcu.navFileScope(func.owner_nav);
|
const file_scope = zcu.navFileScope(func.owner_nav);
|
||||||
const target = &file_scope.mod.resolved_target.result;
|
const target = &file_scope.mod.?.resolved_target.result;
|
||||||
|
|
||||||
var branch_stack = std.ArrayList(Branch).init(gpa);
|
var branch_stack = std.ArrayList(Branch).init(gpa);
|
||||||
defer {
|
defer {
|
||||||
|
|
|
||||||
|
|
@ -1268,7 +1268,7 @@ pub fn function(
|
||||||
const gpa = zcu.gpa;
|
const gpa = zcu.gpa;
|
||||||
const cg = zcu.funcInfo(func_index);
|
const cg = zcu.funcInfo(func_index);
|
||||||
const file_scope = zcu.navFileScope(cg.owner_nav);
|
const file_scope = zcu.navFileScope(cg.owner_nav);
|
||||||
const target = &file_scope.mod.resolved_target.result;
|
const target = &file_scope.mod.?.resolved_target.result;
|
||||||
const fn_ty = zcu.navValue(cg.owner_nav).typeOf(zcu);
|
const fn_ty = zcu.navValue(cg.owner_nav).typeOf(zcu);
|
||||||
const fn_info = zcu.typeToFunc(fn_ty).?;
|
const fn_info = zcu.typeToFunc(fn_ty).?;
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
|
|
|
||||||
|
|
@ -892,7 +892,7 @@ pub fn generate(
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_type: Type = .fromInterned(func.ty);
|
const fn_type: Type = .fromInterned(func.ty);
|
||||||
const mod = zcu.navFileScope(func.owner_nav).mod;
|
const mod = zcu.navFileScope(func.owner_nav).mod.?;
|
||||||
|
|
||||||
var function: CodeGen = .{
|
var function: CodeGen = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ pub fn generateFunction(
|
||||||
) CodeGenError!void {
|
) CodeGenError!void {
|
||||||
const zcu = pt.zcu;
|
const zcu = pt.zcu;
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const target = zcu.navFileScope(func.owner_nav).mod.resolved_target.result;
|
const target = zcu.navFileScope(func.owner_nav).mod.?.resolved_target.result;
|
||||||
switch (target_util.zigBackend(target, false)) {
|
switch (target_util.zigBackend(target, false)) {
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
inline .stage2_aarch64,
|
inline .stage2_aarch64,
|
||||||
|
|
@ -81,7 +81,7 @@ pub fn generateLazyFunction(
|
||||||
) CodeGenError!void {
|
) CodeGenError!void {
|
||||||
const zcu = pt.zcu;
|
const zcu = pt.zcu;
|
||||||
const target = if (Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu)) |inst_index|
|
const target = if (Type.fromInterned(lazy_sym.ty).typeDeclInstAllowGeneratedTag(zcu)) |inst_index|
|
||||||
zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.resolved_target.result
|
zcu.fileByIndex(inst_index.resolveFile(&zcu.intern_pool)).mod.?.resolved_target.result
|
||||||
else
|
else
|
||||||
zcu.getTarget();
|
zcu.getTarget();
|
||||||
switch (target_util.zigBackend(target, false)) {
|
switch (target_util.zigBackend(target, false)) {
|
||||||
|
|
@ -722,7 +722,7 @@ fn lowerNavRef(
|
||||||
const zcu = pt.zcu;
|
const zcu = pt.zcu;
|
||||||
const gpa = zcu.gpa;
|
const gpa = zcu.gpa;
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
|
const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
|
||||||
const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
|
const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
|
||||||
const is_obj = lf.comp.config.output_mode == .Obj;
|
const is_obj = lf.comp.config.output_mode == .Obj;
|
||||||
const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
|
const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
|
||||||
|
|
@ -884,7 +884,7 @@ fn genNavRef(
|
||||||
else
|
else
|
||||||
.{ false, .none, nav.isThreadlocal(ip) };
|
.{ false, .none, nav.isThreadlocal(ip) };
|
||||||
|
|
||||||
const single_threaded = zcu.navFileScope(nav_index).mod.single_threaded;
|
const single_threaded = zcu.navFileScope(nav_index).mod.?.single_threaded;
|
||||||
const name = nav.name;
|
const name = nav.name;
|
||||||
if (lf.cast(.elf)) |elf_file| {
|
if (lf.cast(.elf)) |elf_file| {
|
||||||
const zo = elf_file.zigObjectPtr().?;
|
const zo = elf_file.zigObjectPtr().?;
|
||||||
|
|
|
||||||
|
|
@ -2670,7 +2670,7 @@ pub fn genTypeDecl(
|
||||||
_ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{});
|
_ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{});
|
||||||
try writer.writeByte(';');
|
try writer.writeByte(';');
|
||||||
const file_scope = ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip);
|
const file_scope = ty.typeDeclInstAllowGeneratedTag(zcu).?.resolveFile(ip);
|
||||||
if (!zcu.fileByIndex(file_scope).mod.strip) try writer.print(" /* {} */", .{
|
if (!zcu.fileByIndex(file_scope).mod.?.strip) try writer.print(" /* {} */", .{
|
||||||
ty.containerTypeName(ip).fmt(ip),
|
ty.containerTypeName(ip).fmt(ip),
|
||||||
});
|
});
|
||||||
try writer.writeByte('\n');
|
try writer.writeByte('\n');
|
||||||
|
|
|
||||||
|
|
@ -587,13 +587,8 @@ pub const Object = struct {
|
||||||
// into the garbage can by converting into absolute paths. What
|
// into the garbage can by converting into absolute paths. What
|
||||||
// a terrible tragedy.
|
// a terrible tragedy.
|
||||||
const compile_unit_dir = blk: {
|
const compile_unit_dir = blk: {
|
||||||
if (comp.zcu) |zcu| m: {
|
const zcu = comp.zcu orelse break :blk comp.dirs.cwd;
|
||||||
const d = try zcu.main_mod.root.joinString(arena, "");
|
break :blk try zcu.main_mod.root.toAbsolute(comp.dirs, arena);
|
||||||
if (d.len == 0) break :m;
|
|
||||||
if (std.fs.path.isAbsolute(d)) break :blk d;
|
|
||||||
break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
|
|
||||||
}
|
|
||||||
break :blk try std.process.getCwdAlloc(arena);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const debug_file = try builder.debugFile(
|
const debug_file = try builder.debugFile(
|
||||||
|
|
@ -1135,7 +1130,7 @@ pub const Object = struct {
|
||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const nav = ip.getNav(func.owner_nav);
|
const nav = ip.getNav(func.owner_nav);
|
||||||
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
|
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
|
||||||
const owner_mod = zcu.fileByIndex(file_scope).mod;
|
const owner_mod = zcu.fileByIndex(file_scope).mod.?;
|
||||||
const fn_ty = Type.fromInterned(func.ty);
|
const fn_ty = Type.fromInterned(func.ty);
|
||||||
const fn_info = zcu.typeToFunc(fn_ty).?;
|
const fn_info = zcu.typeToFunc(fn_ty).?;
|
||||||
const target = owner_mod.resolved_target.result;
|
const target = owner_mod.resolved_target.result;
|
||||||
|
|
@ -1735,20 +1730,14 @@ pub const Object = struct {
|
||||||
const gop = try o.debug_file_map.getOrPut(gpa, file_index);
|
const gop = try o.debug_file_map.getOrPut(gpa, file_index);
|
||||||
errdefer assert(o.debug_file_map.remove(file_index));
|
errdefer assert(o.debug_file_map.remove(file_index));
|
||||||
if (gop.found_existing) return gop.value_ptr.*;
|
if (gop.found_existing) return gop.value_ptr.*;
|
||||||
const file = o.pt.zcu.fileByIndex(file_index);
|
const zcu = o.pt.zcu;
|
||||||
|
const path = zcu.fileByIndex(file_index).path;
|
||||||
|
const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa);
|
||||||
|
defer gpa.free(abs_path);
|
||||||
|
|
||||||
gop.value_ptr.* = try o.builder.debugFile(
|
gop.value_ptr.* = try o.builder.debugFile(
|
||||||
try o.builder.metadataString(std.fs.path.basename(file.sub_file_path)),
|
try o.builder.metadataString(std.fs.path.basename(abs_path)),
|
||||||
dir_path: {
|
try o.builder.metadataString(std.fs.path.dirname(abs_path) orelse ""),
|
||||||
const sub_path = std.fs.path.dirname(file.sub_file_path) orelse "";
|
|
||||||
const dir_path = try file.mod.root.joinString(gpa, sub_path);
|
|
||||||
defer gpa.free(dir_path);
|
|
||||||
if (std.fs.path.isAbsolute(dir_path))
|
|
||||||
break :dir_path try o.builder.metadataString(dir_path);
|
|
||||||
var abs_buffer: [std.fs.max_path_bytes]u8 = undefined;
|
|
||||||
const abs_path = std.fs.realpath(dir_path, &abs_buffer) catch
|
|
||||||
break :dir_path try o.builder.metadataString(dir_path);
|
|
||||||
break :dir_path try o.builder.metadataString(abs_path);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
return gop.value_ptr.*;
|
return gop.value_ptr.*;
|
||||||
}
|
}
|
||||||
|
|
@ -2646,11 +2635,9 @@ pub const Object = struct {
|
||||||
const zcu = pt.zcu;
|
const zcu = pt.zcu;
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
|
|
||||||
const std_mod = zcu.std_mod;
|
const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
|
||||||
const std_file_imported = pt.importPkg(std_mod) catch unreachable;
|
|
||||||
|
|
||||||
const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
|
const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
|
||||||
const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index));
|
const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index));
|
||||||
const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
|
const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
|
||||||
const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
|
const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
|
||||||
|
|
||||||
|
|
@ -2683,7 +2670,7 @@ pub const Object = struct {
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const gpa = o.gpa;
|
const gpa = o.gpa;
|
||||||
const nav = ip.getNav(nav_index);
|
const nav = ip.getNav(nav_index);
|
||||||
const owner_mod = zcu.navFileScope(nav_index).mod;
|
const owner_mod = zcu.navFileScope(nav_index).mod.?;
|
||||||
const ty: Type = .fromInterned(nav.typeOf(ip));
|
const ty: Type = .fromInterned(nav.typeOf(ip));
|
||||||
const gop = try o.nav_map.getOrPut(gpa, nav_index);
|
const gop = try o.nav_map.getOrPut(gpa, nav_index);
|
||||||
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
|
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
|
||||||
|
|
@ -3013,7 +3000,7 @@ pub const Object = struct {
|
||||||
if (is_extern) {
|
if (is_extern) {
|
||||||
variable_index.setLinkage(.external, &o.builder);
|
variable_index.setLinkage(.external, &o.builder);
|
||||||
variable_index.setUnnamedAddr(.default, &o.builder);
|
variable_index.setUnnamedAddr(.default, &o.builder);
|
||||||
if (is_threadlocal and !zcu.navFileScope(nav_index).mod.single_threaded)
|
if (is_threadlocal and !zcu.navFileScope(nav_index).mod.?.single_threaded)
|
||||||
variable_index.setThreadLocal(.generaldynamic, &o.builder);
|
variable_index.setThreadLocal(.generaldynamic, &o.builder);
|
||||||
if (is_weak_linkage) variable_index.setLinkage(.extern_weak, &o.builder);
|
if (is_weak_linkage) variable_index.setLinkage(.extern_weak, &o.builder);
|
||||||
if (is_dll_import) variable_index.setDllStorageClass(.dllimport, &o.builder);
|
if (is_dll_import) variable_index.setDllStorageClass(.dllimport, &o.builder);
|
||||||
|
|
@ -4514,7 +4501,7 @@ pub const NavGen = struct {
|
||||||
err_msg: ?*Zcu.ErrorMsg,
|
err_msg: ?*Zcu.ErrorMsg,
|
||||||
|
|
||||||
fn ownerModule(ng: NavGen) *Package.Module {
|
fn ownerModule(ng: NavGen) *Package.Module {
|
||||||
return ng.object.pt.zcu.navFileScope(ng.nav_index).mod;
|
return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
|
fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
|
||||||
|
|
@ -4557,7 +4544,7 @@ pub const NavGen = struct {
|
||||||
}, &o.builder);
|
}, &o.builder);
|
||||||
|
|
||||||
const file_scope = zcu.navFileScopeIndex(nav_index);
|
const file_scope = zcu.navFileScopeIndex(nav_index);
|
||||||
const mod = zcu.fileByIndex(file_scope).mod;
|
const mod = zcu.fileByIndex(file_scope).mod.?;
|
||||||
if (is_threadlocal and !mod.single_threaded)
|
if (is_threadlocal and !mod.single_threaded)
|
||||||
variable_index.setThreadLocal(.generaldynamic, &o.builder);
|
variable_index.setThreadLocal(.generaldynamic, &o.builder);
|
||||||
|
|
||||||
|
|
@ -5121,7 +5108,7 @@ pub const FuncGen = struct {
|
||||||
const func = zcu.funcInfo(inline_func);
|
const func = zcu.funcInfo(inline_func);
|
||||||
const nav = ip.getNav(func.owner_nav);
|
const nav = ip.getNav(func.owner_nav);
|
||||||
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
|
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
|
||||||
const mod = zcu.fileByIndex(file_scope).mod;
|
const mod = zcu.fileByIndex(file_scope).mod.?;
|
||||||
|
|
||||||
self.file = try o.getDebugFile(file_scope);
|
self.file = try o.getDebugFile(file_scope);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ pub const Object = struct {
|
||||||
) !void {
|
) !void {
|
||||||
const zcu = pt.zcu;
|
const zcu = pt.zcu;
|
||||||
const gpa = zcu.gpa;
|
const gpa = zcu.gpa;
|
||||||
const structured_cfg = zcu.navFileScope(nav_index).mod.structured_cfg;
|
const structured_cfg = zcu.navFileScope(nav_index).mod.?.structured_cfg;
|
||||||
|
|
||||||
var nav_gen = NavGen{
|
var nav_gen = NavGen{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
|
|
|
||||||
|
|
@ -86,15 +86,12 @@ fn dumpStatusReport() !void {
|
||||||
|
|
||||||
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse {
|
const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu) orelse {
|
||||||
const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool));
|
const file = zcu.fileByIndex(block.src_base_inst.resolveFile(&zcu.intern_pool));
|
||||||
try stderr.writeAll("Analyzing lost instruction in file '");
|
try stderr.print("Analyzing lost instruction in file '{}'. This should not happen!\n\n", .{file.path.fmt(zcu.comp)});
|
||||||
try writeFilePath(file, stderr);
|
|
||||||
try stderr.writeAll("'. This should not happen!\n\n");
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
try stderr.writeAll("Analyzing ");
|
try stderr.writeAll("Analyzing ");
|
||||||
try writeFilePath(file, stderr);
|
try stderr.print("Analyzing '{}'\n", .{file.path.fmt(zcu.comp)});
|
||||||
try stderr.writeAll("\n");
|
|
||||||
|
|
||||||
print_zir.renderInstructionContext(
|
print_zir.renderInstructionContext(
|
||||||
allocator,
|
allocator,
|
||||||
|
|
@ -108,23 +105,24 @@ fn dumpStatusReport() !void {
|
||||||
error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"),
|
error.OutOfMemory => try stderr.writeAll(" <out of memory dumping zir>\n"),
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
};
|
};
|
||||||
try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");
|
try stderr.print(
|
||||||
try writeFilePath(file, stderr);
|
\\ For full context, use the command
|
||||||
try stderr.writeAll("\n\n");
|
\\ zig ast-check -t {}
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{file.path.fmt(zcu.comp)});
|
||||||
|
|
||||||
var parent = anal.parent;
|
var parent = anal.parent;
|
||||||
while (parent) |curr| {
|
while (parent) |curr| {
|
||||||
fba.reset();
|
fba.reset();
|
||||||
try stderr.writeAll(" in ");
|
const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool));
|
||||||
const cur_block_file, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse {
|
try stderr.print(" in {}\n", .{cur_block_file.path.fmt(zcu.comp)});
|
||||||
const cur_block_file = zcu.fileByIndex(curr.block.src_base_inst.resolveFile(&zcu.intern_pool));
|
_, const cur_block_src_base_node = Zcu.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, zcu) orelse {
|
||||||
try writeFilePath(cur_block_file, stderr);
|
try stderr.writeAll(" > [lost instruction; this should not happen]\n");
|
||||||
try stderr.writeAll("\n > [lost instruction; this should not happen]\n");
|
|
||||||
parent = curr.parent;
|
parent = curr.parent;
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
try writeFilePath(cur_block_file, stderr);
|
try stderr.writeAll(" > ");
|
||||||
try stderr.writeAll("\n > ");
|
|
||||||
print_zir.renderSingleInstruction(
|
print_zir.renderSingleInstruction(
|
||||||
allocator,
|
allocator,
|
||||||
curr.body[curr.body_index],
|
curr.body[curr.body_index],
|
||||||
|
|
@ -146,18 +144,6 @@ fn dumpStatusReport() !void {
|
||||||
|
|
||||||
var crash_heap: [16 * 4096]u8 = undefined;
|
var crash_heap: [16 * 4096]u8 = undefined;
|
||||||
|
|
||||||
fn writeFilePath(file: *Zcu.File, writer: anytype) !void {
|
|
||||||
if (file.mod.root.root_dir.path) |path| {
|
|
||||||
try writer.writeAll(path);
|
|
||||||
try writer.writeAll(std.fs.path.sep_str);
|
|
||||||
}
|
|
||||||
if (file.mod.root.sub_path.len > 0) {
|
|
||||||
try writer.writeAll(file.mod.root.sub_path);
|
|
||||||
try writer.writeAll(std.fs.path.sep_str);
|
|
||||||
}
|
|
||||||
try writer.writeAll(file.sub_file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compilerPanic(msg: []const u8, maybe_ret_addr: ?usize) noreturn {
|
pub fn compilerPanic(msg: []const u8, maybe_ret_addr: ?usize) noreturn {
|
||||||
@branchHint(.cold);
|
@branchHint(.cold);
|
||||||
PanicSwitch.preDispatch();
|
PanicSwitch.preDispatch();
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
|
const Allocator = mem.Allocator;
|
||||||
const os = std.os;
|
const os = std.os;
|
||||||
const fs = std.fs;
|
const fs = std.fs;
|
||||||
|
const Cache = std.Build.Cache;
|
||||||
const Compilation = @import("Compilation.zig");
|
const Compilation = @import("Compilation.zig");
|
||||||
|
const Package = @import("Package.zig");
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
|
|
||||||
/// Returns the sub_path that worked, or `null` if none did.
|
/// Returns the sub_path that worked, or `null` if none did.
|
||||||
/// The path of the returned Directory is relative to `base`.
|
/// The path of the returned Directory is relative to `base`.
|
||||||
/// The handle of the returned Directory is open.
|
/// The handle of the returned Directory is open.
|
||||||
fn testZigInstallPrefix(base_dir: fs.Dir) ?Compilation.Directory {
|
fn testZigInstallPrefix(base_dir: fs.Dir) ?Cache.Directory {
|
||||||
const test_index_file = "std" ++ fs.path.sep_str ++ "std.zig";
|
const test_index_file = "std" ++ fs.path.sep_str ++ "std.zig";
|
||||||
|
|
||||||
zig_dir: {
|
zig_dir: {
|
||||||
|
|
@ -21,7 +24,7 @@ fn testZigInstallPrefix(base_dir: fs.Dir) ?Compilation.Directory {
|
||||||
break :zig_dir;
|
break :zig_dir;
|
||||||
};
|
};
|
||||||
file.close();
|
file.close();
|
||||||
return Compilation.Directory{ .handle = test_zig_dir, .path = lib_zig };
|
return .{ .handle = test_zig_dir, .path = lib_zig };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try lib/std/std.zig
|
// Try lib/std/std.zig
|
||||||
|
|
@ -31,37 +34,50 @@ fn testZigInstallPrefix(base_dir: fs.Dir) ?Compilation.Directory {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
file.close();
|
file.close();
|
||||||
return Compilation.Directory{ .handle = test_zig_dir, .path = "lib" };
|
return .{ .handle = test_zig_dir, .path = "lib" };
|
||||||
}
|
|
||||||
|
|
||||||
/// This is a small wrapper around selfExePathAlloc that adds support for WASI
|
|
||||||
/// based on a hard-coded Preopen directory ("/zig")
|
|
||||||
pub fn findZigExePath(allocator: mem.Allocator) ![]u8 {
|
|
||||||
if (builtin.os.tag == .wasi) {
|
|
||||||
@compileError("this function is unsupported on WASI");
|
|
||||||
}
|
|
||||||
|
|
||||||
return fs.selfExePathAlloc(allocator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Both the directory handle and the path are newly allocated resources which the caller now owns.
|
/// Both the directory handle and the path are newly allocated resources which the caller now owns.
|
||||||
pub fn findZigLibDir(gpa: mem.Allocator) !Compilation.Directory {
|
pub fn findZigLibDir(gpa: Allocator) !Cache.Directory {
|
||||||
const self_exe_path = try findZigExePath(gpa);
|
const cwd_path = try getResolvedCwd(gpa);
|
||||||
|
defer gpa.free(cwd_path);
|
||||||
|
const self_exe_path = try fs.selfExePathAlloc(gpa);
|
||||||
defer gpa.free(self_exe_path);
|
defer gpa.free(self_exe_path);
|
||||||
|
|
||||||
return findZigLibDirFromSelfExe(gpa, self_exe_path);
|
return findZigLibDirFromSelfExe(gpa, cwd_path, self_exe_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Like `std.process.getCwdAlloc`, but also resolves the path with `std.fs.path.resolve`. This
|
||||||
|
/// means the path has no repeated separators, no "." or ".." components, and no trailing separator.
|
||||||
|
/// On WASI, "" is returned instead of ".".
|
||||||
|
pub fn getResolvedCwd(gpa: Allocator) error{
|
||||||
|
OutOfMemory,
|
||||||
|
CurrentWorkingDirectoryUnlinked,
|
||||||
|
Unexpected,
|
||||||
|
}![]u8 {
|
||||||
|
if (builtin.target.os.tag == .wasi) {
|
||||||
|
if (std.debug.runtime_safety) {
|
||||||
|
const cwd = try std.process.getCwdAlloc(gpa);
|
||||||
|
defer gpa.free(cwd);
|
||||||
|
std.debug.assert(mem.eql(u8, cwd, "."));
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const cwd = try std.process.getCwdAlloc(gpa);
|
||||||
|
defer gpa.free(cwd);
|
||||||
|
const resolved = try fs.path.resolve(gpa, &.{cwd});
|
||||||
|
std.debug.assert(fs.path.isAbsolute(resolved));
|
||||||
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Both the directory handle and the path are newly allocated resources which the caller now owns.
|
/// Both the directory handle and the path are newly allocated resources which the caller now owns.
|
||||||
pub fn findZigLibDirFromSelfExe(
|
pub fn findZigLibDirFromSelfExe(
|
||||||
allocator: mem.Allocator,
|
allocator: Allocator,
|
||||||
|
/// The return value of `getResolvedCwd`.
|
||||||
|
/// Passed as an argument to avoid pointlessly repeating the call.
|
||||||
|
cwd_path: []const u8,
|
||||||
self_exe_path: []const u8,
|
self_exe_path: []const u8,
|
||||||
) error{
|
) error{ OutOfMemory, FileNotFound }!Cache.Directory {
|
||||||
OutOfMemory,
|
|
||||||
FileNotFound,
|
|
||||||
CurrentWorkingDirectoryUnlinked,
|
|
||||||
Unexpected,
|
|
||||||
}!Compilation.Directory {
|
|
||||||
const cwd = fs.cwd();
|
const cwd = fs.cwd();
|
||||||
var cur_path: []const u8 = self_exe_path;
|
var cur_path: []const u8 = self_exe_path;
|
||||||
while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
|
while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
|
||||||
|
|
@ -69,18 +85,20 @@ pub fn findZigLibDirFromSelfExe(
|
||||||
defer base_dir.close();
|
defer base_dir.close();
|
||||||
|
|
||||||
const sub_directory = testZigInstallPrefix(base_dir) orelse continue;
|
const sub_directory = testZigInstallPrefix(base_dir) orelse continue;
|
||||||
const p = try fs.path.join(allocator, &[_][]const u8{ dirname, sub_directory.path.? });
|
const p = try fs.path.join(allocator, &.{ dirname, sub_directory.path.? });
|
||||||
defer allocator.free(p);
|
defer allocator.free(p);
|
||||||
return Compilation.Directory{
|
|
||||||
|
const resolved = try resolvePath(allocator, cwd_path, &.{p});
|
||||||
|
return .{
|
||||||
.handle = sub_directory.handle,
|
.handle = sub_directory.handle,
|
||||||
.path = try resolvePath(allocator, p),
|
.path = if (resolved.len == 0) null else resolved,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return error.FileNotFound;
|
return error.FileNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Caller owns returned memory.
|
/// Caller owns returned memory.
|
||||||
pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 {
|
pub fn resolveGlobalCacheDir(allocator: Allocator) ![]u8 {
|
||||||
if (builtin.os.tag == .wasi)
|
if (builtin.os.tag == .wasi)
|
||||||
@compileError("on WASI the global cache dir must be resolved with preopens");
|
@compileError("on WASI the global cache dir must be resolved with preopens");
|
||||||
|
|
||||||
|
|
@ -91,56 +109,107 @@ pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 {
|
||||||
if (builtin.os.tag != .windows) {
|
if (builtin.os.tag != .windows) {
|
||||||
if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {
|
if (std.zig.EnvVar.XDG_CACHE_HOME.getPosix()) |cache_root| {
|
||||||
if (cache_root.len > 0) {
|
if (cache_root.len > 0) {
|
||||||
return fs.path.join(allocator, &[_][]const u8{ cache_root, appname });
|
return fs.path.join(allocator, &.{ cache_root, appname });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (std.zig.EnvVar.HOME.getPosix()) |home| {
|
if (std.zig.EnvVar.HOME.getPosix()) |home| {
|
||||||
return fs.path.join(allocator, &[_][]const u8{ home, ".cache", appname });
|
return fs.path.join(allocator, &.{ home, ".cache", appname });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs.getAppDataDir(allocator, appname);
|
return fs.getAppDataDir(allocator, appname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Similar to std.fs.path.resolve, with a few important differences:
|
/// Similar to `fs.path.resolve`, but converts to a cwd-relative path, or, if that would
|
||||||
/// * If the input is an absolute path, check it against the cwd and try to
|
/// start with a relative up-dir (".."), an absolute path based on the cwd. Also, the cwd
|
||||||
/// convert it to a relative path.
|
/// returns the empty string ("") instead of ".".
|
||||||
/// * If the resulting path would start with a relative up-dir ("../"), instead
|
|
||||||
/// return an absolute path based on the cwd.
|
|
||||||
/// * When targeting WASI, fail with an error message if an absolute path is
|
|
||||||
/// used.
|
|
||||||
pub fn resolvePath(
|
pub fn resolvePath(
|
||||||
ally: mem.Allocator,
|
gpa: Allocator,
|
||||||
p: []const u8,
|
/// The return value of `getResolvedCwd`.
|
||||||
) error{
|
/// Passed as an argument to avoid pointlessly repeating the call.
|
||||||
OutOfMemory,
|
cwd_resolved: []const u8,
|
||||||
CurrentWorkingDirectoryUnlinked,
|
paths: []const []const u8,
|
||||||
Unexpected,
|
) Allocator.Error![]u8 {
|
||||||
}![]u8 {
|
if (builtin.target.os.tag == .wasi) {
|
||||||
if (fs.path.isAbsolute(p)) {
|
std.debug.assert(mem.eql(u8, cwd_resolved, ""));
|
||||||
const cwd_path = try std.process.getCwdAlloc(ally);
|
const res = try fs.path.resolve(gpa, paths);
|
||||||
defer ally.free(cwd_path);
|
if (mem.eql(u8, res, ".")) {
|
||||||
const relative = try fs.path.relative(ally, cwd_path, p);
|
gpa.free(res);
|
||||||
if (isUpDir(relative)) {
|
return "";
|
||||||
ally.free(relative);
|
|
||||||
return ally.dupe(u8, p);
|
|
||||||
} else {
|
|
||||||
return relative;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const resolved = try fs.path.resolve(ally, &.{p});
|
|
||||||
if (isUpDir(resolved)) {
|
|
||||||
ally.free(resolved);
|
|
||||||
const cwd_path = try std.process.getCwdAlloc(ally);
|
|
||||||
defer ally.free(cwd_path);
|
|
||||||
return fs.path.resolve(ally, &.{ cwd_path, p });
|
|
||||||
} else {
|
|
||||||
return resolved;
|
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Heuristic for a fast path: if no component is absolute and ".." never appears, we just need to resolve `paths`.
|
||||||
|
for (paths) |p| {
|
||||||
|
if (fs.path.isAbsolute(p)) break; // absolute path
|
||||||
|
if (mem.indexOf(u8, p, "..") != null) break; // may contain up-dir
|
||||||
|
} else {
|
||||||
|
// no absolute path, no "..".
|
||||||
|
const res = try fs.path.resolve(gpa, paths);
|
||||||
|
if (mem.eql(u8, res, ".")) {
|
||||||
|
gpa.free(res);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std.debug.assert(!fs.path.isAbsolute(res));
|
||||||
|
std.debug.assert(!isUpDir(res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The fast path failed; resolve the whole thing.
|
||||||
|
// Optimization: `paths` often has just one element.
|
||||||
|
const path_resolved = switch (paths.len) {
|
||||||
|
0 => unreachable,
|
||||||
|
1 => try fs.path.resolve(gpa, &.{ cwd_resolved, paths[0] }),
|
||||||
|
else => r: {
|
||||||
|
const all_paths = try gpa.alloc([]const u8, paths.len + 1);
|
||||||
|
defer gpa.free(all_paths);
|
||||||
|
all_paths[0] = cwd_resolved;
|
||||||
|
@memcpy(all_paths[1..], paths);
|
||||||
|
break :r try fs.path.resolve(gpa, all_paths);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
errdefer gpa.free(path_resolved);
|
||||||
|
|
||||||
|
std.debug.assert(fs.path.isAbsolute(path_resolved));
|
||||||
|
std.debug.assert(fs.path.isAbsolute(cwd_resolved));
|
||||||
|
|
||||||
|
if (!std.mem.startsWith(u8, path_resolved, cwd_resolved)) return path_resolved; // not in cwd
|
||||||
|
if (path_resolved.len == cwd_resolved.len) {
|
||||||
|
// equal to cwd
|
||||||
|
gpa.free(path_resolved);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (path_resolved[cwd_resolved.len] != std.fs.path.sep) return path_resolved; // not in cwd (last component differs)
|
||||||
|
|
||||||
|
// in cwd; extract sub path
|
||||||
|
const sub_path = try gpa.dupe(u8, path_resolved[cwd_resolved.len + 1 ..]);
|
||||||
|
gpa.free(path_resolved);
|
||||||
|
return sub_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO move this to std.fs.path
|
/// TODO move this to std.fs.path
|
||||||
pub fn isUpDir(p: []const u8) bool {
|
pub fn isUpDir(p: []const u8) bool {
|
||||||
return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == fs.path.sep);
|
return mem.startsWith(u8, p, "..") and (p.len == 2 or p[2] == fs.path.sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const default_local_zig_cache_basename = ".zig-cache";
|
||||||
|
|
||||||
|
/// Searches upwards from `cwd` for a directory containing a `build.zig` file.
|
||||||
|
/// If such a directory is found, returns the path to it joined to the `.zig_cache` name.
|
||||||
|
/// Otherwise, returns `null`, indicating no suitable local cache location.
|
||||||
|
pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator.Error!?[]u8 {
|
||||||
|
var cur_dir = cwd;
|
||||||
|
while (true) {
|
||||||
|
const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
|
||||||
|
if (fs.cwd().access(joined, .{})) |_| {
|
||||||
|
return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
|
||||||
|
} else |err| switch (err) {
|
||||||
|
error.FileNotFound => {
|
||||||
|
cur_dir = fs.path.dirname(cur_dir) orelse return null;
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
else => return null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
fn includePath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 {
|
||||||
return path.join(arena, &.{
|
return path.join(arena, &.{
|
||||||
comp.zig_lib_directory.path.?,
|
comp.dirs.zig_lib.path.?,
|
||||||
"libc" ++ path.sep_str ++ "include",
|
"libc" ++ path.sep_str ++ "include",
|
||||||
sub_path,
|
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 {
|
fn csuPath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 {
|
||||||
return path.join(arena, &.{
|
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",
|
"libc" ++ path.sep_str ++ "freebsd" ++ path.sep_str ++ "lib" ++ path.sep_str ++ "csu",
|
||||||
sub_path,
|
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 {
|
fn libcPath(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 {
|
||||||
return path.join(arena, &.{
|
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",
|
"libc" ++ path.sep_str ++ "freebsd" ++ path.sep_str ++ "lib" ++ path.sep_str ++ "libc",
|
||||||
sub_path,
|
sub_path,
|
||||||
});
|
});
|
||||||
|
|
@ -438,11 +438,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
// Use the global cache directory.
|
// Use the global cache directory.
|
||||||
var cache: Cache = .{
|
var cache: Cache = .{
|
||||||
.gpa = gpa,
|
.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(.{ .path = null, .handle = fs.cwd() });
|
||||||
cache.addPrefix(comp.zig_lib_directory);
|
cache.addPrefix(comp.dirs.zig_lib);
|
||||||
cache.addPrefix(comp.global_cache_directory);
|
cache.addPrefix(comp.dirs.global_cache);
|
||||||
defer cache.manifest_dir.close();
|
defer cache.manifest_dir.close();
|
||||||
|
|
||||||
var man = cache.obtain();
|
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.abi);
|
||||||
man.hash.add(target_version);
|
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);
|
const abilists_index = try man.addFile(full_abilists_path, abilists_max_size);
|
||||||
|
|
||||||
if (try man.hit()) {
|
if (try man.hit()) {
|
||||||
|
|
@ -461,7 +461,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
return queueSharedObjects(comp, .{
|
return queueSharedObjects(comp, .{
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
.dir_path = .{
|
.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),
|
.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 digest = man.final();
|
||||||
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
||||||
|
|
||||||
var o_directory: Compilation.Directory = .{
|
var o_directory: Cache.Directory = .{
|
||||||
.handle = try comp.global_cache_directory.handle.makeOpenPath(o_sub_path, .{}),
|
.handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
|
||||||
.path = try comp.global_cache_directory.join(arena, &.{o_sub_path}),
|
.path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
|
||||||
};
|
};
|
||||||
defer o_directory.handle.close();
|
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.
|
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;
|
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 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| {
|
man.writeManifest() catch |err| {
|
||||||
|
|
@ -984,7 +984,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
return queueSharedObjects(comp, .{
|
return queueSharedObjects(comp, .{
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
.dir_path = .{
|
.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),
|
.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(
|
fn buildSharedLib(
|
||||||
comp: *Compilation,
|
comp: *Compilation,
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
zig_cache_directory: Compilation.Directory,
|
bin_directory: Cache.Directory,
|
||||||
bin_directory: Compilation.Directory,
|
|
||||||
asm_file_basename: []const u8,
|
asm_file_basename: []const u8,
|
||||||
lib: Lib,
|
lib: Lib,
|
||||||
prog_node: std.Progress.Node,
|
prog_node: std.Progress.Node,
|
||||||
|
|
@ -1057,9 +1056,8 @@ fn buildSharedLib(
|
||||||
});
|
});
|
||||||
|
|
||||||
const root_mod = try Module.create(arena, .{
|
const root_mod = try Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -1079,8 +1077,6 @@ fn buildSharedLib(
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &.{},
|
.cc_argv = &.{},
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const c_source_files = [1]Compilation.CSourceFile{
|
const c_source_files = [1]Compilation.CSourceFile{
|
||||||
|
|
@ -1091,9 +1087,7 @@ fn buildSharedLib(
|
||||||
};
|
};
|
||||||
|
|
||||||
const sub_compilation = try Compilation.create(comp.gpa, arena, .{
|
const sub_compilation = try Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = zig_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.thread_pool = comp.thread_pool,
|
.thread_pool = comp.thread_pool,
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .incremental,
|
.cache_mode = .incremental,
|
||||||
|
|
|
||||||
|
|
@ -365,7 +365,7 @@ fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![
|
||||||
const s = path.sep_str;
|
const s = path.sep_str;
|
||||||
|
|
||||||
var result = std.ArrayList(u8).init(arena);
|
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);
|
try result.appendSlice(s ++ "libc" ++ s ++ "glibc" ++ s ++ "sysdeps" ++ s);
|
||||||
if (is_sparc) {
|
if (is_sparc) {
|
||||||
if (is_64) {
|
if (is_64) {
|
||||||
|
|
@ -439,7 +439,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([
|
||||||
}
|
}
|
||||||
if (opt_nptl) |nptl| {
|
if (opt_nptl) |nptl| {
|
||||||
try args.append("-I");
|
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");
|
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(try lib_path(comp, arena, lib_libc_glibc ++ "sysdeps" ++ s ++ "generic"));
|
||||||
|
|
||||||
try args.append("-I");
|
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("-I");
|
||||||
try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-{s}", .{
|
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");
|
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);
|
const arch_name = std.zig.target.osArchName(target);
|
||||||
try args.append("-I");
|
try args.append("-I");
|
||||||
try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-linux-any", .{
|
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");
|
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 = "libc" ++ path.sep_str;
|
||||||
const lib_libc_glibc = lib_libc ++ "glibc" ++ 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 {
|
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 {
|
pub const BuiltSharedObjects = struct {
|
||||||
|
|
@ -678,11 +674,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
// Use the global cache directory.
|
// Use the global cache directory.
|
||||||
var cache: Cache = .{
|
var cache: Cache = .{
|
||||||
.gpa = gpa,
|
.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(.{ .path = null, .handle = fs.cwd() });
|
||||||
cache.addPrefix(comp.zig_lib_directory);
|
cache.addPrefix(comp.dirs.zig_lib);
|
||||||
cache.addPrefix(comp.global_cache_directory);
|
cache.addPrefix(comp.dirs.global_cache);
|
||||||
defer cache.manifest_dir.close();
|
defer cache.manifest_dir.close();
|
||||||
|
|
||||||
var man = cache.obtain();
|
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.abi);
|
||||||
man.hash.add(target_version);
|
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);
|
const abilists_index = try man.addFile(full_abilists_path, abilists_max_size);
|
||||||
|
|
||||||
if (try man.hit()) {
|
if (try man.hit()) {
|
||||||
|
|
@ -701,7 +697,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
return queueSharedObjects(comp, .{
|
return queueSharedObjects(comp, .{
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
.dir_path = .{
|
.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),
|
.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 digest = man.final();
|
||||||
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest });
|
||||||
|
|
||||||
var o_directory: Compilation.Directory = .{
|
var o_directory: Cache.Directory = .{
|
||||||
.handle = try comp.global_cache_directory.handle.makeOpenPath(o_sub_path, .{}),
|
.handle = try comp.dirs.global_cache.handle.makeOpenPath(o_sub_path, .{}),
|
||||||
.path = try comp.global_cache_directory.join(arena, &.{o_sub_path}),
|
.path = try comp.dirs.global_cache.join(arena, &.{o_sub_path}),
|
||||||
};
|
};
|
||||||
defer o_directory.handle.close();
|
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.
|
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;
|
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 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| {
|
man.writeManifest() catch |err| {
|
||||||
|
|
@ -1122,7 +1118,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
|
||||||
return queueSharedObjects(comp, .{
|
return queueSharedObjects(comp, .{
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
.dir_path = .{
|
.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),
|
.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(
|
fn buildSharedLib(
|
||||||
comp: *Compilation,
|
comp: *Compilation,
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
zig_cache_directory: Compilation.Directory,
|
bin_directory: Cache.Directory,
|
||||||
bin_directory: Compilation.Directory,
|
|
||||||
asm_file_basename: []const u8,
|
asm_file_basename: []const u8,
|
||||||
lib: Lib,
|
lib: Lib,
|
||||||
prog_node: std.Progress.Node,
|
prog_node: std.Progress.Node,
|
||||||
|
|
@ -1208,9 +1203,8 @@ fn buildSharedLib(
|
||||||
});
|
});
|
||||||
|
|
||||||
const root_mod = try Module.create(arena, .{
|
const root_mod = try Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -1230,8 +1224,6 @@ fn buildSharedLib(
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &.{},
|
.cc_argv = &.{},
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const c_source_files = [1]Compilation.CSourceFile{
|
const c_source_files = [1]Compilation.CSourceFile{
|
||||||
|
|
@ -1242,9 +1234,7 @@ fn buildSharedLib(
|
||||||
};
|
};
|
||||||
|
|
||||||
const sub_compilation = try Compilation.create(comp.gpa, arena, .{
|
const sub_compilation = try Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = zig_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.thread_pool = comp.thread_pool,
|
.thread_pool = comp.thread_pool,
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .incremental,
|
.cache_mode = .incremental,
|
||||||
|
|
|
||||||
|
|
@ -134,10 +134,10 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
|
||||||
.basename = basename,
|
.basename = basename,
|
||||||
};
|
};
|
||||||
|
|
||||||
const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
|
const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
|
||||||
const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
|
const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });
|
||||||
const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
|
const cxx_src_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "src" });
|
||||||
const cxx_libc_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "libc" });
|
const cxx_libc_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "libc" });
|
||||||
|
|
||||||
const optimize_mode = comp.compilerRtOptMode();
|
const optimize_mode = comp.compilerRtOptMode();
|
||||||
const strip = comp.compilerRtStrip();
|
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, .{
|
const root_mod = Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -188,8 +187,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &.{},
|
.cc_argv = &.{},
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
comp.setMiscFailure(
|
comp.setMiscFailure(
|
||||||
.libcxx,
|
.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);
|
try cache_exempt_flags.append(cxx_libc_include_path);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.cache_exempt_flags = cache_exempt_flags.items,
|
.cache_exempt_flags = cache_exempt_flags.items,
|
||||||
.owner = root_mod,
|
.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, .{
|
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = comp.global_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
.config = config,
|
.config = config,
|
||||||
|
|
@ -344,9 +339,9 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
.basename = basename,
|
.basename = basename,
|
||||||
};
|
};
|
||||||
|
|
||||||
const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
|
const cxxabi_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxxabi", "include" });
|
||||||
const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
|
const cxx_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "include" });
|
||||||
const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
|
const cxx_src_include_path = try comp.dirs.zig_lib.join(arena, &.{ "libcxx", "src" });
|
||||||
|
|
||||||
const optimize_mode = comp.compilerRtOptMode();
|
const optimize_mode = comp.compilerRtOptMode();
|
||||||
const strip = comp.compilerRtStrip();
|
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, .{
|
const root_mod = Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -403,8 +397,6 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &.{},
|
.cc_argv = &.{},
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
comp.setMiscFailure(
|
comp.setMiscFailure(
|
||||||
.libcxxabi,
|
.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);
|
try cache_exempt_flags.append(cxx_src_include_path);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.cache_exempt_flags = cache_exempt_flags.items,
|
.cache_exempt_flags = cache_exempt_flags.items,
|
||||||
.owner = root_mod,
|
.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, .{
|
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = comp.global_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
.config = config,
|
.config = config,
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
};
|
};
|
||||||
|
|
||||||
const root_mod = Module.create(arena, .{
|
const root_mod = Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -110,8 +109,6 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &common_flags,
|
.cc_argv = &common_flags,
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
comp.setMiscFailure(
|
comp.setMiscFailure(
|
||||||
.libtsan,
|
.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);
|
var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||||
try c_source_files.ensureUnusedCapacity(tsan_sources.len);
|
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| {
|
for (tsan_sources) |tsan_src| {
|
||||||
var cflags = std.ArrayList([]const u8).init(arena);
|
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);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.owner = root_mod,
|
.owner = root_mod,
|
||||||
});
|
});
|
||||||
|
|
@ -155,7 +152,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
try addCcArgs(target, &cflags);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.owner = root_mod,
|
.owner = root_mod,
|
||||||
});
|
});
|
||||||
|
|
@ -179,14 +176,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
try cflags.append("-DNDEBUG");
|
try cflags.append("-DNDEBUG");
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.owner = root_mod,
|
.owner = root_mod,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try c_source_files.ensureUnusedCapacity(sanitizer_common_sources.len);
|
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",
|
"libtsan", "sanitizer_common",
|
||||||
});
|
});
|
||||||
for (sanitizer_common_sources) |common_src| {
|
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);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
"libtsan", "sanitizer_common", common_src,
|
||||||
}),
|
}),
|
||||||
.extra_flags = cflags.items,
|
.extra_flags = cflags.items,
|
||||||
|
|
@ -224,7 +221,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
try addCcArgs(target, &cflags);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
"libtsan", "sanitizer_common", c_src,
|
||||||
}),
|
}),
|
||||||
.extra_flags = cflags.items,
|
.extra_flags = cflags.items,
|
||||||
|
|
@ -242,7 +239,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
|
||||||
try addCcArgs(target, &cflags);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
"libtsan", "sanitizer_common", c_src,
|
||||||
}),
|
}),
|
||||||
.extra_flags = cflags.items,
|
.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(
|
const interception_include_path = try comp.dirs.zig_lib.join(arena, &.{"interception"});
|
||||||
arena,
|
|
||||||
&[_][]const u8{"interception"},
|
|
||||||
);
|
|
||||||
|
|
||||||
try c_source_files.ensureUnusedCapacity(interception_sources.len);
|
try c_source_files.ensureUnusedCapacity(interception_sources.len);
|
||||||
for (interception_sources) |c_src| {
|
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);
|
try addCcArgs(target, &cflags);
|
||||||
|
|
||||||
c_source_files.appendAssumeCapacity(.{
|
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,
|
"libtsan", "interception", c_src,
|
||||||
}),
|
}),
|
||||||
.extra_flags = cflags.items,
|
.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
|
// Workaround for https://github.com/llvm/llvm-project/issues/97627
|
||||||
const headerpad_size: ?u32 = if (target.os.tag.isDarwin()) 32 else null;
|
const headerpad_size: ?u32 = if (target.os.tag.isDarwin()) 32 else null;
|
||||||
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = comp.global_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.thread_pool = comp.thread_pool,
|
.thread_pool = comp.thread_pool,
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
return error.SubCompilationFailed;
|
return error.SubCompilationFailed;
|
||||||
};
|
};
|
||||||
const root_mod = Module.create(arena, .{
|
const root_mod = Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -76,8 +75,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = &.{},
|
.cc_argv = &.{},
|
||||||
.parent = null,
|
.parent = null,
|
||||||
.builtin_mod = null,
|
|
||||||
.builtin_modules = null, // there is only one module in this compilation
|
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
comp.setMiscFailure(
|
comp.setMiscFailure(
|
||||||
.libunwind,
|
.libunwind,
|
||||||
|
|
@ -118,7 +115,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
else => unreachable, // See `unwind_src_list`.
|
else => unreachable, // See `unwind_src_list`.
|
||||||
}
|
}
|
||||||
try cflags.append("-I");
|
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("-D_LIBUNWIND_HIDE_SYMBOLS");
|
||||||
try cflags.append("-Wa,--noexecstack");
|
try cflags.append("-Wa,--noexecstack");
|
||||||
try cflags.append("-fvisibility=hidden");
|
try cflags.append("-fvisibility=hidden");
|
||||||
|
|
@ -148,16 +145,14 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
|
||||||
}
|
}
|
||||||
|
|
||||||
c_source_files[i] = .{
|
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,
|
.extra_flags = cflags.items,
|
||||||
.owner = root_mod,
|
.owner = root_mod,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
const sub_compilation = Compilation.create(comp.gpa, arena, .{
|
||||||
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.self_exe_path = comp.self_exe_path,
|
.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,
|
.config = config,
|
||||||
.root_mod = root_mod,
|
.root_mod = root_mod,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||||
}
|
}
|
||||||
var files = [_]Compilation.CSourceFile{
|
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",
|
"libc", "mingw", "crt", "crtexe.c",
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
try addCrtCcArgs(comp, arena, &args);
|
||||||
var files = [_]Compilation.CSourceFile{
|
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",
|
"libc", "mingw", "crt", "crtdll.c",
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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| {
|
for (mingw32_generic_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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()) {
|
if (target.cpu.arch.isX86()) {
|
||||||
for (mingw32_x86_src) |dep| {
|
for (mingw32_x86_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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) {
|
if (target.cpu.arch == .x86) {
|
||||||
for (mingw32_x86_32_src) |dep| {
|
for (mingw32_x86_32_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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) {
|
} else if (target.cpu.arch == .thumb) {
|
||||||
for (mingw32_arm_src) |dep| {
|
for (mingw32_arm_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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| {
|
for (mingw32_arm32_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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) {
|
} else if (target.cpu.arch == .aarch64) {
|
||||||
for (mingw32_arm_src) |dep| {
|
for (mingw32_arm_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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| {
|
for (mingw32_arm64_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = crt_args.items,
|
.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| {
|
for (mingw32_winpthreads_src) |dep| {
|
||||||
try c_source_files.append(.{
|
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,
|
"libc", "mingw", dep,
|
||||||
}),
|
}),
|
||||||
.extra_flags = winpthreads_args.items,
|
.extra_flags = winpthreads_args.items,
|
||||||
|
|
@ -192,7 +192,7 @@ fn addCcArgs(
|
||||||
"-D__USE_MINGW_ANSI_STDIO=0",
|
"-D__USE_MINGW_ANSI_STDIO=0",
|
||||||
|
|
||||||
"-isystem",
|
"-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",
|
"-DHAVE_CONFIG_H",
|
||||||
|
|
||||||
"-I",
|
"-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();
|
defer arena_allocator.deinit();
|
||||||
const arena = arena_allocator.allocator();
|
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 => {
|
error.FileNotFound => {
|
||||||
log.debug("no {s}.def file available to make a DLL import {s}.lib", .{ lib_name, lib_name });
|
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
|
// 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.
|
// Use the global cache directory.
|
||||||
var cache: Cache = .{
|
var cache: Cache = .{
|
||||||
.gpa = gpa,
|
.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(.{ .path = null, .handle = std.fs.cwd() });
|
||||||
cache.addPrefix(comp.zig_lib_directory);
|
cache.addPrefix(comp.dirs.zig_lib);
|
||||||
cache.addPrefix(comp.global_cache_directory);
|
cache.addPrefix(comp.dirs.global_cache);
|
||||||
defer cache.manifest_dir.close();
|
defer cache.manifest_dir.close();
|
||||||
|
|
||||||
cache.hash.addBytes(build_options.version);
|
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);
|
cache.hash.add(target.cpu.arch);
|
||||||
|
|
||||||
var man = cache.obtain();
|
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);
|
try comp.crt_files.ensureUnusedCapacity(gpa, 1);
|
||||||
comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{
|
comp.crt_files.putAssumeCapacityNoClobber(final_lib_basename, .{
|
||||||
.full_object_path = .{
|
.full_object_path = .{
|
||||||
.root_dir = comp.global_cache_directory,
|
.root_dir = comp.dirs.global_cache,
|
||||||
.sub_path = sub_path,
|
.sub_path = sub_path,
|
||||||
},
|
},
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
|
|
@ -286,11 +286,11 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
|
||||||
|
|
||||||
const digest = man.final();
|
const digest = man.final();
|
||||||
const o_sub_path = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
|
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();
|
defer o_dir.close();
|
||||||
|
|
||||||
const final_def_basename = try std.fmt.allocPrint(arena, "{s}.def", .{lib_name});
|
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,
|
"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());
|
var aro_comp = aro.Compilation.init(gpa, std.fs.cwd());
|
||||||
defer aro_comp.deinit();
|
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: {
|
if (comp.verbose_cc) print: {
|
||||||
std.debug.lockStdErr();
|
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;
|
if (!build_options.have_llvm) return error.ZigCompilerNotBuiltWithLLVMExtensions;
|
||||||
const llvm_bindings = @import("../codegen/llvm/bindings.zig");
|
const llvm_bindings = @import("../codegen/llvm/bindings.zig");
|
||||||
const def_final_path_z = try arena.dupeZ(u8, def_final_path);
|
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(
|
if (llvm_bindings.WriteImportLibrary(
|
||||||
def_final_path_z.ptr,
|
def_final_path_z.ptr,
|
||||||
@intFromEnum(target.toCoffMachine()),
|
@intFromEnum(target.toCoffMachine()),
|
||||||
|
|
@ -370,7 +370,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
|
||||||
defer comp.mutex.unlock();
|
defer comp.mutex.unlock();
|
||||||
try comp.crt_files.putNoClobber(gpa, final_lib_basename, .{
|
try comp.crt_files.putNoClobber(gpa, final_lib_basename, .{
|
||||||
.full_object_path = .{
|
.full_object_path = .{
|
||||||
.root_dir = comp.global_cache_directory,
|
.root_dir = comp.dirs.global_cache,
|
||||||
.sub_path = lib_final_path,
|
.sub_path = lib_final_path,
|
||||||
},
|
},
|
||||||
.lock = man.toOwnedLock(),
|
.lock = man.toOwnedLock(),
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||||
try args.append("-DCRT");
|
try args.append("-DCRT");
|
||||||
var files = [_]Compilation.CSourceFile{
|
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",
|
"libc", "musl", "crt", "crt1.c",
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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");
|
try args.append("-DCRT");
|
||||||
var files = [_]Compilation.CSourceFile{
|
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",
|
"libc", "musl", "crt", "rcrt1.c",
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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");
|
try args.append("-DCRT");
|
||||||
var files = [_]Compilation.CSourceFile{
|
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",
|
"libc", "musl", "crt", "Scrt1.c",
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
try addCcArgs(comp, arena, &args, ext == .o3);
|
||||||
const c_source_file = try c_source_files.addOne();
|
const c_source_file = try c_source_files.addOne();
|
||||||
c_source_file.* = .{
|
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,
|
.extra_flags = args.items,
|
||||||
.owner = undefined,
|
.owner = undefined,
|
||||||
};
|
};
|
||||||
|
|
@ -220,9 +220,8 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||||
&.{ arch_define, family_define };
|
&.{ arch_define, family_define };
|
||||||
|
|
||||||
const root_mod = try Module.create(arena, .{
|
const root_mod = try Module.create(arena, .{
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
.root = .{ .root_dir = comp.zig_lib_directory },
|
.root = .zig_lib_root,
|
||||||
.root_src_path = "",
|
.root_src_path = "",
|
||||||
},
|
},
|
||||||
.fully_qualified_name = "root",
|
.fully_qualified_name = "root",
|
||||||
|
|
@ -242,14 +241,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
|
||||||
.global = config,
|
.global = config,
|
||||||
.cc_argv = cc_argv,
|
.cc_argv = cc_argv,
|
||||||
.parent = null,
|
.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, .{
|
const sub_compilation = try Compilation.create(comp.gpa, arena, .{
|
||||||
.local_cache_directory = comp.global_cache_directory,
|
.dirs = comp.dirs.withoutLocalCache(),
|
||||||
.global_cache_directory = comp.global_cache_directory,
|
|
||||||
.zig_lib_directory = comp.zig_lib_directory,
|
|
||||||
.self_exe_path = comp.self_exe_path,
|
.self_exe_path = comp.self_exe_path,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
.config = config,
|
.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_cimport = comp.verbose_cimport,
|
||||||
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
|
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
|
||||||
.clang_passthrough_mode = comp.clang_passthrough_mode,
|
.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,
|
.owner = root_mod,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -411,25 +406,25 @@ fn addCcArgs(
|
||||||
"-D_XOPEN_SOURCE=700",
|
"-D_XOPEN_SOURCE=700",
|
||||||
|
|
||||||
"-I",
|
"-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",
|
"-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",
|
"-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",
|
"-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",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "musl", "include" }),
|
try comp.dirs.zig_lib.join(arena, &.{ "libc", "musl", "include" }),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", triple }),
|
try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }),
|
||||||
|
|
||||||
"-I",
|
"-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,
|
o_arg,
|
||||||
|
|
||||||
|
|
@ -444,7 +439,7 @@ fn addCcArgs(
|
||||||
|
|
||||||
fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 {
|
fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 {
|
||||||
const target = comp.getTarget();
|
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,
|
"libc", "musl", "crt", std.zig.target.muslArchName(target.cpu.arch, target.abi), basename,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
|
||||||
try addLibcBottomHalfIncludes(comp, arena, &args);
|
try addLibcBottomHalfIncludes(comp, arena, &args);
|
||||||
var files = [_]Compilation.CSourceFile{
|
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),
|
"libc", try sanitize(arena, crt1_reactor_src_file),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
try addLibcBottomHalfIncludes(comp, arena, &args);
|
||||||
var files = [_]Compilation.CSourceFile{
|
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),
|
"libc", try sanitize(arena, crt1_command_src_file),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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 });
|
try addCCArgs(comp, arena, &args, .{ .want_O3 = true, .no_strict_aliasing = true });
|
||||||
for (emmalloc_src_files) |file_path| {
|
for (emmalloc_src_files) |file_path| {
|
||||||
try libc_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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| {
|
for (libc_bottom_half_src_files) |file_path| {
|
||||||
try libc_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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| {
|
for (libc_top_half_src_files) |file_path| {
|
||||||
try libc_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
var emu_dl_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||||
for (emulated_dl_src_files) |file_path| {
|
for (emulated_dl_src_files) |file_path| {
|
||||||
try emu_dl_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||||
for (emulated_process_clocks_src_files) |file_path| {
|
for (emulated_process_clocks_src_files) |file_path| {
|
||||||
try emu_clocks_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||||
for (emulated_getpid_src_files) |file_path| {
|
for (emulated_getpid_src_files) |file_path| {
|
||||||
try emu_getpid_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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);
|
var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
|
||||||
for (emulated_mman_src_files) |file_path| {
|
for (emulated_mman_src_files) |file_path| {
|
||||||
try emu_mman_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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| {
|
for (emulated_signal_bottom_half_src_files) |file_path| {
|
||||||
try emu_signal_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.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| {
|
for (emulated_signal_top_half_src_files) |file_path| {
|
||||||
try emu_signal_sources.append(.{
|
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),
|
"libc", try sanitize(arena, file_path),
|
||||||
}),
|
}),
|
||||||
.extra_flags = args.items,
|
.extra_flags = args.items,
|
||||||
|
|
@ -316,10 +316,10 @@ fn addCCArgs(
|
||||||
"/",
|
"/",
|
||||||
|
|
||||||
"-iwithsysroot",
|
"-iwithsysroot",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", triple }),
|
try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }),
|
||||||
|
|
||||||
"-iwithsysroot",
|
"-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",
|
"-DBULK_MEMORY_THRESHOLD=32",
|
||||||
});
|
});
|
||||||
|
|
@ -336,7 +336,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
) error{OutOfMemory}!void {
|
) error{OutOfMemory}!void {
|
||||||
try args.appendSlice(&[_][]const u8{
|
try args.appendSlice(&[_][]const u8{
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-bottom-half",
|
"libc-bottom-half",
|
||||||
|
|
@ -345,7 +345,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-bottom-half",
|
"libc-bottom-half",
|
||||||
|
|
@ -355,7 +355,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-bottom-half",
|
"libc-bottom-half",
|
||||||
|
|
@ -364,7 +364,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
@ -374,7 +374,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"musl",
|
"musl",
|
||||||
"src",
|
"src",
|
||||||
|
|
@ -382,7 +382,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
@ -392,7 +392,7 @@ fn addLibcBottomHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"musl",
|
"musl",
|
||||||
"src",
|
"src",
|
||||||
|
|
@ -408,7 +408,7 @@ fn addLibcTopHalfIncludes(
|
||||||
) error{OutOfMemory}!void {
|
) error{OutOfMemory}!void {
|
||||||
try args.appendSlice(&[_][]const u8{
|
try args.appendSlice(&[_][]const u8{
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
@ -418,7 +418,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"musl",
|
"musl",
|
||||||
"src",
|
"src",
|
||||||
|
|
@ -426,7 +426,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
@ -436,7 +436,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"musl",
|
"musl",
|
||||||
"src",
|
"src",
|
||||||
|
|
@ -444,7 +444,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
@ -454,7 +454,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"musl",
|
"musl",
|
||||||
"arch",
|
"arch",
|
||||||
|
|
@ -462,7 +462,7 @@ fn addLibcTopHalfIncludes(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
"-I",
|
"-I",
|
||||||
try comp.zig_lib_directory.join(arena, &[_][]const u8{
|
try comp.dirs.zig_lib.join(arena, &.{
|
||||||
"libc",
|
"libc",
|
||||||
"wasi",
|
"wasi",
|
||||||
"libc-top-half",
|
"libc-top-half",
|
||||||
|
|
|
||||||
|
|
@ -1675,8 +1675,8 @@ pub fn spawnLld(
|
||||||
const rand_int = std.crypto.random.int(u64);
|
const rand_int = std.crypto.random.int(u64);
|
||||||
const rsp_path = "tmp" ++ s ++ std.fmt.hex(rand_int) ++ ".rsp";
|
const rsp_path = "tmp" ++ s ++ std.fmt.hex(rand_int) ++ ".rsp";
|
||||||
|
|
||||||
const rsp_file = try comp.local_cache_directory.handle.createFileZ(rsp_path, .{});
|
const rsp_file = try comp.dirs.local_cache.handle.createFileZ(rsp_path, .{});
|
||||||
defer comp.local_cache_directory.handle.deleteFileZ(rsp_path) catch |err|
|
defer comp.dirs.local_cache.handle.deleteFileZ(rsp_path) catch |err|
|
||||||
log.warn("failed to delete response file {s}: {s}", .{ rsp_path, @errorName(err) });
|
log.warn("failed to delete response file {s}: {s}", .{ rsp_path, @errorName(err) });
|
||||||
{
|
{
|
||||||
defer rsp_file.close();
|
defer rsp_file.close();
|
||||||
|
|
@ -1700,7 +1700,7 @@ pub fn spawnLld(
|
||||||
var rsp_child = std.process.Child.init(&.{ argv[0], argv[1], try std.fmt.allocPrint(
|
var rsp_child = std.process.Child.init(&.{ argv[0], argv[1], try std.fmt.allocPrint(
|
||||||
arena,
|
arena,
|
||||||
"@{s}",
|
"@{s}",
|
||||||
.{try comp.local_cache_directory.join(arena, &.{rsp_path})},
|
.{try comp.dirs.local_cache.join(arena, &.{rsp_path})},
|
||||||
) }, arena);
|
) }, arena);
|
||||||
if (comp.clang_passthrough_mode) {
|
if (comp.clang_passthrough_mode) {
|
||||||
rsp_child.stdin_behavior = .Inherit;
|
rsp_child.stdin_behavior = .Inherit;
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ pub fn updateFunc(
|
||||||
.dg = .{
|
.dg = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
.pt = pt,
|
.pt = pt,
|
||||||
.mod = zcu.navFileScope(func.owner_nav).mod,
|
.mod = zcu.navFileScope(func.owner_nav).mod.?,
|
||||||
.error_msg = null,
|
.error_msg = null,
|
||||||
.pass = .{ .nav = func.owner_nav },
|
.pass = .{ .nav = func.owner_nav },
|
||||||
.is_naked_fn = Type.fromInterned(func.ty).fnCallingConvention(zcu) == .naked,
|
.is_naked_fn = Type.fromInterned(func.ty).fnCallingConvention(zcu) == .naked,
|
||||||
|
|
@ -337,7 +337,7 @@ pub fn updateNav(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) l
|
||||||
.dg = .{
|
.dg = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
.pt = pt,
|
.pt = pt,
|
||||||
.mod = zcu.navFileScope(nav_index).mod,
|
.mod = zcu.navFileScope(nav_index).mod.?,
|
||||||
.error_msg = null,
|
.error_msg = null,
|
||||||
.pass = .{ .nav = nav_index },
|
.pass = .{ .nav = nav_index },
|
||||||
.is_naked_fn = false,
|
.is_naked_fn = false,
|
||||||
|
|
@ -490,7 +490,7 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
|
||||||
|
|
||||||
for (self.navs.keys(), self.navs.values()) |nav, *av_block| try self.flushAvBlock(
|
for (self.navs.keys(), self.navs.values()) |nav, *av_block| try self.flushAvBlock(
|
||||||
pt,
|
pt,
|
||||||
zcu.navFileScope(nav).mod,
|
zcu.navFileScope(nav).mod.?,
|
||||||
&f,
|
&f,
|
||||||
av_block,
|
av_block,
|
||||||
self.exported_navs.getPtr(nav),
|
self.exported_navs.getPtr(nav),
|
||||||
|
|
@ -846,7 +846,7 @@ pub fn updateExports(
|
||||||
const gpa = zcu.gpa;
|
const gpa = zcu.gpa;
|
||||||
const mod, const pass: codegen.DeclGen.Pass, const decl_block, const exported_block = switch (exported) {
|
const mod, const pass: codegen.DeclGen.Pass, const decl_block, const exported_block = switch (exported) {
|
||||||
.nav => |nav| .{
|
.nav => |nav| .{
|
||||||
zcu.navFileScope(nav).mod,
|
zcu.navFileScope(nav).mod.?,
|
||||||
.{ .nav = nav },
|
.{ .nav = nav },
|
||||||
self.navs.getPtr(nav).?,
|
self.navs.getPtr(nav).?,
|
||||||
(try self.exported_navs.getOrPut(gpa, nav)).value_ptr,
|
(try self.exported_navs.getOrPut(gpa, nav)).value_ptr,
|
||||||
|
|
|
||||||
|
|
@ -1392,7 +1392,7 @@ fn updateNavCode(
|
||||||
|
|
||||||
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
|
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
|
||||||
|
|
||||||
const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
|
const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
|
||||||
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
||||||
.none => target_util.defaultFunctionAlignment(target),
|
.none => target_util.defaultFunctionAlignment(target),
|
||||||
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,7 @@ pub const UpdateError = error{
|
||||||
std.fs.File.PReadError ||
|
std.fs.File.PReadError ||
|
||||||
std.fs.File.PWriteError;
|
std.fs.File.PWriteError;
|
||||||
|
|
||||||
pub const FlushError =
|
pub const FlushError = UpdateError;
|
||||||
UpdateError ||
|
|
||||||
std.process.GetCwdError;
|
|
||||||
|
|
||||||
pub const RelocError =
|
pub const RelocError =
|
||||||
std.fs.File.PWriteError;
|
std.fs.File.PWriteError;
|
||||||
|
|
@ -967,7 +965,7 @@ const Entry = struct {
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {
|
for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {
|
||||||
const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|
|
const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|
|
||||||
dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod) catch unreachable
|
dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod.?) catch unreachable
|
||||||
else
|
else
|
||||||
.main;
|
.main;
|
||||||
if (sec.getUnit(ty_unit) == unit and unit.getEntry(other_entry) == entry)
|
if (sec.getUnit(ty_unit) == unit and unit.getEntry(other_entry) == entry)
|
||||||
|
|
@ -977,7 +975,7 @@ const Entry = struct {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (dwarf.navs.keys(), dwarf.navs.values()) |nav, other_entry| {
|
for (dwarf.navs.keys(), dwarf.navs.values()) |nav, other_entry| {
|
||||||
const nav_unit = dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav).srcInst(ip).resolveFile(ip)).mod) catch unreachable;
|
const nav_unit = dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav).srcInst(ip).resolveFile(ip)).mod.?) catch unreachable;
|
||||||
if (sec.getUnit(nav_unit) == unit and unit.getEntry(other_entry) == entry)
|
if (sec.getUnit(nav_unit) == unit and unit.getEntry(other_entry) == entry)
|
||||||
log.err("missing Nav({}({d}))", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) });
|
log.err("missing Nav({}({d}))", .{ ip.getNav(nav).fqn.fmt(ip), @intFromEnum(nav) });
|
||||||
}
|
}
|
||||||
|
|
@ -1620,7 +1618,7 @@ pub const WipNav = struct {
|
||||||
|
|
||||||
const new_func_info = zcu.funcInfo(func);
|
const new_func_info = zcu.funcInfo(func);
|
||||||
const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav);
|
const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav);
|
||||||
const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod);
|
const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod.?);
|
||||||
|
|
||||||
const dlw = wip_nav.debug_line.writer(dwarf.gpa);
|
const dlw = wip_nav.debug_line.writer(dwarf.gpa);
|
||||||
if (dwarf.incremental()) {
|
if (dwarf.incremental()) {
|
||||||
|
|
@ -1810,7 +1808,7 @@ pub const WipNav = struct {
|
||||||
fn getNavEntry(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!struct { Unit.Index, Entry.Index } {
|
fn getNavEntry(wip_nav: *WipNav, nav_index: InternPool.Nav.Index) UpdateError!struct { Unit.Index, Entry.Index } {
|
||||||
const zcu = wip_nav.pt.zcu;
|
const zcu = wip_nav.pt.zcu;
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav_index).srcInst(ip).resolveFile(ip)).mod);
|
const unit = try wip_nav.dwarf.getUnit(zcu.fileByIndex(ip.getNav(nav_index).srcInst(ip).resolveFile(ip)).mod.?);
|
||||||
const gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index);
|
const gop = try wip_nav.dwarf.navs.getOrPut(wip_nav.dwarf.gpa, nav_index);
|
||||||
if (gop.found_existing) return .{ unit, gop.value_ptr.* };
|
if (gop.found_existing) return .{ unit, gop.value_ptr.* };
|
||||||
const entry = try wip_nav.dwarf.addCommonEntry(unit);
|
const entry = try wip_nav.dwarf.addCommonEntry(unit);
|
||||||
|
|
@ -1828,7 +1826,7 @@ pub const WipNav = struct {
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
const maybe_inst_index = ty.typeDeclInst(zcu);
|
const maybe_inst_index = ty.typeDeclInst(zcu);
|
||||||
const unit = if (maybe_inst_index) |inst_index|
|
const unit = if (maybe_inst_index) |inst_index|
|
||||||
try wip_nav.dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod)
|
try wip_nav.dwarf.getUnit(zcu.fileByIndex(inst_index.resolveFile(ip)).mod.?)
|
||||||
else
|
else
|
||||||
.main;
|
.main;
|
||||||
const gop = try wip_nav.dwarf.types.getOrPut(wip_nav.dwarf.gpa, ty.toIntern());
|
const gop = try wip_nav.dwarf.types.getOrPut(wip_nav.dwarf.gpa, ty.toIntern());
|
||||||
|
|
@ -2386,7 +2384,7 @@ fn initWipNavInner(
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
const unit = try dwarf.getUnit(file.mod);
|
const unit = try dwarf.getUnit(file.mod.?);
|
||||||
const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);
|
const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);
|
||||||
errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop();
|
errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop();
|
||||||
if (nav_gop.found_existing) {
|
if (nav_gop.found_existing) {
|
||||||
|
|
@ -2514,7 +2512,7 @@ fn initWipNavInner(
|
||||||
try wip_nav.infoAddrSym(sym_index, 0);
|
try wip_nav.infoAddrSym(sym_index, 0);
|
||||||
wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
|
wip_nav.func_high_pc = @intCast(wip_nav.debug_info.items.len);
|
||||||
try diw.writeInt(u32, 0, dwarf.endian);
|
try diw.writeInt(u32, 0, dwarf.endian);
|
||||||
const target = file.mod.resolved_target.result;
|
const target = file.mod.?.resolved_target.result;
|
||||||
try uleb128(diw, switch (nav.status.fully_resolved.alignment) {
|
try uleb128(diw, switch (nav.status.fully_resolved.alignment) {
|
||||||
.none => target_info.defaultFunctionAlignment(target),
|
.none => target_info.defaultFunctionAlignment(target),
|
||||||
else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),
|
else => |a| a.maxStrict(target_info.minFunctionAlignment(target)),
|
||||||
|
|
@ -2726,7 +2724,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
|
||||||
var wip_nav: WipNav = .{
|
var wip_nav: WipNav = .{
|
||||||
.dwarf = dwarf,
|
.dwarf = dwarf,
|
||||||
.pt = pt,
|
.pt = pt,
|
||||||
.unit = try dwarf.getUnit(file.mod),
|
.unit = try dwarf.getUnit(file.mod.?),
|
||||||
.entry = undefined,
|
.entry = undefined,
|
||||||
.any_children = false,
|
.any_children = false,
|
||||||
.func = .none,
|
.func = .none,
|
||||||
|
|
@ -4044,7 +4042,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
|
||||||
|
|
||||||
const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?;
|
const inst_info = ty.typeDeclInst(zcu).?.resolveFull(ip).?;
|
||||||
const file = zcu.fileByIndex(inst_info.file);
|
const file = zcu.fileByIndex(inst_info.file);
|
||||||
const unit = try dwarf.getUnit(file.mod);
|
const unit = try dwarf.getUnit(file.mod.?);
|
||||||
const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file);
|
const file_gop = try dwarf.getModInfo(unit).files.getOrPut(dwarf.gpa, inst_info.file);
|
||||||
if (inst_info.inst == .main_struct_inst) {
|
if (inst_info.inst == .main_struct_inst) {
|
||||||
const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index);
|
const type_gop = try dwarf.types.getOrPut(dwarf.gpa, type_index);
|
||||||
|
|
@ -4348,7 +4346,7 @@ pub fn updateLineNumber(dwarf: *Dwarf, zcu: *Zcu, zir_index: InternPool.TrackedI
|
||||||
var line_buf: [4]u8 = undefined;
|
var line_buf: [4]u8 = undefined;
|
||||||
std.mem.writeInt(u32, &line_buf, decl.src_line + 1, dwarf.endian);
|
std.mem.writeInt(u32, &line_buf, decl.src_line + 1, dwarf.endian);
|
||||||
|
|
||||||
const unit = dwarf.debug_info.section.getUnit(dwarf.getUnitIfExists(file.mod) orelse return);
|
const unit = dwarf.debug_info.section.getUnit(dwarf.getUnitIfExists(file.mod.?) orelse return);
|
||||||
const entry = unit.getEntry(dwarf.decls.get(zir_index) orelse return);
|
const entry = unit.getEntry(dwarf.decls.get(zir_index) orelse return);
|
||||||
try dwarf.getFile().?.pwriteAll(&line_buf, dwarf.debug_info.section.off(dwarf) + unit.off + unit.header_len + entry.off + DebugInfo.declEntryLineOff(dwarf));
|
try dwarf.getFile().?.pwriteAll(&line_buf, dwarf.debug_info.section.off(dwarf) + unit.off + unit.header_len + entry.off + DebugInfo.declEntryLineOff(dwarf));
|
||||||
}
|
}
|
||||||
|
|
@ -4418,18 +4416,10 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
|
||||||
try wip_nav.updateLazy(.unneeded);
|
try wip_nav.updateLazy(.unneeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| {
|
||||||
const cwd = try std.process.getCwdAlloc(dwarf.gpa);
|
const root_dir_path = try mod.root.toAbsolute(zcu.comp.dirs, dwarf.gpa);
|
||||||
defer dwarf.gpa.free(cwd);
|
defer dwarf.gpa.free(root_dir_path);
|
||||||
for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| {
|
mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path);
|
||||||
const root_dir_path = try std.fs.path.resolve(dwarf.gpa, &.{
|
|
||||||
cwd,
|
|
||||||
mod.root.root_dir.path orelse "",
|
|
||||||
mod.root.sub_path,
|
|
||||||
});
|
|
||||||
defer dwarf.gpa.free(root_dir_path);
|
|
||||||
mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var header = std.ArrayList(u8).init(dwarf.gpa);
|
var header = std.ArrayList(u8).init(dwarf.gpa);
|
||||||
|
|
@ -4687,7 +4677,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
|
||||||
header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes());
|
header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes());
|
||||||
dwarf.writeInt(
|
dwarf.writeInt(
|
||||||
header.addManyAsSliceAssumeCapacity(dir_index_info.bytes),
|
header.addManyAsSliceAssumeCapacity(dir_index_info.bytes),
|
||||||
mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod).?).?,
|
mod_info.dirs.getIndex(dwarf.getUnitIfExists(file.mod.?).?) orelse 0,
|
||||||
);
|
);
|
||||||
unit.cross_section_relocs.appendAssumeCapacity(.{
|
unit.cross_section_relocs.appendAssumeCapacity(.{
|
||||||
.source_off = @intCast(header.items.len),
|
.source_off = @intCast(header.items.len),
|
||||||
|
|
@ -4695,7 +4685,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
|
||||||
.target_unit = StringSection.unit,
|
.target_unit = StringSection.unit,
|
||||||
.target_entry = (try dwarf.debug_line_str.addString(
|
.target_entry = (try dwarf.debug_line_str.addString(
|
||||||
dwarf,
|
dwarf,
|
||||||
if (file.mod.builtin_file == file) file.source.? else "",
|
if (file.is_builtin) file.source.? else "",
|
||||||
)).toOptional(),
|
)).toOptional(),
|
||||||
});
|
});
|
||||||
header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes());
|
header.appendNTimesAssumeCapacity(0, dwarf.sectionOffsetBytes());
|
||||||
|
|
|
||||||
|
|
@ -1201,7 +1201,7 @@ fn getNavShdrIndex(
|
||||||
return osec;
|
return osec;
|
||||||
}
|
}
|
||||||
if (nav_init != .none and Value.fromInterned(nav_init).isUndefDeep(zcu))
|
if (nav_init != .none and Value.fromInterned(nav_init).isUndefDeep(zcu))
|
||||||
return switch (zcu.navFileScope(nav_index).mod.optimize_mode) {
|
return switch (zcu.navFileScope(nav_index).mod.?.optimize_mode) {
|
||||||
.Debug, .ReleaseSafe => {
|
.Debug, .ReleaseSafe => {
|
||||||
if (self.data_index) |symbol_index|
|
if (self.data_index) |symbol_index|
|
||||||
return self.symbol(symbol_index).outputShndx(elf_file).?;
|
return self.symbol(symbol_index).outputShndx(elf_file).?;
|
||||||
|
|
@ -1271,7 +1271,7 @@ fn updateNavCode(
|
||||||
|
|
||||||
log.debug("updateNavCode {}({d})", .{ nav.fqn.fmt(ip), nav_index });
|
log.debug("updateNavCode {}({d})", .{ nav.fqn.fmt(ip), nav_index });
|
||||||
|
|
||||||
const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
|
const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
|
||||||
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
||||||
.none => target_util.defaultFunctionAlignment(target),
|
.none => target_util.defaultFunctionAlignment(target),
|
||||||
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
||||||
|
|
|
||||||
|
|
@ -867,11 +867,11 @@ pub fn resolveLibSystem(
|
||||||
success: {
|
success: {
|
||||||
if (self.sdk_layout) |sdk_layout| switch (sdk_layout) {
|
if (self.sdk_layout) |sdk_layout| switch (sdk_layout) {
|
||||||
.sdk => {
|
.sdk => {
|
||||||
const dir = try fs.path.join(arena, &[_][]const u8{ comp.sysroot.?, "usr", "lib" });
|
const dir = try fs.path.join(arena, &.{ comp.sysroot.?, "usr", "lib" });
|
||||||
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
|
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
|
||||||
},
|
},
|
||||||
.vendored => {
|
.vendored => {
|
||||||
const dir = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "darwin" });
|
const dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "darwin" });
|
||||||
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
|
if (try accessLibPath(arena, &test_path, &checked_paths, dir, "System")) break :success;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -4406,7 +4406,7 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi
|
||||||
|
|
||||||
const sdk_dir = switch (sdk_layout) {
|
const sdk_dir = switch (sdk_layout) {
|
||||||
.sdk => comp.sysroot.?,
|
.sdk => comp.sysroot.?,
|
||||||
.vendored => fs.path.join(arena, &.{ comp.zig_lib_directory.path.?, "libc", "darwin" }) catch return null,
|
.vendored => fs.path.join(arena, &.{ comp.dirs.zig_lib.path.?, "libc", "darwin" }) catch return null,
|
||||||
};
|
};
|
||||||
if (readSdkVersionFromSettings(arena, sdk_dir)) |ver| {
|
if (readSdkVersionFromSettings(arena, sdk_dir)) |ver| {
|
||||||
return parseSdkVersion(ver);
|
return parseSdkVersion(ver);
|
||||||
|
|
|
||||||
|
|
@ -954,7 +954,7 @@ fn updateNavCode(
|
||||||
|
|
||||||
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
|
log.debug("updateNavCode {} 0x{x}", .{ nav.fqn.fmt(ip), nav_index });
|
||||||
|
|
||||||
const target = zcu.navFileScope(nav_index).mod.resolved_target.result;
|
const target = zcu.navFileScope(nav_index).mod.?.resolved_target.result;
|
||||||
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
const required_alignment = switch (pt.navAlignment(nav_index)) {
|
||||||
.none => target_util.defaultFunctionAlignment(target),
|
.none => target_util.defaultFunctionAlignment(target),
|
||||||
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
else => |a| a.maxStrict(target_util.minFunctionAlignment(target)),
|
||||||
|
|
@ -1184,7 +1184,7 @@ fn getNavOutputSection(
|
||||||
}
|
}
|
||||||
if (is_const) return macho_file.zig_const_sect_index.?;
|
if (is_const) return macho_file.zig_const_sect_index.?;
|
||||||
if (nav_init != .none and Value.fromInterned(nav_init).isUndefDeep(zcu))
|
if (nav_init != .none and Value.fromInterned(nav_init).isUndefDeep(zcu))
|
||||||
return switch (zcu.navFileScope(nav_index).mod.optimize_mode) {
|
return switch (zcu.navFileScope(nav_index).mod.?.optimize_mode) {
|
||||||
.Debug, .ReleaseSafe => macho_file.zig_data_sect_index.?,
|
.Debug, .ReleaseSafe => macho_file.zig_data_sect_index.?,
|
||||||
.ReleaseFast, .ReleaseSmall => macho_file.zig_bss_sect_index.?,
|
.ReleaseFast, .ReleaseSmall => macho_file.zig_bss_sect_index.?,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -315,8 +315,9 @@ pub fn createEmpty(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {
|
fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {
|
||||||
const gpa = self.base.comp.gpa;
|
const comp = self.base.comp;
|
||||||
const zcu = self.base.comp.zcu.?;
|
const gpa = comp.gpa;
|
||||||
|
const zcu = comp.zcu.?;
|
||||||
const file_scope = zcu.navFileScopeIndex(nav_index);
|
const file_scope = zcu.navFileScopeIndex(nav_index);
|
||||||
const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);
|
const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);
|
||||||
if (fn_map_res.found_existing) {
|
if (fn_map_res.found_existing) {
|
||||||
|
|
@ -345,14 +346,11 @@ fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void
|
||||||
try a.writer().writeInt(u16, 1, .big);
|
try a.writer().writeInt(u16, 1, .big);
|
||||||
|
|
||||||
// getting the full file path
|
// getting the full file path
|
||||||
// TODO don't call getcwd here, that is inappropriate
|
{
|
||||||
var buf: [std.fs.max_path_bytes]u8 = undefined;
|
const full_path = try file.path.toAbsolute(comp.dirs, gpa);
|
||||||
const full_path = try std.fs.path.join(arena, &.{
|
defer gpa.free(full_path);
|
||||||
file.mod.root.root_dir.path orelse try std.posix.getcwd(&buf),
|
try self.addPathComponents(full_path, &a);
|
||||||
file.mod.root.sub_path,
|
}
|
||||||
file.sub_file_path,
|
|
||||||
});
|
|
||||||
try self.addPathComponents(full_path, &a);
|
|
||||||
|
|
||||||
// null terminate
|
// null terminate
|
||||||
try a.append(0);
|
try a.append(0);
|
||||||
|
|
@ -437,9 +435,7 @@ pub fn updateFunc(
|
||||||
.start_line = dbg_info_output.start_line.?,
|
.start_line = dbg_info_output.start_line.?,
|
||||||
.end_line = dbg_info_output.end_line,
|
.end_line = dbg_info_output.end_line,
|
||||||
};
|
};
|
||||||
// The awkward error handling here is due to putFn calling `std.posix.getcwd` which it should not do.
|
try self.putFn(func.owner_nav, out);
|
||||||
self.putFn(func.owner_nav, out) catch |err|
|
|
||||||
return zcu.codegenFail(func.owner_nav, "failed to put fn: {s}", .{@errorName(err)});
|
|
||||||
return self.updateFinish(pt, func.owner_nav);
|
return self.updateFinish(pt, func.owner_nav);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
779
src/main.zig
779
src/main.zig
File diff suppressed because it is too large
Load diff
|
|
@ -2,13 +2,14 @@ const std = @import("std");
|
||||||
const build_options = @import("build_options");
|
const build_options = @import("build_options");
|
||||||
const introspect = @import("introspect.zig");
|
const introspect = @import("introspect.zig");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const fatal = @import("main.zig").fatal;
|
const fatal = std.process.fatal;
|
||||||
|
|
||||||
pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
|
pub fn cmdEnv(arena: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
|
||||||
_ = args;
|
_ = args;
|
||||||
const self_exe_path = try introspect.findZigExePath(arena);
|
const cwd_path = try introspect.getResolvedCwd(arena);
|
||||||
|
const self_exe_path = try std.fs.selfExePathAlloc(arena);
|
||||||
|
|
||||||
var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
|
var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, cwd_path, self_exe_path) catch |err| {
|
||||||
fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
|
fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
defer zig_lib_directory.handle.close();
|
defer zig_lib_directory.handle.close();
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ const fs = std.fs;
|
||||||
const io = std.io;
|
const io = std.io;
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const meta = std.meta;
|
const meta = std.meta;
|
||||||
|
const fatal = std.process.fatal;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const Target = std.Target;
|
const Target = std.Target;
|
||||||
const target = @import("target.zig");
|
const target = @import("target.zig");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const glibc = @import("libs/glibc.zig");
|
const glibc = @import("libs/glibc.zig");
|
||||||
const introspect = @import("introspect.zig");
|
const introspect = @import("introspect.zig");
|
||||||
const fatal = @import("main.zig").fatal;
|
|
||||||
|
|
||||||
pub fn cmdTargets(
|
pub fn cmdTargets(
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ const LazySrcLoc = Zcu.LazySrcLoc;
|
||||||
/// Write human-readable, debug formatted ZIR code to a file.
|
/// Write human-readable, debug formatted ZIR code to a file.
|
||||||
pub fn renderAsTextToFile(
|
pub fn renderAsTextToFile(
|
||||||
gpa: Allocator,
|
gpa: Allocator,
|
||||||
scope_file: *Zcu.File,
|
tree: ?Ast,
|
||||||
|
zir: Zir,
|
||||||
fs_file: std.fs.File,
|
fs_file: std.fs.File,
|
||||||
) !void {
|
) !void {
|
||||||
var arena = std.heap.ArenaAllocator.init(gpa);
|
var arena = std.heap.ArenaAllocator.init(gpa);
|
||||||
|
|
@ -21,8 +22,8 @@ pub fn renderAsTextToFile(
|
||||||
var writer: Writer = .{
|
var writer: Writer = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
.arena = arena.allocator(),
|
.arena = arena.allocator(),
|
||||||
.file = scope_file,
|
.tree = tree,
|
||||||
.code = scope_file.zir.?,
|
.code = zir,
|
||||||
.indent = 0,
|
.indent = 0,
|
||||||
.parent_decl_node = .root,
|
.parent_decl_node = .root,
|
||||||
.recurse_decls = true,
|
.recurse_decls = true,
|
||||||
|
|
@ -36,18 +37,18 @@ pub fn renderAsTextToFile(
|
||||||
try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)});
|
try stream.print("%{d} ", .{@intFromEnum(main_struct_inst)});
|
||||||
try writer.writeInstToStream(stream, main_struct_inst);
|
try writer.writeInstToStream(stream, main_struct_inst);
|
||||||
try stream.writeAll("\n");
|
try stream.writeAll("\n");
|
||||||
const imports_index = scope_file.zir.?.extra[@intFromEnum(Zir.ExtraIndex.imports)];
|
const imports_index = zir.extra[@intFromEnum(Zir.ExtraIndex.imports)];
|
||||||
if (imports_index != 0) {
|
if (imports_index != 0) {
|
||||||
try stream.writeAll("Imports:\n");
|
try stream.writeAll("Imports:\n");
|
||||||
|
|
||||||
const extra = scope_file.zir.?.extraData(Zir.Inst.Imports, imports_index);
|
const extra = zir.extraData(Zir.Inst.Imports, imports_index);
|
||||||
var extra_index = extra.end;
|
var extra_index = extra.end;
|
||||||
|
|
||||||
for (0..extra.data.imports_len) |_| {
|
for (0..extra.data.imports_len) |_| {
|
||||||
const item = scope_file.zir.?.extraData(Zir.Inst.Imports.Item, extra_index);
|
const item = zir.extraData(Zir.Inst.Imports.Item, extra_index);
|
||||||
extra_index = item.end;
|
extra_index = item.end;
|
||||||
|
|
||||||
const import_path = scope_file.zir.?.nullTerminatedString(item.data.name);
|
const import_path = zir.nullTerminatedString(item.data.name);
|
||||||
try stream.print(" @import(\"{}\") ", .{
|
try stream.print(" @import(\"{}\") ", .{
|
||||||
std.zig.fmtEscapes(import_path),
|
std.zig.fmtEscapes(import_path),
|
||||||
});
|
});
|
||||||
|
|
@ -74,7 +75,7 @@ pub fn renderInstructionContext(
|
||||||
var writer: Writer = .{
|
var writer: Writer = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
.arena = arena.allocator(),
|
.arena = arena.allocator(),
|
||||||
.file = scope_file,
|
.tree = scope_file.tree,
|
||||||
.code = scope_file.zir.?,
|
.code = scope_file.zir.?,
|
||||||
.indent = if (indent < 2) 2 else indent,
|
.indent = if (indent < 2) 2 else indent,
|
||||||
.parent_decl_node = parent_decl_node,
|
.parent_decl_node = parent_decl_node,
|
||||||
|
|
@ -106,7 +107,7 @@ pub fn renderSingleInstruction(
|
||||||
var writer: Writer = .{
|
var writer: Writer = .{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
.arena = arena.allocator(),
|
.arena = arena.allocator(),
|
||||||
.file = scope_file,
|
.tree = scope_file.tree,
|
||||||
.code = scope_file.zir.?,
|
.code = scope_file.zir.?,
|
||||||
.indent = indent,
|
.indent = indent,
|
||||||
.parent_decl_node = parent_decl_node,
|
.parent_decl_node = parent_decl_node,
|
||||||
|
|
@ -121,7 +122,7 @@ pub fn renderSingleInstruction(
|
||||||
const Writer = struct {
|
const Writer = struct {
|
||||||
gpa: Allocator,
|
gpa: Allocator,
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
file: *Zcu.File,
|
tree: ?Ast,
|
||||||
code: Zir,
|
code: Zir,
|
||||||
indent: u32,
|
indent: u32,
|
||||||
parent_decl_node: Ast.Node.Index,
|
parent_decl_node: Ast.Node.Index,
|
||||||
|
|
@ -2761,7 +2762,7 @@ const Writer = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeSrcNode(self: *Writer, stream: anytype, src_node: Ast.Node.Offset) !void {
|
fn writeSrcNode(self: *Writer, stream: anytype, src_node: Ast.Node.Offset) !void {
|
||||||
const tree = self.file.tree orelse return;
|
const tree = self.tree orelse return;
|
||||||
const abs_node = src_node.toAbsolute(self.parent_decl_node);
|
const abs_node = src_node.toAbsolute(self.parent_decl_node);
|
||||||
const src_span = tree.nodeToSpan(abs_node);
|
const src_span = tree.nodeToSpan(abs_node);
|
||||||
const start = self.line_col_cursor.find(tree.source, src_span.start);
|
const start = self.line_col_cursor.find(tree.source, src_span.start);
|
||||||
|
|
@ -2773,7 +2774,7 @@ const Writer = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeSrcTok(self: *Writer, stream: anytype, src_tok: Ast.TokenOffset) !void {
|
fn writeSrcTok(self: *Writer, stream: anytype, src_tok: Ast.TokenOffset) !void {
|
||||||
const tree = self.file.tree orelse return;
|
const tree = self.tree orelse return;
|
||||||
const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));
|
const abs_tok = src_tok.toAbsolute(tree.firstToken(self.parent_decl_node));
|
||||||
const span_start = tree.tokenStart(abs_tok);
|
const span_start = tree.tokenStart(abs_tok);
|
||||||
const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(abs_tok).len));
|
const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(abs_tok).len));
|
||||||
|
|
@ -2786,7 +2787,7 @@ const Writer = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: Ast.TokenIndex) !void {
|
fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: Ast.TokenIndex) !void {
|
||||||
const tree = self.file.tree orelse return;
|
const tree = self.tree orelse return;
|
||||||
const span_start = tree.tokenStart(src_tok);
|
const span_start = tree.tokenStart(src_tok);
|
||||||
const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
|
const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
|
||||||
const start = self.line_col_cursor.find(tree.source, span_start);
|
const start = self.line_col_cursor.find(tree.source, span_start);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ const bogus = @import(
|
||||||
);
|
);
|
||||||
|
|
||||||
// error
|
// error
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
//
|
||||||
// bogus-does-not-exist.zig': FileNotFound
|
// bogus-does-not-exist.zig:1:1: error: unable to load 'bogus-does-not-exist.zig': FileNotFound
|
||||||
|
// :2:5: note: file imported here
|
||||||
|
|
|
||||||
8
test/cases/compile_errors/import_of_missing_module.zig
Normal file
8
test/cases/compile_errors/import_of_missing_module.zig
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
const foo = @import("foo");
|
||||||
|
comptime {
|
||||||
|
_ = foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
//
|
||||||
|
// :1:21: error: no module named 'foo' available within module 'root'
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
const foo = @import("foo");
|
|
||||||
comptime {
|
|
||||||
_ = foo;
|
|
||||||
}
|
|
||||||
|
|
||||||
// error
|
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
|
||||||
// :1:21: error: no module named 'foo' available within module root
|
|
||||||
7
test/cases/compile_errors/import_outside_module_path.zig
Normal file
7
test/cases/compile_errors/import_outside_module_path.zig
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
comptime {
|
||||||
|
_ = @import("../a.zig");
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
//
|
||||||
|
// :2:17: error: import of file outside module path
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
export fn a() usize {
|
|
||||||
return @import("../../above.zig").len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// error
|
|
||||||
// target=native
|
|
||||||
//
|
|
||||||
// :2:20: error: import of file outside module path: '../../above.zig'
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
comptime {
|
|
||||||
_ = @import("../a.zig");
|
|
||||||
}
|
|
||||||
|
|
||||||
// error
|
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
|
||||||
// :2:17: error: import of file outside module path: '../a.zig'
|
|
||||||
|
|
@ -126,9 +126,10 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
|
||||||
\\ _ = @import("foo.zig");
|
\\ _ = @import("foo.zig");
|
||||||
\\}
|
\\}
|
||||||
, &[_][]const u8{
|
, &[_][]const u8{
|
||||||
":1:1: error: file exists in multiple modules",
|
":1:1: error: file exists in modules 'foo' and 'root'",
|
||||||
":1:1: note: root of module foo",
|
":1:1: note: files must belong to only one module",
|
||||||
":3:17: note: imported from module root",
|
":1:1: note: file is the root of module 'foo'",
|
||||||
|
":3:17: note: file is imported here by the root of module 'root'",
|
||||||
});
|
});
|
||||||
case.addSourceFile("foo.zig",
|
case.addSourceFile("foo.zig",
|
||||||
\\const dummy = 0;
|
\\const dummy = 0;
|
||||||
|
|
|
||||||
35
test/incremental/bad_import
Normal file
35
test/incremental/bad_import
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#target=x86_64-linux-selfhosted
|
||||||
|
#target=x86_64-linux-cbe
|
||||||
|
#target=x86_64-windows-cbe
|
||||||
|
#target=wasm32-wasi-selfhosted
|
||||||
|
|
||||||
|
#update=initial version
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() !void {
|
||||||
|
_ = @import("foo.zig");
|
||||||
|
try std.io.getStdOut().writeAll("success\n");
|
||||||
|
}
|
||||||
|
const std = @import("std");
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
_ = @import("bad.zig");
|
||||||
|
}
|
||||||
|
#expect_error=bad.zig:1:1: error: unable to load 'bad.zig': FileNotFound
|
||||||
|
#expect_error=foo.zig:2:17: note: file imported here
|
||||||
|
|
||||||
|
#update=change bad import
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
_ = @import("this_is/not_real.zig");
|
||||||
|
}
|
||||||
|
#expect_error=this_is/not_real.zig:1:1: error: unable to load 'not_real.zig': FileNotFound
|
||||||
|
#expect_error=foo.zig:2:17: note: file imported here
|
||||||
|
|
||||||
|
#update=remove import of 'foo.zig'
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() !void {
|
||||||
|
//_ = @import("foo.zig");
|
||||||
|
try std.io.getStdOut().writeAll("success\n");
|
||||||
|
}
|
||||||
|
const std = @import("std");
|
||||||
|
#expect_stdout="success\n"
|
||||||
65
test/incremental/change_module
Normal file
65
test/incremental/change_module
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#target=x86_64-linux-selfhosted
|
||||||
|
#target=x86_64-linux-cbe
|
||||||
|
#target=x86_64-windows-cbe
|
||||||
|
#target=wasm32-wasi-selfhosted
|
||||||
|
#module=foo=foo.zig
|
||||||
|
|
||||||
|
#update=initial version
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() void {
|
||||||
|
_ = @import("foo");
|
||||||
|
//_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#file=other.zig
|
||||||
|
fn f() void {
|
||||||
|
@compileLog(@src().module);
|
||||||
|
}
|
||||||
|
comptime {
|
||||||
|
f();
|
||||||
|
}
|
||||||
|
#expect_error=other.zig:2:5: error: found compile log statement
|
||||||
|
#expect_compile_log=@as([:0]const u8, "foo"[0..3])
|
||||||
|
|
||||||
|
#update=change module of other.zig
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() void {
|
||||||
|
_ = @import("foo");
|
||||||
|
_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
//_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#expect_error=other.zig:2:5: error: found compile log statement
|
||||||
|
#expect_compile_log=@as([:0]const u8, "root"[0..4])
|
||||||
|
|
||||||
|
#update=put other.zig in both modules
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() void {
|
||||||
|
_ = @import("foo");
|
||||||
|
_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#expect_error=foo.zig:1:1: error: file exists in modules 'root' and 'foo'
|
||||||
|
#expect_error=foo.zig:1:1: note: files must belong to only one module
|
||||||
|
#expect_error=main.zig:3:17: note: file is imported here by the root of module 'root'
|
||||||
|
#expect_error=foo.zig:2:17: note: file is imported here by the root of module 'foo'
|
||||||
|
|
||||||
|
#update=put other.zig in no modules
|
||||||
|
#file=main.zig
|
||||||
|
pub fn main() void {
|
||||||
|
_ = @import("foo");
|
||||||
|
//_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#file=foo.zig
|
||||||
|
comptime {
|
||||||
|
//_ = @import("other.zig");
|
||||||
|
}
|
||||||
|
#expect_stdout=""
|
||||||
|
|
@ -20,7 +20,8 @@ pub fn main() !void {
|
||||||
|
|
||||||
#update=delete file
|
#update=delete file
|
||||||
#rm_file=message.zon
|
#rm_file=message.zon
|
||||||
#expect_error=message.zon:1:1: error: unable to load './message.zon': FileNotFound
|
#expect_error=message.zon:1:1: error: unable to load 'message.zon': FileNotFound
|
||||||
|
#expect_error=main.zig:2:37: note: file imported here
|
||||||
|
|
||||||
#update=remove reference to ZON file
|
#update=remove reference to ZON file
|
||||||
#file=main.zig
|
#file=main.zig
|
||||||
|
|
@ -29,7 +30,8 @@ const message: []const u8 = @import("message.zon");
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
try std.io.getStdOut().writeAll("a hardcoded string\n");
|
try std.io.getStdOut().writeAll("a hardcoded string\n");
|
||||||
}
|
}
|
||||||
#expect_error=message.zon:1:1: error: unable to load './message.zon': FileNotFound
|
#expect_error=message.zon:1:1: error: unable to load 'message.zon': FileNotFound
|
||||||
|
#expect_error=main.zig:2:37: note: file imported here
|
||||||
|
|
||||||
#update=recreate ZON file
|
#update=recreate ZON file
|
||||||
#file=message.zon
|
#file=message.zon
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue