Skip to content

Commit 1dc3479

Browse files
authored
Compile Rust library and PHP bindings (#1)
* Takumi bindings * Attempt to run PHPStan for basic static analysis * Initial test suite * Add compiled library release workflow --------- Co-authored-by: avvertix <5672748+avvertix@users.noreply.github.com>
1 parent d2c2ddd commit 1dc3479

36 files changed

Lines changed: 5113 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
build:
11+
name: Build Rust (${{ matrix.os }})
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
include:
18+
- os: ubuntu-latest
19+
lib_src: rust/target/debug/libtakumi_php.so
20+
lib_dst: lib/libtakumi_php.so
21+
artifact: libtakumi_php-linux
22+
- os: macos-latest
23+
lib_src: rust/target/debug/libtakumi_php.dylib
24+
lib_dst: lib/libtakumi_php.dylib
25+
artifact: libtakumi_php-macos
26+
- os: windows-latest
27+
lib_src: rust/target/debug/takumi_php.dll
28+
lib_dst: lib/takumi_php.dll
29+
artifact: libtakumi_php-windows
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v6
34+
35+
- name: Setup Rust
36+
uses: dtolnay/rust-toolchain@stable
37+
38+
- name: Cache Rust dependencies
39+
uses: actions/cache@v5
40+
with:
41+
path: |
42+
~/.cargo/registry
43+
~/.cargo/git
44+
rust/target
45+
key: ${{ runner.os }}-cargo-${{ hashFiles('rust/Cargo.lock') }}
46+
restore-keys: ${{ runner.os }}-cargo-
47+
48+
- name: Run Rust tests
49+
working-directory: rust
50+
run: cargo test
51+
52+
- name: Build Rust library (debug)
53+
working-directory: rust
54+
run: cargo build
55+
56+
- name: Stage library for upload
57+
shell: bash
58+
run: |
59+
mkdir -p lib
60+
cp ${{ matrix.lib_src }} ${{ matrix.lib_dst }}
61+
62+
- name: Upload library artifact
63+
uses: actions/upload-artifact@v7
64+
with:
65+
name: ${{ matrix.artifact }}
66+
path: ${{ matrix.lib_dst }}
67+
retention-days: 1
68+
69+
test:
70+
name: PHP ${{ matrix.php }} (${{ matrix.os }})
71+
needs: build
72+
runs-on: ${{ matrix.os }}
73+
strategy:
74+
fail-fast: true
75+
matrix:
76+
os: [ubuntu-latest, macos-latest, windows-latest]
77+
php: [8.3, 8.4]
78+
include:
79+
- os: ubuntu-latest
80+
lib_dst: lib/libtakumi_php.so
81+
artifact: libtakumi_php-linux
82+
- os: macos-latest
83+
lib_dst: lib/libtakumi_php.dylib
84+
artifact: libtakumi_php-macos
85+
- os: windows-latest
86+
lib_dst: lib/takumi_php.dll
87+
artifact: libtakumi_php-windows
88+
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@v6
92+
93+
- name: Download library artifact
94+
uses: actions/download-artifact@v8
95+
with:
96+
name: ${{ matrix.artifact }}
97+
path: lib
98+
99+
- name: Setup PHP
100+
uses: shivammathur/setup-php@v2
101+
with:
102+
php-version: ${{ matrix.php }}
103+
extensions: ffi, gd, exif, fileinfo
104+
coverage: none
105+
106+
- name: Install Composer dependencies
107+
uses: ramsey/composer-install@v4
108+
109+
- name: Run PHP tests
110+
run: composer test
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Fix PHP code style issues
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
php-code-styling:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v6
19+
with:
20+
ref: ${{ github.head_ref }}
21+
22+
- name: Fix PHP code style issues
23+
uses: aglipanci/laravel-pint-action@2.6
24+
25+
- name: Commit changes
26+
uses: stefanzweifel/git-auto-commit-action@v7
27+
with:
28+
commit_message: Fix styling

.github/workflows/phpstan.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PHPStan
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'phpstan.neon.dist'
8+
- '.github/workflows/phpstan.yml'
9+
10+
jobs:
11+
phpstan:
12+
name: phpstan
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 5
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.4'
22+
coverage: none
23+
24+
- name: Install composer dependencies
25+
uses: ramsey/composer-install@v4
26+
27+
- name: Run PHPStan
28+
run: ./vendor/bin/phpstan --error-format=github

.github/workflows/release.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
name: Build for ${{ matrix.os }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: true
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
include:
20+
- os: ubuntu-latest
21+
lib_src: rust/target/release/libtakumi_php.so
22+
lib_dst: lib/libtakumi_php.so
23+
artifact: libtakumi_php-linux
24+
- os: macos-latest
25+
lib_src: rust/target/release/libtakumi_php.dylib
26+
lib_dst: lib/libtakumi_php.dylib
27+
artifact: libtakumi_php-macos
28+
- os: windows-latest
29+
lib_src: rust/target/release/takumi_php.dll
30+
lib_dst: lib/takumi_php.dll
31+
artifact: libtakumi_php-windows
32+
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v6
36+
37+
- name: Setup Rust
38+
uses: dtolnay/rust-toolchain@stable
39+
40+
- name: Cache Rust dependencies
41+
uses: actions/cache@v5
42+
with:
43+
path: |
44+
~/.cargo/registry
45+
~/.cargo/git
46+
rust/target
47+
key: ${{ runner.os }}-cargo-release-${{ hashFiles('rust/Cargo.lock') }}
48+
restore-keys: ${{ runner.os }}-cargo-release
49+
50+
- name: Build Rust library (release)
51+
working-directory: rust
52+
run: cargo build --release
53+
54+
- name: Stage library
55+
shell: bash
56+
run: cp ${{ matrix.lib_src }} ${{ matrix.lib_dst }}
57+
58+
- name: Upload to GitHub Release
59+
if: github.event_name == 'release'
60+
uses: softprops/action-gh-release@v3
61+
with:
62+
files: ${{ matrix.lib_dst }}
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Update Changelog"
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v6
18+
with:
19+
ref: main
20+
21+
- name: Update Changelog
22+
uses: stefanzweifel/changelog-updater-action@v1
23+
with:
24+
latest-version: ${{ github.event.release.name }}
25+
release-notes: ${{ github.event.release.body }}
26+
27+
- name: Commit updated CHANGELOG
28+
uses: stefanzweifel/git-auto-commit-action@v7
29+
with:
30+
branch: main
31+
commit_message: Update CHANGELOG
32+
file_pattern: CHANGELOG.md

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
All notable changes to `html-shot` will be documented in this file.
4+

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "avvertix/html-shot",
3+
"description": "HTML to image rendering for PHP, powered by Rust and Takumi",
4+
"type": "library",
5+
"license": "MIT",
6+
"require": {
7+
"php": "^8.3",
8+
"ext-ffi": "*"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "^12.0",
12+
"phpstan/phpstan": "^2.0",
13+
"symfony/var-dumper": "^6.4|^7.0|^8.0",
14+
"laravel/pint": "^1.29"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"HtmlShot\\": "src/HtmlShot/"
19+
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"HtmlShot\\Tests\\": "tests/"
24+
}
25+
},
26+
"scripts": {
27+
"test": "vendor/bin/phpunit",
28+
"lint": "vendor/bin/phpstan analyse",
29+
"format": "vendor/bin/pint"
30+
}
31+
}

0 commit comments

Comments
 (0)