P5.2: emit_object() -> string query primitive
The compiler emits the sx object eagerly (the Zig driver, before the post-link callback), so emit_object is a QUERY (not an action): it returns the path from a new BuildConfig.object_path field main.zig forwards — no driver vtable. This completes the build-pipeline QUERY primitives (emit_object / c_object_paths / link_libraries); only link (the genuine action) remains for the vtable step. Extended examples/1662 to also assert emit_object().len > 0. 703/0 both gates.
This commit is contained in:
@@ -66,6 +66,12 @@ pub const BuildConfig = struct {
|
||||
c_object_paths: []const []const u8 = &.{},
|
||||
link_libraries: []const []const u8 = &.{},
|
||||
|
||||
/// Path of the object file the compiler emitted for this build (`.sx-tmp/main.o`
|
||||
/// or the cached `.o`). Forwarded by main.zig before the post-link callback so
|
||||
/// the sx build driver can read it via the `emit_object()` compiler primitive
|
||||
/// (the compiler emits the object eagerly; the primitive returns its path).
|
||||
object_path: ?[]const u8 = null,
|
||||
|
||||
/// Frameworks the binary links against (`-framework` names) and
|
||||
/// the search paths to look them up in (`-F` directories), forwarded
|
||||
/// from the link step so the sx bundler can embed them into
|
||||
|
||||
@@ -69,14 +69,15 @@ pub const bound_fns = [_]BoundFn{
|
||||
// recognizes the names as compiler-API functions.
|
||||
.{ .sx_name = "c_object_paths", .handler = handleBuildPipelineQuery },
|
||||
.{ .sx_name = "link_libraries", .handler = handleBuildPipelineQuery },
|
||||
.{ .sx_name = "emit_object", .handler = handleBuildPipelineQuery },
|
||||
};
|
||||
|
||||
/// Legacy-path stub for the Phase 5 build-pipeline metadata queries — see the
|
||||
/// `bound_fns` comment. These return a `List(string)` the legacy `Value` model
|
||||
/// can't faithfully build (issue 0141), and the only caller (the post-link
|
||||
/// callback) runs on the VM, so bail loudly here instead of guessing.
|
||||
/// Legacy-path stub for the Phase 5 build-pipeline primitives — see the
|
||||
/// `bound_fns` comment. The only caller (the post-link build driver) runs on the
|
||||
/// VM (`core.invokeByFuncId`), so these legacy handlers are never reached; they
|
||||
/// bail loudly instead of fabricating a silent result.
|
||||
fn handleBuildPipelineQuery(_: *Interpreter, _: []const Value) InterpError!Value {
|
||||
Interpreter.last_bail_detail = "build-pipeline query (c_object_paths/link_libraries) is VM-only (post-link); not available on the legacy interpreter";
|
||||
Interpreter.last_bail_detail = "build-pipeline primitive (emit_object/c_object_paths/link_libraries) is VM-only (post-link); not available on the legacy interpreter";
|
||||
return error.CannotEvalComptime;
|
||||
}
|
||||
|
||||
|
||||
@@ -1469,6 +1469,17 @@ pub const Vm = struct {
|
||||
return self.failMsg("comptime link_libraries: no build config threaded into the VM");
|
||||
return try self.makeStringList(table, result_ty, bc.link_libraries);
|
||||
}
|
||||
// `emit_object() -> string` — the compiler emits the object eagerly (the Zig
|
||||
// driver, before the post-link callback); this returns its path. A query,
|
||||
// not an action — so no driver callback is needed (unlike `link`).
|
||||
if (std.mem.eql(u8, name, "emit_object")) {
|
||||
if (args.len != 0) return self.failMsg("comptime emit_object: expected no args");
|
||||
const bc = self.build_config orelse
|
||||
return self.failMsg("comptime emit_object: no build config threaded into the VM");
|
||||
const path = bc.object_path orelse
|
||||
return self.failMsg("comptime emit_object: no object was emitted (object_path unset)");
|
||||
return try self.makeStringValue(table, path);
|
||||
}
|
||||
return null; // not a known compiler function → caller bails to legacy
|
||||
}
|
||||
|
||||
|
||||
@@ -722,6 +722,7 @@ fn compileWithTimer(allocator: std.mem.Allocator, io: std.Io, input_path: []cons
|
||||
// slices reference compileWithTimer locals that outlive the callback.
|
||||
e.build_config.c_object_paths = c_obj_paths;
|
||||
e.build_config.link_libraries = libs;
|
||||
e.build_config.object_path = obj_path;
|
||||
// Android-specific bundling state.
|
||||
if (e.build_config.manifest_path == null) e.build_config.manifest_path = merged_config.manifest_path;
|
||||
if (e.build_config.keystore_path == null) e.build_config.keystore_path = merged_config.keystore_path;
|
||||
|
||||
Reference in New Issue
Block a user