Skip to content
Draft
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
414 changes: 414 additions & 0 deletions .github/scripts/setup-php-windows.ps1

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ on:
- "build.zig"
- "build.zig.zon"
- ".github/workflows/docs.yml"
pull_request:
branches: ["dev"]
paths:
- "src/**"
- "build.zig"
- "build.zig.zon"
- ".github/workflows/docs.yml"
workflow_dispatch:

permissions:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ jobs:
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR"
- name: Run example tests (ReleaseSafe)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseSafe
- name: Run example tests (ReleaseFast)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseFast
- name: Run example tests (ReleaseSmall)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseSmall
7 changes: 7 additions & 0 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,17 @@ jobs:
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR"
- name: Run example tests (ReleaseSafe)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseSafe
- name: Run example tests (ReleaseFast)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseFast
- name: Run example tests (ReleaseSmall)
if: ${{ matrix.debug == false }}
run: |
PHP_INCLUDE_DIR=$(php-config --include-dir)
zig build test-examples -Dphp-include-dir="$PHP_INCLUDE_DIR" -Doptimize=ReleaseSmall
157 changes: 94 additions & 63 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,117 @@
name: Test (Windows)
name: Windows Test

on:
# push:
# branches: ["dev"]
# paths:
# - "src/**"
# - "build.zig"
# - "build.zig.zon"
# - ".github/workflows/test-windows.yml"
# pull_request:
# branches: ["dev"]
# paths:
# - "src/**"
# - "build.zig"
# - "build.zig.zon"
# - ".github/workflows/test-windows.yml"
push:
branches: ["dev"]
paths:
- "src/**"
- "build/**"
- "examples/**"
- "tools/**"
- "build.zig"
- "build.zig.zon"
- ".github/scripts/setup-php-windows.ps1"
- ".github/workflows/test-windows.yml"
pull_request:
branches: ["dev"]
paths:
- "src/**"
- "build/**"
- "examples/**"
- "tools/**"
- "build.zig"
- "build.zig.zon"
- ".github/scripts/setup-php-windows.ps1"
- ".github/workflows/test-windows.yml"
workflow_dispatch:

jobs:
matrix:
name: Generate Windows test matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
steps:
- name: Generate matrix
id: generate
uses: php/php-windows-builder/extension-matrix@v1
with:
php-version-list: "8.2,8.3,8.4,8.5"
arch-list: "x64"
ts-list: "nts,ts"

