Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ jobs:
php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5']
phpunit-versions: ['latest']
preinstalled-glfw: ['libglfw3-dev', '']

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: :glfw, dom, xml, mbstring, zip
coverage: xdebug
tools: cs2pr, phpunit
# - name: Build GLFW lib
# run: cd vendor/glfw && cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON && sudo make install && sudo ldconfig && cd ../../

- name: Install dependenies

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake ${{ matrix.preinstalled-glfw }} xvfb libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev gdb

# Vulkan SDK for Vulkan support testing
sudo apt-get install -y libvulkan-dev vulkan-tools || true

- name: Echo current PHP version, php.ini and php-config
run: |
echo "PHP version: $(php -v)"
Expand All @@ -47,16 +47,21 @@ jobs:
phpize
./configure --enable-glfw
sudo make -j"$(nproc)" install

- name: Enable PHP-GLFW
run: |
run: |
grep -qxF 'extension=glfw.so' /etc/php/${{ matrix.php-versions }}/cli/php.ini || \
echo 'extension=glfw.so' >> /etc/php/${{ matrix.php-versions }}/cli/php.ini

- name: Check Vulkan support
run: |
php -r "echo 'PHP-GLFW loaded: ' . (extension_loaded('glfw') ? 'YES' : 'NO') . PHP_EOL;"
php -r "glfwInit(); echo 'Vulkan supported: ' . (glfwVulkanSupported() ? 'YES' : 'NO') . PHP_EOL;" || echo "glfwVulkanSupported check failed (expected in headless CI)"

- name: Install PHPUnit
run: |
composer install

- name: Run PHPUnit
run: |
xvfb-run --auto-servernum \
Expand All @@ -65,64 +70,61 @@ jobs:
-dxdebug.auto_trace=ON \
-dxdebug.trace_output_dir=trace \
./vendor/bin/phpunit

#- name: Setup upterm session
# if: always()
# uses: lhotari/action-upterm@v1



macos:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['macos-latest']
php-versions: ['8.1', '8.2', '8.3', '8.4', '8.5']
phpunit-versions: ['latest']

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: :glfw, dom, xml, mbstring, zip
coverage: xdebug
tools: cs2pr

# - name: Install dependenies
# run: brew install mesa mesalib-glw

# - name: Build GLFW lib
# run: cd vendor/glfw && cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DBUILD_SHARED_LIBS=ON && sudo make install && cd ../../


- name: Install Vulkan/MoltenVK
run: |
brew install molten-vk vulkan-loader || true
echo "MoltenVK check:"
ls -la /opt/homebrew/lib/libvulkan*.dylib 2>/dev/null || echo "libvulkan not found in /opt/homebrew"
ls -la /usr/local/lib/libvulkan*.dylib 2>/dev/null || echo "libvulkan not found in /usr/local"

- name: Build PHP-GLFW
run: sudo phpize && ./configure --enable-glfw && make

- name: Locate php.ini
run: php -i | grep 'php.ini'

- name: Install PHP-GLFW
run: |
sudo make install && \
grep -qxF 'extension=glfw.so' /opt/homebrew/etc/php/${{ matrix.php-versions }}/php.ini || \
echo 'extension=glfw.so' >> /opt/homebrew/etc/php/${{ matrix.php-versions }}/php.ini


- name: Check Vulkan support
run: |
php -r "echo 'PHP-GLFW loaded: ' . (extension_loaded('glfw') ? 'YES' : 'NO') . PHP_EOL;"
php -r "phpinfo();" | grep -i "glfw\|vulkan" || true

- name: Install PHPUnit
run: composer install
# On MacOS we currently exclude all tests requiring glfwinit to work..
# Initializing it in the Github action results in a segmentation fault.
# I've tried to build php from source in debug mode, and run the script

