Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
sys: Generate the crates for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoz committed Jul 26, 2015
1 parent 8c5eaaf commit c10147d
Show file tree
Hide file tree
Showing 24 changed files with 31,176 additions and 0 deletions.
24 changes: 24 additions & 0 deletions atk-sys/Cargo.toml
@@ -0,0 +1,24 @@

[build-dependencies]
pkg-config = "^0.3.5"

[dependencies]
bitflags = "^0.3"
libc = "^0.1"

[dependencies.glib-sys]
path = "../glib-sys"
version = "^0.2.0"

[dependencies.gobject-sys]
path = "../gobject-sys"
version = "^0.2.0"

[lib]
name = "atk_sys"

[package]
build = "build.rs"
links = "atk"
name = "atk-sys"
version = "0.2.0"
70 changes: 70 additions & 0 deletions atk-sys/build.rs
@@ -0,0 +1,70 @@

extern crate pkg_config;
use std::cmp::Ordering;

const LIBRARY_NAME: &'static str = "atk";
const PACKAGE_NAME: &'static str = "atk";
const VERSIONS: &'static [Version] = &[
Version(2, 7, 90),
Version(2, 8, 0),
Version(2, 9, 3),
Version(2, 9, 4),
Version(2, 10, 0),
Version(2, 12, 0),
];

fn main() {
let lib = pkg_config::find_library(PACKAGE_NAME)
.unwrap_or_else(|e| panic!("{}", e));
let version = Version::new(&lib.version);
let mut cfgs = Vec::new();
for v in VERSIONS.iter().filter(|&&v| v <= version) {
let cfg = v.to_cfg();
println!("cargo:rustc-cfg={}", cfg);
cfgs.push(cfg);
}
println!("cargo:cfg={}", cfgs.connect(" "));
}

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
struct Version(pub u16, pub u16, pub u16);

impl Version {
fn new(s: &str) -> Version {
let mut parts = s.splitn(4, '.')
.map(|s| s.parse())
.take_while(Result::is_ok)
.map(Result::unwrap);
Version(parts.next().unwrap_or(0),
parts.next().unwrap_or(0), parts.next().unwrap_or(0))
}

fn to_cfg(&self) -> String {
match *self {
Version(major, minor, 0) => format!("{}_{}_{}", LIBRARY_NAME, major, minor),
Version(major, minor, patch) =>
format!("{}_{}_{}_{}", LIBRARY_NAME, major, minor, patch),
}
}
}

impl PartialOrd for Version {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Version {
fn cmp(&self, other: &Self) -> Ordering {
match self.0.cmp(&other.0) {
Ordering::Equal => {
match self.1.cmp(&other.1) {
Ordering::Equal => self.2.cmp(&other.2),
x => x,
}
}
x => x,
}
}
}

0 comments on commit c10147d

Please sign in to comment.