Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | use std::env; |
| 2 | use std::path::PathBuf; |
| 3 | |
| 4 | fn main() { |
| 5 | let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); |
| 6 | let c_core_dir = PathBuf::from(project_dir.clone()).join("..").join("c_core"); |
| 7 | |
| 8 | // Tell cargo to look for shared libraries in the specified directory |
| 9 | let lib_dir = PathBuf::from(project_dir.clone()).join("..").join("..").join("build").join("macos").join("release"); |
| 10 | println!("cargo:rustc-link-search=native={}", lib_dir.display()); |
| 11 | |
| 12 | // Fallback for Linux |
| 13 | let linux_lib_dir = PathBuf::from(project_dir).join("..").join("..").join("build").join("linux").join("release"); |
| 14 | println!("cargo:rustc-link-search=native={}", linux_lib_dir.display()); |
| 15 | |
| 16 | // Tell cargo to tell rustc to link the shared library. |
| 17 | println!("cargo:rustc-link-lib=zftpd_ffi"); |
| 18 | |
| 19 | // Tell cargo to invalidate the built crate whenever the wrapper changes |
| 20 | let header_path = c_core_dir.join("pal_ffi.h"); |
| 21 | println!("cargo:rerun-if-changed={}", header_path.display()); |
| 22 | |
| 23 | // The bindgen::Builder is the main entry point |
| 24 | // to bindgen, and lets you build up options for |
| 25 | // the resulting bindings. |
| 26 | let bindings = bindgen::Builder::default() |
| 27 | // The input header we would like to generate |
| 28 | // bindings for. |
| 29 | .header(header_path.to_str().unwrap()) |
| 30 | // Include path |
| 31 | .clang_arg(format!("-I{}", c_core_dir.display())) |
| 32 | // Tell cargo to invalidate the built crate whenever any of the |
| 33 | // included header files changed. |
| 34 | .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) |
| 35 | // Finish the builder and generate the bindings. |
| 36 | .generate() |
| 37 | // Unwrap the Result and panic on failure. |
| 38 | .expect("Unable to generate bindings"); |
| 39 | |
| 40 | // Write the bindings to the $OUT_DIR/bindings.rs file. |
| 41 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 42 | bindings |
| 43 | .write_to_file(out_path.join("bindings.rs")) |
| 44 | .expect("Couldn't write bindings!"); |
| 45 | } |
| 46 |