From 401c38b35a27c948a8fdfe5c0a8241b7511534c9 Mon Sep 17 00:00:00 2001 From: Matteo Biggio Date: Wed, 20 Mar 2024 10:08:57 +0100 Subject: [PATCH] First commit --- .gitignore | 1 + Cargo.toml | 12 ++++++++++++ build.rs | 32 ++++++++++++++++++++++++++++++++ src/lib.rs | 5 +++++ wrapper.h | 1 + 5 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 src/lib.rs create mode 100644 wrapper.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..eb2efd1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "cplex-sys" +version = "0.1.0" +edition = "2021" +publish = ["artifactory"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[build-dependencies] +bindgen = "0.69" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f686392 --- /dev/null +++ b/build.rs @@ -0,0 +1,32 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + // Tell cargo to look for shared libraries in the specified directory + println!("cargo:rustc-link-search=/usr/local/cplex/lib/x86-64_linux/static_pic"); + + // Tell cargo to tell rustc to link the system bzip2 + // shared library. + println!("cargo:rustc-link-lib=cplex"); + + // The bindgen::Builder is the main entry point + // to bindgen, and lets you build up options for + // the resulting bindings. + let bindings = bindgen::Builder::default() + // The input header we would like to generate + // bindings for. + .header("wrapper.h") + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + // Finish the builder and generate the bindings. + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a38a13a --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000..65c6ff9 --- /dev/null +++ b/wrapper.h @@ -0,0 +1 @@ +#include \ No newline at end of file