Files
sx/examples/1663-platform-build-pipeline-link.sx
agra f7362ee013 P5.2b: link() build-pipeline action on the VM via a host vtable
The one genuine action primitive: link(objects, output, libraries, frameworks,
flags, target) in library/modules/std/build.sx. Per the user decision to drop
fallibility from the build callback, link is plain VOID — a link failure bails
on the VM (hard build error), no -> ! / failable-tuple needed.

comptime_vm.zig can't depend on the driver (core/main/target), so link
dispatches through a new compiler_hooks.BuildHooks { ctx, link } vtable that
main.zig installs into BuildConfig.build_hooks before the post-link callback.
The driver side is main.LinkHooksCtx (unions explicit + CLI link flags, calls
target.link). New VM readers readStringList / readStringArg (inverse of
makeStringList) decode the List(string)/string args from flat memory.

Smoke test examples/1663-platform-build-pipeline-link (AOT): a post-link
callback re-links the build's own objects (c_object_paths + emit_object) into a
temp output via sx link — the relinked binary is a functional executable that
runs. Negative-probe verified (bad path -> ld fails -> ComptimeVmBail -> build
exit 1). The Zig driver still auto-links; removing that is P5.4.

704/0 both gates.
2026-06-19 08:11:36 +03:00

32 lines
1.1 KiB
Plaintext

#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/std/build.sx";
// P5.2b smoke test — the `link` build-pipeline ACTION runs on the comptime VM,
// dispatching through the host-installed linker hook (the VM can't link itself).
// The post-link callback (which runs on the VM — core.invokeByFuncId) re-links
// the build's own objects into a temp output via the sx `link` primitive. A link
// failure bails → the build fails; success → the callback returns true and the
// build's binary runs ("runtime main"). AOT snapshots the binary, so the link's
// success is observed via the build exit code.
relink :: () -> bool abi(.compiler) {
objs := List(string).{};
cobjs := c_object_paths();
i : i64 = 0;
while i < cobjs.len { objs.append(cobjs.items[i]); i += 1; }
objs.append(emit_object());
fws := List(string).{};
flags := List(string).{};
link(objs, ".sx-tmp/1663-link-out", link_libraries(), fws, flags, "");
return true;
}
configure :: () abi(.compiler) {
opts := build_options();
opts.set_post_link_callback(relink);
}
#run configure();
main :: () { print("runtime main\n"); }