1
0
mirror of https://github.com/bspeice/aeron-rs synced 2025-08-27 09:45:25 -04:00

Rename to aeron-driver-sys, update to 1.25.0 release

This commit is contained in:
2020-01-12 16:47:29 -05:00
parent 531bc0d64c
commit b9b5b74b7c
11 changed files with 11 additions and 11 deletions

1
aeron-driver-sys/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

View File

@ -0,0 +1,17 @@
[package]
name = "aeron-driver-sys"
version = "1.0.0+1.25.0"
authors = ["Bradlee Speice <bradlee@speice.io>"]
edition = "2018"
links = "aeron_driver"
build = "build.rs"
[dependencies]
[build-dependencies]
bindgen = "0.51"
cmake = "0.1"
dunce = "1.0.0"
[features]
static = []

View File

@ -0,0 +1,4 @@
#include <stddef.h>
#include <aeronmd.h>
#include <aeron_driver_context.h>
#include <command/aeron_control_protocol.h>

108
aeron-driver-sys/build.rs Normal file
View File

@ -0,0 +1,108 @@
use cmake::Config;
use dunce::canonicalize;
use std::env;
use std::path::{Path, PathBuf};
pub enum LinkType {
Dynamic,
Static,
}
impl LinkType {
fn detect() -> LinkType {
if cfg!(feature = "static") {
LinkType::Static
} else {
LinkType::Dynamic
}
}
fn link_lib(&self) -> &'static str {
match self {
LinkType::Dynamic => "dylib=",
LinkType::Static => "static=",
}
}
fn target_name(&self) -> &'static str {
match self {
LinkType::Dynamic => "aeron_driver",
LinkType::Static => "aeron_driver_static",
}
}
}
pub fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=bindings.h");
let aeron_path = canonicalize(Path::new("./aeron")).unwrap();
let header_path = aeron_path.join("aeron-driver/src/main/c");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let link_type = LinkType::detect();
println!(
"cargo:rustc-link-lib={}{}",
link_type.link_lib(),
link_type.target_name()
);
match link_type {
LinkType::Static => {
// On Windows, there are some extra libraries needed for static link
// that aren't included by Aeron.
if cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=shell32");
println!("cargo:rustc-link-lib=iphlpapi");
}
}
_ => (),
};
let cmake_output = Config::new(&aeron_path)
.build_target(link_type.target_name())
.build();
// Trying to figure out the final path is a bit weird;
// For Linux/OSX, it's just build/lib
// For Windows, the .lib file is in build/lib/{profile}, but the DLL
// is shipped in build/binaries/{profile}
let base_lib_dir = cmake_output.join("build");
println!(
"cargo:rustc-link-search=native={}",
base_lib_dir.join("lib").display()
);
// Because the `cmake_output` path is different for debug/release, we're not worried
// about accidentally linking in the wrong library
println!(
"cargo:rustc-link-search=native={}",
base_lib_dir.join("lib/Debug").display()
);
println!(
"cargo:rustc-link-search=native={}",
base_lib_dir.join("binaries/Debug").display()
);
println!(
"cargo:rustc-link-search=native={}",
base_lib_dir.join("lib/Release").display()
);
println!(
"cargo:rustc-link-search=native={}",
base_lib_dir.join("binaries/Release").display()
);
println!("cargo:include={}", header_path.display());
let bindings = bindgen::Builder::default()
.clang_arg(&format!("-I{}", header_path.display()))
.header("bindings.h")
.whitelist_function("aeron_.*")
.whitelist_type("aeron_.*")
.whitelist_var("AERON_.*")
.constified_enum_module("aeron_.*_enum")
.generate()
.expect("Unable to generate aeron_driver bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}

View File

@ -0,0 +1,19 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(clippy::all)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(test)]
mod tests {
#[test]
fn version_check() {
let major = unsafe { crate::aeron_version_major() };
let minor = unsafe { crate::aeron_version_minor() };
let patch = unsafe { crate::aeron_version_patch() };
assert_eq!(major, 1);
assert_eq!(minor, 25);
assert_eq!(patch, 0);
}
}