最后活跃于 1781952239

travisshears's Avatar travisshears 修订了这个 Gist 1781952239. 转到此修订

1 file changed, 72 insertions

factor_raylib_apple_silicon.md(文件已创建)

@@ -0,0 +1,72 @@
1 + # Factor + Raylib on Apple Silicon
2 +
3 +
4 + ## Running
5 +
6 + ```bash
7 + /Applications/factor/factor ./game.factor
8 + ```
9 +
10 + ## macOS Setup
11 +
12 + Getting Factor and raylib working together on macOS (Apple Silicon) requires a few extra steps due to an architecture mismatch.
13 +
14 + ### The Problem
15 +
16 + The official Factor distribution for macOS is **x86_64 only** — there is no ARM64 build as of June 2026. On Apple Silicon Macs it runs under Rosetta 2.
17 +
18 + Homebrew installs native ARM64 packages, so `brew install raylib` gives you an ARM64 `libraylib.dylib` that an x86_64 process cannot load:
19 +
20 + ```
21 + dll-valid? f
22 + DLL" /opt/homebrew/lib/libraylib.dylib" ← ARM64, fails in x86_64 Factor
23 + ```
24 +
25 + ### The Fix
26 +
27 + **Step 1 — Build an x86_64 raylib from source:**
28 +
29 + ```bash
30 + git clone --depth 1 https://github.com/raysan5/raylib.git /tmp/raylib-src
31 + cd /tmp/raylib-src/src
32 + make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED CC="clang -arch x86_64"
33 + ```
34 +
35 + **Step 2 — Install it to `/usr/local/lib`:**
36 +
37 + ```bash
38 + sudo mkdir -p /usr/local/lib
39 + sudo cp /tmp/raylib-src/src/libraylib.dylib /usr/local/lib/libraylib.dylib
40 + ```
41 +
42 + `/usr/local/lib` is in Factor's default library search path, so it will be found by `find-library`.
43 +
44 + **Step 3 — Override the library registration in your `.factor` file:**
45 +
46 + Factor's raylib vocabulary registers the library using the bare filename `"libraylib.dylib"`. On a hardened/notarized binary like Factor, macOS strips `DYLD_LIBRARY_PATH` at launch, so the OS linker can't resolve bare filenames from non-standard paths. However, Factor's own `find-library` word does its own filesystem search and finds the dylib correctly.
47 +
48 + The workaround is to re-register the library with its full path inside a `<< ... >>` parse-time block at the top of your source file:
49 +
50 + ```factor
51 + USING: alien.libraries alien.libraries.finder kernel raylib ;
52 + IN: your-vocab
53 +
54 + << "raylib" "raylib" find-library cdecl add-library >>
55 + ```
56 +
57 + The `<< ... >>` block is required — `add-library` called outside of one runs after alien function stubs are already resolved and has no effect.
58 +
59 + ### Why `find-library` Works
60 +
61 + Factor's macOS library finder searches these paths in order:
62 +
63 + 1. `DYLD_LIBRARY_PATH` (stripped by hardened runtime — always empty)
64 + 2. `@executable_path`-relative paths
65 + 3. Default fallback: `~/lib`, `/usr/local/lib`, `/lib`, `/usr/lib`
66 +
67 + Since our x86_64 `libraylib.dylib` is in `/usr/local/lib`, `find-library` returns the full path and `dlopen` succeeds:
68 +
69 + ```
70 + dll-valid? t
71 + DLL" /usr/local/lib/libraylib.dylib" ← x86_64, works
72 + ```
上一页 下一页