• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

davidcole1340 / ext-php-rs / 16323306954

16 Jul 2025 03:10PM UTC coverage: 22.222% (+0.6%) from 21.654%
16323306954

Pull #482

github

web-flow
Merge de76d2402 into 1166e2910
Pull Request #482: feat(cargo-php)!: escalate privilege and to copy extension and edit ini file

0 of 48 new or added lines in 1 file covered. (0.0%)

193 existing lines in 10 files now uncovered.

870 of 3915 relevant lines covered (22.22%)

3.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/unix_build.rs
1
use std::{path::PathBuf, process::Command};
2

3
use anyhow::{bail, Context, Result};
4

5
use crate::{find_executable, path_from_env, PHPInfo, PHPProvider};
6

7
pub struct Provider<'a> {
8
    info: &'a PHPInfo,
9
}
10

11
impl Provider<'_> {
12
    /// Runs `php-config` with one argument, returning the stdout.
13
    fn php_config(arg: &str) -> Result<String> {
14
        let cmd = Command::new(Self::find_bin()?)
15
            .arg(arg)
16
            .output()
17
            .context("Failed to run `php-config`")?;
18
        let stdout = String::from_utf8_lossy(&cmd.stdout);
19
        if !cmd.status.success() {
20
            let stderr = String::from_utf8_lossy(&cmd.stderr);
21
            bail!("Failed to run `php-config`: {} {}", stdout, stderr);
22
        }
23
        Ok(stdout.to_string())
24
    }
25

26
    fn find_bin() -> Result<PathBuf> {
27
        // If path is given via env, it takes priority.
28
        if let Some(path) = path_from_env("PHP_CONFIG") {
29
            if !path.try_exists()? {
30
                // If path was explicitly given and it can't be found, this is a hard error
31
                bail!("php-config executable not found at {:?}", path);
32
            }
33
            return Ok(path);
34
        }
35
        find_executable("php-config").with_context(|| {
36
            "Could not find `php-config` executable. \
37
            Please ensure `php-config` is in your PATH or the \
38
            `PHP_CONFIG` environment variable is set."
39
        })
40
    }
41
}
42

43
impl<'a> PHPProvider<'a> for Provider<'a> {
UNCOV
44
    fn new(info: &'a PHPInfo) -> Result<Self> {
×
UNCOV
45
        Ok(Self { info })
×
46
    }
47

48
    fn get_includes(&self) -> Result<Vec<PathBuf>> {
×
49
        Ok(Self::php_config("--includes")?
×
50
            .split(' ')
×
51
            .map(|s| s.trim_start_matches("-I"))
×
UNCOV
52
            .map(PathBuf::from)
×
UNCOV
53
            .collect())
×
54
    }
55

UNCOV
56
    fn get_defines(&self) -> Result<Vec<(&'static str, &'static str)>> {
×
UNCOV
57
        let mut defines = vec![];
×
58
        if self.info.thread_safety()? {
×
UNCOV
59
            defines.push(("ZTS", "1"));
×
60
        }
UNCOV
61
        Ok(defines)
×
62
    }
63

UNCOV
64
    fn print_extra_link_args(&self) -> Result<()> {
×
65
        #[cfg(feature = "embed")]
UNCOV
66
        println!("cargo:rustc-link-lib=php");
×
67

UNCOV
68
        Ok(())
×
69
    }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc