Skip to content

Commit

Permalink
[feat] Change some stuff for libraw
Browse files Browse the repository at this point in the history
  • Loading branch information
uttarayan21 committed Feb 7, 2024
1 parent 13239b1 commit a14436e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
13 changes: 0 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ members = [
libraw-sys = { path = "libraw-sys", version = "1.0.0-rc.1", registry = "ktra" }
libraw_r = { path = ".", version = "1.0.0-rc.1", registry = "ktra" }


# [profile.dev]
# opt-level = 0
# debug = true
# debug-assertions = true
# overflow-checks = true
# lto = false
# panic = 'unwind'
# incremental = true
# codegen-units = 256
# rpath = false

# [profile.bench]
[profile.release]
panic = "abort"
debug = true
18 changes: 16 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ pub fn riio(out_dir: impl AsRef<Path>) -> anyhow::Result<()> {
.map(|p| format!("-I{}", p.to_str().unwrap()))
.inspect(|p| println!("cargo:warning=clang_args: {}", p));

bindgen::Builder::default()
let bindings = bindgen::Builder::default()
.header("io/io.h")
.allowlist_file("io/io.h")
.blocklist_type(".*")
.clang_args(clang_args)
.clang_args(clang_args);

let triple = std::env::var("TARGET")?;
let bindings = if triple.ends_with("emscripten") {
// Check emcc
let out = std::process::Command::new("emcc")
.arg("--cflags")
.output()?;
let cflags = String::from_utf8(out.stdout)?;
bindings.clang_args(cflags.split_whitespace())
} else {
bindings
};

bindings
.generate()
.expect("failed to generate bindings")
.write_to_file(out_dir.as_ref().join("io.rs"))
Expand Down
2 changes: 1 addition & 1 deletion io/riio.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int32_t lod_read(struct LibrawOpaqueDatastream *this_,
uintptr_t sz,
uintptr_t nmemb);

int32_t lod_seek(struct LibrawOpaqueDatastream *this_, int64_t offset, uint32_t whence);
int32_t lod_seek(struct LibrawOpaqueDatastream *this_, int64_t offset, int32_t whence);

int64_t lod_tell(struct LibrawOpaqueDatastream *this_);

Expand Down
10 changes: 8 additions & 2 deletions libraw-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#[cfg(feature = "openmp")]
extern crate openmp_sys;

pub use self::bindings::*;

#[cfg(all(windows, target_env = "msvc", not(feature = "bindgen")))]
#[path = "windows.rs"]
mod bindings;
Expand All @@ -26,5 +24,13 @@ mod bindings;
#[path = "linux.rs"]
mod bindings;

#[cfg(all(target_family = "wasm", not(feature = "bindgen")))]
mod bindings {
compile_error!("WebAssembly is not supported without bindgen");
compile_error!("Please enable the `bindgen` feature to generate the bindings");
}

#[cfg(feature = "bindgen")]
mod bindings;

pub use self::bindings::*;
11 changes: 5 additions & 6 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub trait MaybeDebug {}
#[cfg(not(feature = "debug"))]
impl<T> MaybeDebug for T {}


//
// ```c++
// class DllDef LibRaw_abstract_datastream
Expand Down Expand Up @@ -71,13 +70,13 @@ pub trait LibrawDatastream: Read + Seek + Eof + MaybeDebug {
/// # Safety
///
///
unsafe fn seek(&mut self, offset: i64, whence: u32) -> i32 {
unsafe fn seek(&mut self, offset: i64, whence: i32) -> i32 {
match whence {
sys::SEEK_SET => {
libc::SEEK_SET => {
std::io::Seek::seek(self, std::io::SeekFrom::Start(offset as u64)).ok()
}
sys::SEEK_CUR => std::io::Seek::seek(self, std::io::SeekFrom::Current(offset)).ok(),
sys::SEEK_END => std::io::Seek::seek(self, std::io::SeekFrom::End(offset)).ok(),
libc::SEEK_CUR => std::io::Seek::seek(self, std::io::SeekFrom::Current(offset)).ok(),
libc::SEEK_END => std::io::Seek::seek(self, std::io::SeekFrom::End(offset)).ok(),
_ => return 0,
}
.expect("Failed to seek");
Expand Down Expand Up @@ -320,7 +319,7 @@ pub unsafe extern "C" fn lod_read(
pub unsafe extern "C" fn lod_seek(
this: *mut LibrawOpaqueDatastream,
offset: i64,
whence: u32,
whence: i32,
) -> i32 {
assert!(!this.is_null());
let this = unsafe { &mut *this };
Expand Down

0 comments on commit a14436e

Please sign in to comment.