commit 14365ec9bee8fd3ae7afc7a6e28350196c081b95 Author: Magnus Ulimoen Date: Thu Jul 23 22:28:15 2020 +0200 Start of the project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c0f4002 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "skanny" +version = "0.1.0" +authors = ["Magnus Ulimoen "] +edition = "2018" + +[dependencies] + +[workspace] +members = [ + "sane-sys" +] diff --git a/sane-sys/Cargo.toml b/sane-sys/Cargo.toml new file mode 100644 index 0000000..9999ae9 --- /dev/null +++ b/sane-sys/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "sane-sys" +version = "0.1.0" +authors = ["Magnus Ulimoen "] +edition = "2018" +links = "sane" +build = "build.rs" +readme = "README.md" + +[dependencies] + +[build-dependencies] +bindgen = "0.54.1" diff --git a/sane-sys/README.md b/sane-sys/README.md new file mode 100644 index 0000000..031daaf --- /dev/null +++ b/sane-sys/README.md @@ -0,0 +1,7 @@ +# sane-sys + +FFI wrapper for the [SANE API](http://www.sane-project.org) for consumption by rustaceans. + +## Prerequisites + +Requires the SANE library to be installed, including the headers when building this library. diff --git a/sane-sys/build.rs b/sane-sys/build.rs new file mode 100644 index 0000000..586417d --- /dev/null +++ b/sane-sys/build.rs @@ -0,0 +1,20 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + println!("cargo:rerun-if-changed=src/wrapper.h"); + println!("cargo:rerun-if-changed=build.rs"); + + println!("cargo:rustc-link-lib=sane"); + + let bindings = bindgen::Builder::default() + .header("src/wrapper.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .generate() + .expect("Unable to generate bindings to SANE"); + + let out_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write SANE bindings"); +} diff --git a/sane-sys/src/lib.rs b/sane-sys/src/lib.rs new file mode 100644 index 0000000..cf6af3c --- /dev/null +++ b/sane-sys/src/lib.rs @@ -0,0 +1,31 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +pub const fn SANE_VERSION_MAJOR(code: SANE_Int) -> SANE_Word { + (code >> 24) as SANE_Word & 0xff +} + +pub const fn SANE_VERSION_MINOR(code: SANE_Int) -> SANE_Word { + (code >> 16) as SANE_Word & 0xff +} + +pub const fn SANE_VERSION_BUILD(code: SANE_Int) -> SANE_Word { + (code >> 0) as SANE_Word & 0xffff +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn smokescreen() { + use std::ptr::null_mut; + let status = unsafe { sane_init(null_mut(), None) }; + assert_eq!(status, SANE_Status_SANE_STATUS_GOOD); + + unsafe { sane_exit() } + } +} diff --git a/sane-sys/src/wrapper.h b/sane-sys/src/wrapper.h new file mode 100644 index 0000000..4ae7d4b --- /dev/null +++ b/sane-sys/src/wrapper.h @@ -0,0 +1 @@ +#include diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}