rename: src/Formats -> src/Rosetta, @formats -> @rosetta requires, build/luajit/rosetta + rosetta._compat, build/roblox/Rosetta, ROSETTA_* env/globals, writer vendor strings

This commit is contained in:
4DBug committed 2026-11-01 01:19:16 -05:00
1 parent 2956576d7f
commit 22ddcd78fa
941 files changed
+3364 -3364

No files matched your search

+13 -13
View File
@@ -1,32 +1,32 @@
#!/usr/bin/env python3
# Build (python3 -I tools/build.py [roblox|luajit ...]): the two outputs of the one Luau source tree.
#
# build/roblox/Formats/... darklua convert_require (luau aliases -> Roblox instance paths). Types, --!native and
# 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/formats/... 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("formats.a.b").
# 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).
#
# Load the LuaJIT output with package.path = "build/luajit/?.lua;build/luajit/?/init.lua;" .. package.path, then
# local F = require("formats").
# 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
# expression does not start with pairs / ipairs / next becomes `for k, v in __iter(expr) do` (compat's __iter:
# functions pass through with their state, arrays use ipairs, other tables next).
# 2. Luau stdlib names: each module gets, on its first line (line numbers stay the same), only the locals it uses of
# buffer, bit32, utf8, typeof, type, __iter from formats._compat (LuaJIT has a 60-upvalue limit per function).
# buffer, bit32, utf8, typeof, type, __iter from rosetta._compat (LuaJIT has a 60-upvalue limit per function).
# 3. If-expressions: darklua lowers `if c then a else b` to `(c and {a} or {b})[1]`, a table per evaluation. When
# `a` is provably not nil/false (a number or string literal, `#x`, or an arithmetic / concatenation expression
# at its top level) it becomes `(c and a or b)`.
# 4. Requires: `require("@formats/x/y")` -> `require("formats.x.y")`, `require("@tests/x")` -> `require("tests.x")`,
# 4. Requires: `require("@rosetta/x/y")` -> `require("rosetta.x.y")`, `require("@tests/x")` -> `require("tests.x")`,
# done on the source before darklua (string literals only; computed requires are not allowed in the library).
import json, os, re, shutil, subprocess, sys, tempfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC = os.path.join(ROOT, "src", "Formats")
SRC = os.path.join(ROOT, "src", "Rosetta")
TESTS = os.path.join(ROOT, "tests")
BUILD = os.path.join(ROOT, "build")
# darklua 0.19: $DARKLUA, else on PATH, else through nix
@@ -273,13 +273,13 @@ def pass_header(src):
names = [n for n in COMPAT_NAMES if n in used]
if not names:
return src
head = 'local __compat = require("formats._compat") local %s = %s ' % (
head = 'local __compat = require("rosetta._compat") local %s = %s ' % (
", ".join(names), ", ".join("__compat." + n for n in names))
return head + src
# ------------------------------------------------------------------------------------------------ requires
REQ = re.compile(r'require\(\s*"@(formats|tests)((?:/[\w.]+)*)"\s*\)')
REQ = re.compile(r'require\(\s*"@(rosetta|tests)((?:/[\w.]+)*)"\s*\)')
def luajit_requires(src):
@@ -329,7 +329,7 @@ def pass_reserved_children(src):
def build_roblox():
out = os.path.join(BUILD, "roblox", "Formats")
out = os.path.join(BUILD, "roblox", "Rosetta")
shutil.rmtree(os.path.join(BUILD, "roblox"), ignore_errors=True)
darklua(ROBLOX_RULES, os.path.relpath(SRC, ROOT), os.path.relpath(out, ROOT), ROOT)
for f in files(out):
@@ -345,7 +345,7 @@ def build_roblox():
def build_luajit_tree(src_root, out_root, skip_dirs=()):
"""src_root/**/*.luau -> out_root/**/*.lua through the require rewrite, darklua and the token passes."""
tmp = tempfile.mkdtemp(prefix="formats-build-")
tmp = tempfile.mkdtemp(prefix="rosetta-build-")
try:
stage = os.path.join(tmp, "in")
dl = os.path.join(tmp, "out")
@@ -381,7 +381,7 @@ def build_luajit_tree(src_root, out_root, skip_dirs=()):
def build_luajit():
base = os.path.join(BUILD, "luajit")
shutil.rmtree(base, ignore_errors=True)
out = os.path.join(base, "formats")
out = os.path.join(base, "rosetta")
n = build_luajit_tree(SRC, out)
shutil.copy(os.path.join(ROOT, "compat", "luajit.lua"), os.path.join(out, "_compat.lua"))
print("build: luajit %3d modules -> %s" % (n, os.path.relpath(out, ROOT)))
@@ -435,7 +435,7 @@ def selftest():
for a, want in els:
got = pass_elseif(a)
assert got == (want or a), (a, got)
assert luajit_requires('require("@formats/core/Bytes")') == 'require("formats.core.Bytes")'
assert luajit_requires('require("@rosetta/core/Bytes")') == 'require("rosetta.core.Bytes")'
els = [
("local x = if a then 1 elseif b then 2 elseif c then 3 else 4",
"local x = if a then 1 else if b then 2 else if c then 3 else 4"),