diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 12ef3b7..f8b9238 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,12 +56,12 @@ jobs: - name: Prepare binary artifact run: | mkdir -p dist - cp target/x86_64-unknown-linux-gnu/release/libext_biscuit_php.so dist/ext_biscuit_php-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so + cp target/x86_64-unknown-linux-gnu/release/libbiscuit.so dist/biscuit-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so - name: Calculate checksums run: | cd dist - sha256sum ext_biscuit_php-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so > ext_biscuit_php-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so.sha256 + sha256sum biscuit-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so > biscuit-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so.sha256 - name: Upload artifacts uses: actions/upload-artifact@v4 @@ -98,11 +98,11 @@ jobs: - name: Verify checksum run: | cd dist - sha256sum -c ext_biscuit_php-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so.sha256 + sha256sum -c biscuit-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so.sha256 - name: Test binary loading run: | - php -dextension=./dist/ext_biscuit_php-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so -m | grep biscuit || echo "Extension loaded successfully" + php -dextension=./dist/biscuit-linux-x86_64-php${{ matrix.php-version }}-${{ matrix.phpts }}.so -m | grep biscuit || echo "Extension loaded successfully" create-release: name: Create GitHub Release @@ -137,14 +137,14 @@ jobs: | Platform | PHP Version | Thread Safety | Binary | Checksum | |----------|-------------|---------------|--------|----------| - | Linux x86_64 | 8.1 | TS | ext_biscuit_php-linux-x86_64-php8.1-ts.so | .sha256 | - | Linux x86_64 | 8.1 | NTS | ext_biscuit_php-linux-x86_64-php8.1-nts.so | .sha256 | - | Linux x86_64 | 8.2 | TS | ext_biscuit_php-linux-x86_64-php8.2-ts.so | .sha256 | - | Linux x86_64 | 8.2 | NTS | ext_biscuit_php-linux-x86_64-php8.2-nts.so | .sha256 | - | Linux x86_64 | 8.3 | TS | ext_biscuit_php-linux-x86_64-php8.3-ts.so | .sha256 | - | Linux x86_64 | 8.3 | NTS | ext_biscuit_php-linux-x86_64-php8.3-nts.so | .sha256 | - | Linux x86_64 | 8.4 | TS | ext_biscuit_php-linux-x86_64-php8.4-ts.so | .sha256 | - | Linux x86_64 | 8.4 | NTS | ext_biscuit_php-linux-x86_64-php8.4-nts.so | .sha256 | + | Linux x86_64 | 8.1 | TS | biscuit-linux-x86_64-php8.1-ts.so | .sha256 | + | Linux x86_64 | 8.1 | NTS | biscuit-linux-x86_64-php8.1-nts.so | .sha256 | + | Linux x86_64 | 8.2 | TS | biscuit-linux-x86_64-php8 + | Linux x86_64 | 8.2 | NTS | biscuit-linux-x86_64-php8.2-nts.so | .sha256 | + | Linux x86_64 | 8.3 | TS | biscuit-linux-x86_64-php8.3-ts.so | .sha256 | + | Linux x86_64 | 8.3 | NTS | biscuit-linux-x86_64-php8.3-nts.so | .sha256 | + | Linux x86_64 | 8.4 | TS | biscuit-linux-x86_64-php8.4-ts.so | .sha256 | + | Linux x86_64 | 8.4 | NTS | biscuit-linux-x86_64-php8.4-nts.so | .sha256 | ### Choosing the Right Binary @@ -162,12 +162,12 @@ jobs: 2. Download the appropriate binary for your PHP version and thread safety 3. Verify the checksum: ```bash - sha256sum -c ext_biscuit_php-linux-x86_64-php8.x-{ts|nts}.so.sha256 + sha256sum -c biscuit-linux-x86_64-php8.x-{ts|nts}.so.sha256 ``` 4. Move the binary to your PHP extension directory 5. Add to your php.ini: ```ini - extension=ext_biscuit_php-linux-x86_64-php8.x-{ts|nts}.so + extension=biscuit-linux-x86_64-php8.x-{ts|nts}.so ``` 6. Verify installation: ```bash diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e13689..cba2db1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,4 +62,4 @@ jobs: mago lint --reporting-format=github - name: "Run PHPUnit" - run: php -dextension=./target/release/libext_biscuit_php.so vendor/bin/phpunit + run: php -dextension=./target/release/libbiscuit.so vendor/bin/phpunit diff --git a/Cargo.lock b/Cargo.lock index f03f1eb..aef9dee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" [[package]] name = "bindgen" -version = "0.70.1" +version = "0.72.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" dependencies = [ "bitflags", "cexpr", @@ -130,6 +130,15 @@ dependencies = [ "time", ] +[[package]] +name = "biscuit-php" +version = "0.1.0" +dependencies = [ + "biscuit-auth", + "ext-php-rs", + "hex", +] + [[package]] name = "biscuit-quote" version = "0.3.0" @@ -319,6 +328,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9710d3b3739c2e349eb44fe848ad0b7c8cb1e42bd87ee49371df2f7acaf3e675" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.5.0" @@ -379,9 +403,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" dependencies = [ "darling_core", "darling_macro", @@ -389,9 +413,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" dependencies = [ "fnv", "ident_case", @@ -403,9 +427,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.20.11" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ "darling_core", "quote", @@ -571,20 +595,11 @@ dependencies = [ "version_check", ] -[[package]] -name = "ext-biscuit-php" -version = "0.1.0" -dependencies = [ - "biscuit-auth", - "ext-php-rs", - "hex", -] - [[package]] name = "ext-php-rs" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fc03db60bfe6d05e80db431c1a61910ff549f88d4d6d5a7cc235a4b90734d4f" +checksum = "a36419de1b3681694a550c86af9fd60a041bb3aabcf32241076c4735c003b340" dependencies = [ "anyhow", "bindgen", @@ -602,14 +617,13 @@ dependencies = [ [[package]] name = "ext-php-rs-derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617ed494cb1c1bffa2fc1cd664216a223aa0155b73d176ac1935ac2f864fce8f" +checksum = "cf63307d7bdb091f6dc294b4c51e9f8e44d1950ced0ca2c58fe1b89401665aec" dependencies = [ - "anyhow", "convert_case", "darling", - "lazy_static", + "itertools 0.14.0", "proc-macro2", "quote", "syn 2.0.106", @@ -807,6 +821,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.15" @@ -823,12 +846,6 @@ dependencies = [ "libc", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libbz2-rs-sys" version = "0.2.2" @@ -851,26 +868,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "liblzma" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c36d08cad03a3fbe2c4e7bb3a9e84c57e4ee4135ed0b065cade3d98480c648" -dependencies = [ - "liblzma-sys", -] - -[[package]] -name = "liblzma-sys" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01b9596486f6d60c3bbe644c0e1be1aa6ccc472ad630fe8927b456973d7cb736" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "libz-rs-sys" version = "0.5.2" @@ -901,6 +898,16 @@ version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" +[[package]] +name = "lzma-rust2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c60a23ffb90d527e23192f1246b14746e2f7f071cb84476dd879071696c18a4a" +dependencies = [ + "crc", + "sha2 0.10.9", +] + [[package]] name = "memchr" version = "2.7.6" @@ -1308,9 +1315,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustc_version" @@ -1857,9 +1864,9 @@ dependencies = [ [[package]] name = "zip" -version = "4.6.1" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa8cd6af31c3b31c6631b8f483848b91589021b28fffe50adada48d4f4d2ed1" +checksum = "eb2a05c7c36fde6c09b08576c9f7fb4cda705990f73b58fe011abf7dfb24168b" dependencies = [ "aes", "arbitrary", @@ -1871,7 +1878,7 @@ dependencies = [ "getrandom 0.3.4", "hmac", "indexmap", - "liblzma", + "lzma-rust2", "memchr", "pbkdf2", "ppmd-rust", diff --git a/Cargo.toml b/Cargo.toml index 6747f8d..7a0a84e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,19 @@ [package] -name = "ext-biscuit-php" +name = "biscuit-php" version = "0.1.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "PHP wrapper for Biscuit authorization tokens" +authors = ["Pierre Tondereau "] [dependencies] -ext-php-rs = "0.14.2" +ext-php-rs = "0.15" biscuit-auth = { version = "6.0.0", features = ["pem"] } hex = "0.4" [lib] -name = "ext_biscuit_php" +name = "biscuit" crate-type = ["cdylib"] + +[profile.release] +strip = "debuginfo" diff --git a/README.md b/README.md index 62f0335..46c07cc 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,23 @@ sudo phpenmod biscuit php -m | grep biscuit ``` +### PIE installation + +We support [PIE](https://github.com/php/pie/) installation: +```bash +pie install ptondereau/biscuit-php +``` + +and you can add in your `composer.json`: +```json +{ + // ... + "ext-biscuit": "*", + // ... +} +``` + + ### Build from Source If pre-built binaries are not available for your platform: diff --git a/composer.json b/composer.json index 4940c18..c649206 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,9 @@ { - "name": "ptondereau/ext-biscuit-php", + "$schema": "https://getcomposer.org/schema.json", + "name": "ptondereau/biscuit-php", "description": "PHP bindings for Biscuit authorization tokens", - "type": "library", "license": "Apache-2.0", + "type": "php-ext", "authors": [ { "name": "Pierre Tondereau", @@ -30,5 +31,16 @@ "allow-plugins": { "carthage-software/mago": true } + }, + "php-ext": { + "build-path": "pie", + "extension-name": "biscuit", + "configure-options": [ + { + "name": "debug", + "description": "Build in debug mode", + "needs-value": false + } + ] } } \ No newline at end of file diff --git a/pie/.gitignore b/pie/.gitignore new file mode 100644 index 0000000..d72fc42 --- /dev/null +++ b/pie/.gitignore @@ -0,0 +1,20 @@ +build +target +autom4te.cache +include +modules +Makefile +Makefile.objects +Makefile.fragments +config.h +config.h.in +config.log +config.nice +config.status +configure +configure.ac +libtool +run-tests.php +src +Cargo.toml +Cargo.lock \ No newline at end of file diff --git a/pie/config.m4 b/pie/config.m4 new file mode 100644 index 0000000..ca318d0 --- /dev/null +++ b/pie/config.m4 @@ -0,0 +1,42 @@ +PHP_ARG_ENABLE([debug], [Build the extension in debug mode], [ --enable-debug Build the extension in debug mode], no, no) + +AC_PATH_PROG([CARGO], [cargo]) +if test -z "$CARGO"; then + AC_MSG_ERROR([Cargo not found! Install Rust via https://rustup.rs]) +fi + +AC_PATH_PROG([RUSTC], [rustc]) +if test -z "$RUSTC"; then + AC_MSG_ERROR([Rust compiler (rustc) not found! Install Rust via https://rustup.rs]) +fi + +CARGO_FLAGS="--release" +CARGO_BUILD_DIR="target/release" + +if test "$PHP_DEBUG" == "yes"; then + CARGO_FLAGS="" + CARGO_BUILD_DIR="target/debug" +fi +cat >>Makefile.objects<< EOF +EXT_NAME = biscuit +all: cargo_build + +clean: cargo_clean + +cargo_build: + @echo "Building the Rust extension" + PHP_CONFIG=$(which $PHP_PHP_CONFIG) PHP=$PHP_EXECUTABLE cargo build $CARGO_FLAGS + cp $CARGO_BUILD_DIR/AS_ESCAPE([lib$(EXT_NAME)]).so AS_ESCAPE([$(phplibdir)])/AS_ESCAPE([$(EXT_NAME)]).so + +cargo_clean: + @echo "Cleaning the Rust extension" + cargo clean + +.PHONY: cargo_build cargo_clean +EOF + +AC_CONFIG_LINKS([ + Cargo.toml:../Cargo.toml + src:../src + Cargo.lock:../Cargo.lock +]) \ No newline at end of file