Skip to content

Commit 474064f

Browse files
committed
macOS: bundle GLFW+GLEW dylibs, add CI workflow to build them
1 parent 9f6f571 commit 474064f

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build macOS bundled libs (GLFW + GLEW)
2+
3+
on:
4+
workflow_dispatch: # manual trigger only
5+
6+
jobs:
7+
build:
8+
runs-on: macos-latest # arm64 runner
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install GLFW and GLEW via Homebrew
14+
run: brew install glfw glew
15+
16+
- name: Collect and fix dylib install names
17+
run: |
18+
mkdir -p libs/macos-arm64
19+
20+
# GLFW
21+
GLFW=$(brew --prefix glfw)/lib/libglfw.3.dylib
22+
cp "$GLFW" libs/macos-arm64/libglfw.3.dylib
23+
install_name_tool -id @rpath/libglfw.3.dylib libs/macos-arm64/libglfw.3.dylib
24+
25+
# GLEW
26+
GLEW=$(brew --prefix glew)/lib/libGLEW.dylib
27+
# Get actual versioned name
28+
GLEW_VER=$(ls $(brew --prefix glew)/lib/libGLEW.*.dylib | head -1)
29+
GLEW_BASE=$(basename "$GLEW_VER")
30+
cp "$GLEW_VER" libs/macos-arm64/$GLEW_BASE
31+
install_name_tool -id @rpath/$GLEW_BASE libs/macos-arm64/$GLEW_BASE
32+
# Also create libGLEW.dylib symlink-equivalent copy
33+
cp "$GLEW_VER" libs/macos-arm64/libGLEW.dylib
34+
install_name_tool -id @rpath/libGLEW.dylib libs/macos-arm64/libGLEW.dylib
35+
36+
echo "=== arm64 libs ==="
37+
file libs/macos-arm64/*.dylib
38+
otool -L libs/macos-arm64/libglfw.3.dylib
39+
otool -L libs/macos-arm64/libGLEW.dylib
40+
41+
- name: Upload as artifact
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: macos-arm64-libs
45+
path: libs/macos-arm64/
46+
47+
- name: Commit to repo
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
git add libs/macos-arm64/
52+
git diff --staged --quiet || git commit -m "ci: add bundled macOS arm64 GLFW+GLEW dylibs"
53+
git push

mode/CppMode.jar

391 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,17 @@ else if (ch == 1) {
459459
boolean macGpp = false;
460460
try { macGpp = Runtime.getRuntime().exec(new String[]{"g++","--version"}).waitFor()==0; }
461461
catch (Exception ignored) {}
462-
boolean macGlfw = new File("/opt/homebrew/include/GLFW/glfw3.h").exists()
462+
String macArch = System.getProperty("os.arch","").contains("aarch64") ? "arm64" : "x64";
463+
File macLibsDir = new File(System.getProperty("user.home") +
464+
"/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch);
465+
// Also check relative to the mode's own directory
466+
boolean hasBundledGlfw = new File(macLibsDir, "libglfw.3.dylib").exists();
467+
boolean hasBundledGlew = new File(macLibsDir, "libGLEW.dylib").exists();
468+
boolean macGlfw = hasBundledGlfw
469+
|| new File("/opt/homebrew/include/GLFW/glfw3.h").exists()
463470
|| new File("/usr/local/include/GLFW/glfw3.h").exists();
464-
boolean macGlew = new File("/opt/homebrew/include/GL/glew.h").exists()
471+
boolean macGlew = hasBundledGlew
472+
|| new File("/opt/homebrew/include/GL/glew.h").exists()
465473
|| new File("/usr/local/include/GL/glew.h").exists();
466474
if (macGpp && macGlfw && macGlew) return; // everything present, skip wizard
467475
// Try the guided installer first (Xcode Command Line Tools, then
@@ -3164,10 +3172,17 @@ else if (!cmd.contains(defaultsCpp.getAbsolutePath()))
31643172
"-lcomdlg32", "-lshell32", "-lole32", "-luuid",
31653173
"-mwindows", "-pthread", "-D_USE_MATH_DEFINES");
31663174
} else if (mac) {
3167-
// macOS has no separate libGL/libGLU — OpenGL is a system framework,
3168-
// bundled with Xcode Command Line Tools (no extra install needed).
3169-
// GLFW/GLEW come from Homebrew, so link against its lib directory too.
3170-
if (homebrewPrefix != null) {
3175+
// macOS: prefer bundled dylibs shipped with the mode (libs/macos-arm64
3176+
// or libs/macos-x64) so users need no Homebrew install at all.
3177+
String arch = System.getProperty("os.arch","").contains("aarch64") ? "arm64" : "x64";
3178+
File macLibsDir = new File(runtimeDir.getParentFile(), "libs/macos-" + arch);
3179+
boolean hasBundled = new File(macLibsDir, "libglfw.3.dylib").exists()
3180+
&& new File(macLibsDir, "libGLEW.dylib").exists();
3181+
if (hasBundled) {
3182+
cmd.add("-L" + macLibsDir.getAbsolutePath());
3183+
cmd.add("-Wl,-rpath," + macLibsDir.getAbsolutePath());
3184+
cmd.add("-Wl,-rpath,@executable_path");
3185+
} else if (homebrewPrefix != null) {
31713186
cmd.add("-L" + homebrewPrefix + "/lib");
31723187
}
31733188
Collections.addAll(cmd, "-lglfw", "-lGLEW", "-lm", "-pthread");

0 commit comments

Comments
 (0)