Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,13 @@ pub mod dynamic;
#[path = "build/static.rs"]
pub mod r#static;

/// Copies a file.
#[cfg(feature = "runtime")]
fn copy(source: &str, destination: &Path) {
use std::fs::File;
use std::io::{Read, Write};

let mut string = String::new();
File::open(source)
.unwrap()
.read_to_string(&mut string)
.unwrap();
File::create(destination)
.unwrap()
.write_all(string.as_bytes())
.unwrap();
}

/// Copies the code used to find and link to `libclang` shared libraries into
/// the build output directory so that it may be used when linking at runtime.
#[cfg(feature = "runtime")]
fn main() {
use std::env;

if cfg!(feature = "static") {
panic!("`runtime` and `static` features can't be combined");
}

let out = env::var("OUT_DIR").unwrap();
copy("build/macros.rs", &Path::new(&out).join("macros.rs"));
copy("build/common.rs", &Path::new(&out).join("common.rs"));
copy("build/dynamic.rs", &Path::new(&out).join("dynamic.rs"));
}

/// Finds and links to the required libraries dynamically or statically.
Expand Down
8 changes: 4 additions & 4 deletions src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ https://docs.rs/clang-sys/latest/clang_sys/{0}/index.html

Instructions for installing `libclang` can be found here:
https://rust-lang.github.io/rust-bindgen/requirements.html
"#,
"#,
stringify!($name),
library
.version()
Expand Down Expand Up @@ -226,9 +226,9 @@ https://rust-lang.github.io/rust-bindgen/requirements.html
pub fn load_manually() -> Result<SharedLibrary, String> {
#[allow(dead_code)]
mod build {
include!(concat!(env!("OUT_DIR"), "/macros.rs"));
pub mod common { include!(concat!(env!("OUT_DIR"), "/common.rs")); }
pub mod dynamic { include!(concat!(env!("OUT_DIR"), "/dynamic.rs")); }
include!("../build/macros.rs");
pub mod common { include!("../build/common.rs"); }
pub mod dynamic { include!("../build/dynamic.rs"); }
}

let (directory, filename) = build::dynamic::find(true)?;
Expand Down