Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion mupdf-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ fn cp_r(dir: &Path, dest: &Path, excluding_dir_names: &'static [&'static str]) {
}
}

const CPU_FLAGS: &[(&str, &str)] = &[
("sse4.1", "HAVE_SSE4_1"),
("avx", "HAVE_AVX"),
("avx2", "HAVE_AVX2"),
("fma", "HAVE_FMA"),
// ("neon", "HAVE_NEON"),
];

#[cfg(not(target_env = "msvc"))]
fn build_libmupdf() {
use std::process::Command;

let features_var =
std::env::var("CARGO_CFG_TARGET_FEATURE").expect("We need cargo to build this");
let target_features = features_var.split(',').collect::<Vec<_>>();

let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) {
"bench" | "release" => "release",
_ => "debug",
Expand Down Expand Up @@ -117,6 +129,12 @@ fn build_libmupdf() {
"verbose=yes".to_owned(),
];

for (feature, flag) in CPU_FLAGS {
if target_features.contains(feature) {
make_flags.push(format!("{flag}=yes"));
}
}

// this may be unused if none of the features below are enabled
#[allow(unused_variables, unused_mut)]
let mut add_lib = |cflags_name: &'static str, pkgcfg_name: &'static str| {
Expand Down Expand Up @@ -171,11 +189,31 @@ fn build_libmupdf() {
let cxx = cxx_compiler.path().to_string_lossy();
let cxx_flags = cxx_compiler.cflags_env();

let feature_cflags = CPU_FLAGS
.iter()
.map(|(f, _)| f)
.filter(|f| target_features.contains(f))
.map(|f| format!("-m{f}"))
.collect::<Vec<_>>();

#[cfg(target_arch = "x86_64")]
{
make_flags.push("XCFLAGS='-msse4.1'".to_owned());
}

println!("cargo::warning=using feature_cflags {feature_cflags:?}");

make_flags.push(format!("CC={}", cc));
make_flags.push(format!("CXX={}", cxx));
make_flags.push(format!("XCFLAGS={}", c_flags.to_string_lossy()));
make_flags.push(format!(
"XCFLAGS={} {}",
c_flags.to_string_lossy(),
feature_cflags.join(" ")
));
make_flags.push(format!("XCXXFLAGS={}", cxx_flags.to_string_lossy()));

println!("cargo::warning=using make_flags {make_flags:?}");

// Enable parallel compilation
if let Ok(n) = std::thread::available_parallelism() {
make_flags.push(format!("-j{}", n));
Expand Down Expand Up @@ -256,6 +294,7 @@ fn build_libmupdf() {
if cfg!(not(feature = "js")) {
cl_env.push("/DFZ_ENABLE_JS#0".to_string());
}

// Enable parallel compilation
cl_env.push("/MP".to_string());
let d = msbuild
Expand Down Expand Up @@ -474,6 +513,10 @@ fn main() {
if cfg!(target_os = "android") {
build.flag("-DHAVE_ANDROID").flag_if_supported("-std=c99");
}
#[cfg(target_arch = "x86_64")]
{
build.flag("-DARCH_HAS_SSE=1");
}
build.compile("libmupdf-wrapper.a");

let bindings = bindgen::Builder::default()
Expand Down
2 changes: 1 addition & 1 deletion mupdf-sys/mupdf
Submodule mupdf updated 373 files
13 changes: 13 additions & 0 deletions mupdf-sys/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3281,3 +3281,16 @@ int32_t mupdf_highlight_selection(fz_context *ctx, fz_stext_page *page, fz_point
}
return count;
}

int32_t mupdf_search_stext_page_cb(fz_context *ctx, fz_stext_page *page, const char *needle, fz_search_callback_fn *cb, void *opaque, mupdf_error_t **errptr) {
int32_t count = 0;
fz_try(ctx)
{
count = fz_search_stext_page_cb(ctx, page, needle, cb, opaque);
}
fz_catch(ctx)
{
mupdf_save_error(ctx, errptr);
}
return count;
}
6 changes: 3 additions & 3 deletions src/colorspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ mod test {
)
.unwrap();
assert_eq!(n, 3);
assert!((0.6..0.7).contains(&gray[0]));
assert!((0.6..0.7).contains(&gray[1]));
assert!((0.6..0.7).contains(&gray[2]));
assert!((0.59..0.61).contains(&gray[0]), "gray = {:?}", gray);
assert!((0.59..0.61).contains(&gray[1]), "gray = {:?}", gray);
assert!((0.59..0.61).contains(&gray[2]), "gray = {:?}", gray);
assert_eq!(gray[3], 0.0);
}
}
12 changes: 6 additions & 6 deletions src/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ mod test {
[Quad {
ul: Point {
x: 56.8,
y: 69.32512
y: 69.32953
},
ur: Point {
x: 115.85405,
y: 69.32512
x: 115.85159,
y: 69.32953
},
ll: Point {
x: 56.8,
y: 87.311844
y: 87.29713
},
lr: Point {
x: 115.85405,
y: 87.311844
x: 115.85159,
y: 87.29713
}
}]
);
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ unsafe fn rust_vec_from_ffi_ptr<R: FFIAnalogue>(
ptr: *mut R::FFIType,
len: i32,
) -> Result<FzArray<R>, Error> {
println!("being called with ptr {ptr:?}, len {len}");

let Some(ptr) = NonNull::new(ptr) else {
return Err(Error::UnexpectedNullPtr);
};
Expand Down
14 changes: 7 additions & 7 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,20 @@ mod test {
[Quad {
ul: Point {
x: 56.8,
y: 69.32512,
y: 69.32953
},
ur: Point {
x: 115.85405,
y: 69.32512,
x: 115.85159,
y: 69.32953
},
ll: Point {
x: 56.8,
y: 87.311844,
y: 87.29713
},
lr: Point {
x: 115.85405,
y: 87.311844,
},
x: 115.85159,
y: 87.29713
}
}]
);

Expand Down
Loading
Loading