summaryrefslogtreecommitdiff
path: root/rust/examples/template
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-06-29 11:35:06 -0400
committerKyleMiles <krm504@nyu.edu>2021-06-29 14:00:21 -0400
commit70be4645d30c8017524ae2b444ac7e0c0a8448a6 (patch)
tree3bdad671acaa346b2c893448fba7c4908363cfbd /rust/examples/template
parentf388a25624c5860c45f6e002577a2c283002ce47 (diff)
Rust API : No longer update to latest cargo nightly; Add link args back to -sys to reduce build errors
Diffstat (limited to 'rust/examples/template')
-rw-r--r--rust/examples/template/CMakeLists.txt89
-rw-r--r--rust/examples/template/README.md12
2 files changed, 7 insertions, 94 deletions
diff --git a/rust/examples/template/CMakeLists.txt b/rust/examples/template/CMakeLists.txt
deleted file mode 100644
index a06a5af6..00000000
--- a/rust/examples/template/CMakeLists.txt
+++ /dev/null
@@ -1,89 +0,0 @@
-cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
-
-project(test_headless)
-
-file(GLOB PLUGIN_SOURCES
- ${PROJECT_SOURCE_DIR}/Cargo.toml
- ${PROJECT_SOURCE_DIR}/src/*.rs)
-
-file(GLOB API_SOURCES
- ${PROJECT_SOURCE_DIR}/../../../binaryninjacore.h
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/build.rs
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/Cargo.toml
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/src/*
- ${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()
-set(PLUGIN_PATH ${TARGET_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
-
-add_custom_target(test_headless ALL DEPENDS ${PLUGIN_PATH})
-add_dependencies(test_headless binaryninjaapi)
-
-find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin)
-set(INSTALL_UPDATE_NIGHTLY ${RUSTUP_PATH} install nightly)
-
-if(APPLE)
- if(UNIVERSAL)
- if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- else()
- set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- endif()
-
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=aarch64-apple-darwin ${CARGO_OPTS}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
- COMMAND mkdir -p ${TARGET_DIR}
- COMMAND lipo -create ${AARCH64_LIB_PATH} ${X86_64_LIB_PATH} -output ${PLUGIN_PATH}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
- else()
- if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- else()
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- endif()
-
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
- endif()
-elseif(WIN32)
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
-else()
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
-endif()
diff --git a/rust/examples/template/README.md b/rust/examples/template/README.md
index f10f89c8..998a9cd2 100644
--- a/rust/examples/template/README.md
+++ b/rust/examples/template/README.md
@@ -1,17 +1,19 @@
+# Template
+
[The only official method of providing linker arguments to a crate is through that crate's `build.rs`](https://github.com/rust-lang/cargo/issues/9554), thus this template.
Please see `Cargo.toml` for further configuration options.
-### Plugins
+## Plugins
Enable
```
[lib]
crate-type = ["cdylib"]
```
-in Cargo.toml`
-
-### Standalone executables
+in `Cargo.toml`.
-All standalone executables should call both `binaryninja::headless::init()` and `binaryninja::headless::shutdown()`.
+## Standalone executables
+All standalone executables should call both `binaryninja::headless::init()` and `binaryninja::headless::shutdown()` (see [`src/main.rs`](src/main.rs)).
+Standalone executables will fail to link if you do not provide a `build.rs`. The one provided here should work.