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

add feature "static" to allow static linkage for unix/macos #127

Merged
merged 3 commits into from
Jun 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install libarchive-dev
run: sudo apt-get update; sudo apt-get install libarchive-dev libb2-dev liblz4-dev libacl1-dev libzstd-dev nettle-dev
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

steps:
- name: Install Dependencies
run: sudo apt-get update; sudo apt-get install libarchive-dev
run: sudo apt-get update; sudo apt-get install libarchive-dev libb2-dev liblz4-dev libacl1-dev libzstd-dev nettle-dev
- name: Checkout sources
uses: actions/checkout@v4
- name: Install ${{ matrix.version }}
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

* Raise MSRV to 1.65.0
* Fix use slice::from_raw_parts only if size > 0 [#126]
* Add feature "static" to allow static linkage for unix/macos [#127]

[#126]: https://github.com/OSSystems/compress-tools-rs/pull/126
[#127]: https://github.com/OSSystems/compress-tools-rs/pull/127

## [0.14.3] - 2023-05-26

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ libc = "0.2.86"
async_support = ["async-trait", "futures-channel", "futures-core", "futures-io", "futures-util", "futures-executor"]
futures_support = ["async_support", "blocking"]
tokio_support = ["async_support", "tokio", "tokio-util"]
static = []

[dev-dependencies]
tempfile = "3.1"
Expand Down
38 changes: 38 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,48 @@ 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);
}

if cfg!(feature = "static") {
pkg_config::Config::new()
.statik(cfg!(feature = "static"))
.probe("libb2")
.expect("Unable to find libb2");

pkg_config::Config::new()
.statik(cfg!(feature = "static"))
.probe("liblz4")
.expect("Unable to find liblz4");

pkg_config::Config::new()
.statik(cfg!(feature = "static"))
.probe("libzstd")
.expect("Unable to find libzstd");
}

pkg_config::Config::new()
.atleast_version("3.2.0")
.statik(cfg!(feature = "static"))
.probe("libarchive")
.expect("Unable to find libarchive");

if cfg!(feature = "static") {
println!("cargo:rustc-link-lib=static=archive");
}
}

#[cfg(target_env = "msvc")]
Expand Down
Loading