bind-builder 0.1.0-alpha.1

Build dependency to help make crates that rely on native dependencies more portable.
Documentation
  • Coverage
  • 91.67%
    33 out of 36 items documented0 out of 32 items with examples
  • Size
  • Source code size: 29.38 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ccamel55

bind-builder

Rust build dependency that helps you build and link native libraries.

Requirements

  • cmake must be installed and available in the system path.
  • git if you wish to clone repositories.
  • c/c++ build tools.

Usage

Before you start, make sure that the cmake project you want to build has install targets setup for the libraries you want to link against. See cmake documentation to learn more.

Note: it is very important that install targets are set up correctly. Some libraries like zlib hardcode ${CMAKE_INSTALL_PREFIX} which results in generated binaries being misplaced.

Example

let project = CMakeBuilder::clone(
    "some-repo",
    "git@github.com:user/repo.git",
    "tag"
    )
    .generator("Ninja")
    .build();

let library = LocalLibrary::from(project)
    .link_target("some_library")
    .link_system_target("some_system_library")
    .get();

cxx_build::bridge("src/bindings.rs")
    .cpp(true)
    .static_flag(true)
    .std("c++20")
    .file("src/cpp_crate.cpp")
    .include(Path::new("src"))
    .bind_library(library)
    .compile("rust-cxx-testing");

If you are linking against shared libraries, and building for Linux or MacOS, you will need to explicitly set the @rpath to contain the binaries current directory.

This can be done by adding the following to your final artifact's build.rs:

#[cfg(target_os="macos")]
println!("cargo:rustc-link-arg=-Wl,-rpath,@loader_path");

#[cfg(target_os="linux")]
println!("cargo:rustc-link-arg=-Wl,-rpath,$ORIGIN");