- replace anyhow with custom error type
This commit is contained in:
40
build.rs
40
build.rs
@@ -1,6 +1,5 @@
|
||||
extern crate bindgen;
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -10,15 +9,36 @@ use std::fmt::Debug;
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
use bindgen::callbacks::ItemInfo;
|
||||
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
use regex::Regex;
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
struct Error(String);
|
||||
|
||||
impl Debug for Error {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl Error {
|
||||
fn msg<S: ToString>(msg: S) -> Box<dyn std::error::Error> {
|
||||
Box::new(Error(msg.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if env::var("DOCS_RS").is_err() {
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR")?).canonicalize()?;
|
||||
let libczi_dir = PathBuf::from("libczi");
|
||||
let libczi_src = libczi_dir.join("Src/libCZI");
|
||||
let libcziapi_inc = libczi_dir.join("Src/libCZIAPI/inc");
|
||||
@@ -41,9 +61,9 @@ fn main() -> Result<()> {
|
||||
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
let bindings = {
|
||||
let mut libcziapi_a = out_dir.join("build/Src/libCZIAPI/liblibCZIAPIStatic.a");
|
||||
let mut libcziapi_a = dst.join("build/Src/libCZIAPI/liblibCZIAPIStatic.a");
|
||||
if !libcziapi_a.exists() {
|
||||
libcziapi_a = out_dir.join("build/Src/libCZIAPI/liblibCZIAPIStatic.lib");
|
||||
libcziapi_a = dst.join("build/Src/libCZIAPI/liblibCZIAPIStatic.lib");
|
||||
}
|
||||
bindgen::Builder::default().parse_callbacks(Box::new(DeMangler::new(libcziapi_a)?))
|
||||
};
|
||||
@@ -78,7 +98,7 @@ fn main() -> Result<()> {
|
||||
)
|
||||
.generate()?;
|
||||
|
||||
bindings.write_to_file(out_dir.join("lib_czi_api.rs"))?;
|
||||
bindings.write_to_file(dst.join("lib_czi_api.rs"))?;
|
||||
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
{
|
||||
@@ -131,7 +151,7 @@ struct DeMangler {
|
||||
|
||||
#[cfg(not(feature = "dynamic"))]
|
||||
impl DeMangler {
|
||||
fn new(a_file: PathBuf) -> Result<Self> {
|
||||
fn new(a_file: PathBuf) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let cmd = std::process::Command::new("nm").arg(&a_file).output()?;
|
||||
let pat = Regex::new(r"^[\da-f]*\s[A-Z]\s(.*_Z(\d+)(libCZI_.*))$")?;
|
||||
let mut map = HashMap::new();
|
||||
|
||||
Reference in New Issue
Block a user