From 5c17b8c88dc8a4d4a82a0ebf897f91fc0a107fbf Mon Sep 17 00:00:00 2001 From: billow Date: Fri, 10 May 2024 12:00:55 +0800 Subject: [PATCH] Try to fix rust workflow --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ build.rs | 32 ++++++++++++++++++-------------- il-tests/src/main.rs | 2 +- src/wrapper.rs | 2 +- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 280b042..7f177ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -354,6 +354,8 @@ name = "rizin-rs" version = "0.1.2" dependencies = [ "bindgen", + "glob", + "itertools", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ed8a883..733a4f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,8 @@ exclude = ["rizin/*"] [build-dependencies] bindgen = "0.69.4" +glob = "0.3" +itertools = "0.12.1" [profile.dev] rpath = true diff --git a/build.rs b/build.rs index e52367f..a793fd4 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,15 @@ +#![feature(iter_collect_into)] + +use crate::common::search_libs; use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; use std::collections::HashSet; use std::env; use std::error::Error; use std::path::PathBuf; +#[path = "build/common.rs"] +pub mod common; + const IGNORE_MACROS: [&str; 20] = [ "FE_DIVBYZERO", "FE_DOWNWARD", @@ -63,22 +69,15 @@ fn main() -> Result<(), Box> { println!("cargo:rustc-link-lib=dylib={}", lib); } - let rizin_dir = PathBuf::from(env::var("HOME")?).join(".local"); - let lib_dir = rizin_dir.join("lib64"); - if lib_dir.exists() { - println!("cargo:rustc-link-search={}", lib_dir.to_str().unwrap()); - } - let lib_dir = rizin_dir.join("lib"); - if lib_dir.exists() { - println!("cargo:rustc-link-search={}", lib_dir.to_str().unwrap()); - } - + let (lib_dir, _, _) = search_libs(RZ_LIBRARIES, "RIZIN_DIR")?; + println!("cargo:rustc-link-search={}", lib_dir.to_str().unwrap()); println!("cargo:rerun-if-changed=wrapper.h"); - let inc_dir = rizin_dir.join("include"); - let bindings = bindgen::Builder::default() - .header("wrapper.h") - .clang_args([ + let builder = bindgen::Builder::default().header("wrapper.h"); + let builder = if let Ok(dir) = env::var("RIZIN_DIR").or(env::var("HOME")) { + let rizin_dir = PathBuf::from(dir).join(".local"); + let inc_dir = rizin_dir.join("include"); + builder.clang_args([ "-I", inc_dir.to_str().unwrap(), "-I", @@ -88,6 +87,11 @@ fn main() -> Result<(), Box> { "-I", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/", ]) + } else { + builder + }; + + let bindings = builder .derive_default(true) .generate_inline_functions(true) .blocklist_type("u128") diff --git a/il-tests/src/main.rs b/il-tests/src/main.rs index c53bf67..da6ee9b 100644 --- a/il-tests/src/main.rs +++ b/il-tests/src/main.rs @@ -2,7 +2,7 @@ use std::cmp::min; use std::error::Error; use std::fmt; use std::fmt::{Display, Formatter}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use dashmap::DashMap; use hex::ToHex; diff --git a/src/wrapper.rs b/src/wrapper.rs index e75e624..36e455c 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -374,8 +374,8 @@ impl DerefMut for PVector { #[cfg(test)] mod test { - use std::mem::size_of; use crate::wrapper::*; + use std::mem::size_of; #[test] fn test_core() {