Skip to content
Merged
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
88 changes: 88 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,94 @@ jobs:
DEFAULT_CROSS_BUILD_ENV_URL: "https://github.com/pyodide/pyodide/releases/download/0.28.0a3/xbuildenv-0.28.0a3.tar.bz2"
RUSTFLAGS: "-C link-arg=-sSIDE_MODULE=2 -Z link-native-libraries=no -Z emscripten-wasm-eh"

test-php:
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-15]
php-version: ["8.2", "8.3", "8.4"]
clang: ["20"]

name: PHP ${{ matrix.php-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6

- uses: dtolnay/rust-toolchain@stable

- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v4
if: matrix.os == 'ubuntu-22.04'
with:
path: ${{ runner.temp }}/llvm-${{ matrix.clang }}
key: ${{ matrix.os }}-llvm-${{ matrix.clang }}

- name: Setup LLVM & Clang
id: clang
uses: KyleMayes/install-llvm-action@v2
if: matrix.os == 'ubuntu-22.04'
with:
version: ${{ matrix.clang }}
directory: ${{ runner.temp }}/llvm-${{ matrix.clang }}
cached: ${{ steps.cache-llvm.outputs.cache-hit }}

- name: Configure Clang
if: matrix.os == 'ubuntu-22.04'
run: |
echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/lib" >> $GITHUB_ENV
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring
coverage: none

- name: Build PHP extension
run: |
export PHP_CONFIG=$(which php-config)

cargo build --release

EXT_DIR=$(php -r "echo ini_get('extension_dir');")

if [[ "${{ matrix.os }}" == "macos-15" ]]; then
BUILT_LIB=$(find target/release -name "libcss_inline_php.dylib" -o -name "css_inline_php.dylib" | head -1)
if [[ -z "$BUILT_LIB" ]]; then
BUILT_LIB=$(find target/release -name "*.dylib" | head -1)
fi
sudo cp "$BUILT_LIB" "$EXT_DIR/css_inline.so"
else
BUILT_LIB=$(find target/release -name "*.so" | head -1)
sudo cp "$BUILT_LIB" "$EXT_DIR/css_inline.so"
fi
working-directory: ./bindings/php
shell: bash

- name: Enable and verify extension
run: |
if [[ "${{ matrix.os }}" == "macos-15" ]]; then
PHP_INI_DIR=$(php -i | grep "Scan this dir for additional .ini files" | cut -d' ' -f9 | tr -d ' ')
echo "extension=css_inline" | sudo tee "$PHP_INI_DIR/99-css_inline.ini"
else
echo "extension=css_inline" | sudo tee /etc/php/${{ matrix.php-version }}/cli/conf.d/99-css_inline.ini
fi
shell: bash

- name: Install dependencies
run: composer install --no-interaction --prefer-dist
working-directory: ./bindings/php

- name: Lint PHP code
run: composer lint
working-directory: ./bindings/php

- name: Run tests
run: composer test
working-directory: ./bindings/php

test-ruby:
strategy:
fail-fast: false
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/php-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: "[PHP] Release"

on:
push:
tags:
- php-v*

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
php: "8.2"
artifact: libcss_inline_php.so
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
php: "8.3"
artifact: libcss_inline_php.so
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
php: "8.4"
artifact: libcss_inline_php.so
- os: macos-15
target: x86_64-apple-darwin
php: "8.2"
artifact: libcss_inline_php.dylib
cross: true
- os: macos-15
target: x86_64-apple-darwin
php: "8.3"
artifact: libcss_inline_php.dylib
cross: true
- os: macos-15
target: x86_64-apple-darwin
php: "8.4"
artifact: libcss_inline_php.dylib
cross: true
- os: macos-15
target: aarch64-apple-darwin
php: "8.2"
artifact: libcss_inline_php.dylib
- os: macos-15
target: aarch64-apple-darwin
php: "8.3"
artifact: libcss_inline_php.dylib
- os: macos-15
target: aarch64-apple-darwin
php: "8.4"
artifact: libcss_inline_php.dylib

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v6

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.cross && matrix.target || '' }}

- uses: Swatinem/rust-cache@v2
with:
workspaces: bindings/php
cache-all-crates: "true"

- name: Build
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cargo build --release --target ${{ matrix.target }}
else
cargo build --release
fi
working-directory: bindings/php

