Skip to content

Auto-load the native library on Linux via the Kit (platform-gated, no Windows/Mac impact)#48

Merged
SethMorrowSoftware merged 1 commit into
mainfrom
claude/beautiful-cray-lwlsgr
Jun 15, 2026
Merged

Auto-load the native library on Linux via the Kit (platform-gated, no Windows/Mac impact)#48
SethMorrowSoftware merged 1 commit into
mainfrom
claude/beautiful-cray-lwlsgr

Conversation

@SethMorrowSoftware

Copy link
Copy Markdown
Owner

Goal

Make the no-sudo Linux load automatic — drop box2dxt.so beside the OXT engine (or bundle it in a standalone) and Kit/demo stacks load it on their own, with no Windows/Mac regression.

The key insight

The auto-fire that broke Windows in #47 was Windows-only: realpath doesn't exist there, so the binding threw. But realpath does exist on macOS (it's POSIX) and harmlessly returns nothing (no /proc). So we don't need to avoid the call everywhere — just on Windows. A single platform gate is enough.

The change

b2kSetup (the Kit's world-creation entry, which runs before any physics call) now does:

if the platform is "Linux" then get b2LoadNativeLibHere()
  • Linux: preloads box2dxt.so from the engine's own folder before the first binding resolves → it just works, no sudo.
  • Windows/macOS: the gate is false, so the POSIX helper is never touched — they keep loading the library from beside the stack/app exactly as before.

the platform is rock-solid in LiveCodeScript, so the gate is reliable (unlike platform detection inside the LCB, which is why this lives in the Kit, not in b2Version/checkABI).

Scope

  • src/box2dxt-kit.livecodescript — the one gated line at the top of b2kSetup.
  • examples/* — re-synced embedded Kit (tools/sync-embedded-kit.py).
  • examples/box2dxt-selftest.livecodescriptkStHarnessV 18→19 and a new stTestLoaderHelper: on Linux it asserts b2LoadNativeLibHere() returns a 0/1 flag without error (which also proves the realpath/dlopen bindings resolve); off Linux it records that the gate skips it.

Verified locally

tools/check-livecodescript.py passes — Kit + all examples balanced, no smart quotes, embedded Kit in sync.

Needs an OXT pass

Still the same gate as before: on a Linux box, build the lib with -DBOX2DXT_BARE_SONAME=ON, drop it beside the engine, open a demo (or run the self-test) — it should load with no sudo. On Windows, loading a demo should behave exactly as today (the gate skips the new path).

Note

Covers Kit/demo usage (which is all the examples and the typical user). Raw b2*-only users on Linux still call b2LoadNativeLibHere() themselves — documented on the handler.

https://claude.ai/code/session_01EVV5fGeXqtWs8WDrmgWNku


Generated by Claude Code

b2kSetup now calls b2LoadNativeLibHere() when (and only when) the platform is
Linux, so Kit/demo users get the no-sudo engine-folder load automatically while
Windows/macOS never touch the POSIX path. The breakage that forced the helper
to be a manual call in #47 was Windows-only -- realpath is absent there, but
present and harmless on macOS -- so a single platform gate is enough. Drop
box2dxt.so beside the engine (or bundle it in a standalone) and the demos run
on Linux with no /usr/lib, no sudo, no LD_LIBRARY_PATH.

- src/box2dxt-kit.livecodescript: gated preload at the top of b2kSetup.
- examples/*: re-synced embedded Kit.
- examples/box2dxt-selftest: bump kStHarnessV 18->19 + add stTestLoaderHelper
  (Linux-gated; on Linux it also proves the realpath/dlopen bindings resolve).

https://claude.ai/code/session_01EVV5fGeXqtWs8WDrmgWNku
@SethMorrowSoftware SethMorrowSoftware marked this pull request as ready for review June 15, 2026 22:29
@SethMorrowSoftware SethMorrowSoftware merged commit 61a52be into main Jun 15, 2026
7 checks passed
SethMorrowSoftware pushed a commit that referenced this pull request Jun 15, 2026
Moves the auto-load into the extension itself so it works for BOTH Kit and raw
b2* callers, with nothing baked into individual stacks -- the cleaner home the
Kit gating was a stand-in for. _autoEnsure() calls b2LoadNativeLibHere() inside
a try/catch and is invoked from b2Version/checkABI (the gateways). On Linux it
preloads from the engine folder; on macOS it returns 0 (no /proc); on Windows
the POSIX realpath binding throws and the catch swallows it, so nothing breaks.

This is a SPIKE: its whole purpose is to confirm LiveCode Builder supports
try/catch. If the extension compiles in OXT, it does -- and we can drop the Kit
gating (#48) in a follow-up. If it will NOT compile, try/catch is unavailable
and we keep the Kit approach (the merged main) or switch to a getenv platform
check. The Kit gating is intentionally left in place here so Linux still loads
during the spike; the redundancy is harmless.

https://claude.ai/code/session_01EVV5fGeXqtWs8WDrmgWNku
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants