Skip to content

Commit 7cc4c22

Browse files
committed
Initial commit: native PHP extension for Stoolap
PHP C extension wrapping libstoolap with full API coverage: - Database, Statement, Transaction, StoolapException classes - Positional ($1) and named (:key) parameter binding - Bulk fetch, batch execution, prepared statement caching - queryOne auto-injects LIMIT 1 (comment/subquery aware) - Use-after-close protection on Statement and Transaction - CI for Linux/macOS x PHP 8.1-8.4, publish workflow with prebuilt binaries, PIE support via composer.json php-ext type
0 parents  commit 7cc4c22

13 files changed

Lines changed: 7104 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags-ignore: ['**']
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
STOOLAP_VERSION: v0.3.4
16+
17+
jobs:
18+
build-lib:
19+
name: Build libstoolap - ${{ matrix.target }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- os: ubuntu-latest
25+
target: x86_64-unknown-linux-gnu
26+
lib: libstoolap.so
27+
- os: macos-latest
28+
target: aarch64-apple-darwin
29+
lib: libstoolap.dylib
30+
- os: windows-latest
31+
target: x86_64-pc-windows-msvc
32+
lib: stoolap.dll
33+
runs-on: ${{ matrix.os }}
34+
steps:
35+
- name: Clone stoolap engine
36+
run: git clone --depth 1 --branch ${{ env.STOOLAP_VERSION }} https://github.com/stoolap/stoolap.git stoolap-engine
37+
38+
- name: Install Rust
39+
uses: dtolnay/rust-toolchain@stable
40+
41+
- name: Cache Rust build
42+
uses: actions/cache@v4
43+
with:
44+
path: |
45+
stoolap-engine/target
46+
~/.cargo/registry
47+
key: rust-${{ matrix.target }}-${{ env.STOOLAP_VERSION }}
48+
49+
- name: Build libstoolap
50+
working-directory: stoolap-engine
51+
run: cargo build --release --features ffi
52+
53+
- name: Upload library
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: lib-${{ matrix.target }}
57+
path: stoolap-engine/target/release/${{ matrix.lib }}
58+
if-no-files-found: error
59+
60+
test:
61+
name: Test - PHP ${{ matrix.php }} (${{ matrix.os }})
62+
needs: build-lib
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
os: [ubuntu-latest, macos-latest]
67+
php: ['8.1', '8.2', '8.3', '8.4']
68+
runs-on: ${{ matrix.os }}
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Determine library artifact
73+
id: lib
74+
shell: bash
75+
run: |
76+
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
77+
echo "name=lib-aarch64-apple-darwin" >> $GITHUB_OUTPUT
78+
echo "file=libstoolap.dylib" >> $GITHUB_OUTPUT
79+
else
80+
echo "name=lib-x86_64-unknown-linux-gnu" >> $GITHUB_OUTPUT
81+
echo "file=libstoolap.so" >> $GITHUB_OUTPUT
82+
fi
83+
84+
- name: Download libstoolap
85+
uses: actions/download-artifact@v4
86+
with:
87+
name: ${{ steps.lib.outputs.name }}
88+
path: .
89+
90+
- name: Setup PHP
91+
uses: shivammathur/setup-php@v2
92+
with:
93+
php-version: ${{ matrix.php }}
94+
95+
- name: Build extension
96+
run: |
97+
cd ext
98+
phpize
99+
./configure --with-stoolap=${{ github.workspace }}
100+
make
101+
102+
- name: Install dependencies
103+
run: composer install --no-interaction
104+
105+
- name: Run tests
106+
shell: bash
107+
run: |
108+
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
109+
export DYLD_LIBRARY_PATH=${{ github.workspace }}:${DYLD_LIBRARY_PATH:-}
110+
else
111+
export LD_LIBRARY_PATH=${{ github.workspace }}:${LD_LIBRARY_PATH:-}
112+
fi
113+
php -d extension=ext/modules/stoolap.so vendor/bin/phpunit --testdox

.github/workflows/publish.yml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
permissions:
8+
contents: write
9+
10+
env:
11+
STOOLAP_VERSION: v0.3.4
12+
13+
jobs:
14+
build-lib:
15+
name: Build libstoolap - ${{ matrix.target }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- os: ubuntu-latest
21+
target: x86_64-unknown-linux-gnu
22+
lib: libstoolap.so
23+
- os: macos-latest
24+
target: aarch64-apple-darwin
25+
lib: libstoolap.dylib
26+
runs-on: ${{ matrix.os }}
27+
steps:
28+
- name: Clone stoolap engine
29+
run: git clone --depth 1 --branch ${{ env.STOOLAP_VERSION }} https://github.com/stoolap/stoolap.git stoolap-engine
30+
31+
- name: Install Rust
32+
uses: dtolnay/rust-toolchain@stable
33+
34+
- name: Cache Rust build
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
stoolap-engine/target
39+
~/.cargo/registry
40+
key: rust-${{ matrix.target }}-${{ env.STOOLAP_VERSION }}
41+
42+
- name: Build libstoolap
43+
working-directory: stoolap-engine
44+
run: cargo build --release --features ffi
45+
46+
- name: Upload library
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: lib-${{ matrix.target }}
50+
path: stoolap-engine/target/release/${{ matrix.lib }}
51+
if-no-files-found: error
52+
53+
build-ext:
54+
name: Build - PHP ${{ matrix.php }} (${{ matrix.platform }}-${{ matrix.arch }})
55+
needs: build-lib
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
os: [ubuntu-latest, macos-latest]
60+
php: ['8.1', '8.2', '8.3', '8.4']
61+
include:
62+
- os: ubuntu-latest
63+
target: x86_64-unknown-linux-gnu
64+
lib: libstoolap.so
65+
platform: linux
66+
arch: x86_64
67+
- os: macos-latest
68+
target: aarch64-apple-darwin
69+
lib: libstoolap.dylib
70+
platform: darwin
71+
arch: arm64
72+
runs-on: ${{ matrix.os }}
73+
steps:
74+
- uses: actions/checkout@v4
75+
76+
- name: Download libstoolap
77+
uses: actions/download-artifact@v4
78+
with:
79+
name: lib-${{ matrix.target }}
80+
path: lib
81+
82+
- name: Install libstoolap to /usr/local/lib
83+
shell: bash
84+
run: |
85+
sudo mkdir -p /usr/local/lib
86+
sudo cp lib/${{ matrix.lib }} /usr/local/lib/
87+
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
88+
sudo ldconfig
89+
fi
90+
91+
- name: Setup PHP
92+
uses: shivammathur/setup-php@v2
93+
with:
94+
php-version: ${{ matrix.php }}
95+
96+
- name: Build extension
97+
run: |
98+
cd ext
99+
phpize
100+
./configure --with-stoolap=/usr/local/lib
101+
make
102+
103+
- name: Install dependencies
104+
run: composer install --no-interaction
105+
106+
- name: Run tests
107+
shell: bash
108+
run: |
109+
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
110+
export DYLD_LIBRARY_PATH=/usr/local/lib:${DYLD_LIBRARY_PATH:-}
111+
else
112+
export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH:-}
113+
fi
114+
php -d extension=ext/modules/stoolap.so vendor/bin/phpunit --testdox
115+
116+
- name: Package
117+
shell: bash
118+
run: |
119+
DIST_DIR="stoolap-${{ github.ref_name }}-php${{ matrix.php }}-${{ matrix.platform }}-${{ matrix.arch }}"
120+
mkdir -p "$DIST_DIR"
121+
cp ext/modules/stoolap.so "$DIST_DIR/"
122+
cp lib/${{ matrix.lib }} "$DIST_DIR/"
123+
tar czf "${DIST_DIR}.tar.gz" "$DIST_DIR"
124+
125+
- name: Upload package
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: stoolap-php${{ matrix.php }}-${{ matrix.platform }}-${{ matrix.arch }}
129+
path: "*.tar.gz"
130+
if-no-files-found: error
131+
132+
release:
133+
name: Create GitHub Release
134+
needs: build-ext
135+
runs-on: ubuntu-latest
136+
steps:
137+
- uses: actions/checkout@v4
138+
139+
- name: Download all packages
140+
uses: actions/download-artifact@v4
141+
with:
142+
path: dist
143+
pattern: stoolap-*
144+
merge-multiple: true
145+
146+
- name: Create GitHub Release
147+
uses: softprops/action-gh-release@v2
148+
with:
149+
files: dist/*.tar.gz
150+
generate_release_notes: true

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/vendor/
2+
composer.lock
3+
composer.phar
4+
.phpunit.result.cache
5+
6+
# Binary libraries
7+
*.dylib
8+
*.so
9+
*.dll
10+
*.lib
11+
12+
# PHP extension build artifacts
13+
ext/autom4te.cache/
14+
ext/build/
15+
ext/modules/
16+
ext/.libs/
17+
ext/configure
18+
ext/configure.ac
19+
ext/config.h
20+
ext/config.h.in
21+
ext/config.log
22+
ext/config.nice
23+
ext/config.status
24+
ext/libtool
25+
ext/Makefile
26+
ext/Makefile.frag
27+
ext/Makefile.fragments
28+
ext/Makefile.objects
29+
ext/run-tests.php
30+
ext/*.lo
31+
ext/*.la
32+
ext/*.o
33+
ext/*.dep

0 commit comments

Comments
 (0)