1
0
mirror of synced 2025-02-20 04:01:01 +01:00

build: Fixed building and loading of Rust plugins

This commit is contained in:
WerWolv 2022-02-17 11:42:56 +01:00
parent 716d52f3e3
commit b9508d853e
6 changed files with 34 additions and 31 deletions

View File

@ -21,19 +21,17 @@ macro(addVersionDefines)
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} -DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR} -DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH} ")
add_compile_definitions(
$<$<CONFIG:Release>:IMHEX_VERSION="${IMHEX_VERSION}">
$<$<CONFIG:Debug>:IMHEX_VERSION="${IMHEX_VERSION}-Debug">
$<$<CONFIG:RelWithDebInfo>:IMHEX_VERSION="${IMHEX_VERSION}-ReleaseWithDebugInfo">
$<$<CONFIG:MinSizeRel>:IMHEX_VERSION="${IMHEX_VERSION}-ReleaseMinimumSize">
)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION})
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION}-Debug)
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION}-RelWithDebInfo)
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION}-MinSizeRel)
endif ()
add_compile_definitions(
$<$<CONFIG:Release>:RELEASE>
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:RelWithDebInfo>:RELEASE>
$<$<CONFIG:MinSizeRel>:RELEASE>
)
add_compile_definitions(IMHEX_VERSION="${IMHEX_VERSION_STRING}")
endmacro()

View File

@ -13,17 +13,6 @@ impl Parse for AttrList {
}
}
fn symbol(name: &str) -> String {
let pkg_name = std::env::var("CARGO_PKG_NAME").unwrap();
format!(
"_ZN3hex6plugin{}{}8internal{}{}Ev",
pkg_name.len(),
pkg_name,
name.len(),
name,
)
}
#[proc_macro_attribute]
pub fn plugin_setup(attr: TokenStream, item: TokenStream) -> TokenStream {
let args = syn::parse_macro_input!(attr as AttrList)
@ -36,11 +25,14 @@ pub fn plugin_setup(attr: TokenStream, item: TokenStream) -> TokenStream {
let function = syn::parse_macro_input!(item as syn::ItemFn);
let plugin_name_export = symbol("getPluginName");
let plugin_author_export = symbol("getPluginAuthor");
let plugin_desc_export = symbol("getPluginDescription");
let plugin_init_export = symbol("initializePlugin");
let plugin_set_imgui_ctxt_export = symbol("setImGuiContext");
let plugin_name_export = "getPluginName";
let plugin_author_export = "getPluginAuthor";
let plugin_desc_export = "getPluginDescription";
let plugin_version_export = "getCompatibleVersion";
let plugin_init_export = "initializePlugin";
let plugin_set_imgui_ctx_export = "setImGuiContext";
let imhex_version = std::env::var("IMHEX_VERSION").unwrap();
quote!(
#[export_name = #plugin_name_export]
@ -58,11 +50,16 @@ pub fn plugin_setup(attr: TokenStream, item: TokenStream) -> TokenStream {
concat!(#description, "\0").as_ptr()
}
#[export_name = #plugin_set_imgui_ctxt_export]
#[export_name = #plugin_set_imgui_ctx_export]
pub unsafe extern "C" fn set_imgui_context(context: *mut ::hex::imgui::sys::ImGuiContext) {
::hex::imgui::sys::igSetCurrentContext(context);
}
#[export_name = #plugin_version_export]
pub unsafe extern "C" fn plugin_version() -> *const u8 {
concat!(#imhex_version, "\0").as_ptr()
}
#[export_name = #plugin_init_export]
pub extern "C" #function
)

View File

@ -11,7 +11,8 @@
#include <hex/api/task.hpp>
#include <hex/api/keybinding.hpp>
#include <imgui.h>
using ImGuiID = unsigned int;
struct ImVec2;
namespace hex {

View File

@ -13,7 +13,8 @@ namespace hex {
struct View;
enum class Keys {
enum class Keys
{
Space = GLFW_KEY_SPACE,
Apostrophe = GLFW_KEY_APOSTROPHE,
Comma = GLFW_KEY_COMMA,
@ -141,6 +142,9 @@ namespace hex {
class Shortcut {
public:
Shortcut() = default;
Shortcut(Keys key) : m_keys({ key }) { }
Shortcut operator+(const Key &other) const {
Shortcut result = *this;
result.m_keys.insert(other);

View File

@ -6,6 +6,8 @@
#include <unistd.h>
#include <imgui.h>
namespace hex {
namespace ImHexApi::Common {

View File

@ -27,6 +27,7 @@ add_custom_target(${PROJECT_NAME} ALL
LIBIMHEX_SOURCE_DIRECTORY=${LIBIMHEX_SOURCE_DIRECTORY}
LIBIMHEX_OUTPUT_DIRECTORY=$<TARGET_FILE_DIR:libimhex>
CXX_COMPILER=${CMAKE_CXX_COMPILER}
IMHEX_VERSION=${IMHEX_VERSION_STRING}
${CARGO_CMD}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PLUGIN_OUTPUT_PATH} "${CMAKE_CURRENT_BINARY_DIR}/../${PROJECT_NAME}.hexplug"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}