Skip to content

Commit 1fc5305

Browse files
committed
feat(embed): use link-php as a feature to link php library with compiled target
1 parent a2d21a4 commit 1fc5305

File tree

12 files changed

+130
-24
lines changed

12 files changed

+130
-24
lines changed

.cargo/config.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ linker = "rust-lld"
88
linker = "rust-lld"
99

1010
[alias]
11-
ci-test = "hack test --workspace --feature-powerset --clean-per-run"
11+
ci-test = "hack test --package ext-php-rs --package tests --feature-powerset --clean-per-run --exclude-features=link-php"
12+
ci-test-link = "hack test --package ext-php-rs --feature-powerset --clean-per-run --features=link-php"
13+
ci-test-other = "hack test --workspace --exclude ext-php-rs --exclude tests --feature-powerset"

.github/workflows/build.yml

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ jobs:
7676
env:
7777
DOCS_RS: ""
7878
run: cargo clean && cargo build
79-
build:
80-
name: Build and Test
79+
80+
test:
81+
name: Build and test
8182
runs-on: ${{ matrix.os }}
8283
strategy:
8384
matrix:
@@ -151,8 +152,114 @@ jobs:
151152
uses: taiki-e/install-action@v2
152153
with:
153154
tool: cargo-hack
154-
# Test
155-
- name: Test features matrix
155+
- name: Test
156156
env:
157157
EXT_PHP_RS_TEST: ""
158158
run: cargo ci-test
159+
160+
test-link:
161+
name: Test that requires linking php library
162+
runs-on: ${{ matrix.os }}
163+
strategy:
164+
matrix:
165+
os: [ubuntu-latest, macos-latest, windows-latest]
166+
php: ["8.2", "8.3", "8.4"]
167+
clang: ["15", "17"]
168+
phpts: [ts, nts]
169+
exclude:
170+
# ext-php-rs requires nightly Rust when on Windows.
171+
- os: windows-latest
172+
rust: stable
173+
- os: macos-latest
174+
clang: "17"
175+
- os: ubuntu-latest
176+
clang: "15"
177+
- os: windows-latest
178+
clang: "15"
179+
env:
180+
CARGO_TERM_COLOR: always
181+
steps:
182+
- name: Checkout code
183+
uses: actions/checkout@v4
184+
- name: Setup PHP
185+
uses: shivammathur/setup-php@v2
186+
with:
187+
php-version: ${{ matrix.php }}
188+
env:
189+
phpts: ${{ matrix.phpts }}
190+
debug: true
191+
- name: Setup Rust
192+
uses: dtolnay/rust-toolchain@master
193+
with:
194+
toolchain: stable
195+
components: rustfmt, clippy
196+
- run: rustup show
197+
- name: Cache cargo dependencies
198+
uses: Swatinem/rust-cache@v2
199+
# Uncomment the following if statement if caching nightly deps
200+
# ends up causing too much cache invalidation.
201+
# if: matrix.rust == 'stable'
202+
with:
203+
# increment this manually to force cache eviction
204+
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
205+
# LLVM & Clang
206+
- name: Cache LLVM and Clang
207+
id: cache-llvm
208+
uses: actions/cache@v4
209+
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
210+
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
211+
with:
212+
path: ${{ runner.temp }}/llvm-${{ matrix.clang }}
213+
key: ${{ matrix.os }}-llvm-${{ matrix.clang }}
214+
- name: Setup LLVM & Clang
215+
id: clang
216+
uses: KyleMayes/install-llvm-action@v2
217+
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
218+
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
219+
with:
220+
version: ${{ matrix.clang }}
221+
directory: ${{ runner.temp }}/llvm-${{ matrix.clang }}
222+
cached: ${{ steps.cache-llvm.outputs.cache-hit }}
223+
- name: Configure Clang
224+
# Macos build doesn't work with clang < 18. As a build for version 18 is not available, we skip the setup
225+
if: "!contains(matrix.os, 'windows') && !contains(matrix.os, 'macos')"
226+
run: |
227+
echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/lib" >> $GITHUB_ENV
228+
echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV
229+
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ matrix.clang }}/bin/llvm-config" >> $GITHUB_ENV
230+
- name: Install cargo-hack
231+
uses: taiki-e/install-action@v2
232+
with:
233+
tool: cargo-hack
234+
- name: Test
235+
env:
236+
EXT_PHP_RS_TEST: ""
237+
run: cargo ci-test-link
238+
239+
test-others:
240+
name: Test others crates not depen
241+
runs-on: ${{ matrix.os }}
242+
strategy:
243+
matrix:
244+
os: [ubuntu-latest, macos-latest, windows-latest]
245+
rust: [stable, nightly]
246+
env:
247+
CARGO_TERM_COLOR: always
248+
steps:
249+
- name: Checkout code
250+
uses: actions/checkout@v4
251+
- name: Setup Rust
252+
uses: dtolnay/rust-toolchain@master
253+
with:
254+
toolchain: ${{ matrix.rust }}
255+
components: rustfmt, clippy
256+
- run: rustup show
257+
- name: Install cargo-hack
258+
uses: taiki-e/install-action@v2
259+
with:
260+
tool: cargo-hack
261+
# Test
262+
- name: Test
263+
env:
264+
EXT_PHP_RS_TEST: ""
265+
run: cargo ci-test-other

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ zip = "2.2"
3838

