This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys: Generate the crates for the first time
- Loading branch information
Showing
24 changed files
with
31,176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.