# On MacOS we currently exclude all tests requiring glfwinit to work..
# Initializing it in the Github action results in a segmentation fault.
# I've tried to build php from source in debug mode, and run the script
# through gdb but I had no luck. The failure happens in "_glfwPlatformInit"
# all down to the CoreFoundation. The tests run fine on my mac tho.. So
# all down to the CoreFoundation. The tests run fine on my mac tho.. So
# the assumption is that it simply fails because of a missin screen..
# xvfb is not available anymore for macos so...
# xvfb is not available anymore for macos so...
# If anybody skilled is able to make it run in the "macos-latest" environment
# I will be deeply grateful.
- name: Run PHPUnit
# I will be deeply grateful.
- name: Run PHPUnit
run: php vendor/bin/phpunit --exclude-group=glfwinit

# - name: Setup upterm session
# if: always()
# uses: lhotari/action-upterm@v1
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ vendor/glfw/src/glfw3*.cmake
vendor/glfw/src/glfw_config.h
vendor/glfw/src/libglfw*.dylib
vendor/autoload.php
.idea/
vendor/glfw/build/
configure.ac
CLAUDE.md
82 changes: 40 additions & 42 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ esac

if test "$build_mac" = "yes"; then
AC_MSG_RESULT([building for MacOS])
else
else
AC_MSG_RESULT([building for Linux])
fi

Expand All @@ -43,9 +43,9 @@ check_for_glfw3() {
}

if test "$PHP_GLFW" != "no"; then

AC_MSG_CHECKING([for glfw installation])

if test "x$PHP_GLFW_DIR" != "xno"; then
if test -r "$PHP_GLFW_DIR/include/GLFW/glfw3.h"; then
GLFW_DIR=$PHP_GLFW_DIR
Expand All @@ -57,13 +57,11 @@ if test "$PHP_GLFW" != "no"; then
fi

if test "x$GLFW_DIR" = "x"; then
AC_MSG_RESULT([GLFW lib not found, trying to build])
# Build glfw
AC_MSG_RESULT([GLFW lib not found, building from vendor source with Vulkan support])
cd vendor/glfw
# cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=./ && make install
cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_DOCS=OFF -DBUILD_SHARED_LIBS=ON && sudo make install
if test "$build_linux" = "yes"; then
sudo ldconfig
sudo ldconfig
fi
cd ./../../
check_for_glfw3
Expand All @@ -75,46 +73,46 @@ if test "$PHP_GLFW" != "no"; then

AC_MSG_RESULT([found in $GLFW_DIR ($PHP_LIBDIR)])

dnl Check for Vulkan/MoltenVK support
AC_MSG_CHECKING([for Vulkan/MoltenVK support])
VULKAN_FOUND=no
if test "$build_mac" = "yes"; then
dnl macOS: check for MoltenVK via Homebrew
for vulkan_dir in /opt/homebrew /usr/local /usr; do
if test -r "$vulkan_dir/lib/libvulkan.dylib"; then
VULKAN_DIR=$vulkan_dir
VULKAN_FOUND=yes
break
fi
done
else
dnl Linux: check for libvulkan
for vulkan_dir in /usr /usr/local /opt; do
if test -r "$vulkan_dir/lib/libvulkan.so" -o -r "$vulkan_dir/lib/x86_64-linux-gnu/libvulkan.so"; then
VULKAN_DIR=$vulkan_dir
VULKAN_FOUND=yes
break
fi
done
fi

if test "$VULKAN_FOUND" = "yes"; then
AC_MSG_RESULT([found in $VULKAN_DIR])
AC_DEFINE(PHPGLFW_VULKAN_SUPPORT, 1, [Vulkan/MoltenVK support available])
else
AC_MSG_RESULT([not found — Vulkan features will be unavailable])
fi

# GLFW lib common sources
GLFWLIB_SRC_FILES=""
GLFWPLATTFORMARGS=""

if test "$build_mac" = "yes"; then
AC_DEFINE(_GLFW_COCOA, 1, [Cocoa support])
GLFWPLATTFORMARGS="-D_GLFW_COCOA"
# GLFWLIB_SRC_FILES="$GLFWLIB_SRC_FILES \
# vendor/glfw/src/cocoa_init.m \
# vendor/glfw/src/cocoa_joystick.m \
# vendor/glfw/src/cocoa_monitor.m \
# vendor/glfw/src/cocoa_window.m \
# vendor/glfw/src/cocoa_time.c \
# vendor/glfw/src/posix_thread.c \
# vendor/glfw/src/nsgl_context.m \
# vendor/glfw/src/egl_context.c \
# vendor/glfw/src/osmesa_context.c"
else
else
AC_DEFINE(_GLFW_X11, 1, [X11 support])
GLFWPLATTFORMARGS="-D_GLFW_X11"
# GLFWLIB_SRC_FILES="vendor/glfw/src/context.c \
# vendor/glfw/src/init.c \
# vendor/glfw/src/input.c \
# vendor/glfw/src/monitor.c \
# vendor/glfw/src/vulkan.c \
# vendor/glfw/src/window.c"

