Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
toblux committed Feb 4, 2024
1 parent 06ac991 commit 59b2c3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The safe Rust bindings to `libeditorconfig`, built on top of this `editorconfig-

## Dependencies

To use this crate, `pkg-config` and `libeditorconfig >=0.12.5 <1.0.0` must be installed. For example, on Debian or Ubuntu you could use `apt install pkg-config libeditorconfig-dev` and on macOS `brew install pkg-config editorconfig` to install the dependencies.
To use this crate, `pkg-config` and `libeditorconfig >= 0.12.5` must be installed. For example, on Debian or Ubuntu you could use `apt install pkg-config libeditorconfig-dev` and on macOS `brew install pkg-config editorconfig` to install the dependencies.

You can check if `pkg-config` can find the library and which version is installed with:

Expand Down
14 changes: 6 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This build script currently assumes that `libeditorconfig >=0.12.5 <1.0.0` is
// This build script currently assumes that `libeditorconfig >= 0.12.5` is
// installed and that `pkg-config` can find it.

use pkg_config::{Config, Library};
Expand All @@ -8,25 +8,23 @@ const LIBRARY_NAME: &str = "editorconfig";
// Technically libeditorconfig v0.12.2 already supports pkg-config:
// https://github.com/editorconfig/editorconfig-core-c/releases/tag/v0.12.2
const MIN_VERSION: &str = "0.12.5";
const MAX_VERSION: &str = "1.0.0";

fn main() {
if let Ok(lib) = Config::new()
.range_version(MIN_VERSION..MAX_VERSION)
.atleast_version(MIN_VERSION)
.probe(LIBRARY_NAME)
{
if cfg!(feature = "buildtime-bindgen") {
gen_bindings(lib);
}
} else {
eprintln!(
"Unable to find lib {} >= {} < {}",
LIBRARY_NAME, MIN_VERSION, MAX_VERSION
);
eprintln!("Unable to find lib {} >= {}", LIBRARY_NAME, MIN_VERSION);
}
}

fn gen_bindings(lib: Library) {
use std::{env, path::PathBuf};

let include_paths = lib
.include_paths
.iter()
Expand All @@ -40,7 +38,7 @@ fn gen_bindings(lib: Library) {
.expect("Failed to generate bindings");

// Write auto-generated bindings to `$OUT_DIR/bindings.rs`
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Failed to write bindings");
Expand Down

0 comments on commit 59b2c3f

Please sign in to comment.