Start of the project

This commit is contained in:
Magnus Ulimoen 2020-07-23 22:28:15 +02:00
commit 14365ec9be
8 changed files with 89 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "skanny"
version = "0.1.0"
authors = ["Magnus Ulimoen <magnus@ulimoen.dev>"]
edition = "2018"
[dependencies]
[workspace]
members = [
"sane-sys"
]

13
sane-sys/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "sane-sys"
version = "0.1.0"
authors = ["Magnus Ulimoen <magnus@ulimoen.dev>"]
edition = "2018"
links = "sane"
build = "build.rs"
readme = "README.md"
[dependencies]
[build-dependencies]
bindgen = "0.54.1"

7
sane-sys/README.md Normal file
View File

@ -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.

20
sane-sys/build.rs Normal file
View File

@ -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");
}

31
sane-sys/src/lib.rs Normal file
View File

@ -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() }
}
}

1
sane-sys/src/wrapper.h Normal file
View File

@ -0,0 +1 @@
#include <sane/sane.h>

3
src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}