Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Never pick up Strawberry Perl's pkg-config as a valid implementation #165

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ jobs:
cargo build --verbose
- run: |
cargo test --verbose
windows_build:
name: windows ${{ matrix.rust }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
rust:
- 1.30.0
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- run: rustup component add rustfmt-preview
- run: |
cargo build --verbose
- name: cargo test
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://github.com/mesonbuild/cidata/raw/master/win32/pkg-config.exe" -OutFile pkg-config.exe
$env:PATH += ";$PWD"
cargo test --verbose
73 changes: 72 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,14 +652,85 @@ impl Config {
self.statik.unwrap_or_else(|| self.infer_static(name))
}

#[cfg(windows)]
fn find_pkg_config_in(&self, mut path: PathBuf, pathexts: &[OsString]) -> Option<OsString> {
path.push("pkg-config");
for pathext in pathexts {
path.set_extension(pathext);
if !path.is_file() {
return None;
}
// Strawberry Perl's pkg-config is pkg-config.bat
if pathext.eq_ignore_ascii_case("bat") {
let mut cmd = Command::new(path.as_os_str());
let out = match cmd.arg("--help").output() {
Ok(o) => o,
Err(e) => {
eprintln!("Ignoring unusable pkg-config ({:?}): {:?}", path, e);
return None;
}
};
if let Ok(out) = str::from_utf8(&out.stdout) {
if out.contains("Pure-Perl") {
eprintln!("Ignoring Strawberry Perl pkg-config: {:?}", path);
return None;
}
}
}
}
Some(path.into_os_string())
}

fn pkg_config_from_path(&self) -> OsString {
#[cfg(windows)]
{
// Resolve pkg-config in PATH to find the absolute path to pkg-config that we should
// use, so that we can skip Strawberry Perl's pure-perl implementation of pkg-config.
// Despite its presence in PATH, the implementation is for internal use and not meant
// to be used as a MinGW distribution.
use std::os::windows::prelude::*;
let pathexts = env::var_os("PATHEXT").map_or_else(
|| {
["COM", "EXE", "BAT"]
.iter()
.map(|v| OsStr::new(v).to_owned())
.collect::<Vec<_>>()
},
|v| {
env::split_paths(&v)
// PATHEXT is a list of .EXT but we want EXT
.map(|v| {
OsString::from_wide(
&v.as_os_str().encode_wide().skip(1).collect::<Vec<u16>>(),
)
})
.collect::<Vec<_>>()
},
);
// Windows first searches for the specified command in the current directory,
// regardless of the value of PATH.
if let Some(ret) = self.find_pkg_config_in(".".into(), &pathexts) {
return ret;
}
if let Some(paths) = env::var_os("PATH") {
for path in env::split_paths(&paths) {
if let Some(ret) = self.find_pkg_config_in(path, &pathexts) {
return ret;
}
}
}
}
OsString::from("pkg-config")
}

fn run(&self, name: &str, args: &[&str]) -> Result<Vec<u8>, Error> {
let pkg_config_exe = self.targeted_env_var("PKG_CONFIG");
let fallback_exe = if pkg_config_exe.is_none() {
Some(OsString::from("pkgconf"))
} else {
None
};
let exe = pkg_config_exe.unwrap_or_else(|| OsString::from("pkg-config"));
let exe = pkg_config_exe.unwrap_or_else(|| self.pkg_config_from_path());

let mut cmd = self.command(exe, name, args);

Expand Down
Loading