Skip to content

Commit

Permalink
add linux support (#13)
Browse files Browse the repository at this point in the history
* correct wrong information in README

the README said that "`CUSTOM_TINYINST_PATH` = path to local Tinyinst repo"
the actual buildscript uses `CUSTOM_TINYINST_DIR`

* add linux support

note: this commit was only tested on linux

* make the tests work on linux
  • Loading branch information
lenawanel authored Sep 21, 2023
1 parent b286b72 commit c628a58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
31 changes: 11 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
#[cfg(target_os = "linux")]
use std::process::exit;

#[cfg(not(target_os = "linux"))]
use std::{env, fs, path::Path, process::Command};

#[cfg(not(target_os = "linux"))]
use cmake::Config;
#[cfg(not(target_os = "linux"))]
use git2::{Oid, Repository};
#[cfg(not(target_os = "linux"))]
use which::which;

#[cfg(not(target_os = "linux"))]
const TINYINST_URL: &str = "https://github.com/googleprojectzero/TinyInst.git";
#[cfg(not(target_os = "linux"))]
const TINYINST_DIRNAME: &str = "Tinyinst";
#[cfg(not(target_os = "linux"))]
const TINYINST_REVISION: &str = "cfb9b15a53e5e6489f2f72c77e804fb0a7af94b5";
const TINYINST_REVISION: &str = "69ae1ff55eac8cb5d2e9a257c5650486ffe2af04";

#[cfg(not(target_os = "linux"))]
fn build_dep_check(tools: &[&str]) -> bool {
for tool in tools {
let found = which(tool);
Expand All @@ -30,13 +19,6 @@ fn build_dep_check(tools: &[&str]) -> bool {
return true;
}

#[cfg(target_os = "linux")]
fn main() {
println!("cargo:warning=Tinyinst doesn't support linux");
exit(0);
}

#[cfg(not(target_os = "linux"))]
fn main() {
if !build_dep_check(&["git", "cxxbridge", "cmake"]) {
return;
Expand All @@ -46,6 +28,8 @@ fn main() {
let cmake_generator = "Visual Studio 17 2022";
#[cfg(target_vendor = "apple")]
let cmake_generator = "Xcode";
#[cfg(target_os = "linux")]
let cmake_generator = "Unix Makefiles";

let custom_tinyinst_generator =
env::var_os("CUSTOM_TINYINST_GENERATOR").map(|x| x.to_string_lossy().to_string());
Expand Down Expand Up @@ -143,10 +127,17 @@ fn main() {
&tinyinst_path.to_string_lossy()
);

#[cfg(not(target_os = "linux"))]
println!(
"cargo:rustc-link-search={}/build/Release",
&tinyinst_path.to_string_lossy()
);

#[cfg(target_os = "linux")]
println!(
"cargo:rustc-link-search={}/build",
&tinyinst_path.to_string_lossy()
);
println!(
"cargo:rustc-link-search={}/build/third_party/obj/wkit/lib",
&tinyinst_path.to_string_lossy()
Expand All @@ -168,7 +159,7 @@ fn main() {
println!("cargo:rerun-if-changed=Tinyinst/litecov.cpp");
}

#[cfg(not(target_os = "linux"))]
// #[cfg(not(target_os = "linux"))]
fn copy_tinyinst_files(tinyinst_path: &Path) {
// source
Command::new("cxxbridge")
Expand Down
13 changes: 12 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ elseif (APPLE)
macOS/dyld_cache_map_parser.cpp
macOS/dyld_cache_map_parser.h
)
elseif (UNIX)
set (platform_specific_files
Linux/debugger.h
Linux/debugger.cpp
Linux/elffile.h
Linux/elffile.cpp
Linux/procmaps.h
Linux/procmaps.cpp
Linux/syscallhook.h
Linux/syscallhook.cpp
)
endif()

add_library(tinyinst STATIC
Expand All @@ -137,7 +148,7 @@ else()
${CMAKE_CURRENT_BINARY_DIR}/third_party/obj/wkit/lib/xed.lib
Dbghelp.lib
)
elseif (APPLE)
else ()
target_link_libraries(tinyinst
${CMAKE_CURRENT_BINARY_DIR}/third_party/obj/wkit/lib/libxed.a
)
Expand Down
4 changes: 2 additions & 2 deletions src/tinyinst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ mod tests {

#[cfg(target_os = "windows")]
const TEST_FILENAME: &str = "test.exe";
#[cfg(target_vendor = "apple")]
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
const TEST_FILENAME: &str = "test";

#[cfg(target_vendor = "apple")]
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
const TEST_PATH: &str = "test/build/";
#[cfg(target_os = "windows")]
const TEST_PATH: &str = "test/build/Debug/";
Expand Down

0 comments on commit c628a58

Please sign in to comment.