mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Compare commits
2 commits
d22231c039
...
431f653552
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
431f653552 | ||
|
|
b40ea9908d |
7 changed files with 80 additions and 4 deletions
|
|
@ -34,7 +34,10 @@ cmake .. \
|
|||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-DZIG_EXTRA_BUILD_ARGS="-Duse-llvm=true" \
|
||||
-GNinja
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ cmake .. \
|
|||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,10 @@ cmake .. \
|
|||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
|
|
@ -97,7 +100,10 @@ cmake .. \
|
|||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-DZIG_NO_LIB=ON \
|
||||
-GNinja
|
||||
-GNinja \
|
||||
-DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \
|
||||
-DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE
|
||||
# https://github.com/ziglang/zig/issues/22213
|
||||
|
||||
unset CC
|
||||
unset CXX
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ verbose_llvm_bc: ?[]const u8,
|
|||
verbose_cimport: bool,
|
||||
verbose_llvm_cpu_features: bool,
|
||||
verbose_link: bool,
|
||||
link_depfile: ?[]const u8,
|
||||
disable_c_depfile: bool,
|
||||
stack_report: bool,
|
||||
debug_compiler_runtime_libs: bool,
|
||||
|
|
@ -1403,6 +1404,7 @@ pub const MiscTask = enum {
|
|||
compiler_rt,
|
||||
libzigc,
|
||||
analyze_mod,
|
||||
link_depfile,
|
||||
docs_copy,
|
||||
docs_wasm,
|
||||
|
||||
|
|
@ -1732,6 +1734,7 @@ pub const CreateOptions = struct {
|
|||
verbose_generic_instances: bool = false,
|
||||
verbose_llvm_ir: ?[]const u8 = null,
|
||||
verbose_llvm_bc: ?[]const u8 = null,
|
||||
link_depfile: ?[]const u8 = null,
|
||||
verbose_cimport: bool = false,
|
||||
verbose_llvm_cpu_features: bool = false,
|
||||
debug_compiler_runtime_libs: bool = false,
|
||||
|
|
@ -2247,6 +2250,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
|
|||
.verbose_generic_instances = options.verbose_generic_instances,
|
||||
.verbose_llvm_ir = options.verbose_llvm_ir,
|
||||
.verbose_llvm_bc = options.verbose_llvm_bc,
|
||||
.link_depfile = options.link_depfile,
|
||||
.verbose_cimport = options.verbose_cimport,
|
||||
.verbose_llvm_cpu_features = options.verbose_llvm_cpu_features,
|
||||
.verbose_link = options.verbose_link,
|
||||
|
|
@ -5442,6 +5446,7 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) SubU
|
|||
.verbose_generic_instances = comp.verbose_intern_pool,
|
||||
.verbose_llvm_ir = comp.verbose_llvm_ir,
|
||||
.verbose_llvm_bc = comp.verbose_llvm_bc,
|
||||
.link_depfile = comp.link_depfile,
|
||||
.verbose_cimport = comp.verbose_cimport,
|
||||
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
|
||||
}) catch |err| switch (err) {
|
||||
|
|
@ -7878,6 +7883,7 @@ fn buildOutputFromZig(
|
|||
.verbose_generic_instances = comp.verbose_intern_pool,
|
||||
.verbose_llvm_ir = comp.verbose_llvm_ir,
|
||||
.verbose_llvm_bc = comp.verbose_llvm_bc,
|
||||
.link_depfile = comp.link_depfile,
|
||||
.verbose_cimport = comp.verbose_cimport,
|
||||
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
|
||||
.clang_passthrough_mode = comp.clang_passthrough_mode,
|
||||
|
|
@ -8015,6 +8021,7 @@ pub fn build_crt_file(
|
|||
.verbose_generic_instances = comp.verbose_generic_instances,
|
||||
.verbose_llvm_ir = comp.verbose_llvm_ir,
|
||||
.verbose_llvm_bc = comp.verbose_llvm_bc,
|
||||
.link_depfile = comp.link_depfile,
|
||||
.verbose_cimport = comp.verbose_cimport,
|
||||
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
|
||||
.clang_passthrough_mode = comp.clang_passthrough_mode,
|
||||
|
|
|
|||
49
src/link.zig
49
src/link.zig
|
|
@ -384,6 +384,9 @@ pub const File = struct {
|
|||
comp: *Compilation,
|
||||
emit: Path,
|
||||
|
||||
/// Only populated if `comp.link_depfile != null`.
|
||||
depfile_inputs: std.ArrayList([]const u8) = .empty,
|
||||
|
||||
file: ?fs.File,
|
||||
/// When using the LLVM backend, the emitted object is written to a file with this name. This
|
||||
/// object file then becomes a normal link input to LLD or a self-hosted linker.
|
||||
|
|
@ -859,6 +862,7 @@ pub const File = struct {
|
|||
pub fn destroy(base: *File) void {
|
||||
base.releaseLock();
|
||||
if (base.file) |f| f.close();
|
||||
base.depfile_inputs.deinit(base.comp.gpa);
|
||||
switch (base.tag) {
|
||||
.plan9 => unreachable,
|
||||
inline else => |tag| {
|
||||
|
|
@ -1142,6 +1146,15 @@ pub const File = struct {
|
|||
|
||||
pub fn loadInput(base: *File, input: Input) anyerror!void {
|
||||
if (base.tag == .lld) return;
|
||||
|
||||
if (base.comp.link_depfile != null) if (input.path()) |p| {
|
||||
try base.depfile_inputs.append(base.comp.gpa, try std.fs.path.resolve(base.comp.arena, &.{
|
||||
base.comp.dirs.cwd,
|
||||
p.root_dir.path orelse ".",
|
||||
p.sub_path,
|
||||
}));
|
||||
};
|
||||
|
||||
switch (base.tag) {
|
||||
inline .elf, .elf2, .wasm => |tag| {
|
||||
dev.check(tag.devFeature());
|
||||
|
|
@ -1156,6 +1169,10 @@ pub const File = struct {
|
|||
pub fn prelink(base: *File) FlushError!void {
|
||||
assert(!base.post_prelink);
|
||||
|
||||
if (base.tag != .lld) if (base.comp.link_depfile) |depfile_path| {
|
||||
base.comp.thread_pool.spawnWg(&base.comp.link_task_wait_group, workerCreateDepFile, .{ base, depfile_path });
|
||||
};
|
||||
|
||||
// In this case, an object file is created by the LLVM backend, so
|
||||
// there is no prelink phase. The Zig code is linked as a standard
|
||||
// object along with the others.
|
||||
|
|
@ -1170,6 +1187,38 @@ pub const File = struct {
|
|||
}
|
||||
}
|
||||
|
||||
fn workerCreateDepFile(base: *File, path: []const u8) void {
|
||||
createDepFile(base, path) catch |err| base.comp.lockAndSetMiscFailure(
|
||||
.link_depfile,
|
||||
"unable to write linker dependency file: {t}",
|
||||
.{err},
|
||||
);
|
||||
}
|
||||
|
||||
fn createDepFile(base: *File, path: []const u8) anyerror!void {
|
||||
var buf: [4096]u8 = undefined;
|
||||
var af = try std.fs.cwd().atomicFile(path, .{ .write_buffer = &buf });
|
||||
defer af.deinit();
|
||||
|
||||
writeDepFile(base, &af.file_writer.interface) catch return af.file_writer.err.?;
|
||||
|
||||
try af.finish();
|
||||
}
|
||||
|
||||
fn writeDepFile(base: *File, w: *std.Io.Writer) std.Io.Writer.Error!void {
|
||||
try w.print("{f}:", .{base.emit});
|
||||
|
||||
for (base.depfile_inputs.items) |p| {
|
||||
try w.print(" \\\n {s}", .{p});
|
||||
}
|
||||
|
||||
for (base.depfile_inputs.items) |p| {
|
||||
try w.print("\n\n{s}:", .{p});
|
||||
}
|
||||
|
||||
try w.writeByte('\n');
|
||||
}
|
||||
|
||||
pub const Tag = enum {
|
||||
coff2,
|
||||
elf,
|
||||
|
|
|
|||
|
|
@ -1009,6 +1009,10 @@ fn elfLink(lld: *Lld, arena: Allocator) !void {
|
|||
try argv.append("-znorelro");
|
||||
}
|
||||
|
||||
if (comp.link_depfile) |depfile_path| {
|
||||
try argv.append(try allocPrint(arena, "--dependency-file={s}", .{depfile_path}));
|
||||
}
|
||||
|
||||
try argv.append("-o");
|
||||
try argv.append(full_out_path);
|
||||
|
||||
|
|
|
|||
|
|
@ -821,6 +821,7 @@ fn buildOutputType(
|
|||
var verbose_generic_instances = false;
|
||||
var verbose_llvm_ir: ?[]const u8 = null;
|
||||
var verbose_llvm_bc: ?[]const u8 = null;
|
||||
var link_depfile: ?[]const u8 = null;
|
||||
var verbose_cimport = false;
|
||||
var verbose_llvm_cpu_features = false;
|
||||
var time_report = false;
|
||||
|
|
@ -2704,6 +2705,8 @@ fn buildOutputType(
|
|||
{
|
||||
emit_implib = .{ .yes = linker_args_it.nextOrFatal() };
|
||||
emit_implib_arg_provided = true;
|
||||
} else if (mem.eql(u8, arg, "--dependency-file")) {
|
||||
link_depfile = linker_args_it.nextOrFatal();
|
||||
} else if (mem.eql(u8, arg, "-Brepro") or mem.eql(u8, arg, "/Brepro")) {
|
||||
linker_repro = true;
|
||||
} else if (mem.eql(u8, arg, "-undefined")) {
|
||||
|
|
@ -3479,6 +3482,7 @@ fn buildOutputType(
|
|||
.verbose_generic_instances = verbose_generic_instances,
|
||||
.verbose_llvm_ir = verbose_llvm_ir,
|
||||
.verbose_llvm_bc = verbose_llvm_bc,
|
||||
.link_depfile = link_depfile,
|
||||
.verbose_cimport = verbose_cimport,
|
||||
.verbose_llvm_cpu_features = verbose_llvm_cpu_features,
|
||||
.time_report = time_report,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue