Remove use_system_unicorn and build_with_cmake

This commit is contained in:
2022-05-06 14:46:50 +02:00
parent a54dfda14d
commit 20c0a4b643
2 changed files with 14 additions and 26 deletions

View File

@@ -34,12 +34,10 @@ bitflags = "1.3"
libc = "0.2" libc = "0.2"
[build-dependencies] [build-dependencies]
cc = { optional = true, version = "1.0" } cc = { version = "1.0" }
cmake = { optional = true, version = "0.1" } cmake = { version = "0.1" }
pkg-config = { optional = true, version = "0.3" } pkg-config = { version = "0.3" }
[features] [features]
default = ["build_unicorn_cmake"] default = []
build_unicorn_cmake = ["cc", "cmake"]
use_system_unicorn = ["pkg-config"]
dynamic_linkage = [] dynamic_linkage = []

View File

@@ -1,23 +1,16 @@
#[cfg(feature = "use_system_unicorn")]
use pkg_config; use pkg_config;
#[cfg(feature = "build_unicorn_cmake")]
use std::env; use std::env;
#[cfg(feature = "build_unicorn_cmake")]
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(feature = "build_unicorn_cmake")]
use std::process::Command; use std::process::Command;
#[cfg(all(feature = "build_unicorn_cmake"))]
fn ninja_available() -> bool { fn ninja_available() -> bool {
Command::new("ninja").arg("--version").spawn().is_ok() Command::new("ninja").arg("--version").spawn().is_ok()
} }
#[cfg(all(feature = "build_unicorn_cmake"))]
fn msvc_cmake_tools_available() -> bool { fn msvc_cmake_tools_available() -> bool {
Command::new("cmake").arg("--version").spawn().is_ok() && ninja_available() Command::new("cmake").arg("--version").spawn().is_ok() && ninja_available()
} }
#[cfg(all(feature = "build_unicorn_cmake"))]
fn setup_env_msvc(compiler: &cc::Tool) { fn setup_env_msvc(compiler: &cc::Tool) {
// If PATH already contains what we need, skip this // If PATH already contains what we need, skip this
if msvc_cmake_tools_available() { if msvc_cmake_tools_available() {
@@ -67,7 +60,6 @@ fn setup_env_msvc(compiler: &cc::Tool) {
} }
} }
#[cfg(feature = "build_unicorn_cmake")]
fn build_with_cmake() { fn build_with_cmake() {
let uc_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let uc_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let compiler = cc::Build::new().get_compiler(); let compiler = cc::Build::new().get_compiler();
@@ -119,14 +111,12 @@ fn build_with_cmake() {
} }
fn main() { fn main() {
if cfg!(feature = "use_system_unicorn") { match pkg_config::Config::new()
#[cfg(feature = "use_system_unicorn")]
{
let lib = pkg_config::Config::new()
.atleast_version("2") .atleast_version("2")
.cargo_metadata(false) .cargo_metadata(false)
.probe("unicorn") .probe("unicorn")
.expect("Fail to find globally installed unicorn"); {
Ok(lib) => {
for dir in lib.link_paths { for dir in lib.link_paths {
println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap()); println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap());
} }
@@ -139,8 +129,8 @@ fn main() {
println!("cargo:rustc-link-lib=m"); println!("cargo:rustc-link-lib=m");
} }
} }
} else { Err(_) => {
#[cfg(feature = "build_unicorn_cmake")]
build_with_cmake(); build_with_cmake();
} }
};
} }