@@ -531,6 +531,135 @@ jobs:
531531 DEFAULT_CROSS_BUILD_ENV_URL : " https://github.com/pyodide/pyodide/releases/download/0.28.0a3/xbuildenv-0.28.0a3.tar.bz2"
532532 RUSTFLAGS : " -C link-arg=-sSIDE_MODULE=2 -Z link-native-libraries=no -Z emscripten-wasm-eh"
533533
534+ test-php :
535+ strategy :
536+ fail-fast : false
537+ matrix :
538+ os : [ubuntu-22.04, macos-13]
539+ php-version : ["8.2", "8.3", "8.4"]
540+ clang : ["20"]
541+
542+ name : PHP ${{ matrix.php-version }} on ${{ matrix.os }}
543+ runs-on : ${{ matrix.os }}
544+ env :
545+ CARGO_TERM_COLOR : always
546+ steps :
547+ - uses : actions/checkout@v4
548+
549+ - uses : dtolnay/rust-toolchain@stable
550+
551+ - name : Cache cargo dependencies
552+ uses : Swatinem/rust-cache@v2
553+ with :
554+ workspaces : bindings/php
555+
556+ - name : Cache LLVM and Clang
557+ id : cache-llvm
558+ uses : actions/cache@v4
559+ if : matrix.os == 'ubuntu-22.04'
560+ with :
561+ path : ${{ runner.temp }}/llvm-${{ matrix.clang }}
562+ key : ${{ matrix.os }}-llvm-${{ matrix.clang }}
563+
564+ - name : Setup LLVM & Clang
565+ id : clang
566+ uses : KyleMayes/install-llvm-action@v2
567+ if : matrix.os == 'ubuntu-22.04'
568+ with :
569+ version : ${{ matrix.clang }}
570+ directory : ${{ runner.temp }}/llvm-${{ matrix.clang }}
571+ cached : ${{ steps.cache-llvm.outputs.cache-hit }}
572+
573+ - name : Configure Clang
574+ if : matrix.os == 'ubuntu-22.04'
575+ run : |
576+ echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/lib" >> $GITHUB_ENV
577+ echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
578+ echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV
579+
580+ - uses : shivammathur/setup-php@v2
581+ with :
582+ php-version : ${{ matrix.php-version }}
583+ extensions : mbstring
584+ coverage : none
585+
586+ - name : Build PHP extension
587+ run : |
588+ # Export PHP configuration for ext-php-rs
589+ export PHP_CONFIG=$(which php-config)
590+
591+ cargo build --release
592+
593+ # Get PHP extension directory
594+ EXT_DIR=$(php -r "echo ini_get('extension_dir');")
595+
596+ # Find the built library - ext-php-rs names it differently on different platforms
597+ if [[ "${{ matrix.os }}" == "macos-13" ]]; then
598+ # On macOS, look for .dylib files
599+ BUILT_LIB=$(find target/release -name "libcss_inline_php.dylib" -o -name "css_inline_php.dylib" | head -1)
600+ if [[ -z "$BUILT_LIB" ]]; then
601+ # Fallback: any .dylib file
602+ BUILT_LIB=$(find target/release -name "*.dylib" | head -1)
603+ fi
604+ sudo cp "$BUILT_LIB" "$EXT_DIR/css_inline.so"
605+ else
606+ # On Linux, look for .so files
607+ BUILT_LIB=$(find target/release -name "libcss_inline_php.so" -o -name "css_inline_php.so" | head -1)
608+ if [[ -z "$BUILT_LIB" ]]; then
609+ # Fallback: any .so file
610+ BUILT_LIB=$(find target/release -name "*.so" | head -1)
611+ fi
612+ sudo cp "$BUILT_LIB" "$EXT_DIR/css_inline.so"
613+ fi
614+
615+ echo "Built library: $BUILT_LIB"
616+ echo "Installed to: $EXT_DIR/css_inline.so"
617+
618+ # Verify the file exists and has correct permissions
619+ ls -la "$EXT_DIR/css_inline.so"
620+ working-directory : ./bindings/php
621+ shell : bash
622+
623+ - name : Enable and verify extension
624+ run : |
625+ # Create ini file to load extension
626+ if [[ "${{ matrix.os }}" == "macos-13" ]]; then
627+ # On macOS, find the additional ini directory
628+ PHP_INI_DIR=$(php -i | grep "Scan this dir for additional .ini files" | cut -d' ' -f9 | tr -d ' ')
629+ if [[ -z "$PHP_INI_DIR" || "$PHP_INI_DIR" == "(none)" ]]; then
630+ # If no scan dir, use the main php.ini location
631+ PHP_INI=$(php -i | grep "Loaded Configuration File" | cut -d' ' -f9)
632+ PHP_INI_DIR=$(dirname "$PHP_INI")/conf.d
633+ sudo mkdir -p "$PHP_INI_DIR"
634+ fi
635+ echo "extension=css_inline" | sudo tee "$PHP_INI_DIR/99-css_inline.ini"
636+ else
637+ echo "extension=css_inline" | sudo tee /etc/php/${{ matrix.php-version }}/cli/conf.d/99-css_inline.ini
638+ fi
639+
640+ # Verify extension is loaded
641+ php -m | grep -i css_inline || (
642+ echo "Extension failed to load. Debugging info:"
643+ echo "PHP Version:"
644+ php -v
645+ echo "Extension dir contents:"
646+ ls -la $(php -r "echo ini_get('extension_dir');")
647+ echo "PHP info grep for css_inline:"
648+ php -i | grep -i css_inline || true
649+ echo "Try loading directly:"
650+ php -d "extension=$(php -r 'echo ini_get("extension_dir");')/css_inline.so" -m | grep -i css_inline || true
651+ exit 1
652+ )
653+ shell : bash
654+
655+ - name : Install dependencies
656+ run : composer install --no-interaction --prefer-dist
657+ working-directory : ./bindings/php
658+
659+ - name : Run tests
660+ run : composer test
661+ working-directory : ./bindings/php
662+
534663 test-ruby :
535664 strategy :
536665 fail-fast : false
0 commit comments