3939
[features]
4040
closure = []
41+
link-php = []
4142

4243
[workspace]
4344
members = [

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait PHPProvider<'a>: Sized {
5050
}
5151

5252
/// Prints any extra link arguments.
53-
fn print_extra_link_args(&self, _has_embed: bool) -> Result<()> {
53+
fn print_extra_link_args(&self) -> Result<()> {
5454
Ok(())
5555
}
5656
}
@@ -347,7 +347,7 @@ fn main() -> Result<()> {
347347
if info.thread_safety()? {
348348
println!("cargo:rustc-cfg=php_zts");
349349
}
350-
provider.print_extra_link_args(has_embed)?;
350+
provider.print_extra_link_args()?;
351351

352352
// Generate guide tests
353353
let test_md = skeptic::markdown_files_of_directory("guide");

src/embed/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Embed {
5959
///
6060
/// # Example
6161
///
62-
/// ```
62+
/// ```no_run
6363
/// use ext_php_rs::embed::Embed;
6464
///
6565
/// Embed::run(|| {
@@ -123,7 +123,7 @@ impl Embed {
123123
///
124124
/// # Example
125125
///
126-
/// ```
126+
/// ```no_run
127127
/// use ext_php_rs::embed::Embed;
128128
///
129129
/// Embed::run(|| {
@@ -179,7 +179,7 @@ impl Embed {
179179
///
180180
/// # Example
181181
///
182-
/// ```
182+
/// ```no_run
183183
/// use ext_php_rs::embed::Embed;
184184
///
185185
/// Embed::run(|| {
@@ -211,7 +211,7 @@ impl Embed {
211211
}
212212
}
213213

214-
#[cfg(test)]
214+
#[cfg(all(test, feature = "link-php"))]
215215
mod tests {
216216
use super::Embed;
217217

src/types/iterator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ impl<'a> FromZvalMut<'a> for &'a mut ZendIterator {
182182
}
183183
}
184184

185-
#[cfg(test)]
186-
#[cfg(php_embed)]
185+
#[cfg(all(test, php_embed, feature = "link-php"))]
187186
mod tests {
188187
use crate::embed::Embed;
189188

src/types/string.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ impl<'a> FromZval<'a> for &'a str {
455455
}
456456
}
457457

458-
#[cfg(test)]
459-
#[cfg(php_embed)]
458+
#[cfg(all(test, php_embed, feature = "link-php"))]
460459
mod tests {
461460
use crate::embed::Embed;
462461

src/zend/try_catch.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ pub unsafe fn bailout() -> ! {
102102
ext_php_rs_zend_bailout();
103103
}
104104

105-
#[cfg(php_embed)]
106-
#[cfg(test)]
105+
#[cfg(all(test, php_embed, feature = "link-php"))]
107106
mod tests {
108107
use crate::embed::Embed;
109108
use crate::zend::{bailout, try_catch};

tests/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(windows, feature(abi_vectorcall))]
2-
#![cfg(php_embed)]
2+
#![cfg(all(php_embed, feature = "link-php"))]
33

44
extern crate ext_php_rs;
55

tests/sapi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![cfg_attr(windows, feature(abi_vectorcall))]
2-
#![cfg(php_embed)]
2+
#![cfg(all(php_embed, feature = "link-php"))]
33

44
extern crate ext_php_rs;
55

0 commit comments

Comments
 (0)