Expand description
luna-aot — ahead-of-time compiler from Lua source to a self-contained native binary.
§Scaffold pipeline (bytecode embed)
- CLI
cli::run/ libraryembed::embed_bytecodetake a.luasource file. - luna-core’s frontend parses + compiles it to bytecode (a
luna_core::runtime::Prototree). - The bytecode is dumped via
luna_core::vm::dump(luna’s own body format —"\x1bLua" + version-byteheader + the"\x00LunaV1\x00"sentinel + luna body). - The dump bytes are written into a
.luna.bytecodesection of an ELF / Mach-O / PE object file viaobject::write::Object, bracketed by two public symbols__luna_bytecode_startand__luna_bytecode_endthat the runtime stub (or a custom host binary)extern "C"s. - The CLI invokes system
ccto link the bytecode object + a minimal C entry point into a final executable. The default scaffold entry just prints the embedded bytecode length tostderrand exits — proving the section is reachable end-to-end.
§Why a separate crate
This crate pulls object + clap and all of cranelift;
embedders who only want the runtime JIT keep using luna-jit, and
embedders who only want pure interp keep using luna-core — both stay free of luna-aot’s build-time
dep tree.
luna-core 0-third-party-dep contract is unaffected. This
crate depends on luna-core but luna-core does not depend on
anything here. The CI gate
(cargo tree -p luna-core --prefix none | grep -cE " v[0-9]")
continues to report 1.
Modules§
- cli
luna-aotCLI surface — clap-derive. Sub-commands:- embed
- The AOT pipeline:
parse + compile Lua source → dump luna bytecode → embed into an
object file’s
.luna.bytecodedata section → link. - runtime_
stub - The Rust runtime stub that the AOT-produced binary calls at
process start. This module is library code today: the
scaffold’s linked binary uses a tiny C
main(seecrate::embed) that prints the bytecode length. Swapping that C entry out for this Rust stub makes the binary run the embedded bytecode through aVm.
Constants§
- BYTECODE_
END_ SYMBOL - Symbol name marking the end of the embedded bytecode section.
External (C-ABI) symbol; the runtime stub declares it as
extern "C" { static __luna_bytecode_end: u8; }and computes the length as(&end as *const u8).offset_from(&start as *const u8). - BYTECODE_
SECTION_ NAME - Object-file section name for the embedded bytecode.
ELF/Mach-O conventions: a leading dot is the standard for non-loader-
special sections; we pick
.luna.bytecodesoobjdump -s -j .luna.bytecode <out>displays the dump bytes for inspection. - BYTECODE_
START_ SYMBOL - Symbol name marking the start of the embedded bytecode section.
External (C-ABI) symbol; the runtime stub declares it as
extern "C" { static __luna_bytecode_start: u8; }.