Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ linker = "rust-lld"

[target.i686-pc-windows-msvc]
linker = "rust-lld"

[alias]
ci-test = "hack test --package ext-php-rs --package tests --feature-powerset --clean-per-run --exclude-features=link-php"
ci-test-link = "hack test --package ext-php-rs --feature-powerset --clean-per-run --features=link-php"
ci-test-other = "hack test --workspace --exclude ext-php-rs --exclude tests --feature-powerset"
15 changes: 0 additions & 15 deletions .github/actions/embed/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/embed/action.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/actions/zts/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/zts/action.yml

This file was deleted.

148 changes: 85 additions & 63 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,29 @@ jobs:
env:
DOCS_RS: ""
run: cargo clean && cargo build
build:
name: Build and Test

test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: ["8.0", "8.1", "8.2", "8.3", "8.4"]
rust: [stable, nightly]
clang: ["15", "17"]
phpts: [ts, nts]
exclude:
# ext-php-rs requires nightly Rust when on Windows.
- os: windows-latest
rust: stable
# setup-php doesn't support thread safe PHP on Linux and macOS.
- os: macos-latest
phpts: ts
- os: ubuntu-latest
phpts: ts
- os: macos-latest
clang: "17"
rust: nightly
- os: ubuntu-latest
clang: "15"
rust: nightly
- os: windows-latest
clang: "15"
rust: stable
include:
- os: ubuntu-latest
rust: nightly
phpts: nts
php: "8.4"
env:
CARGO_TERM_COLOR: always
steps:
Expand All @@ -118,63 +116,87 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- run: rustup show
- name: Cache cargo dependencies
uses: Swatinem/rust-cache@v2
# Uncomment the following if statement if caching nightly deps
# ends up causing too much cache invalidation.
# if: matrix.rust == 'stable'
- name: Install LLVM and Clang
uses: jhchundev/[email protected]
if: "contains(matrix.os, 'windows')"
with:
# increment this manually to force cache eviction
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
# LLVM & Clang
- name: Cache LLVM and Clang
id: cache-llvm
uses: actions/cache@v4
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
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
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
version: "15.0"
- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
version: ${{ matrix.clang }}
directory: ${{ runner.temp }}/llvm-${{ matrix.clang }}
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
- name: Configure Clang
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
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
# Build
- name: Build
tool: cargo-hack
# show clang version if on windows
- run: clang --version
if: "contains(matrix.os, 'windows')"
- name: Test
env:
EXT_PHP_RS_TEST: ""
run: cargo build --release --features closure,anyhow --all
# Test
- name: Test inline examples
# Macos fails on unstable rust. We skip the inline examples test for now.
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
run: cargo test --release --all --features closure,anyhow --no-fail-fast
build-zts:
name: Build with ZTS
runs-on: ubuntu-latest
run: cargo ci-test

test-link:
name: Test link php
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: ["8.2", "8.3", "8.4"]
phpts: [ts, nts]
env:
CARGO_TERM_COLOR: always
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build
uses: ./.github/actions/zts
test-embed:
name: Test with embed
runs-on: ubuntu-latest
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
env:
phpts: ${{ matrix.phpts }}
debug: true
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
- run: rustup show
- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
- name: Test
env:
EXT_PHP_RS_TEST: ""
run: cargo ci-test-link

test-others:
name: Test others
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, nightly]
env:
CARGO_TERM_COLOR: always
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack
# Test
- name: Test
uses: ./.github/actions/embed
env:
EXT_PHP_RS_TEST: ""
run: cargo ci-test-other
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ zip = "2.2"

[features]
closure = []
embed = []
link-php = []

