P5.5: migrate the 35 BuildOptions accessors off #compiler to VM-native abi(.compiler)
`BuildOptions :: struct #compiler { ...35 methods... }` becomes
`BuildOptions :: struct { }` (an opaque null-sentinel handle) plus 35 free
`ufcs (self: BuildOptions, …) abi(.compiler)` decls in build.sx, each serviced
by a new `comptime_vm.callBuildOptionFn` arm (off `callCompilerFn`). No legacy
`compiler_lib` handler: the names are registered in `bound_fns` with a single
bailing stub only so `weldedCompilerFn` accepts them.
- String lifetime: setters dupe the arg into the persistent `Vm.gpa` (the
Compilation allocator, threaded into both `tryEval` and `runBuildCallback` —
not the per-eval VM arena) and write/append to the threaded `BuildConfig`.
Getters read the field/slice or compute the target predicate from the triple.
- Dispatch routing (Option B): a `#run`/const-init entry that directly calls a
compiler-domain/welded fn (`emit_llvm.entryNeedsVm`) runs on the VM with no
legacy fallback regardless of the `-Dcomptime-flat` gate, so gate-OFF stays
green without a legacy BuildOptions handler (P5.7 retires the legacy interp).
- Mark the 5 `platform/bundle.sx` getter-calling helpers `abi(.compiler)` (they
are comptime-only bundler code; otherwise their now-welded getter calls trip
the runtime-call gate).
- 37 `.ir` snapshots regenerated (std transitively imports build.sx → string-
pool/type-table indices shift); verified `.ir`-only, zero behavior-stream diffs.
BuildOptions `compiler_call` strict bails gone (1609/1614/1615 strict-clean);
1616 now bails on a separate, pre-existing unported bitwise/shift VM gap (`shr`),
to port first in P5.6. 703/0 both gates.
Also sweep the outdated "flat memory" terminology to "comptime/byte-addressable"
across comptime_vm + the plan/checkpoint/CLAUDE docs: the comptime VM is
arena-backed, byte-addressable memory where `Addr` is a real host pointer, not a
flat contiguous address space (flag names `-Dcomptime-flat`/`SX_COMPTIME_FLAT` kept).
This commit is contained in:
@@ -11,88 +11,97 @@ OS : OperatingSystem = .unknown;
|
||||
ARCH : Architecture = .unknown;
|
||||
POINTER_SIZE : i64 = 8;
|
||||
|
||||
BuildOptions :: struct #compiler {
|
||||
add_link_flag :: (self: BuildOptions, flag: [:0]u8);
|
||||
add_framework :: (self: BuildOptions, name: [:0]u8);
|
||||
set_output_path :: (self: BuildOptions, path: [:0]u8);
|
||||
set_wasm_shell :: (self: BuildOptions, path: [:0]u8);
|
||||
|
||||
// Register a directory of runtime assets to bundle alongside the
|
||||
// binary. `src` is the path on disk (relative to the CWD at build
|
||||
// time); `dest` is the relative location inside the bundle / APK.
|
||||
// Apple .app: copied to `<bundle>/<dest>/`. Android APK (Week 7):
|
||||
// zipped under `<dest>/` at the APK root. Idiomatic chess form is
|
||||
// `opts.add_asset_dir("assets", "assets")`.
|
||||
add_asset_dir :: (self: BuildOptions, src: [:0]u8, dest: [:0]u8);
|
||||
asset_dir_count :: (self: BuildOptions) -> i64;
|
||||
asset_dir_src_at :: (self: BuildOptions, i: i64) -> string;
|
||||
asset_dir_dest_at :: (self: BuildOptions, i: i64) -> string;
|
||||
|
||||
// Name-based alternative to `set_post_link_callback`. The
|
||||
// compiler resolves `<module_name>.bundle_main` after linking.
|
||||
set_post_link_module :: (self: BuildOptions, module_name: [:0]u8);
|
||||
|
||||
// Path of the freshly-linked binary, only meaningful while a
|
||||
// post-link callback is running. Returns "" before linking.
|
||||
binary_path :: (self: BuildOptions) -> string;
|
||||
|
||||
// Apple `.app` / Android `.apk` bundling parameters. Accessors
|
||||
// return "" when unset so the bundler can use a single string
|
||||
// type. macOS bundling needs `bundle_path` and `bundle_id`;
|
||||
// codesign / provisioning are iOS-device-only.
|
||||
set_bundle_path :: (self: BuildOptions, path: [:0]u8);
|
||||
set_bundle_id :: (self: BuildOptions, id: [:0]u8);
|
||||
set_codesign_identity :: (self: BuildOptions, identity: [:0]u8);
|
||||
set_provisioning_profile :: (self: BuildOptions, path: [:0]u8);
|
||||
|
||||
bundle_path :: (self: BuildOptions) -> string;
|
||||
bundle_id :: (self: BuildOptions) -> string;
|
||||
codesign_identity :: (self: BuildOptions) -> string;
|
||||
provisioning_profile :: (self: BuildOptions) -> string;
|
||||
|
||||
// Target accessors. Empty triple before linking; predicates mirror
|
||||
// TargetConfig.is{MacOS,IOS,IOSDevice,IOSSimulator}() on the Zig
|
||||
// side. Used by the sx bundler to switch Info.plist shape and
|
||||
// codesigning ceremony per platform.
|
||||
target_triple :: (self: BuildOptions) -> string;
|
||||
is_macos :: (self: BuildOptions) -> bool;
|
||||
is_ios :: (self: BuildOptions) -> bool;
|
||||
is_ios_device :: (self: BuildOptions) -> bool;
|
||||
is_ios_simulator :: (self: BuildOptions) -> bool;
|
||||
is_android :: (self: BuildOptions) -> bool;
|
||||
|
||||
// Framework list accessors. The bundler walks `framework_count() *
|
||||
// framework_at(i)` to find each `-framework` name and recursively
|
||||
// copies its `<Name>.framework` directory from one of
|
||||
// `framework_path_at(0..framework_path_count())` into
|
||||
// `<bundle>/Frameworks/`. Slice returns aren't natively expressible
|
||||
// through the compiler-hook bridge yet, hence the indexed form.
|
||||
framework_count :: (self: BuildOptions) -> i64;
|
||||
framework_at :: (self: BuildOptions, i: i64) -> string;
|
||||
framework_path_count :: (self: BuildOptions) -> i64;
|
||||
framework_path_at :: (self: BuildOptions, i: i64) -> string;
|
||||
|
||||
// Android APK bundling parameters. `manifest_path` overrides the
|
||||
// bundler's auto-generated AndroidManifest.xml; `keystore_path`
|
||||
// overrides the default `$HOME/.android/debug.keystore`. Accessors
|
||||
// return "" when unset.
|
||||
set_manifest_path :: (self: BuildOptions, path: [:0]u8);
|
||||
set_keystore_path :: (self: BuildOptions, path: [:0]u8);
|
||||
manifest_path :: (self: BuildOptions) -> string;
|
||||
keystore_path :: (self: BuildOptions) -> string;
|
||||
|
||||
// `#jni_main #jni_class("path") { ... }` decls collected during
|
||||
// lowering. The Android bundler walks `0..jni_main_count()` and
|
||||
// for each entry writes a `.java` file at
|
||||
// `<stage>/java/<runtime_path>.java`, compiles via javac + d8, and
|
||||
// bundles the resulting classes.dex into the APK.
|
||||
jni_main_count :: (self: BuildOptions) -> i64;
|
||||
jni_main_runtime_path_at :: (self: BuildOptions, i: i64) -> string;
|
||||
jni_main_java_source_at :: (self: BuildOptions, i: i64) -> string;
|
||||
}
|
||||
// An opaque compile-time build-configuration handle. `build_options()` hands one
|
||||
// back; its real state lives on the compiler's threaded `BuildConfig`. The handle
|
||||
// itself is a null-sentinel word (never dereferenced) — every accessor below takes
|
||||
// it as an ignored `self` and reads/writes the `BuildConfig` instead. The accessors
|
||||
// are free `abi(.compiler)` functions (resolved on `opt.method(...)` via UFCS) and
|
||||
// serviced by `comptime_vm.callCompilerFn` — migrated off the old `struct #compiler`
|
||||
// hook surface (Phase 5.5).
|
||||
BuildOptions :: struct { }
|
||||
|
||||
build_options :: () -> BuildOptions abi(.compiler);
|
||||
|
||||
// ── BuildOptions accessors (free `abi(.compiler)` functions, UFCS) ───────────
|
||||
|
||||
add_link_flag :: ufcs (self: BuildOptions, flag: [:0]u8) abi(.compiler);
|
||||
add_framework :: ufcs (self: BuildOptions, name: [:0]u8) abi(.compiler);
|
||||
set_output_path :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
set_wasm_shell :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
|
||||
// Register a directory of runtime assets to bundle alongside the
|
||||
// binary. `src` is the path on disk (relative to the CWD at build
|
||||
// time); `dest` is the relative location inside the bundle / APK.
|
||||
// Apple .app: copied to `<bundle>/<dest>/`. Android APK: zipped under
|
||||
// `<dest>/` at the APK root. Idiomatic form is
|
||||
// `opts.add_asset_dir("assets", "assets")`.
|
||||
add_asset_dir :: ufcs (self: BuildOptions, src: [:0]u8, dest: [:0]u8) abi(.compiler);
|
||||
asset_dir_count :: ufcs (self: BuildOptions) -> i64 abi(.compiler);
|
||||
asset_dir_src_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
asset_dir_dest_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
|
||||
// Name-based alternative to `on_build`. The compiler resolves
|
||||
// `<module_name>.bundle_main` after linking.
|
||||
set_post_link_module :: ufcs (self: BuildOptions, module_name: [:0]u8) abi(.compiler);
|
||||
|
||||
// Path of the freshly-linked binary, only meaningful while a
|
||||
// post-link callback is running. Returns "" before linking.
|
||||
binary_path :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
|
||||
// Apple `.app` / Android `.apk` bundling parameters. Accessors
|
||||
// return "" when unset so the bundler can use a single string
|
||||
// type. macOS bundling needs `bundle_path` and `bundle_id`;
|
||||
// codesign / provisioning are iOS-device-only.
|
||||
set_bundle_path :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
set_bundle_id :: ufcs (self: BuildOptions, id: [:0]u8) abi(.compiler);
|
||||
set_codesign_identity :: ufcs (self: BuildOptions, identity: [:0]u8) abi(.compiler);
|
||||
set_provisioning_profile :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
|
||||
bundle_path :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
bundle_id :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
codesign_identity :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
provisioning_profile :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
|
||||
// Target accessors. Empty triple before linking; predicates mirror
|
||||
// TargetConfig.is{MacOS,IOS,IOSDevice,IOSSimulator}() on the Zig
|
||||
// side. Used by the sx bundler to switch Info.plist shape and
|
||||
// codesigning ceremony per platform.
|
||||
target_triple :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
is_macos :: ufcs (self: BuildOptions) -> bool abi(.compiler);
|
||||
is_ios :: ufcs (self: BuildOptions) -> bool abi(.compiler);
|
||||
is_ios_device :: ufcs (self: BuildOptions) -> bool abi(.compiler);
|
||||
is_ios_simulator :: ufcs (self: BuildOptions) -> bool abi(.compiler);
|
||||
is_android :: ufcs (self: BuildOptions) -> bool abi(.compiler);
|
||||
|
||||
// Framework list accessors. The bundler walks `framework_count() *
|
||||
// framework_at(i)` to find each `-framework` name and recursively
|
||||
// copies its `<Name>.framework` directory from one of
|
||||
// `framework_path_at(0..framework_path_count())` into
|
||||
// `<bundle>/Frameworks/`. Indexed form (slice returns are expressible
|
||||
// now via `List`, but the bundler still walks these by index).
|
||||
framework_count :: ufcs (self: BuildOptions) -> i64 abi(.compiler);
|
||||
framework_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
framework_path_count :: ufcs (self: BuildOptions) -> i64 abi(.compiler);
|
||||
framework_path_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
|
||||
// Android APK bundling parameters. `manifest_path` overrides the
|
||||
// bundler's auto-generated AndroidManifest.xml; `keystore_path`
|
||||
// overrides the default `$HOME/.android/debug.keystore`. Accessors
|
||||
// return "" when unset.
|
||||
set_manifest_path :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
set_keystore_path :: ufcs (self: BuildOptions, path: [:0]u8) abi(.compiler);
|
||||
manifest_path :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
keystore_path :: ufcs (self: BuildOptions) -> string abi(.compiler);
|
||||
|
||||
// `#jni_main #jni_class("path") { ... }` decls collected during
|
||||
// lowering. The Android bundler walks `0..jni_main_count()` and
|
||||
// for each entry writes a `.java` file at
|
||||
// `<stage>/java/<runtime_path>.java`, compiles via javac + d8, and
|
||||
// bundles the resulting classes.dex into the APK.
|
||||
jni_main_count :: ufcs (self: BuildOptions) -> i64 abi(.compiler);
|
||||
jni_main_runtime_path_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
jni_main_java_source_at :: ufcs (self: BuildOptions, i: i64) -> string abi(.compiler);
|
||||
|
||||
// The build callback registrar (Phase 5). Registers the sx function that drives
|
||||
// the build — the compiler invokes it after codegen with the `BuildOptions`
|
||||
// handle. `#run on_build(build);` (from inside a `#run` block) is the override
|
||||
|
||||
@@ -223,7 +223,7 @@ IOS_MIN_OS : string : "14.0";
|
||||
// carry the keys the iOS launcher needs (UIDeviceFamily,
|
||||
// LSRequiresIPhoneOS, UIApplicationSceneManifest, DTPlatformName,
|
||||
// MinimumOSVersion); macOS doesn't need any of those.
|
||||
build_info_plist :: (opts: BuildOptions, exe_name: string, bundle_id: string) -> string {
|
||||
build_info_plist :: (opts: BuildOptions, exe_name: string, bundle_id: string) -> string abi(.compiler) {
|
||||
if opts.is_ios() {
|
||||
platform_key := if opts.is_ios_simulator() then "iPhoneSimulator" else "iPhoneOS";
|
||||
return format(#string PLIST
|
||||
@@ -371,7 +371,7 @@ copy_asset_dir :: (src: string, dest: string, bundle: string) -> bool {
|
||||
// paths into `<dest_dir>`. Walks the framework paths in order; first
|
||||
// hit wins. Falls back to a `cp -R` subprocess because fs.sx Phase 1A
|
||||
// doesn't expose `list_dir` / `walk` yet.
|
||||
embed_framework :: (opts: BuildOptions, name: string, dest_dir: string) -> bool {
|
||||
embed_framework :: (opts: BuildOptions, name: string, dest_dir: string) -> bool abi(.compiler) {
|
||||
subdir := concat(name, ".framework");
|
||||
path_count := opts.framework_path_count();
|
||||
i : i64 = 0;
|
||||
@@ -580,7 +580,7 @@ absolutify :: (path: string) -> string {
|
||||
path
|
||||
}
|
||||
|
||||
android_bundle_main :: (opts: BuildOptions, binary: string, apk_path: string, bundle_id: string) -> bool {
|
||||
android_bundle_main :: (opts: BuildOptions, binary: string, apk_path: string, bundle_id: string) -> bool abi(.compiler) {
|
||||
// The bundler `cd`s into the stage dir for `zip` steps, so any
|
||||
// relative path the caller gave us would resolve against the wrong
|
||||
// cwd. Pin everything to absolute paths up front.
|
||||
@@ -872,7 +872,7 @@ lib_name_from_so_basename :: (basename: string) -> string {
|
||||
// `android:hasCode="true"` so Android loads the bundled classes.dex.
|
||||
// Otherwise it falls back to the legacy NativeActivity shape with an
|
||||
// `android.app.lib_name` meta-data entry pointing at the .so.
|
||||
build_android_manifest :: (opts: BuildOptions, package: string, lib_name: string) -> string {
|
||||
build_android_manifest :: (opts: BuildOptions, package: string, lib_name: string) -> string abi(.compiler) {
|
||||
pkg_esc := xml.escape(package);
|
||||
lib_esc := xml.escape(lib_name);
|
||||
if opts.jni_main_count() > 0 {
|
||||
@@ -969,7 +969,7 @@ dir_part :: (path: string) -> string {
|
||||
// the resulting class files via `d8 --release --lib <android.jar>
|
||||
// --output <stage>` so `<stage>/classes.dex` lands where the
|
||||
// orchestrator can zip it into the APK.
|
||||
compile_jni_main_sources :: (opts: BuildOptions, stage: string, android_jar: string, d8_path: string) -> bool {
|
||||
compile_jni_main_sources :: (opts: BuildOptions, stage: string, android_jar: string, d8_path: string) -> bool abi(.compiler) {
|
||||
java_root := path_join(stage, "java");
|
||||
classes_root := path_join(stage, "classes");
|
||||
if !create_dir_all(str_to_cstr(java_root)) {
|
||||
|
||||
Reference in New Issue
Block a user