Skip to content

Commit c42f714

Browse files
authored
Merge pull request #1 from humanmade/fix-build-php-version
Fix build version
2 parents 43c0694 + 25ad85b commit c42f714

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,34 @@ jobs:
7070
steps:
7171
- uses: actions/checkout@v4
7272
- uses: actions-rust-lang/setup-rust-toolchain@v1
73+
with:
74+
cache-key: ${{ matrix.target }}-${{ matrix.php-version }}-${{ matrix.platform }}-${{ matrix.distro }}
7375

7476
- name: Setup PHP
7577
uses: shivammathur/setup-php@v2
7678
with:
7779
php-version: ${{ matrix.php-version }}
80+
extensions: none
7881

7982
- name: Generate version for tag
8083
if: github.ref_type == 'tag'
8184
run: echo "ERROR_MESSAGE_FORMAT_VERSION=${{github.ref_name}}" >> $GITHUB_ENV
8285

86+
- run: php -i -c tests/php.ini
87+
8388
- name: Generate version for branch
8489
if: github.ref_type == 'branch'
8590
run: echo "ERROR_MESSAGE_FORMAT_VERSION=0.0.1+${{github.ref_name}}" | sed 's!/!-!g' >> $GITHUB_ENV
8691

8792
- name: Update Cargo.toml version
8893
run: sed -i "s/^version = .*/version = \"${{ env.ERROR_MESSAGE_FORMAT_VERSION }}\"/" Cargo.toml
8994

95+
- uses: mxschmitt/action-tmate@v3
96+
if: runner.debug == '1'
97+
98+
- name: Test
99+
run: cargo test -- --nocapture
100+
90101
- run: cargo build --release --target ${{ matrix.target }}
91102

92103
- run: ls -la target/${{ matrix.target }}/release/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ $url = $_SERVER['REQUEST_URI'];
99
ini_set( 'error_message_format', '{message} from URL' . $url );
1010
```
1111

12+
## Compatibily
13+
14+
Supports PHP versions 8+
15+
16+
⚠️ Currently `error_message_format` is not compatible with Xdebug.
17+
1218
## Resources
1319

1420
- [ext-php-rs Documentation](https://docs.rs/ext-php-rs)

tests/test.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
use assertables::assert_contains;
2+
use std::sync::{Arc, Condvar, Mutex, OnceLock};
23

34
mod utils;
45

6+
// Global state to track build completion
7+
static BUILD_STATE: OnceLock<(Arc<Mutex<bool>>, Arc<Condvar>)> = OnceLock::new();
8+
9+
// Call this function to ensure the build has happened and completed
10+
// All threads will wait for the build to finish before proceeding
11+
fn ensure_setup() {
12+
let (build_complete, condvar) = BUILD_STATE.get_or_init(|| {
13+
let pair = (Arc::new(Mutex::new(false)), Arc::new(Condvar::new()));
14+
let (build_complete, condvar) = pair.clone();
15+
16+
// Start the build in the background
17+
std::thread::spawn(move || {
18+
utils::build();
19+
let mut completed = build_complete.lock().unwrap();
20+
*completed = true;
21+
condvar.notify_all();
22+
});
23+
24+
pair
25+
});
26+
27+
// Wait for build to complete
28+
let mut completed = build_complete.lock().unwrap();
29+
while !*completed {
30+
completed = condvar.wait(completed).unwrap();
31+
}
32+
}
33+
534
#[test]
635
fn test_build() {
7-
utils::build();
36+
ensure_setup();
837
}
938

1039
#[test]
1140
fn test_version() {
12-
utils::build();
41+
ensure_setup();
1342
let output = utils::run_cli("<?php phpinfo(); ?>");
1443
assert_contains!(
1544
output.trim(),
@@ -22,7 +51,7 @@ fn test_version() {
2251

2352
#[test]
2453
fn test_cli_error_output_default() {
25-
utils::build();
54+
ensure_setup();
2655
let code = r#"
2756
<?php
2857
trigger_error('This is a test error', E_USER_WARNING);
@@ -33,7 +62,7 @@ trigger_error('This is a test error', E_USER_WARNING);
3362

3463
#[test]
3564
fn test_cli_error_output() {
36-
utils::build();
65+
ensure_setup();
3766
let code = r#"
3867
<?php
3968
ini_set('error_message_format', '{message} with an append');

tests/utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ pub fn run_cli(code: &str) -> String {
4040
.output()
4141
.unwrap();
4242

43-
dbg!(&output);
44-
4543
fs::remove_file(script_filename).unwrap();
4644
String::from_utf8(output.stdout).unwrap()
4745
}

0 commit comments

Comments
 (0)