reverted build.rs
This commit is contained in:
@ -18,12 +18,7 @@ fn find_unicorn(unicorn_dir: &Path) -> Option<PathBuf> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn out_dir() -> PathBuf {
|
fn download_unicorn() -> Option<String> {
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
|
||||||
Path::new(&out_dir).to_path_buf()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn download_unicorn() -> PathBuf {
|
|
||||||
// https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-tar
|
// https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-tar
|
||||||
let pkg_version;
|
let pkg_version;
|
||||||
if let Ok(unicorn_version) = env::var("UNICORN_VERSION") {
|
if let Ok(unicorn_version) = env::var("UNICORN_VERSION") {
|
||||||
@ -31,7 +26,7 @@ fn download_unicorn() -> PathBuf {
|
|||||||
} else {
|
} else {
|
||||||
pkg_version = env::var("CARGO_PKG_VERSION").unwrap();
|
pkg_version = env::var("CARGO_PKG_VERSION").unwrap();
|
||||||
}
|
}
|
||||||
let out_dir = out_dir();
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
let resp = client
|
let resp = client
|
||||||
.get(format!(
|
.get(format!(
|
||||||
@ -48,107 +43,85 @@ fn download_unicorn() -> PathBuf {
|
|||||||
let mut archive = Archive::new(tar);
|
let mut archive = Archive::new(tar);
|
||||||
archive.unpack(&out_dir).unwrap();
|
archive.unpack(&out_dir).unwrap();
|
||||||
|
|
||||||
find_unicorn(&out_dir).unwrap()
|
match find_unicorn(&out_dir) {
|
||||||
|
Some(dir) => Some(String::from(out_dir.join(dir).to_str()?)),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::branches_sharing_code)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let profile = env::var("PROFILE").unwrap();
|
let profile = env::var("PROFILE").unwrap();
|
||||||
|
|
||||||
if let Some(unicorn_dir) = find_unicorn(&out_dir()) {
|
let unicorn_dir = download_unicorn().unwrap();
|
||||||
let rust_build_path = unicorn_dir.join("rust_build");
|
|
||||||
|
println!("cargo:rerun-if-changed={}", &unicorn_dir);
|
||||||
|
|
||||||
|
// We don't use TARGET since we can't cross-build.
|
||||||
|
if env::consts::OS == "windows" {
|
||||||
|
// Windows
|
||||||
|
let mut cmd = Command::new("cmake");
|
||||||
|
cmd.current_dir(&unicorn_dir)
|
||||||
|
.arg("-B")
|
||||||
|
.arg("rust_build")
|
||||||
|
.arg("-DUNICORN_BUILD_SHARED=off")
|
||||||
|
.arg("-G")
|
||||||
|
.arg("Visual Studio 16 2019");
|
||||||
|
|
||||||
|
if profile == "debug" {
|
||||||
|
cmd.arg("-DCMAKE_BUILD_TYPE=Debug");
|
||||||
|
} else {
|
||||||
|
cmd.arg("-DCMAKE_BUILD_TYPE=Release");
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.output()
|
||||||
|
.expect("Fail to create build directory on Windows.");
|
||||||
|
|
||||||
|
let mut platform = "x64";
|
||||||
|
let mut conf = "Release";
|
||||||
|
if std::mem::size_of::<usize>() == 4 {
|
||||||
|
platform = "Win32";
|
||||||
|
}
|
||||||
|
if profile == "debug" {
|
||||||
|
conf = "Debug";
|
||||||
|
}
|
||||||
|
|
||||||
|
Command::new("msbuild")
|
||||||
|
.current_dir(format!("{}/rust_build", &unicorn_dir))
|
||||||
|
.arg("unicorn.sln")
|
||||||
|
.arg("-m")
|
||||||
|
.arg("-p:Platform=".to_owned() + platform)
|
||||||
|
.arg("-p:Configuration=".to_owned() + conf)
|
||||||
|
.output()
|
||||||
|
.expect("Fail to build unicorn on Win32.");
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-link-search={}",
|
"cargo:rustc-link-search={}/rust_build/{}",
|
||||||
rust_build_path.to_str().unwrap()
|
unicorn_dir, conf
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}",
|
|
||||||
rust_build_path.join("Debug").to_str().unwrap()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}",
|
|
||||||
rust_build_path.join("Release").to_str().unwrap()
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let unicorn_dir = if env::var("CI").is_ok() {
|
// Most Unix-like systems
|
||||||
Path::new("..").join("..")
|
|
||||||
} else {
|
|
||||||
println!("cargo:warning=Unicorn not found. Downloading...");
|
|
||||||
download_unicorn()
|
|
||||||
};
|
|
||||||
|
|
||||||
let rust_build_path = unicorn_dir.join("rust_build");
|
|
||||||
|
|
||||||
let mut cmd = Command::new("cmake");
|
let mut cmd = Command::new("cmake");
|
||||||
|
cmd.current_dir(&unicorn_dir)
|
||||||
|
.arg("-B")
|
||||||
|
.arg("rust_build")
|
||||||
|
.arg("-DUNICORN_BUILD_SHARED=off");
|
||||||
|
|
||||||
// We don't use TARGET since we can't cross-build.
|
if profile == "debug" {
|
||||||
if env::consts::OS == "windows" {
|
cmd.arg("-DCMAKE_BUILD_TYPE=Debug");
|
||||||
// Windows
|
|
||||||
cmd.current_dir(&unicorn_dir)
|
|
||||||
.arg("-B")
|
|
||||||
.arg("rust_build")
|
|
||||||
.arg("-DUNICORN_BUILD_SHARED=off")
|
|
||||||
.arg("-G")
|
|
||||||
.arg("Visual Studio 16 2019");
|
|
||||||
|
|
||||||
if profile == "debug" {
|
|
||||||
cmd.arg("-DCMAKE_BUILD_TYPE=Debug");
|
|
||||||
} else {
|
|
||||||
cmd.arg("-DCMAKE_BUILD_TYPE=Release");
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.output()
|
|
||||||
.expect("Fail to create build directory on Windows.");
|
|
||||||
|
|
||||||
let mut platform = "x64";
|
|
||||||
let mut conf = "Release";
|
|
||||||
if std::mem::size_of::<usize>() == 4 {
|
|
||||||
platform = "Win32";
|
|
||||||
}
|
|
||||||
if profile == "debug" {
|
|
||||||
conf = "Debug";
|
|
||||||
}
|
|
||||||
|
|
||||||
Command::new("msbuild")
|
|
||||||
.current_dir(&rust_build_path)
|
|
||||||
.arg("unicorn.sln")
|
|
||||||
.arg("-m")
|
|
||||||
.arg("-p:Platform=".to_owned() + platform)
|
|
||||||
.arg("-p:Configuration=".to_owned() + conf)
|
|
||||||
.output()
|
|
||||||
.expect("Fail to build unicorn on Win32.");
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}",
|
|
||||||
rust_build_path.join(conf).to_str().unwrap()
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Most Unix-like systems
|
cmd.arg("-DCMAKE_BUILD_TYPE=Release");
|
||||||
let mut cmd = Command::new("cmake");
|
|
||||||
cmd.current_dir(&unicorn_dir)
|
|
||||||
.arg("-B")
|
|
||||||
.arg("rust_build")
|
|
||||||
.arg("-DUNICORN_BUILD_SHARED=off");
|
|
||||||
|
|
||||||
if profile == "debug" {
|
|
||||||
cmd.arg("-DCMAKE_BUILD_TYPE=Debug");
|
|
||||||
} else {
|
|
||||||
cmd.arg("-DCMAKE_BUILD_TYPE=Release");
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.output()
|
|
||||||
.expect("Fail to create build directory on *nix.");
|
|
||||||
|
|
||||||
Command::new("make")
|
|
||||||
.current_dir(&rust_build_path)
|
|
||||||
.arg("-j6")
|
|
||||||
.output()
|
|
||||||
.expect("Fail to build unicorn on *nix.");
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search={}",
|
|
||||||
rust_build_path.to_str().unwrap()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.output()
|
||||||
|
.expect("Fail to create build directory on *nix.");
|
||||||
|
|
||||||
|
Command::new("make")
|
||||||
|
.current_dir(format!("{}/rust_build", &unicorn_dir))
|
||||||
|
.arg("-j6")
|
||||||
|
.output()
|
||||||
|
.expect("Fail to build unicorn on *nix.");
|
||||||
|
|
||||||
|
println!("cargo:rustc-link-search={}/rust_build", unicorn_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a workaround for Unicorn static link since libunicorn.a is also linked again lib*-softmmu.a.
|
// This is a workaround for Unicorn static link since libunicorn.a is also linked again lib*-softmmu.a.
|
||||||
@ -157,7 +130,7 @@ fn main() {
|
|||||||
//
|
//
|
||||||
// Lazymio(@wtdcode): Why do I stick to static link? See: https://github.com/rust-lang/cargo/issues/5077
|
// Lazymio(@wtdcode): Why do I stick to static link? See: https://github.com/rust-lang/cargo/issues/5077
|
||||||
println!("cargo:rustc-link-lib=unicorn");
|
println!("cargo:rustc-link-lib=unicorn");
|
||||||
for arch in &[
|
for arch in [
|
||||||
"x86_64",
|
"x86_64",
|
||||||
"arm",
|
"arm",
|
||||||
"armeb",
|
"armeb",
|
||||||
@ -174,11 +147,10 @@ fn main() {
|
|||||||
"m68k",
|
"m68k",
|
||||||
"ppc",
|
"ppc",
|
||||||
"ppc64",
|
"ppc64",
|
||||||
] {
|
]
|
||||||
|
.iter()
|
||||||
|
{
|
||||||
println!("cargo:rustc-link-lib={}-softmmu", arch);
|
println!("cargo:rustc-link-lib={}-softmmu", arch);
|
||||||
}
|
}
|
||||||
println!("cargo:rustc-link-lib=unicorn-common");
|
println!("cargo:rustc-link-lib=unicorn-common");
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
println!("cargo:rerun-if-changed=src");
|
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,12 @@ extern "C" {
|
|||||||
|
|
||||||
pub struct UcHook<'a, D: 'a, F: 'a> {
|
pub struct UcHook<'a, D: 'a, F: 'a> {
|
||||||
pub callback: F,
|
pub callback: F,
|
||||||
pub uc: Unicorn<'a, D>,
|
pub uc: Unicorn,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IsUcHook<'a> {}
|
pub trait IsUcHook {}
|
||||||
|
|
||||||
impl<'a, D, F> IsUcHook<'a> for UcHook<'a, D, F> {}
|
impl<'a, D, F> IsUcHook for UcHook<'a, D, F> {}
|
||||||
|
|
||||||
pub extern "C" fn code_hook_proxy<D, F>(
|
pub extern "C" fn code_hook_proxy<D, F>(
|
||||||
uc: uc_handle,
|
uc: uc_handle,
|
||||||
|
@ -77,16 +77,15 @@ impl Drop for Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UnicornInner<'a, D> {
|
pub struct UnicornInner {
|
||||||
pub uc: uc_handle,
|
pub uc: uc_handle,
|
||||||
pub arch: Arch,
|
pub arch: Arch,
|
||||||
/// to keep ownership over the hook for this uc instance's lifetime
|
/// to keep ownership over the hook for this uc instance's lifetime
|
||||||
pub hooks: Vec<(ffi::uc_hook, Box<dyn ffi::IsUcHook<'a> + 'a>)>,
|
pub hooks: Vec<(ffi::uc_hook, Box<dyn ffi::IsUcHook>)>,
|
||||||
pub data: D,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drop UC
|
/// Drop UC
|
||||||
impl<'a, D> Drop for UnicornInner<'a, D> {
|
impl Drop for UnicornInner {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if !self.uc.is_null() {
|
if !self.uc.is_null() {
|
||||||
unsafe { ffi::uc_close(self.uc) };
|
unsafe { ffi::uc_close(self.uc) };
|
||||||
@ -96,25 +95,25 @@ impl<'a, D> Drop for UnicornInner<'a, D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A Unicorn emulator instance.
|
/// A Unicorn emulator instance.
|
||||||
pub struct Unicorn<'a, D: 'a> {
|
pub struct Unicorn {
|
||||||
inner: Rc<UnsafeCell<UnicornInner<'a, D>>>,
|
inner: Rc<UnsafeCell<UnicornInner<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Unicorn<'a, ()> {
|
impl<'a> Unicorn<'a> {
|
||||||
/// Create a new instance of the unicorn engine for the specified architecture
|
/// Create a new instance of the unicorn engine for the specified architecture
|
||||||
/// and hardware mode.
|
/// and hardware mode.
|
||||||
pub fn new(arch: Arch, mode: Mode) -> Result<Unicorn<'a, ()>, uc_error> {
|
pub fn new(arch: Arch, mode: Mode) -> Result<Unicorn<'a>, uc_error> {
|
||||||
Self::new_with_data(arch, mode, ())
|
Self::new_with_data(arch, mode, ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, D> Unicorn<'a, D>
|
impl<'a, D> Unicorn<'a>
|
||||||
where
|
where
|
||||||
D: 'a,
|
D: 'a,
|
||||||
{
|
{
|
||||||
/// Create a new instance of the unicorn engine for the specified architecture
|
/// Create a new instance of the unicorn engine for the specified architecture
|
||||||
/// and hardware mode.
|
/// and hardware mode.
|
||||||
pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result<Unicorn<'a, D>, uc_error> {
|
pub fn new_with_data(arch: Arch, mode: Mode, data: D) -> Result<Unicorn<'a>, uc_error> {
|
||||||
let mut handle = core::ptr::null_mut();
|
let mut handle = core::ptr::null_mut();
|
||||||
let err = unsafe { ffi::uc_open(arch, mode, &mut handle) };
|
let err = unsafe { ffi::uc_open(arch, mode, &mut handle) };
|
||||||
if err == uc_error::OK {
|
if err == uc_error::OK {
|
||||||
|
Reference in New Issue
Block a user