mirror of
https://github.com/0xNikilite/oboromi.git
synced 2026-01-31 01:15:22 +01:00
Improve Boost patching and add Zydis/ZYCore linking
Enhanced the Boost patching logic in build.rs to handle multiple patterns and use CARGO_CFG_TARGET_OS for platform detection. Added static linking for Zydis and ZYCore libraries.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
/oboromi.log
|
||||
/third_party/boost_1_89_0
|
||||
@@ -5,47 +5,48 @@ use std::fs;
|
||||
|
||||
fn patch_boost_for_macos() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// This patch is specifically for macOS to fix the Boost hash issue
|
||||
if !cfg!(target_os = "macos") {
|
||||
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||
if target_os != "macos" {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let file_path = "../third_party/ext-boost/boost/container_hash/hash.hpp";
|
||||
let path = Path::new(file_path);
|
||||
|
||||
|
||||
if !path.exists() {
|
||||
println!("cargo:warning=Boost hash.hpp not found at {}, skipping patch", file_path);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let content = fs::read_to_string(path)?;
|
||||
|
||||
let target = "struct hash_base : std::unary_function<T, std::size_t> {};";
|
||||
|
||||
if content.contains(target) {
|
||||
let patched_content = content.replace(
|
||||
target,
|
||||
"struct hash_base { typedef T argument_type; typedef std::size_t result_type; };"
|
||||
);
|
||||
fs::write(path, patched_content)?;
|
||||
println!("cargo:warning=Successfully patched Boost for macOS compatibility");
|
||||
println!("cargo:warning=Replaced unary_function inheritance with typedefs");
|
||||
} else {
|
||||
let previous_target = "struct hash_base : boost::unary_function<T, std::size_t> {};";
|
||||
if content.contains(previous_target) {
|
||||
let patched_content = content.replace(
|
||||
previous_target,
|
||||
"struct hash_base { typedef T argument_type; typedef std::size_t result_type; };"
|
||||
);
|
||||
fs::write(path, patched_content)?;
|
||||
println!("cargo:warning=Updated Boost patch for macOS compatibility");
|
||||
println!("cargo:warning=Replaced boost::unary_function with typedefs");
|
||||
} else if content.contains("typedef T argument_type;") {
|
||||
println!("cargo:warning=Boost already properly patched, skipping");
|
||||
} else {
|
||||
println!("cargo:warning=Could not find target string in Boost file, patch may not be needed");
|
||||
|
||||
// Multiple possible patterns to replace
|
||||
let patterns = [
|
||||
"struct hash_base : std::unary_function<T, std::size_t> {};",
|
||||
"struct hash_base : boost::unary_function<T, std::size_t> {};",
|
||||
"struct hash_base : ::std::unary_function<T, std::size_t> {};",
|
||||
];
|
||||
|
||||
let replacement = "struct hash_base { typedef T argument_type; typedef std::size_t result_type; };";
|
||||
let mut patched = false;
|
||||
let mut patched_content = content.clone();
|
||||
|
||||
for pattern in patterns {
|
||||
if patched_content.contains(pattern) {
|
||||
patched_content = patched_content.replace(pattern, replacement);
|
||||
patched = true;
|
||||
}
|
||||
}
|
||||
|
||||
if patched {
|
||||
fs::write(path, patched_content)?;
|
||||
println!("cargo:warning=Successfully patched Boost hash.hpp for macOS compatibility");
|
||||
} else if content.contains("typedef T argument_type;") {
|
||||
println!("cargo:warning=Boost hash.hpp already properly patched, skipping");
|
||||
} else {
|
||||
println!("cargo:warning=Could not find pattern to patch in Boost hash.hpp");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -416,6 +417,8 @@ fn main() {
|
||||
println!("cargo:rustc-link-lib=static=mcl");
|
||||
println!("cargo:rustc-link-lib=static=dynarmic");
|
||||
println!("cargo:rustc-link-lib=static=fmt");
|
||||
println!("cargo:rustc-link-lib=static=zydis");
|
||||
println!("cargo:rustc-link-lib=static=zycore");
|
||||
|
||||
if is_windows {
|
||||
println!("cargo:rustc-link-lib=dylib=msvcrt");
|
||||
|
||||
Reference in New Issue
Block a user