P5.4 core: drive the whole build from sx default_pipeline (no auto-emit/link)

The compiler's post-IR role shrinks to: codegen -> invoke the build callback.
There is NO Zig auto-emit / auto-link anymore; emit + link are sx-called actions.

- emit_object() is now an ACTION (verify + emit via a host BuildHooks vtable),
  returning the object path. New query primitives build_output/build_target/
  build_frameworks/build_flags (data reads from the merged BuildConfig).
- library/modules/build.sx imports compiler.sx and defines default_pipeline:
  emit_object -> gather c_object_paths -> link(objs, output, libs, fws, flags,
  target). The std<->build import cycle is handled by the resolver.
- The compiler FORCE-LOWERS default_pipeline (well-known name) and AUTO-INVOKES
  it post-codegen when no on_build/set_post_link_callback override was
  registered (driver's final fallback: invokeByName default_pipeline).
- Prelude-less programs (e.g. asm tests) don't import build.sx, so the BUILD
  path auto-imports modules/build.sx (idempotent if already transitive) so
  default_pipeline is always available. JIT sx run is untouched (emits in-process).
- Removed the build cache short-circuits (incompatible with the always-run sx
  driver; a future cache can live in default_pipeline).

Benign 37-.ir churn (build.sx grew); zero behavior changes (verified diff is
.ir-only). 705/0 both gates.
This commit is contained in:
agra
2026-06-19 09:22:54 +03:00
parent 1f796e92ec
commit d178454841
44 changed files with 93042 additions and 80510 deletions

View File

@@ -1,3 +1,9 @@
// `List` (for the default build script) + the compiler-API build primitives
// (`emit_object`/`link`/`c_object_paths`/…). The std↔build import cycle (std's
// tail imports cli.sx which imports this file) is handled by the resolver.
#import "modules/std.sx";
#import "modules/compiler.sx";
OperatingSystem :: enum { macos; linux; windows; wasm; ios; android; unknown; }
Architecture :: enum { aarch64; x86_64; wasm32; wasm64; unknown; }
@@ -102,3 +108,21 @@ set_post_link_callback :: ufcs (self: BuildOptions, cb: () -> bool) abi(.compile
// `build :: (opt: BuildOptions) -> bool abi(.compiler) { … }`. The stdlib default
// implementation lives below (the default `build` script).
on_build :: (cb: (opt: BuildOptions) -> bool abi(.compiler)) abi(.compiler);
// ── The default build script ────────────────────────────────────────────────
//
// `default_pipeline` is the stdlib build driver: the compiler invokes it after
// codegen (everything is sx-driven — there is no auto-emit/auto-link). It emits
// the sx object, gathers the C companion objects, and links them into the output
// with the build's libraries / frameworks / flags / target. A user overrides the
// whole pipeline with their own `#run on_build(custom);` in main.sx (last-wins).
// The compiler FORCE-LOWERS this well-known name and auto-invokes it after
// codegen when no `#run on_build(custom);` override was registered (no library
// `#run` needed). A user override takes over entirely.
default_pipeline :: (opt: BuildOptions) -> bool abi(.compiler) {
obj := emit_object();
objs := c_object_paths();
objs.append(obj);
link(objs, build_output(), link_libraries(), build_frameworks(), build_flags(), build_target());
return true;
}

View File

@@ -15,11 +15,17 @@
c_object_paths :: () -> List(string) abi(.compiler);
link_libraries :: () -> List(string) abi(.compiler);
// The object file the compiler emitted for this build. The compiler emits it
// eagerly; this returns its path (a query, not an action). The sx driver passes
// it to `link` alongside the C objects.
// Verify + emit the codegen'd module to its object file; returns the path. An
// ACTION — the compiler no longer auto-emits; the sx driver calls this.
emit_object :: () -> string abi(.compiler);
// Build-config metadata the sx driver passes to `link` (the merged CLI + `#run`
// build config the compiler accumulated for this build).
build_output :: () -> string abi(.compiler); // the output binary path
build_target :: () -> string abi(.compiler); // the target triple ("" = host)
build_frameworks :: () -> List(string) abi(.compiler); // `-framework` names
build_flags :: () -> List(string) abi(.compiler); // extra link flags
// Link `objects` into `output`, with the given libraries / frameworks / link
// flags / target triple. The one genuine ACTION primitive — the compiler keeps
// the proven linker (Option B); the sx driver orchestrates. Not fallible (the