build: single-file bundles build/Rosetta.luau + build/rosetta.lua (tools/bundle.py), terse README with generated format / codec tables

- tools/bundle.py: every module a function in __FILES with a cached __include; requires become __include
  calls, so only the API and its load-time requires run on require. Rosetta._internal(path) includes any
  module by its src path. --!native modules get @native on each function (NATIVE re-checked on the bundle);
  linemaps map bundle lines back to sources (--where). LuaJIT bundle inlines the compat prelude.
- tools/build.py: the multi-file trees move to build/_modules (gitignored); each target also writes its bundle.
- tools/test.sh: api + docs/example tests also run against both bundles; fails when build/ is stale.
- default.project.json mounts build/Rosetta.luau; examples/love loads build/rosetta.lua.
- README: one line, install, quick start, doc links, generated format table and codec list
  (tools/gen_registry.py), licence TODO. DOCS lint checks the generated sections and the links.
This commit is contained in:
4DBug committed 2026-11-01 01:00:35 -06:00
1 parent 0bd7b87d2b
commit bcf6d46fb7
16 files changed
+399611 -210

No files matched your search

+21 -12
View File
@@ -1,16 +1,20 @@
#!/usr/bin/env python3
# Build (python3 -I tools/build.py [roblox|luajit ...]): the two outputs of the one Luau source tree.
#
# build/roblox/Rosetta/... darklua convert_require (luau aliases -> Roblox instance paths). Types, --!native and
# @native are kept. Mounted by default.project.json (rojo build / rojo serve).
# build/luajit/rosetta/... plain Lua 5.1 for LuaJIT / LÖVE: darklua strips types, attributes (@native) and the
# Luau-only syntax, then the token passes below; requires become require("rosetta.a.b").
# build/luajit/tools/... tools/*.luau (bench), built the same way.
# build/luajit/tests/... the tests, built the same way (require("@tests/T") -> require("tests.T")); tests/gen
# fixture modules are copied as they are (plain string literals; darklua is slow on them).
# The shipped files are the single-file bundles build/Rosetta.luau (roblox) and build/rosetta.lua (luajit), written by
# tools/bundle.py after each target (committed). The multi-file trees below are internal (gitignored), for the tests:
# build/_modules/roblox/Rosetta/... darklua convert_require (luau aliases -> Roblox instance paths). Types, --!native
# and @native are kept.
# build/_modules/luajit/rosetta/... plain Lua 5.1 for LuaJIT / LÖVE: darklua strips types, attributes (@native) and
# the Luau-only syntax, then the token passes below; requires become
# require("rosetta.a.b"). tools/bundle.py builds build/rosetta.lua from it.
# build/_modules/luajit/tools/... tools/*.luau (bench), built the same way.
# build/_modules/luajit/tests/... the tests, built the same way (require("@tests/T") -> require("tests.T"));
# tests/gen fixture modules are copied as they are (plain string literals; darklua
# is slow on them).
#
# Load the LuaJIT output with package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path, then
# local F = require("rosetta").
# Load the LuaJIT tree with package.path = "build/_modules/luajit/?.lua;build/_modules/luajit/?/init.lua;" ..
# package.path, then local F = require("rosetta").
#
# What darklua 0.19 cannot do, done here as token-level passes (lexer from imgui-luau tools/minify.py):
# 1. Generalized iteration (`for k, v in t do`): darklua has no rule for it. Every generic for whose iterator
@@ -29,6 +33,7 @@ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC = os.path.join(ROOT, "src", "Rosetta")
TESTS = os.path.join(ROOT, "tests")
BUILD = os.path.join(ROOT, "build")
MODULES = os.path.join(BUILD, "_modules")
# darklua 0.19: $DARKLUA, else on PATH, else through nix
DARKLUA = os.environ.get("DARKLUA", "").split() or (["darklua"] if shutil.which("darklua") else
["nix", "shell", "nixpkgs#darklua", "-c", "darklua"])
@@ -329,8 +334,8 @@ def pass_reserved_children(src):
def build_roblox():
out = os.path.join(BUILD, "roblox", "Rosetta")
shutil.rmtree(os.path.join(BUILD, "roblox"), ignore_errors=True)
out = os.path.join(MODULES, "roblox", "Rosetta")
shutil.rmtree(os.path.join(MODULES, "roblox"), ignore_errors=True)
darklua(ROBLOX_RULES, os.path.relpath(SRC, ROOT), os.path.relpath(out, ROOT), ROOT)
for f in files(out):
with open(f) as fh:
@@ -379,7 +384,7 @@ def build_luajit_tree(src_root, out_root, skip_dirs=()):
def build_luajit():
base = os.path.join(BUILD, "luajit")
base = os.path.join(MODULES, "luajit")
shutil.rmtree(base, ignore_errors=True)
out = os.path.join(base, "rosetta")
n = build_luajit_tree(SRC, out)
@@ -459,7 +464,11 @@ if __name__ == "__main__":
if "--test" in targets:
selftest()
sys.exit(0)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import bundle
if "roblox" in targets:
build_roblox()
bundle.bundle_roblox()
if "luajit" in targets:
build_luajit()
bundle.bundle_luajit()