Start of the project
This commit is contained in:
		
							
								
								
									
										13
									
								
								sane-sys/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								sane-sys/Cargo.toml
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										7
									
								
								sane-sys/README.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										20
									
								
								sane-sys/build.rs
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										31
									
								
								sane-sys/src/lib.rs
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										1
									
								
								sane-sys/src/wrapper.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
#include <sane/sane.h>
 | 
			
		||||
		Reference in New Issue
	
	Block a user