Skip to content

Commit

Permalink
support prebuilt library binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Dec 13, 2024
1 parent 54ef445 commit f943319
Show file tree
Hide file tree
Showing 15 changed files with 1,352 additions and 58 deletions.
15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,26 @@ documentation.workspace = true
readme = "README.md"

[dependencies]
system-deps-meta = { workspace = true, optional = true }
pkg-config = "0.3.25"
toml = { version = "0.8", default-features = false, features = ["parse"] }
version-compare = "0.2"
heck = "0.5"
cfg-expr = { version = "0.17", features = ["targets"] }

[build-dependencies]
system-deps-meta = { workspace = true, optional = true }

[dev-dependencies]
lazy_static = "1"
system-deps-meta = { workspace = true, features = ["test"] }
itertools = "0.13"
assert_matches = "1.5"
tiny_http = "0.12"

[features]
default = [ ]
# How to do this using resolver v2? Since features are separated
binary = [ "system-deps-meta/binary" ]
gz = [ "system-deps-meta/gz" ]
xz = [ "system-deps-meta/xz" ]
zip = [ "system-deps-meta/zip" ]
32 changes: 32 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub fn main() {
#[cfg(feature = "binary")]
binary::build().unwrap_or_else(|e| panic!("{}", e));
}

#[cfg(feature = "binary")]
mod binary {
use std::{fs, path::Path};

use system_deps_meta::{
binary::{merge_binary, Paths},
error::{BinaryError, Error},
parse::read_metadata,
BUILD_MANIFEST, BUILD_TARGET_DIR,
};

// Add pkg-config paths to the overrides
pub fn build() -> Result<(), Error> {
// Read metadata from the crate graph
let metadata = read_metadata(BUILD_MANIFEST, "system-deps", merge_binary)?;

// Download the binaries and get their pkg_config paths
let paths: Paths = metadata.into_iter().collect();

// Write the binary paths to a file for later use
let dest = Path::new(BUILD_TARGET_DIR).join("paths.toml");
fs::write(&dest, paths.to_string()?).map_err(BinaryError::InvalidDirectory)?;
println!("cargo:rustc-env=BINARY_PATHS={}", dest.display());

Ok(())
}
}
Loading

0 comments on commit f943319

Please sign in to comment.