Skip to content

Commit 707f610

Browse files
committed
Use OSMesa for macOS core tests
1 parent 4225ee3 commit 707f610

2 files changed

Lines changed: 63 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ jobs:
6262
- name: Install Modules
6363
run: npm ci
6464

65+
- name: Install MacOS OpenGL Runtime
66+
if: matrix.target == 'darwin-x64' || matrix.target == 'darwin-arm64'
67+
run: |
68+
brew install mesa
69+
mesa_prefix="$(brew --prefix mesa)"
70+
echo "DYLD_LIBRARY_PATH=$mesa_prefix/lib:${DYLD_LIBRARY_PATH:-}" >> "$GITHUB_ENV"
71+
echo "DYLD_FALLBACK_LIBRARY_PATH=$mesa_prefix/lib:${DYLD_FALLBACK_LIBRARY_PATH:-}" >> "$GITHUB_ENV"
72+
find "$mesa_prefix/lib" -maxdepth 1 \( -name '*OSMesa*' -o -name '*EGL*' -o -name '*GL*' \) -print
73+
6574
- name: Tests - Linux
6675
if: matrix.target == 'linux-x64' || matrix.target == 'linux-arm64'
6776
run: xvfb-run --auto-servernum npm run test:ci

test/init.ts

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
import { platform } from 'node:process';
2-
import { init, addThreeHelpers, glfw } from '../ts/index.ts';
32
import * as three from 'three';
3+
import type { TGlfw, TInitOpts } from '../ts/types.ts';
4+
5+
const bootstrapMacosGlfw = async (): Promise<TGlfw | null> => {
6+
if (platform !== 'darwin') {
7+
return null;
8+
}
9+
10+
const nodeGlobal = globalThis as unknown as Record<string, unknown>;
11+
12+
// @node-3d/glfw normally initializes on import. The macOS CI path needs
13+
// glfwInitHint before glfwInit so it can use the Null platform.
14+
nodeGlobal['__isGlfwInited'] = true;
15+
const { glfw: bootstrappedGlfw } = await import('@node-3d/glfw');
16+
bootstrappedGlfw.initHint(bootstrappedGlfw.PLATFORM, bootstrappedGlfw.PLATFORM_NULL);
17+
18+
if (!bootstrappedGlfw.init()) {
19+
throw new Error('Failed to initialize GLFW for macOS tests');
20+
}
21+
22+
bootstrappedGlfw.defaultWindowHints();
23+
nodeGlobal['__isGlfwInited'] = true;
24+
25+
return bootstrappedGlfw;
26+
};
27+
28+
const macosGlfw = await bootstrapMacosGlfw();
29+
const core = await import('../ts/index.ts');
30+
const { init, addThreeHelpers, glfw } = core;
431

532
const initOptsLinux = {
633
width: 400,
@@ -15,21 +42,44 @@ const initOpts = {
1542
major: 2,
1643
minor: 1,
1744
};
45+
const initOptsMacos: TInitOpts = {
46+
...initOpts,
47+
isVisible: false,
48+
onBeforeWindow(_window, currentGlfw) {
49+
const windowGlfw = currentGlfw as TGlfw;
50+
windowGlfw.windowHint(windowGlfw.CONTEXT_CREATION_API, windowGlfw.OSMESA_CONTEXT_API);
51+
windowGlfw.windowHint(windowGlfw.STENCIL_BITS, 8);
52+
windowGlfw.windowHint(windowGlfw.DEPTH_BITS, 0);
53+
windowGlfw.windowHint(windowGlfw.SAMPLES, 0);
54+
},
55+
};
1856

1957
if (platform === 'darwin') {
20-
glfw.windowHint(glfw.STENCIL_BITS, 8);
58+
(macosGlfw ?? glfw).windowHint(glfw.STENCIL_BITS, 8);
2159
// this would be nice... - https://github.com/glfw/glfw/pull/2571
2260
// glfw.windowHint(glfw.CONTEXT_RENDERER, glfw.SOFTWARE_RENDERER);
2361
}
2462

25-
const inited = init(platform === 'linux' ? initOptsLinux : initOpts);
63+
const getInitOpts = (): TInitOpts => {
64+
if (platform === 'linux') {
65+
return initOptsLinux;
66+
}
67+
68+
if (platform === 'darwin') {
69+
return initOptsMacos;
70+
}
71+
72+
return initOpts;
73+
};
74+
75+
const inited = init(getInitOpts());
2676
addThreeHelpers(three);
2777

2878
const { doc } = inited;
2979
const window = doc;
3080
const document = doc;
3181

32-
export { Image } from '../ts/index.ts';
82+
export const { Image } = core;
3383

3484
export { doc, window, document };
3585

0 commit comments

Comments
 (0)