Skip to content

Commit

Permalink
build: add default brew libarchive path on macos
Browse files Browse the repository at this point in the history
On macos brew installs libarchive.pc file not into the default path.
Manually setting the ENV before being able to use cargo ... or esp.
vs code "test"/"debug" features is a pain.
So adding this workaround.
  • Loading branch information
mbehr1 authored and otavio committed Jun 24, 2024
1 parent cda8dca commit 4152415
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ fn main() {

#[cfg(not(target_env = "msvc"))]
fn find_libarchive() {
const MACOS_HOMEBREW_LIBARCHIVE_PATH: &str = "/opt/homebrew/opt/libarchive/lib/pkgconfig/";

if cfg!(target_os = "macos")
&& pkg_config::Config::new()
.atleast_version("3.2.0")
.probe("libarchive")
.is_err()
&& std::path::Path::new(MACOS_HOMEBREW_LIBARCHIVE_PATH).exists()
{
// on OSX brew doesn't install libarchive in the default path...
// try that workaround as it's a pain providing this in the env e.g.
// for vs code usage.
// todo should add to current one and set afterwards to current value!
std::env::set_var("PKG_CONFIG_PATH", MACOS_HOMEBREW_LIBARCHIVE_PATH);
}

pkg_config::Config::new()
.atleast_version("3.2.0")
.probe("libarchive")
Expand Down

0 comments on commit 4152415

Please sign in to comment.