- name: Rename artifact
run: |
mkdir -p dist
if [ "${{ matrix.cross }}" = "true" ]; then
cp bindings/php/target/${{ matrix.target }}/release/${{ matrix.artifact }} dist/css_inline-php${{ matrix.php }}-${{ matrix.target }}.so
else
cp bindings/php/target/release/${{ matrix.artifact }} dist/css_inline-php${{ matrix.php }}-${{ matrix.target }}.so
fi

- name: Upload artifact
uses: actions/upload-artifact@v6
with:
name: css_inline-php${{ matrix.php }}-${{ matrix.target }}
path: dist/

release:
needs: build
runs-on: ubuntu-22.04
permissions:
contents: write

steps:
- uses: actions/checkout@v6

- name: Extract Version
run: echo "version=${GITHUB_REF#refs/tags/php-v}" >> $GITHUB_ENV

- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: artifacts
merge-multiple: true

- name: List artifacts
run: ls -la artifacts/

- name: GitHub Release
uses: softprops/action-gh-release@v2
with:
make_latest: false
draft: true
name: "[PHP] Release ${{ env.version }}"
files: artifacts/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ into:
- Optionally caches external stylesheets
- Works on Linux, Windows, and macOS
- Supports HTML5 & CSS3
- Bindings for [Python](https://github.com/Stranger6667/css-inline/tree/master/bindings/python), [Ruby](https://github.com/Stranger6667/css-inline/tree/master/bindings/ruby), [JavaScript](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript), [Java](https://github.com/Stranger6667/css-inline/tree/master/bindings/java), [C](https://github.com/Stranger6667/css-inline/tree/master/bindings/c), and a [WebAssembly](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript/wasm) module to run in browsers.
- Bindings for [Python](https://github.com/Stranger6667/css-inline/tree/master/bindings/python), [Ruby](https://github.com/Stranger6667/css-inline/tree/master/bindings/ruby), [JavaScript](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript), [Java](https://github.com/Stranger6667/css-inline/tree/master/bindings/java), [C](https://github.com/Stranger6667/css-inline/tree/master/bindings/c), [PHP](https://github.com/Stranger6667/css-inline/tree/master/bindings/php), and a [WebAssembly](https://github.com/Stranger6667/css-inline/tree/master/bindings/javascript/wasm) module to run in browsers.
- Command Line Interface

## Playground
Expand Down
4 changes: 2 additions & 2 deletions bindings/javascript/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/>
<meta
name="keywords"
content="CSS inlining, WebAssembly, browser playground, Rust, Python, Ruby, JavaScript, Java, style attribute, HTML, CSS"
content="CSS inlining, WebAssembly, browser playground, Rust, Python, Ruby, JavaScript, Java, PHP, style attribute, HTML, CSS"
/>
<title>CSS Inline | High-performance CSS inlining</title>
<link
Expand Down Expand Up @@ -165,7 +165,7 @@ <h1 class="text-4xl font-semibold leading-6 text-gray-900">
</p>
<p class="mt-2 text-base leading-7 text-gray-900">
css-inline uses components from Mozilla's Servo project and provides
bindings for Rust, Python, Ruby, JavaScript, Java, and C. The
bindings for Rust, Python, Ruby, JavaScript, Java, C, and PHP. The
playground runs the library compiled to WebAssembly in the browser.
Paste HTML with CSS into the text area and click "Inline" to process
the output.
Expand Down
12 changes: 12 additions & 0 deletions bindings/php/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]

[target.x86_64-pc-windows-msvc]
linker = "rust-lld"
rustflags = ["-C", "link-arg=/FORCE"]
4 changes: 4 additions & 0 deletions bindings/php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/composer.lock
/.phpunit.cache/
/.php-cs-fixer.cache
21 changes: 21 additions & 0 deletions bindings/php/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/tests')
->in(__DIR__ . '/stubs')
->in(__DIR__ . '/benchmarks')
->name('*.php');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PER-CS' => true,
'@PHP82Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'single_quote' => true,
'trailing_comma_in_multiline' => true,
])
->setFinder($finder);
19 changes: 19 additions & 0 deletions bindings/php/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "css_inline"
version = "0.18.0"
edition = "2021"
authors = ["Dmitry Dygalo <[email protected]>"]

[lib]
name = "css_inline_php"
crate-type = ["cdylib"]

[dependencies]
ext-php-rs = "0.15.2"
rayon = "1"

[dependencies.css-inline]
path = "../../css-inline"
version = "*"
default-features = false
features = ["http", "file", "stylesheet-cache"]
Loading
Loading