Skip to content

Commit

Permalink
Set PKG_CONFIG_SYSROOT_DIR based on SDKROOT for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Apr 9, 2022
1 parent 8633257 commit 2cdbe26
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
use std::process::{self, Command};
Expand Down Expand Up @@ -203,6 +204,17 @@ impl Build {
build.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
}

if raw_target.contains("apple-darwin") {
if let Some(sdkroot) = env::var_os("SDKROOT") {
if !sdkroot.is_empty()
&& env::var_os("PKG_CONFIG_SYSROOT_DIR").is_none()
{
// Set PKG_CONFIG_SYSROOT_DIR for pkg-config crate
build.env("PKG_CONFIG_SYSROOT_DIR", sdkroot);
}
}
}

// Enable unstable `target-applies-to-host` option automatically for nightly Rust
// when target is the same as host but may have specified glibc version
if host_target == raw_target
Expand Down
25 changes: 25 additions & 0 deletions tests/hello-rustls/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/hello-rustls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ edition = "2018"
[dependencies]
reqwest = { version = "0.11.9", default-features = false, features = ["rustls-tls"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[target.'cfg(target_os = "macos")'.dependencies]
libz-sys = "1.1.5"
3 changes: 3 additions & 0 deletions tests/hello-rustls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(target_os = "macos")]
use libz_sys as _;

#[tokio::main]
async fn main() {
let response = reqwest::Client::new()
Expand Down

0 comments on commit 2cdbe26

Please sign in to comment.