Skip to content

Commit 49e56af

Browse files
committed
[fix] In progress (for compile x86_64)
1 parent a49d926 commit 49e56af

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ name = "jpeg"
1111
crate-type = ["staticlib", "cdylib", "rlib"]
1212

1313
[build-dependencies]
14+
anyhow = "1.0.75"
15+
bindgen = "0.69.1"
1416
cc = { version = "1.0.73", features = ["parallel"] }
17+
nasm-rs = { version = "0.2.5", features = ["parallel"] }
1518
# sorse = { version = "0.1.0", registry = "ktra" }
1619
sorse = { path = "../sorse/" }
1720

build.rs

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use anyhow::{Error, Result};
12
use std::env;
23
use std::fs::File;
34
use std::io::{BufRead, BufReader};
45
use std::path::Path;
56
use std::str::FromStr;
6-
pub type Error = Box<dyn std::error::Error>;
7-
pub type Result<T, E = Error> = std::result::Result<T, E>;
7+
// pub type Error = Box<dyn std::error::Error>;
8+
// pub type Result<T, E = Error> = std::result::Result<T, E>;
89

910
static MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
1011

@@ -146,13 +147,13 @@ mod compile {
146147
}
147148

148149
impl FromStr for JpegLib {
149-
type Err = String;
150+
type Err = Error;
150151

151152
fn from_str(s: &str) -> Result<Self, Self::Err> {
152153
match s {
153154
"jpeg8" => Ok(JpegLib::Jpeg8),
154155
"jpeg7" => Ok(JpegLib::Jpeg7),
155-
_ => Err(format!("Unknown jpeg lib: {}", s)),
156+
_ => Err(anyhow::anyhow!("Unknown jpeg lib: {}", s)),
156157
}
157158
}
158159
}
@@ -169,10 +170,10 @@ mod compile {
169170
.strip_prefix("set(VERSION ")
170171
.and_then(|s| s.strip_suffix(')'))
171172
.map(|s| s.to_string())
172-
.ok_or_else(|| "Unable to get version from CMakeLists.txt".into());
173+
.ok_or_else(|| anyhow::anyhow!("Unable to get version from CMakeLists.txt"));
173174
}
174175
}
175-
Err("Unable to get version from CMakeLists.txt".into())
176+
anyhow::bail!("Unable to get version from CMakeLists.txt")
176177
}
177178

178179
fn turbo_version() -> Result<(u32, u32, u32)> {
@@ -411,7 +412,7 @@ mod compile {
411412
None
412413
}
413414
})
414-
.ok_or_else(|| -> Box<dyn std::error::Error> { "failed to find inline".into() })?)
415+
.ok_or_else(|| anyhow::anyhow!("failed to find inline"))?)
415416
}
416417

417418
fn try_build_c(c: &str) -> Result<bool> {
@@ -454,19 +455,15 @@ mod compile {
454455
pub fn simd() -> Result<(PathBuf, String)> {
455456
let target_arch = env::var("CARGO_CFG_TARGET_ARCH")?;
456457
match target_arch.as_str() {
457-
"x86_64" => todo!(),
458+
"x86_64" => simd_x86_64(),
458459
"i386" => todo!(),
459460
"aarch64" => simd_neon(),
460-
_ => Err("Unsupported arch for simd".into()),
461+
_ => Err(anyhow::anyhow!("Unsupported arch for simd")),
461462
}
462463
}
463464

464-
pub fn simd_x86_64() -> Result<()> {
465-
let simd = PathBuf::from(std::env::var("OUT_DIR")?)
466-
.join("libjpeg")
467-
.join("simd");
468-
env::set_current_dir(simd)?;
469-
let asm_sources = [
465+
pub fn simd_x86_64() -> Result<(PathBuf, String)> {
466+
let sources = [
470467
"x86_64/jsimdcpu.asm",
471468
"x86_64/jfdctflt-sse.asm",
472469
"x86_64/jccolor-sse2.asm",
@@ -495,11 +492,25 @@ mod compile {
495492
"x86_64/jidctint-avx2.asm",
496493
"x86_64/jquanti-avx2.asm",
497494
];
495+
496+
let sources: Vec<PathBuf> = sources
497+
.iter()
498+
.map(|s| {
499+
PathBuf::from(MANIFEST_DIR)
500+
.join("vendor")
501+
.join("simd")
502+
.join(s)
503+
})
504+
.collect();
505+
506+
// let sources = sources.iter_mut().map(|src| {
507+
// });
508+
498509
let mut simd = cc::Build::new();
499-
simd.files(asm_sources);
510+
simd.files(sources);
500511
simd.flag("-E");
501-
simd.compile("sss");
502-
Ok(())
512+
simd.compile("sus");
513+
todo!()
503514
}
504515

505516
pub fn simd_neon() -> Result<(PathBuf, String)> {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
// #![no_std]

0 commit comments

Comments
 (0)