-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
33,745 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR) | ||
|
||
project(svd_ninja) | ||
|
||
if(NOT BN_API_BUILD_EXAMPLES AND NOT BN_INTERNAL_BUILD) | ||
if(NOT BN_API_PATH) | ||
# If we have not already defined the API source directory try and find it. | ||
find_path( | ||
BN_API_PATH | ||
NAMES binaryninjaapi.h | ||
# List of paths to search for the clone of the api | ||
HINTS ../../.. ../../binaryninja/api/ binaryninjaapi binaryninja-api $ENV{BN_API_PATH} | ||
REQUIRED | ||
) | ||
endif() | ||
set(CARGO_STABLE_VERSION 1.83.0) | ||
add_subdirectory(${BN_API_PATH} binaryninjaapi) | ||
endif() | ||
|
||
file(GLOB_RECURSE PLUGIN_SOURCES CONFIGURE_DEPENDS | ||
${PROJECT_SOURCE_DIR}/Cargo.toml | ||
${PROJECT_SOURCE_DIR}/src/*.rs) | ||
|
||
if(CMAKE_BUILD_TYPE MATCHES Debug) | ||
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug) | ||
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target) | ||
else() | ||
set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release) | ||
set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release) | ||
endif() | ||
|
||
if(FORCE_COLORED_OUTPUT) | ||
set(CARGO_OPTS ${CARGO_OPTS} --color always) | ||
endif() | ||
|
||
# NOTE: --no-default-features is set to disable building artifacts used for testing | ||
# NOTE: the linker is looking in the target dir and linking on it apparently. | ||
set(CARGO_FEATURES "--no-default-features") | ||
set(OUTPUT_FILE_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
set(OUTPUT_PDB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}.pdb) | ||
set(OUTPUT_FILE_PATH ${BN_CORE_PLUGIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
set(OUTPUT_PDB_PATH ${BN_CORE_PLUGIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}.pdb) | ||
|
||
add_custom_target(${PROJECT_NAME} ALL DEPENDS ${OUTPUT_FILE_PATH}) | ||
add_dependencies(${PROJECT_NAME} binaryninjaapi) | ||
get_target_property(BN_API_SOURCE_DIR binaryninjaapi SOURCE_DIR) | ||
list(APPEND CMAKE_MODULE_PATH "${BN_API_SOURCE_DIR}/cmake") | ||
find_package(BinaryNinjaCore REQUIRED) | ||
|
||
set(BINJA_LIB_DIR ${BN_INSTALL_BIN_DIR}) | ||
|
||
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_FILE_PATH ${OUTPUT_FILE_PATH}) | ||
|
||
# Add the whole api to the depends too | ||
file(GLOB_RECURSE API_SOURCES CONFIGURE_DEPENDS | ||
${BN_API_SOURCE_DIR}/binaryninjacore.h | ||
${BN_API_SOURCE_DIR}/rust/src/*.rs | ||
${BN_API_SOURCE_DIR}/rust/binaryninjacore-sys/src/*.rs) | ||
|
||
find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin) | ||
set(RUSTUP_COMMAND ${RUSTUP_PATH} run ${CARGO_STABLE_VERSION} cargo) | ||
|
||
if(APPLE) | ||
if(UNIVERSAL) | ||
if(CMAKE_BUILD_TYPE MATCHES Debug) | ||
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${OUTPUT_FILE_NAME}) | ||
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${OUTPUT_FILE_NAME}) | ||
else() | ||
set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${OUTPUT_FILE_NAME}) | ||
set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${OUTPUT_FILE_NAME}) | ||
endif() | ||
|
||
add_custom_command( | ||
OUTPUT ${OUTPUT_FILE_PATH} | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} clean --target=aarch64-apple-darwin ${CARGO_OPTS} --package binaryninjacore-sys | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} clean --target=x86_64-apple-darwin ${CARGO_OPTS} --package binaryninjacore-sys | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} build --target=aarch64-apple-darwin ${CARGO_OPTS} ${CARGO_FEATURES} | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} build --target=x86_64-apple-darwin ${CARGO_OPTS} ${CARGO_FEATURES} | ||
COMMAND lipo -create ${AARCH64_LIB_PATH} ${X86_64_LIB_PATH} -output ${OUTPUT_FILE_PATH} | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} | ||
) | ||
else() | ||
if(CMAKE_BUILD_TYPE MATCHES Debug) | ||
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/debug/${OUTPUT_FILE_NAME}) | ||
else() | ||
set(LIB_PATH ${PROJECT_BINARY_DIR}/target/release/${OUTPUT_FILE_NAME}) | ||
endif() | ||
|
||
add_custom_command( | ||
OUTPUT ${OUTPUT_FILE_PATH} | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} clean ${CARGO_OPTS} --package binaryninjacore-sys | ||
COMMAND ${CMAKE_COMMAND} -E env | ||
MACOSX_DEPLOYMENT_TARGET=10.14 BINARYNINJADIR=${BINJA_LIB_DIR} | ||
${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${LIB_PATH} ${OUTPUT_FILE_PATH} | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} | ||
) | ||
endif() | ||
elseif(WIN32) | ||
add_custom_command( | ||
OUTPUT ${OUTPUT_FILE_PATH} | ||
COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} clean ${CARGO_OPTS} --package binaryninjacore-sys | ||
COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE_NAME} ${OUTPUT_FILE_PATH} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_PDB_NAME} ${OUTPUT_PDB_PATH} | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} | ||
) | ||
else() | ||
add_custom_command( | ||
OUTPUT ${OUTPUT_FILE_PATH} | ||
COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} clean ${CARGO_OPTS} --package binaryninjacore-sys | ||
COMMAND ${CMAKE_COMMAND} -E env BINARYNINJADIR=${BINJA_LIB_DIR} ${RUSTUP_COMMAND} build ${CARGO_OPTS} ${CARGO_FEATURES} | ||
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_DIR}/${OUTPUT_FILE_NAME} ${OUTPUT_FILE_PATH} | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "svd_ninja" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
|
||
[dependencies] | ||
binaryninja.workspace = true | ||
binaryninjacore-sys.workspace = true | ||
svd-parser = "0.14.8" | ||
log = "0.4" | ||
|
||
[dev-dependencies] | ||
insta = { version = "1.42", features = ["yaml"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let link_path = std::env::var_os("DEP_BINARYNINJACORE_PATH") | ||
.expect("DEP_BINARYNINJACORE_PATH not specified"); | ||
|
||
println!("cargo::rustc-link-lib=dylib=binaryninjacore"); | ||
println!("cargo::rustc-link-search={}", link_path.to_str().unwrap()); | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
{ | ||
println!( | ||
"cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", | ||
link_path.to_string_lossy() | ||
); | ||
} | ||
|
||
let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR specified"); | ||
let out_dir_path = PathBuf::from(out_dir); | ||
|
||
// Copy all binaries to OUT_DIR for unit tests. | ||
let bin_dir: PathBuf = "fixtures/".into(); | ||
if let Ok(entries) = std::fs::read_dir(bin_dir) { | ||
for entry in entries { | ||
let entry = entry.unwrap(); | ||
let path = entry.path(); | ||
if path.is_file() { | ||
let file_name = path.file_name().unwrap(); | ||
let dest_path = out_dir_path.join(file_name); | ||
std::fs::copy(&path, &dest_path).expect("failed to copy binary to OUT_DIR"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.