[workspace]
members = [
Expand Down
38 changes: 23 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ use impl_::Provider;
const MIN_PHP_API_VER: u32 = 20200930;
const MAX_PHP_API_VER: u32 = 20240924;

const PHP_81_API_VER: u32 = 20210902;
const PHP_82_API_VER: u32 = 20220829;
const PHP_83_API_VER: u32 = 20230831;
const PHP_84_API_VER: u32 = 20240924;

/// Provides information about the PHP installation.
pub trait PHPProvider<'a>: Sized {
/// Create a new PHP provider.
Expand All @@ -30,6 +35,9 @@ pub trait PHPProvider<'a>: Sized {
/// Retrieve a list of absolute include paths.
fn get_includes(&self) -> Result<Vec<PathBuf>>;

/// Retrieve a list of compiled sapis
fn get_sapis(&self) -> Result<Vec<String>>;

/// Retrieve a list of macro definitions to pass to the compiler.
fn get_defines(&self) -> Result<Vec<(&'static str, &'static str)>>;

Expand Down Expand Up @@ -162,7 +170,6 @@ fn build_wrapper(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<()> {
Ok(())
}

#[cfg(feature = "embed")]
/// Builds the embed library.
fn build_embed(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<()> {
let mut build = cc::Build::new();
Expand All @@ -178,11 +185,14 @@ fn build_embed(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<()> {
}

/// Generates bindings to the Zend API.
fn generate_bindings(defines: &[(&str, &str)], includes: &[PathBuf]) -> Result<String> {
fn generate_bindings(
defines: &[(&str, &str)],
includes: &[PathBuf],
has_embed: bool,
) -> Result<String> {
let mut bindgen = bindgen::Builder::default();

#[cfg(feature = "embed")]
{
if has_embed {
bindgen = bindgen.header("src/embed/embed.h");
}

Expand Down Expand Up @@ -245,16 +255,9 @@ fn check_php_version(info: &PHPInfo) -> Result<()> {
//
// The PHP version cfg flags should also stack - if you compile on PHP 8.2 you
// should get both the `php81` and `php82` flags.
const PHP_81_API_VER: u32 = 20210902;

const PHP_82_API_VER: u32 = 20220829;

const PHP_83_API_VER: u32 = 20230831;

const PHP_84_API_VER: u32 = 20240924;

println!(
"cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, docs)"
"cargo::rustc-check-cfg=cfg(php80, php81, php82, php83, php84, php_zts, php_debug, php_embed, docs)"
);
println!("cargo:rustc-cfg=php80");

Expand Down Expand Up @@ -317,16 +320,21 @@ fn main() -> Result<()> {
let info = PHPInfo::get(&php)?;
let provider = Provider::new(&info)?;

let sapis = provider.get_sapis()?;
let includes = provider.get_includes()?;
let defines = provider.get_defines()?;
let has_embed = sapis.contains(&"embed".to_string());

check_php_version(&info)?;
build_wrapper(&defines, &includes)?;

#[cfg(feature = "embed")]
build_embed(&defines, &includes)?;
if has_embed {
println!("cargo:rustc-cfg=php_embed");

build_embed(&defines, &includes)?;
}

let bindings = generate_bindings(&defines, &includes)?;
let bindings = generate_bindings(&defines, &includes, has_embed)?;

let out_file =
File::create(&out_path).context("Failed to open output bindings file for writing")?;
Expand Down
8 changes: 4 additions & 4 deletions src/builders/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use crate::{
use std::{ffi::CString, mem, ptr};

/// Function representation in Rust.
#[cfg(not(windows))]
#[cfg(not(target_family = "windows"))]
pub type FunctionHandler = extern "C" fn(execute_data: &mut ExecuteData, retval: &mut Zval);
#[cfg(windows)]
#[cfg(target_family = "windows")]
pub type FunctionHandler =
extern "vectorcall" fn(execute_data: &mut ExecuteData, retval: &mut Zval);

/// Function representation in Rust using pointers.
#[cfg(not(windows))]
#[cfg(not(target_family = "windows"))]
type FunctionPointerHandler = extern "C" fn(execute_data: *mut ExecuteData, retval: *mut Zval);
#[cfg(windows)]
#[cfg(target_family = "windows")]
type FunctionPointerHandler =
extern "vectorcall" fn(execute_data: *mut ExecuteData, retval: *mut Zval);

Expand Down
4 changes: 2 additions & 2 deletions src/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
mod class;
mod function;
mod module;
#[cfg(feature = "embed")]
#[cfg(php_embed)]
mod sapi;

pub use class::ClassBuilder;
pub use function::FunctionBuilder;
pub use module::{ModuleBuilder, ModuleStartup};
#[cfg(feature = "embed")]
#[cfg(php_embed)]
pub use sapi::SapiBuilder;
4 changes: 2 additions & 2 deletions src/describe/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ impl ToStub for Constant {
}
}

#[cfg(windows)]
#[cfg(target_family = "windows")]
const NEW_LINE_SEPARATOR: &str = "\r\n";
#[cfg(not(windows))]
#[cfg(not(target_family = "windows"))]
const NEW_LINE_SEPARATOR: &str = "\n";

/// Takes a class name and splits the namespace off from the actual class name.
Expand Down
Loading
Loading