Skip to content

Commit a49d926

Browse files
committed
[fix] Use CARGO_CFG_TARGET_POINTER_WIDTH instead of mem::size_of
1 parent 02039a6 commit a49d926

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ links = "jpeg"
99
[lib]
1010
name = "jpeg"
1111
crate-type = ["staticlib", "cdylib", "rlib"]
12-
links = "jpeg"
1312

1413
[build-dependencies]
1514
cc = { version = "1.0.73", features = ["parallel"] }
16-
itoa = { version = "1.0.4" }
1715
# sorse = { version = "0.1.0", registry = "ktra" }
1816
sorse = { path = "../sorse/" }
1917

build.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ mod compile {
268268
jconfigint.write_all(b"#undef inline")?;
269269
let inline = inline(&compiler, env("FORCE_INLINE", true))?;
270270
jconfigint.define("INLINE", inline);
271+
let target_pointer_width: u8 = env::var("CARGO_CFG_TARGET_POINTER_WIDTH")?.parse()?;
271272
jconfigint.define(
272273
"SIZEOF_SIZE_T",
273-
itoa::Buffer::new().format(core::mem::size_of::<usize>()),
274+
(target_pointer_width / 8).to_string().as_str(),
274275
);
275276

276277
let thread_local = if compiler.is_like_msvc() {
@@ -298,13 +299,14 @@ mod compile {
298299
jconfigint.define("HAVE_INTRIN_H", None);
299300
}
300301
if compiler.is_like_msvc() && have_intin_h {
301-
if core::mem::size_of::<usize>() == 8 {
302-
jconfigint.define("HAVE__BITSCANFORWARD", None);
303-
} else {
302+
if target_pointer_width == 64 {
304303
jconfigint.define("HAVE__BITSCANFORWARD64", None);
304+
} else if target_pointer_width == 32 {
305+
jconfigint.define("HAVE__BITSCANFORWARD", None);
305306
}
306307
}
307-
let fallthrough = r##"
308+
jconfigint.write_all(
309+
br##"
308310
#if defined(__has_attribute)
309311
#if __has_attribute(fallthrough)
310312
#define FALLTHROUGH __attribute__((fallthrough));
@@ -314,9 +316,8 @@ mod compile {
314316
#else
315317
#define FALLTHROUGH
316318
#endif
317-
"##;
318-
use std::io::Write;
319-
jconfigint.write_all(fallthrough.as_bytes())?;
319+
"##,
320+
)?;
320321
jconfigint.write()?;
321322

322323
Ok(())
@@ -330,10 +331,7 @@ mod compile {
330331
);
331332

332333
let jpeg_lib_version = jpeg_lib_version()?;
333-
jconfig.define(
334-
"JPEG_LIB_VERSION",
335-
itoa::Buffer::new().format(jpeg_lib_version),
336-
);
334+
jconfig.define("JPEG_LIB_VERSION", jpeg_lib_version.to_string().as_str());
337335

338336
jconfig.define("LIBJPEG_TURBO_VERSION", version()?.as_str());
339337
let turbo_version = turbo_version()?;

0 commit comments

Comments
 (0)