Browse Source

Start of the project

master
Magnus Ulimoen 3 years ago
commit
14365ec9be
  1. 2
      .gitignore
  2. 12
      Cargo.toml
  3. 13
      sane-sys/Cargo.toml
  4. 7
      sane-sys/README.md
  5. 20
      sane-sys/build.rs
  6. 31
      sane-sys/src/lib.rs
  7. 1
      sane-sys/src/wrapper.h
  8. 3
      src/main.rs

2
.gitignore vendored

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

12
Cargo.toml

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

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

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

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

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

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

3
src/main.rs

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