P5.2 metadata queries: c_object_paths / link_libraries on the VM

Two abi(.compiler) build-pipeline primitives the sx driver will pass to link:
- c_object_paths() -> List(string)  (#import c companion objects)
- link_libraries() -> List(string)  (#library names)

They live in a new stdlib home library/modules/std/build.sx and are serviced
by comptime_vm.callCompilerFn reading two new BuildConfig fields that main.zig
forwards before the post-link callback. New reusable VM helper makeStringList
builds a List(string) in flat memory from the call's result type offsets
(target-aware); invoke/callCompilerFn now thread ins.ty for that. Legacy
handlers bail loudly (VM-only by nature — post-link; List(string) isn't
faithfully buildable in the legacy Value model, 0141).

Smoke test examples/1662-platform-build-pipeline-queries (AOT + a 1-line C
#source → one object): a post-link callback verifies the VM-built list is
well-formed; build exit 0 only if so (negative-probe confirmed a real guard).

emit_object + link (the actions) deferred to P5.2b — they replace the Zig
driver's auto-emit/auto-link and need a host-installed callback vtable.

703/0 both gates.
This commit is contained in:
agra
2026-06-19 07:42:27 +03:00
parent 7cba33ea6d
commit 44dfdcddf9
13 changed files with 191 additions and 11 deletions

View File

@@ -61,8 +61,25 @@ pub const bound_fns = [_]BoundFn{
// ── BuildOptions (migrated off `#compiler` onto `abi(.compiler)`) ─────────
.{ .sx_name = "build_options", .handler = handleBuildOptions },
.{ .sx_name = "set_post_link_callback", .handler = handleSetPostLinkCallback },
// ── build-pipeline metadata queries (Phase 5.2) ──────────────────────────
// VM-only: the post-link callback that calls these always runs on the VM
// (`core.invokeByFuncId`), so `comptime_vm.callCompilerFn` services them and
// these legacy handlers are never reached (they bail loudly rather than
// fabricate a silent empty List). Registered here only so `weldedCompilerFn`
// recognizes the names as compiler-API functions.
.{ .sx_name = "c_object_paths", .handler = handleBuildPipelineQuery },
.{ .sx_name = "link_libraries", .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.
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";
return error.CannotEvalComptime;
}
// Kind codes accepted by `register_type` — mirror `TypeTable.kindCode`. An
// enum-like type is minted as a `tagged_union` (the general payload-carrying
// form, as `define` does), so both 2 (`enum`) and 3 (`tagged_union`) are taken.