Add dynamic_linage feature
This commit is contained in:
parent
8fb4b45f57
commit
f49f62ecef
@ -41,3 +41,4 @@ pkg-config = { version = "0.3" }
|
|||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
build_unicorn_cmake = []
|
build_unicorn_cmake = []
|
||||||
|
dynamic_linkage = []
|
@ -84,12 +84,17 @@ fn build_with_cmake() {
|
|||||||
config.generator("Ninja");
|
config.generator("Ninja");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !cfg!(feature = "dynamic_linkage") {
|
||||||
|
config.define("BUILD_SHARED_LIBS", "OFF");
|
||||||
|
} else {
|
||||||
|
config.define("BUILD_SHARED_LIBS", "ON");
|
||||||
|
}
|
||||||
|
|
||||||
// need to clear build target and append "build" to the path because
|
// need to clear build target and append "build" to the path because
|
||||||
// unicorn's CMakeLists.txt doesn't properly support 'install', so we use
|
// unicorn's CMakeLists.txt doesn't properly support 'install', so we use
|
||||||
// the build artifacts from the build directory, which cmake crate sets
|
// the build artifacts from the build directory, which cmake crate sets
|
||||||
// to "<out_dir>/build/"
|
// to "<out_dir>/build/"
|
||||||
let dst = config
|
let dst = config
|
||||||
.define("BUILD_SHARED_LIBS", "OFF")
|
|
||||||
.define("UNICORN_BUILD_TESTS", "OFF")
|
.define("UNICORN_BUILD_TESTS", "OFF")
|
||||||
.define("UNICORN_INSTALL", "OFF")
|
.define("UNICORN_INSTALL", "OFF")
|
||||||
.no_build_target(true)
|
.no_build_target(true)
|
||||||
@ -99,8 +104,13 @@ fn build_with_cmake() {
|
|||||||
dst.join("build").display()
|
dst.join("build").display()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Lazymio(@wtdcode): Why do I stick to static link? See: https://github.com/rust-lang/cargo/issues/5077
|
// Lazymio(@wtdcode): Dynamic linkage might not work with local installation.
|
||||||
println!("cargo:rustc-link-lib=static=unicorn");
|
// See: https://github.com/rust-lang/cargo/issues/5077
|
||||||
|
if !cfg!(feature = "dynamic_linkage") {
|
||||||
|
println!("cargo:rustc-link-lib=static=unicorn");
|
||||||
|
} else {
|
||||||
|
println!("cargo:rustc-link-lib=dylib=unicorn");
|
||||||
|
}
|
||||||
if !compiler.is_like_msvc() {
|
if !compiler.is_like_msvc() {
|
||||||
println!("cargo:rustc-link-lib=pthread");
|
println!("cargo:rustc-link-lib=pthread");
|
||||||
println!("cargo:rustc-link-lib=m");
|
println!("cargo:rustc-link-lib=m");
|
||||||
@ -111,11 +121,11 @@ fn main() {
|
|||||||
if cfg!(feature = "build_unicorn_cmake") {
|
if cfg!(feature = "build_unicorn_cmake") {
|
||||||
build_with_cmake();
|
build_with_cmake();
|
||||||
} else {
|
} else {
|
||||||
if !pkg_config::Config::new()
|
let mut config = pkg_config::Config::new();
|
||||||
.atleast_version("2")
|
if !cfg!(feature = "dynamic_linkage") {
|
||||||
.probe("unicorn")
|
config.statik(true);
|
||||||
.is_ok()
|
}
|
||||||
{
|
if !config.atleast_version("2").probe("unicorn").is_ok() {
|
||||||
build_with_cmake();
|
build_with_cmake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user