Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup EMSDK
uses: emscripten-core/setup-emsdk@v16
with:
version: 6.0.4
version: 7.0.0
actions-cache-folder: emsdk-cache

- name: Use Node.js 26.x
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ jobs:
submodules: recursive
- uses: emscripten-core/setup-emsdk@v16
with:
version: 6.0.4
version: 7.0.0
actions-cache-folder: emsdk-cache
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
cache: npm
# The lua submodule follows release tags, never a commit in between them. Asked of the
# remote rather than the checkout, which fetches the submodule without its tags.
- name: Check the lua submodule is on a release tag
run: |
commit=$(git -C lua rev-parse HEAD)
tag=$(git ls-remote --tags https://github.com/lua/lua | awk -v c="$commit" '$1 == c { sub("refs/tags/", "", $2); sub(/\^\{\}$/, "", $2); print $2 }' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
if [ -z "$tag" ]; then
echo "lua is at $commit, which is not a release tag of lua/lua" >&2
exit 1
fi
echo "lua is at $tag"
- run: npm ci
- run: npm run lint:nofix
- run: npm run build:wasm
Expand Down
2 changes: 1 addition & 1 deletion lua
Submodule lua updated 38 files
+10 −9 lapi.c
+16 −3 lauxlib.c
+14 −21 lbaselib.c
+9 −10 lcode.c
+1 −1 ldblib.c
+2 −2 ldebug.c
+34 −14 ldo.c
+1 −1 ldo.h
+1 −1 lgc.c
+6 −6 llimits.h
+1 −1 loadlib.c
+2 −1 lobject.h
+8 −17 lopcodes.c
+10 −5 lopcodes.h
+15 −24 lparser.c
+3 −2 lparser.h
+2 −2 lstate.c
+20 −20 lstate.h
+8 −2 lstrlib.c
+7 −4 ltablib.c
+4 −4 ltests.c
+5 −5 ltm.c
+13 −7 lua.c
+20 −24 luaconf.h
+5 −8 lundump.c
+2 −2 lundump.h
+5 −2 lutf8lib.c
+17 −11 lvm.c
+8 −3 makefile
+5 −4 manual/2html
+33 −20 manual/manual.of
+26 −0 testes/calls.lua
+3 −0 testes/errors.lua
+12 −0 testes/events.lua
+19 −0 testes/locals.lua
+10 −0 testes/pm.lua
+13 −0 testes/sort.lua
+13 −1 testes/utf8.lua
755 changes: 378 additions & 377 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
],
"devDependencies": {
"@types/node": "*",
"chai": "6.2.2",
"chai": "6.3.0",
"chai-as-promised": "8.0.2",
"fengari": "0.1.5",
"mocha": "12.0.0",
"oxfmt": "0.66.0",
"oxlint": "1.81.0",
"playwright": "1.62.1",
"rolldown": "1.2.6",
"tslib": "2.8.1",
"mocha": "12.0.3",
"oxfmt": "0.79.0",
"oxlint": "1.94.0",
"playwright": "1.65.1",
"rolldown": "1.3.3",
"tslib": "2.9.1",
"typescript": "7.0.2"
},
"dependencies": {
Expand Down
20 changes: 0 additions & 20 deletions rolldown.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { copyFile } from 'node:fs/promises'
import { defineConfig } from 'rolldown'
import pkg from './package.json' with { type: 'json' }
import { UNWIND_BRAND } from './src/utils'

export default defineConfig({
// The CLI is an entry of its own: it imports the library by package name at run time rather
Expand Down Expand Up @@ -43,25 +42,6 @@ export default defineConfig({
}
},
},
{
// A consumer's minifier renames the glue's unwind class but not a string compared
// against its name, so isEmscriptenUnwind goes by a brand on the prototype instead.
name: 'emscripten-unwind-brand',
transform(code, id) {
if (!id.endsWith('glue.js')) {
return
}
const branded = code.replace(/class EmscriptenEH\s*\{\s*\}/, (match) => {
return `${match}EmscriptenEH.prototype.${UNWIND_BRAND}=true;`
})
if (branded === code) {
// A silent miss would ship a build where every Lua error path is subtly wrong.
this.error('EmscriptenEH declaration not found in the glue, so the unwind brand would be a no-op')
}
// Generated code with no sourcemap of its own, so there is nothing to preserve.
return { code: branded, map: null }
},
},
{
// A node builtin is imported behind a runtime check for Node, which a bundler targeting
// the browser does not see, so it refuses to resolve it. webpack takes the comment; the
Expand Down
20 changes: 8 additions & 12 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ export interface LuaEmscriptenModule extends EmscriptenModule {
removeFunction: typeof removeFunction
setValue: typeof setValue
getValue: typeof getValue
// `filesystems` is the only member missing upstream; mkdirTree and the rest come from typeof FS.
FS: typeof FS & {
filesystems: {
NODEFS: Emscripten.FileSystemType
MEMFS: Emscripten.FileSystemType
}
}
FS: typeof FS
// Exported by the build, since Emscripten 7 no longer hangs the backends off FS.filesystems.
NODEFS: Emscripten.FileSystemType
PATH: EmscriptenPath
stringToNewUTF8: typeof stringToNewUTF8
lengthBytesUTF8: typeof lengthBytesUTF8
Expand Down Expand Up @@ -262,9 +258,9 @@ function assertMountFits(live: readonly ResolvedMount[], candidate: ResolvedMoun
}
}

function mountHostDirectory(fs: EmscriptenFS, { virtualPath, hostPath }: ResolvedMount): void {
fs.mkdirTree(virtualPath)
fs.mount(fs.filesystems.NODEFS, { root: hostPath }, virtualPath)
function mountHostDirectory(emscripten: LuaEmscriptenModule, { virtualPath, hostPath }: ResolvedMount): void {
emscripten.FS.mkdirTree(virtualPath)
emscripten.FS.mount(emscripten.NODEFS, { root: hostPath }, virtualPath)
}

/** Everything the wasm module needs before it starts, and nothing that outlives that. */
Expand Down Expand Up @@ -294,7 +290,7 @@ function createPreRun(config: PreRunConfig): (initializedModule: LuaEmscriptenMo
// Nothing to do for `fs: 'host'`: that glue is NODERAWFS, so the filesystem already is the
// host's, working directory included.
for (const mount of config.mounts) {
mountHostDirectory(initializedModule.FS, mount)
mountHostDirectory(initializedModule, mount)
}

if (config.stdin || config.stdout || config.stderr) {
Expand Down Expand Up @@ -608,7 +604,7 @@ export default class LuaModule extends LuaBindings {

const mount = resolveMount(virtualPath, hostPath)
assertMountFits(this.mounts, mount)
mountHostDirectory(this.emscripten.FS, mount)
mountHostDirectory(this.emscripten, mount)
this.mounts.push(mount)
}

Expand Down
8 changes: 7 additions & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ export default class LuaRuntime {
}

public exists(path: string): boolean {
return this.filesystem.analyzePath(path).exists
// Emscripten 7 dropped FS.analyzePath, which did this same lookup and caught its error.
try {
this.filesystem.lookupPath(path, { follow: true })
return true
} catch {
return false
}
}

/** Where relative paths resolve from, `/` unless something changed it or `fs` is `'host'`. */
Expand Down
11 changes: 2 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ export const isPromise = (target: unknown): target is PromiseLike<unknown> => {
return typeof target === 'object' && target !== null && typeof (target as PromiseLike<unknown>).then === 'function'
}

/** Read by the build, which brands the glue's unwind classes with it. */
export const UNWIND_BRAND = '__emscriptenUnwind'

/**
* A Lua longjmp out of a C function that a JS callback is on the stack of, which has to be rethrown
* rather than turned into a Lua error. With `SUPPORT_LONGJMP=wasm` it is a `WebAssembly.Exception`
* the wasm caller resumes unwinding from; the branded `EmscriptenEH` covers the other unwinds
* Emscripten still throws from JS (its class is module local, hence the brand).
* the wasm caller resumes unwinding from, and the glue throws no unwind of its own from JS.
*/
export const isEmscriptenUnwind = (value: unknown): boolean => {
if (typeof WebAssembly.Exception === 'function' && value instanceof WebAssembly.Exception) {
return true
}
return (value as Record<string, unknown> | null | undefined)?.[UNWIND_BRAND] === true
return value instanceof WebAssembly.Exception
}
2 changes: 1 addition & 1 deletion test/filesystem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Filesystem', () => {
const lua = await getLua()
lua.writeFile('fs-probe.lua', 'return 1')

expect(lua.filesystem.analyzePath('/fs-probe.lua').exists).to.be.true
expect(lua.filesystem.readFile('/fs-probe.lua', { encoding: 'utf8' })).to.be.equal('return 1')
})

it('path should expose the emscripten path helpers', async () => {
Expand Down
5 changes: 4 additions & 1 deletion utils/build-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ try {
}

const dockerVolume = `${rootdir}:/wasmoon`
const command = `docker run --rm -v "${dockerVolume}" emscripten/emsdk /wasmoon/utils/build-wasm.sh ${args.join(' ')}`
// Pinned to the version the workflows in .github/ install, so a local build makes the same glue CI
// tests rather than whatever `latest` is today.
const EMSDK_VERSION = '7.0.0'
const command = `docker run --rm -v "${dockerVolume}" emscripten/emsdk:${EMSDK_VERSION} /wasmoon/utils/build-wasm.sh ${args.join(' ')}`

execute(command)
1 change: 1 addition & 0 deletions utils/build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ COMMON=(
'addFunction', \
'removeFunction', \
'FS', \
'NODEFS', \
'PATH', \
'ENV', \
'getValue', \
Expand Down