Files
sx/examples/1662-platform-build-pipeline-queries.sx
agra d8affd45e8 rename std/build.sx -> modules/compiler.sx (the compiler-API surface)
Per user direction: the low-level abi(.compiler) primitive surface is the
comptime 'compiler' library, so name the file compiler.sx (a peer of build.sx)
instead of the interim std/build.sx — which also frees the 'build' name for the
default build IMPLEMENTATION (default_build + on_build slot), which will live in
modules/build.sx alongside the BuildOptions DSL.

Updated the two example imports + the plan's Phase 5 file-split note. 704/0
both gates.
2026-06-19 08:17:35 +03:00

44 lines
1.6 KiB
Plaintext

#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/compiler.sx";
// P5.2 smoke test — the build-pipeline query primitives (`c_object_paths` /
// `link_libraries` / `emit_object`) run on the comptime VM: the list queries
// return a `List(string)` the VM builds in flat memory; `emit_object` returns
// the compiler-emitted object path. Registered as a post-link callback (which
// runs on the VM — core.invokeByFuncId), so the build state is live there.
//
// The `#import c` source compiles to one `.o`, so `c_object_paths()` must return
// a one-element list whose single string is the (non-empty) object path. AOT
// snapshots the executed binary, so success is observed via the build exit code:
// the callback returns true only if the VM-built list is well-formed.
#import c {
#source "1662-platform-build-pipeline-queries.c";
};
c_marker :: () -> i64 extern;
check :: () -> bool abi(.compiler) {
objs := c_object_paths();
libs := link_libraries();
obj := emit_object(); // the compiler-emitted sx object path
if obj.len == 0 { return false; }
if objs.len != 1 { return false; }
if objs.items[0].len == 0 { return false; }
// `link_libraries` must be a well-formed (possibly empty) list — touch each
// entry so a malformed fat pointer would fault rather than pass silently.
sum : i64 = 0;
i : i64 = 0;
while i < libs.len { sum += libs.items[i].len; i += 1; }
return sum >= 0;
}
configure :: () abi(.compiler) {
opts := build_options();
opts.set_post_link_callback(check);
}
#run configure();
main :: () { print("runtime main: {}\n", c_marker()); }