test:
runs-on: windows-latest
name: test (PHP ${{ matrix['php-version'] }}, ${{ matrix.arch }}, ${{ matrix.ts }})
needs: matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php: ["8.2", "8.3", "8.4", "8.5"]
matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
- name: Setup PHP SDK with dev headers
id: setup-php-sdk
uses: php/setup-php-sdk@v0.12
with:
version: ${{ matrix.php }}
arch: x64
ts: nts
- name: Resolve PHP dev paths
id: php-paths
shell: bash
- name: Install pkg-config
shell: pwsh
run: |
choco install pkgconfiglite --no-progress -y
where.exe pkg-config
- name: Setup PHP runtime and development files
shell: pwsh
run: |
.\.github\scripts\setup-php-windows.ps1 `
-PhpVersion "${{ matrix['php-version'] }}" `
-Arch "${{ matrix.arch }}" `
-ThreadSafety "${{ matrix.ts }}" `
-Destination (Join-Path $env:RUNNER_TEMP "php-sdk")
- name: Verify PHP installation
shell: pwsh
run: |
# setup-php-sdk lays out:
# <workspace>/php-bin -> PHP runtime (php.exe), already on PATH
# <workspace>/php-dev -> dev pack with include/ and lib/
DEV_DIR="$(cygpath -u "${{ github.workspace }}")/php-dev"
INCLUDE_DIR="$DEV_DIR/include"
LIB_DIR="$DEV_DIR/lib"
[ -d "$INCLUDE_DIR" ] || { echo "missing $INCLUDE_DIR"; ls -la "$DEV_DIR" || true; exit 1; }
[ -d "$LIB_DIR" ] || { echo "missing $LIB_DIR"; ls -la "$DEV_DIR" || true; exit 1; }
# Pass native (backslash) paths to zig
INCLUDE_WIN="$(cygpath -w "$INCLUDE_DIR")"
LIB_WIN="$(cygpath -w "$LIB_DIR")"
echo "include=$INCLUDE_WIN" >> "$GITHUB_OUTPUT"
echo "lib=$LIB_WIN" >> "$GITHUB_OUTPUT"
echo "PHP include: $INCLUDE_WIN"
echo "PHP lib: $LIB_WIN"
php -n -v
php -n -r 'printf("PHP %s (%s, PHP_DEBUG=%d)\n", PHP_VERSION, PHP_ZTS ? "ZTS" : "NTS", PHP_DEBUG);'
Get-ChildItem -LiteralPath $env:PHP_LIB_DIR -Filter "php8*.lib"
if (!(Test-Path -LiteralPath $env:LIBC_FILE)) {
throw "Missing libc file $env:LIBC_FILE"
}
Get-Content -LiteralPath $env:LIBC_FILE
zig libc -target $env:LIBC_TARGET $env:LIBC_FILE
Write-Host "PHP Visual Studio: $env:PHP_VS_VERSION"
Write-Host "MSVC toolset: $env:MSVC_TOOLSET"
- name: Run unit tests
shell: bash
shell: pwsh
run: |
zig build test \
-Dtarget=native-native-msvc \
-Dphp-include-dir="${{ steps.php-paths.outputs.include }}" \
-Dphp-lib-dir="${{ steps.php-paths.outputs.lib }}"
zig build test `
-Dtarget=native-native-msvc `
"-Dlibc-file=$env:LIBC_FILE" `
"-Dphp-include-dir=$env:PHP_INCLUDE_DIR" `
"-Dphp-lib-dir=$env:PHP_LIB_DIR" `
"-Dwindows-zts=$env:WINDOWS_ZTS"
- name: Run example tests
shell: bash
shell: pwsh
run: |
zig build test-examples \
-Dtarget=native-native-msvc \
-Dphp-include-dir="${{ steps.php-paths.outputs.include }}" \
-Dphp-lib-dir="${{ steps.php-paths.outputs.lib }}"
zig build test-examples `
-Dtarget=native-native-msvc `
"-Dlibc-file=$env:LIBC_FILE" `
"-Dphp-include-dir=$env:PHP_INCLUDE_DIR" `
"-Dphp-lib-dir=$env:PHP_LIB_DIR" `
"-Dwindows-zts=$env:WINDOWS_ZTS"
- name: Run example tests (ReleaseSafe)
shell: bash
shell: pwsh
run: |
zig build test-examples \
-Dtarget=native-native-msvc \
-Dphp-include-dir="${{ steps.php-paths.outputs.include }}" \
-Dphp-lib-dir="${{ steps.php-paths.outputs.lib }}" \
zig build test-examples `
-Dtarget=native-native-msvc `
"-Dlibc-file=$env:LIBC_FILE" `
"-Dphp-include-dir=$env:PHP_INCLUDE_DIR" `
"-Dphp-lib-dir=$env:PHP_LIB_DIR" `
"-Dwindows-zts=$env:WINDOWS_ZTS" `
-Doptimize=ReleaseSafe
- name: Run example tests (ReleaseFast)
shell: bash
shell: pwsh
run: |
zig build test-examples \
-Dtarget=native-native-msvc \
-Dphp-include-dir="${{ steps.php-paths.outputs.include }}" \
-Dphp-lib-dir="${{ steps.php-paths.outputs.lib }}" \
zig build test-examples `
-Dtarget=native-native-msvc `
"-Dlibc-file=$env:LIBC_FILE" `
"-Dphp-include-dir=$env:PHP_INCLUDE_DIR" `
"-Dphp-lib-dir=$env:PHP_LIB_DIR" `
"-Dwindows-zts=$env:WINDOWS_ZTS" `
-Doptimize=ReleaseFast
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
zig-out
.zig-cache
zig-pkg

# For msvc cross-compilation test
/tmp
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Zig framework for building PHP extensions with PHP C API bindings.

## Requirements

- zig: 0.16.0
- zig: 0.17.0-dev.1282+c0f9b51d8
- php: 8.2-8.5 (tested on linux/macos)

## Features
Expand Down Expand Up @@ -109,11 +109,16 @@ const phpz = Phpz.init(phpz_dep, .{
.php_include_dir = .{ .cwd_relative = "/usr/include/php" },
});

// Import the phpz module into your extension library
lib.root_module.addImport("phpz", phpz.mod);

// Apply OS-specific linker settings (macOS undefined symbols, Windows php8.lib)
phpz.apply(lib);
// Create the PHP extension library and import the phpz module.
const lib = phpz.addExtension(b, .{
.name = "my_php_extension",
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
.linkage = .dynamic,
});
```

Then `zig build` !
Expand Down
4 changes: 1 addition & 3 deletions bench/zig_ext/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn build(b: *std.Build) void {
});

const ext_name = "bench_zig";
const ext_lib = b.addLibrary(.{
const ext_lib = phpz.addExtension(b, .{
.name = ext_name,
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
Expand All @@ -31,8 +31,6 @@ pub fn build(b: *std.Build) void {
}),
.linkage = .dynamic,
});
ext_lib.root_module.addImport("phpz", phpz.mod);
phpz.apply(ext_lib);

const ext_filename = if (target.result.os.tag == .windows)
"php_" ++ ext_name ++ ".dll"
Expand Down
2 changes: 1 addition & 1 deletion bench/zig_ext/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .bench_zig,
.version = "0.1.0",
.fingerprint = 0x5dddb3f44fe50dfa,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0-dev.1282+c0f9b51d8",
.dependencies = .{
.phpz = .{
.path = "../..",
Expand Down
Loading
Loading