# GLFWLIB_SRC_FILES="$GLFWLIB_SRC_FILES \
# vendor/glfw/src/x11_init.c \
# vendor/glfw/src/x11_monitor.c \
# vendor/glfw/src/x11_window.c \x
# vendor/glfw/src/xkb_unicode.c \
# vendor/glfw/src/posix_time.c \
# vendor/glfw/src/posix_thread.c \
# vendor/glfw/src/glx_context.c \
# vendor/glfw/src/egl_context.c \
# vendor/glfw/src/osmesa_context.c \
# vendor/glfw/src/null_joystick.c"

# PHP_ADD_BUILD_DIR($ext_builddir/vendor/glfw/src)
fi

PHPGLFW_SRC_FILES="phpglfw.c \
Expand All @@ -136,13 +134,13 @@ if test "$PHP_GLFW" != "no"; then
GLFWPLATTFORMARGS="-DNVG_NO_STB=1 $GLFWPLATTFORMARGS"

# the generated arginfo file has unicode issues because we have classes like "\\UInt"
# im just going to supress those warnings for now, please don't judge me
# im just going to supress those warnings for now, please don't judge me
GLFWPLATTFORMARGS="-Wno-unicode $GLFWPLATTFORMARGS"

PHP_ADD_LIBRARY_WITH_PATH(glfw, [$GLFW_DIR/lib], GLFW_SHARED_LIBADD)
AC_DEFINE(HAVE_GLFW, 1, [Whether you have glfw])
PHP_SUBST(GLFW_SHARED_LIBADD)

PHP_REQUIRE_CXX()
PHP_NEW_EXTENSION(glfw, $PHPGLFW_SRC_FILES $GLFWLIB_SRC_FILES, $ext_shared, , $GLFWPLATTFORMARGS -Wall)

Expand All @@ -167,7 +165,7 @@ if test "$PHP_GLFW" != "no"; then
vendor/miniaudio/*.h \
vendor/opengametools/src/*.h \
vendor/glfw/include/GLFW/*.h])

PHP_ADD_BUILD_DIR($ext_builddir/src)

fi
fi
50 changes: 50 additions & 0 deletions tests/Vulkan/VulkanSupportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace GL\Tests\Vulkan;

use PHPUnit\Framework\TestCase;

/**
* Tests for Vulkan/MoltenVK support detection.
*
* @group glfwinit
*/
#[\PHPUnit\Framework\Attributes\Group('glfwinit')]
class VulkanSupportTest extends TestCase
{
protected function setUp(): void
{
if (!glfwInit()) {
$this->markTestSkipped('glfwInit() failed — no display available');
}
}

/**
* glfwVulkanSupported() must return a valid value (int 0/1 or bool) without crashing.
*/
public function testVulkanSupportedDoesNotCrash(): void
{
$result = glfwVulkanSupported();
$this->assertTrue(
$result === true || $result === false || $result === 0 || $result === 1,
'glfwVulkanSupported() must return a boolean-compatible value, got: ' . var_export($result, true),
);
}

/**
* Log Vulkan support status for CI diagnostic visibility.
*/
public function testVulkanSupportedReportsStatus(): void
{
$supported = (bool) glfwVulkanSupported();

fwrite(STDERR, sprintf(
"\n[VulkanSupportTest] glfwVulkanSupported() = %s\n",
$supported ? 'true (Vulkan available)' : 'false (Vulkan not available)',
));

// This test always passes — it's purely diagnostic.
// The actual value depends on the system's Vulkan installation.
$this->addToAssertionCount(1);
}
}
Loading