From 481319fcef8c698d189779075d81aa7f04d70544 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Sat, 14 Mar 2026 23:59:12 +0100 Subject: [PATCH 1/2] Add Linux support for GLFW extension and fix macOS C++ linking - Enable GLFW on Linux in ext.json (was "no", now "yes") - Add Linux-specific static libs to lib.json - Create Linux GLFW library builder (builds from vendor/glfw with X11) - Add -lc++ to macOS builds for ogt_vox_c_wrapper.cpp Co-Authored-By: Claude Opus 4.6 (1M context) --- config/ext.json | 2 +- config/lib.json | 6 ++++++ src/SPC/builder/extension/glfw.php | 8 ++++++++ src/SPC/builder/linux/library/glfw.php | 27 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/SPC/builder/linux/library/glfw.php diff --git a/config/ext.json b/config/ext.json index 79d3831ec..7223055ec 100644 --- a/config/ext.json +++ b/config/ext.json @@ -210,7 +210,7 @@ "support": { "Windows": "wip", "BSD": "no", - "Linux": "no" + "Linux": "yes" }, "notes": true, "type": "external", diff --git a/config/lib.json b/config/lib.json index 58cbd4ba0..2acead37e 100644 --- a/config/lib.json +++ b/config/lib.json @@ -174,6 +174,12 @@ "OpenGL", "Cocoa", "IOKit" + ], + "static-libs-linux": [ + "libglfw3.a" + ], + "headers": [ + "GLFW" ] }, "gmp": { diff --git a/src/SPC/builder/extension/glfw.php b/src/SPC/builder/extension/glfw.php index 7cfdaaaf6..71b4691dc 100644 --- a/src/SPC/builder/extension/glfw.php +++ b/src/SPC/builder/extension/glfw.php @@ -23,6 +23,14 @@ public function patchBeforeBuildconf(): bool public function patchBeforeConfigure(): bool { FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/configure', '-lglfw ', '-lglfw3 '); + if (PHP_OS_FAMILY === 'Darwin') { + // C++ standard library needed for ogt_vox_c_wrapper.cpp + FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/configure', + '-framework IOKit', + '-framework IOKit -lc++' + ); + } return true; } diff --git a/src/SPC/builder/linux/library/glfw.php b/src/SPC/builder/linux/library/glfw.php new file mode 100644 index 000000000..8f2e06f8a --- /dev/null +++ b/src/SPC/builder/linux/library/glfw.php @@ -0,0 +1,27 @@ +setBuildDir("{$this->source_dir}/vendor/glfw") + ->setReset(false) + ->addConfigureArgs( + '-DGLFW_BUILD_EXAMPLES=OFF', + '-DGLFW_BUILD_TESTS=OFF', + '-DGLFW_BUILD_WAYLAND=OFF', + ) + ->build('.'); + // patch pkgconf + $this->patchPkgconfPrefix(['glfw3.pc']); + } +} From e2ca9491a4c18bd47e44a506346f362d2f6cb448 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Sun, 15 Mar 2026 01:06:27 +0100 Subject: [PATCH 2/2] Fix C++ linking: use builder extra-libs instead of configure string replacement The previous approach tried to patch the configure script string which was fragile and didn't work on all platforms. Now uses the proper builder option mechanism (same pattern as iconv extension). Uses -lc++ on macOS (Clang) and -lstdc++ on Linux (GCC/musl). --- src/SPC/builder/extension/glfw.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/SPC/builder/extension/glfw.php b/src/SPC/builder/extension/glfw.php index 71b4691dc..165d6ee51 100644 --- a/src/SPC/builder/extension/glfw.php +++ b/src/SPC/builder/extension/glfw.php @@ -23,14 +23,12 @@ public function patchBeforeBuildconf(): bool public function patchBeforeConfigure(): bool { FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/configure', '-lglfw ', '-lglfw3 '); - if (PHP_OS_FAMILY === 'Darwin') { - // C++ standard library needed for ogt_vox_c_wrapper.cpp - FileSystem::replaceFileStr( - SOURCE_PATH . '/php-src/configure', - '-framework IOKit', - '-framework IOKit -lc++' - ); - } + + // ogt_vox_c_wrapper.cpp requires the C++ standard library + $cxxLib = PHP_OS_FAMILY === 'Darwin' ? '-lc++' : '-lstdc++'; + $extraLibs = trim($this->builder->getOption('extra-libs', '') . ' ' . $cxxLib); + $this->builder->setOption('extra-libs', $extraLibs); + return true; }