Skip to content

Commit

Permalink
Introduces Compile.getEmittedX() functions, drops Compile.emit_X. R…
Browse files Browse the repository at this point in the history
…esolves ziglang#14971
  • Loading branch information
Felix (xq) Queißner committed Jul 25, 2023
1 parent ed5031f commit d961b1f
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 163 deletions.
5 changes: 0 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn build(b: *std.Build) !void {
.target = target,
});
autodoc_test.overrideZigLibDir(.{ .path = "lib" });
autodoc_test.emit_bin = .no_emit; // https://github.com/ziglang/zig/issues/16351
const install_std_docs = b.addInstallDirectory(.{
.source_dir = autodoc_test.getEmittedDocs(),
.install_dir = .prefix,
Expand Down Expand Up @@ -196,10 +195,6 @@ pub fn build(b: *std.Build) !void {
exe.pie = pie;
exe.sanitize_thread = sanitize_thread;
exe.entitlements = entitlements;
// TODO -femit-bin/-fno-emit-bin should be inferred by the build system
// based on whether or not the exe is run or installed.
// https://github.com/ziglang/zig/issues/16351
if (no_bin) exe.emit_bin = .no_emit;

exe.build_id = b.option(
std.Build.Step.Compile.BuildId,
Expand Down
52 changes: 3 additions & 49 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const NativeTargetInfo = std.zig.system.NativeTargetInfo;
const Sha256 = std.crypto.hash.sha2.Sha256;
const Build = @This();

const build_util = @import("Build/util.zig");

pub const Cache = @import("Build/Cache.zig");

/// deprecated: use `Step.Compile`.
Expand Down Expand Up @@ -1679,7 +1681,7 @@ pub const LazyPath = union(enum) {
.generated => |gen| return gen.path orelse {
std.debug.getStderrMutex().lock();
const stderr = std.io.getStdErr();
dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {};
build_util.dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {};
@panic("misconfigured build script");
},
}
Expand All @@ -1694,54 +1696,6 @@ pub const LazyPath = union(enum) {
}
};

/// In this function the stderr mutex has already been locked.
fn dumpBadGetPathHelp(
s: *Step,
stderr: fs.File,
src_builder: *Build,
asking_step: ?*Step,
) anyerror!void {
const w = stderr.writer();
try w.print(
\\getPath() was called on a GeneratedFile that wasn't built yet.
\\ source package path: {s}
\\ Is there a missing Step dependency on step '{s}'?
\\
, .{
src_builder.build_root.path orelse ".",
s.name,
});

const tty_config = std.io.tty.detectConfig(stderr);
tty_config.setColor(w, .red) catch {};
try stderr.writeAll(" The step was created by this stack trace:\n");
tty_config.setColor(w, .reset) catch {};

const debug_info = std.debug.getSelfDebugInfo() catch |err| {
try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
return;
};
const ally = debug_info.allocator;
std.debug.writeStackTrace(s.getStackTrace(), w, ally, debug_info, tty_config) catch |err| {
try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
return;
};
if (asking_step) |as| {
tty_config.setColor(w, .red) catch {};
try stderr.writeAll(" The step that is missing a dependency on the above step was created by this stack trace:\n");
tty_config.setColor(w, .reset) catch {};

std.debug.writeStackTrace(as.getStackTrace(), w, ally, debug_info, tty_config) catch |err| {
try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
return;
};
}

tty_config.setColor(w, .red) catch {};
try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
tty_config.setColor(w, .reset) catch {};
}

/// Allocates a new string for assigning a value to a named macro.
/// If the value is omitted, it is set to 1.
/// `name` and `value` need not live longer than the function call.
Expand Down
5 changes: 4 additions & 1 deletion lib/std/Build/Step.zig
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,10 @@ pub fn evalZigProcess(
});
}

if (s.cast(Compile)) |compile| if (compile.emit_bin == .no_emit) return result;
if (s.cast(Compile)) |compile| {
if (compile.generated_bin == null) // TODO(xq): How to handle this properly?!
return result;
}

return result orelse return s.fail(
"the following command failed to communicate the compilation result:\n{s}",
Expand Down
Loading

0 comments on commit d961b1f

Please sign in to comment.