[librsvg/wip/rust-api: 7/11] librsvg_crate: Add a build.rs to find libcroco via pkg-config
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/rust-api: 7/11] librsvg_crate: Add a build.rs to find libcroco via pkg-config
- Date: Sat, 16 Feb 2019 01:35:00 +0000 (UTC)
commit 254452d4d1a1a74aced0f9379c87ba3de3d96407
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 13 18:12:32 2019 -0600
librsvg_crate: Add a build.rs to find libcroco via pkg-config
This will also pull in libxml2 automatically.
Cargo.lock | 1 +
librsvg_crate/Cargo.toml | 4 +++
librsvg_crate/build.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
---
diff --git a/Cargo.lock b/Cargo.lock
index 4f5f0d7b..a4145ef2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -591,6 +591,7 @@ dependencies = [
"cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rsvg_internals 0.0.1",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/librsvg_crate/Cargo.toml b/librsvg_crate/Cargo.toml
index 16309072..d361501e 100644
--- a/librsvg_crate/Cargo.toml
+++ b/librsvg_crate/Cargo.toml
@@ -3,6 +3,7 @@ name = "librsvg"
version = "0.0.1"
authors = ["Federico Mena Quintero <federico gnome org>"]
workspace = "../"
+build = "build.rs"
[lib]
name = "librsvg"
@@ -16,3 +17,6 @@ url = "1.7.2"
[dev-dependencies]
cairo-rs = { version = "0.5.0", features = ["png"] }
+
+[build-dependencies]
+pkg-config = "0.3.14"
diff --git a/librsvg_crate/build.rs b/librsvg_crate/build.rs
new file mode 100644
index 00000000..5dc5139e
--- /dev/null
+++ b/librsvg_crate/build.rs
@@ -0,0 +1,65 @@
+extern crate pkg_config;
+
+use std::env;
+use std::io;
+use std::io::prelude::*;
+use std::process;
+
+use pkg_config::{Config, Error};
+
+fn main() {
+ // libcroco pulls in libxml2, so the first one is enough
+ if let Err(s) = find("libcroco-0.6", "0.6.1", &["croco-0.6"]) {
+ let _ = writeln!(io::stderr(), "{}", s);
+ process::exit(1);
+ }
+}
+
+// This is stolen from the -sys crates in gtk-rs
+fn find(package_name: &str, version: &str, shared_libs: &[&str]) -> Result<(), Error> {
+ if let Ok(inc_dir) = env::var("GTK_INCLUDE_DIR") {
+ println!("cargo:include={}", inc_dir);
+ }
+ if let Ok(lib_dir) = env::var("GTK_LIB_DIR") {
+ for lib_ in shared_libs.iter() {
+ println!("cargo:rustc-link-lib=dylib={}", lib_);
+ }
+ println!("cargo:rustc-link-search=native={}", lib_dir);
+ return Ok(());
+ }
+
+ let target = env::var("TARGET").unwrap();
+ let hardcode_shared_libs = target.contains("windows");
+
+ let mut config = Config::new();
+ config.atleast_version(version);
+ config.print_system_libs(false);
+
+ if hardcode_shared_libs {
+ config.cargo_metadata(false);
+ }
+ match config.probe(package_name) {
+ Ok(library) => {
+ if let Ok(paths) = std::env::join_paths(library.include_paths) {
+ // Exposed to other build scripts as DEP_CAIRO_INCLUDE; use env::split_paths
+ println!("cargo:include={}", paths.to_string_lossy());
+ }
+ if hardcode_shared_libs {
+ for lib_ in shared_libs.iter() {
+ println!("cargo:rustc-link-lib=dylib={}", lib_);
+ }
+ for path in library.link_paths.iter() {
+ println!("cargo:rustc-link-search=native={}", path.to_str().unwrap());
+ }
+ }
+ Ok(())
+ }
+ Err(Error::EnvNoPkgConfig(_)) | Err(Error::Command { .. }) => {
+ for lib_ in shared_libs.iter() {
+ println!("cargo:rustc-link-lib=dylib={}", lib_);
+ }
+ Ok(())
+ }
+ Err(err) => Err(err),
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]