Files
sx/examples/1662-platform-build-pipeline-queries.sx
agra 65ac370683 P5.4: migrate all callers to on_build; delete set_post_link_callback
on_build is now the sole post-build callback mechanism. Migrated the 9 callers
(0602/0603/1611/1614/1615/1616 + the platform bundle_main) from
opts.set_post_link_callback(cb) to on_build(cb), giving each callback the
(opt: BuildOptions) param. Deleted set_post_link_callback from build.sx,
compiler_lib (bound_fns + handleSetPostLinkCallback), and the VM arm.

Reworked the P5 smoke tests for the new semantics: an on_build override REPLACES
the build (must emit+link or delegate), unlike the old post-link callback which
ran after the auto-link. 1662 (queries) + 1664 (override+List-grow) now delegate
to default_pipeline for the real build; deleted 1661/1663 (the primitives are now
exercised by every AOT build). bundle_main invoked with pass_options=true.

Benign 37-.ir churn (build.sx shrank). 703/0 both gates.
2026-06-19 09:37:05 +03:00

33 lines
1.2 KiB
Plaintext

#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/compiler.sx";
// P5.4 — the build-pipeline query primitives on the comptime VM. A custom
// `on_build` override inspects the build metadata (`c_object_paths` returns the
// VM-built `List(string)` of C companion objects), then DELEGATES to the stdlib
// `default_pipeline` for the real emit + link. The `#import c` source compiles to
// one object, so `c_object_paths()` must be a one-element list of a non-empty
// path. AOT runs the produced binary → "runtime main: 42".
#import c {
#source "1662-platform-build-pipeline-queries.c";
};
c_marker :: () -> i64 extern;
build :: (opt: BuildOptions) -> bool abi(.compiler) {
objs := c_object_paths();
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.
libs := link_libraries();
sum : i64 = 0;
i : i64 = 0;
while i < libs.len { sum += libs.items[i].len; i += 1; }
if sum < 0 { return false; }
return default_pipeline(opt); // the real emit + link
}
#run on_build(build);
main :: () { print("runtime main: {}\n", c_marker()); }