Skip to content

Commit

Permalink
[feat] Use 'emcc --cflags' to pass emscripten flags to clang for bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
uttarayan21 committed Feb 6, 2024
1 parent ab26be0 commit 13239b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion libraw-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ links = "raw_r"
libc = "0.2.123"
libz-sys = { version = "1.1.8", optional = true, features = ["static"], default-features = false }
# We want to switch out to libjpeg-turbo but currently the build system depends cmake and doesn't build on windows for some reason
mozjpeg-sys = { version = "1.0", optional = true, features = ["jpeg80_abi"], registry = "ktra" }
# mozjpeg-sys = { version = "1.0", optional = true, features = ["jpeg80_abi"], registry = "ktra" }
mozjpeg-sys = { git = "https://github.com/uttarayan21/mozjpeg-sys", optional = true, features = ["jpeg80_abi"] }
openmp-sys = { version = "1.2.3", optional = true }

[build-dependencies]
Expand Down
30 changes: 21 additions & 9 deletions libraw-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,30 @@ fn build(out_dir: impl AsRef<Path>, libraw_dir: impl AsRef<Path>) -> Result<()>

#[cfg(feature = "bindgen")]
fn bindings(out_dir: impl AsRef<Path>, libraw_dir: impl AsRef<Path>) -> Result<()> {
let bindings = bindgen::Builder::default()
.header(
libraw_dir
.as_ref()
.join("libraw")
.join("libraw.h")
.to_string_lossy(),
)
let bindings = bindgen::Builder::default().header(
libraw_dir
.as_ref()
.join("libraw")
.join("libraw.h")
.to_string_lossy(),
);
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
};

let bindings = bindings
.use_core()
.ctypes_prefix("libc")
.generate_comments(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// API improvements
.derive_eq(true)
.size_t_is_usize(true)
Expand Down

0 comments on commit 13239b1

Please sign in to comment.