From e082a4fa29c7ac2dfe307511ca7ffcf1606ae80c Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:11:41 +0700 Subject: [PATCH 1/9] Added Rust output binary `target` to Git ignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1a33836..cbc88d9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ zClipboard-1.0.1 # AUR repo aur __pycache__ -*.json \ No newline at end of file +*.json +target \ No newline at end of file From 60f450b65d53808464190a032c6536b8eb17c857 Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:13:52 +0700 Subject: [PATCH 2/9] Added build flag supports to `CMakeLists.txt` `Z_ENABLE_ALL_FEATURES` => Enable all features of application `Z_STATIC_LINKING` => Enable static linking mode (required for static linking) `Z_USE_LIB_NOTIFY` => Enable `Linux` native notification, using `libnotify` (Only for Linux, and cannot use it if the macro `Z_STATIC_LINKING` is enabled.) --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49c08bc..cb204e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,10 +36,36 @@ target_link_libraries( PRIVATE Qt6::Gui PRIVATE Qt6::Network ) + +# We don't suggest enable this in production. if(Z_DEBUG) add_compile_definitions(${PROJECT_NAME} PRIVATE Z_DEBUG) endif() +# Enable all features, except to 'Z_DEBUG' flag. +if(Z_ENABLE_ALL_FEATURES) + add_compile_definitions(${PROJECT_NAME} PRIVATE Z_ENABLE_ALL_FEATURES) +endif + +# Static linking mode. Beta. +if(Z_STATIC_LINKING) + add_compile_definitions(${PROJECT_NAME} PRIVATE Z_STATIC_LINKING) +endif() + +# Use it if you want use native notification +# in Linux. (Suggested.) +if(Z_USE_LIB_NOTIFY) + if(NOT LINUX) + message(FATAL_ERROR "Could not use 'LibNotify' in operating system outside of Linux") + endif + + if(Z_STATIC_LINKING) + message(FATAL_ERROR "Could not use 'LibNotify' if you want use static linking mode") + endif() + + add_compile_definitions(${PROJECT_NAME} PRIVATE Z_USE_LIB_NOTIFY) +endif() + if(NOT WIN32) target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::SODIUM) endif() From 80111a1b3fa6c71f4d722060331b59c702c71a5e Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:14:23 +0700 Subject: [PATCH 3/9] Added `Cargo.lock` with package name `rustlib_test` & version info: `0.1.0` --- rustlib_test/Cargo.lock | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 rustlib_test/Cargo.lock diff --git a/rustlib_test/Cargo.lock b/rustlib_test/Cargo.lock new file mode 100644 index 0000000..da7739d --- /dev/null +++ b/rustlib_test/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "rustlib_test" +version = "0.1.0" From f35b31b2b1b85ccdbba395d0d341774a2dd2bb5a Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:14:43 +0700 Subject: [PATCH 4/9] Added `Cargo.toml` with package name `rustlib_test` & version info: `0.1.0`, with lib crate-type is `staticlib` --- rustlib_test/Cargo.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 rustlib_test/Cargo.toml diff --git a/rustlib_test/Cargo.toml b/rustlib_test/Cargo.toml new file mode 100644 index 0000000..8ef22bf --- /dev/null +++ b/rustlib_test/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rustlib_test" +version = "0.1.0" +edition = "2024" + +[lib] +crate-type = ["staticlib"] + +[profile.dev] +panic = "abort" \ No newline at end of file From 5b93eaeedda6e756383622e232ac98d3d1de2129 Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:15:00 +0700 Subject: [PATCH 5/9] Added test case bingding Rust -> C++ calls. --- rustlib_test/main.cxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 rustlib_test/main.cxx diff --git a/rustlib_test/main.cxx b/rustlib_test/main.cxx new file mode 100644 index 0000000..f5f3247 --- /dev/null +++ b/rustlib_test/main.cxx @@ -0,0 +1,22 @@ +#include +#include + +using std::cout; +using std::endl; +using std::string; + +extern "C" { + void greet(); + char *get_reim_name(); + void free_name(char *name); +} + +int main() { + greet(); + + auto raw_name = get_reim_name(); + auto name_string = string(raw_name); + free_name(raw_name); + + cout << name_string << endl; +} \ No newline at end of file From f011d1162a5e7029b205eb0b296260d96e5bda49 Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:15:09 +0700 Subject: [PATCH 6/9] Added function test --- rustlib_test/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 rustlib_test/src/lib.rs diff --git a/rustlib_test/src/lib.rs b/rustlib_test/src/lib.rs new file mode 100644 index 0000000..c57f671 --- /dev/null +++ b/rustlib_test/src/lib.rs @@ -0,0 +1,26 @@ +#![deny(clippy::all, clippy::pedantic, clippy::nursery, clippy::perf)] + +use std::{ffi::CString, os::raw::c_char}; +use std::ptr::null_mut; + +#[unsafe(no_mangle)] +pub unsafe extern "C" fn greet() { + println!("Hello World"); +} + +#[unsafe(no_mangle)] +pub extern "C" fn get_reim_name() -> *mut c_char { + CString + ::new("REIM DEVELOPER") + .map(|name| name.into_raw()) + .unwrap_or(null_mut()) +} + +#[unsafe(no_mangle)] +pub unsafe extern "C" fn free_name(c_string: *mut c_char) { + if !c_string.is_null() { + unsafe { + let _ = CString::from_raw(c_string); + } + } +} \ No newline at end of file From 6fee4e8349136167ef56d47b9c80983a7a17ca6f Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:20:52 +0700 Subject: [PATCH 7/9] Fix: Make syntax error on GitHub CI --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb204e3..770123e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ endif() # Enable all features, except to 'Z_DEBUG' flag. if(Z_ENABLE_ALL_FEATURES) add_compile_definitions(${PROJECT_NAME} PRIVATE Z_ENABLE_ALL_FEATURES) -endif +endif() # Static linking mode. Beta. if(Z_STATIC_LINKING) From 067b4a9e97d1d55b58d34bfc1ad6534ad114cacb Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:24:06 +0700 Subject: [PATCH 8/9] Fix: CMake syntax error in line `61` --- CMakeLists.txt | 2 +- .../Include/SettingWindow_Translator.hpp | 33 +++++++++++++++++++ .../Translator/SettingWindow_Translator.cc | 33 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Source/GUI/Windows/Translator/Include/SettingWindow_Translator.hpp create mode 100644 Source/GUI/Windows/Translator/SettingWindow_Translator.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 770123e..f6c1484 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ endif() if(Z_USE_LIB_NOTIFY) if(NOT LINUX) message(FATAL_ERROR "Could not use 'LibNotify' in operating system outside of Linux") - endif + endif() if(Z_STATIC_LINKING) message(FATAL_ERROR "Could not use 'LibNotify' if you want use static linking mode") diff --git a/Source/GUI/Windows/Translator/Include/SettingWindow_Translator.hpp b/Source/GUI/Windows/Translator/Include/SettingWindow_Translator.hpp new file mode 100644 index 0000000..84aa511 --- /dev/null +++ b/Source/GUI/Windows/Translator/Include/SettingWindow_Translator.hpp @@ -0,0 +1,33 @@ +#ifndef SETTING_WINDOW_TRANSLATOR_HPP +#define SETTING_WINDOW_TRANSLATOR_HPP +#include "../../../../Utils/Include/Namespace_Macro.hpp" +#include "../../../../Lib_Memory/Include/Memory.hpp" +#include "../../../../GUI/Toolkit/Include/SettingWindow_Components.hpp" +#include +#include + +using ZClipboard::Lib_Memory::PtrUnique; +using ZClipboard::GUI::Toolkit::SettingWindowComponentsManager; + +GUI_WINDOW_TRANSLATOR_NAMESPACE + + class SettingWindowTranslator { + private: + using Settings = QSettings; + using Components = SettingWindowComponentsManager; + using Window = QDialog; + + private: + PtrUnique settings; + + private: + void VietNameseTranslator(Window *window, Components *components); + void EnglishTranslator(Window *window, Components *components); + + public: + void LoadTranslator(Window *window, Components *components); + }; + +END_NAMESPACE + +#endif // SETTING_WINDOW_TRANSLATOR_HPP \ No newline at end of file diff --git a/Source/GUI/Windows/Translator/SettingWindow_Translator.cc b/Source/GUI/Windows/Translator/SettingWindow_Translator.cc new file mode 100644 index 0000000..7dc075c --- /dev/null +++ b/Source/GUI/Windows/Translator/SettingWindow_Translator.cc @@ -0,0 +1,33 @@ +#include "Include/SettingWindow_Translator.hpp" +#include "../../../Language/Include/Language.hpp" + +using ZClipboard::GUI::Windows::Translator::SettingWindowTranslator; +using ZClipboard::Lib_Memory::MakePtr; + +using Self = SettingWindowTranslator; + +#if defined (Z_DEBUG) + +#endif + +void Self::VietNameseTranslator(Window *window, Components *components) { + constexpr auto TITLE = SETTING_DIALOG_VI; + + + window->setWindowTitle(TITLE); +} + +void Self::EnglishTranslator(Window *window, Components *components) { + const auto TITLE = SETTING_DIALOG_EN; + + window->setWindowTitle(TITLE); +} + +void Self::LoadTranslator(Window *window, Components *components) { + if(!settings) { + settings = MakePtr(); + + + } + +} \ No newline at end of file From 6f28482d8c2a9815b074354c34310a473c1b2c1f Mon Sep 17 00:00:00 2001 From: Reim-developer Date: Mon, 28 Jul 2025 03:28:01 +0700 Subject: [PATCH 9/9] Added Bash script helper for test FFI Rust -> C++ --- rustlib_test/test.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 rustlib_test/test.sh diff --git a/rustlib_test/test.sh b/rustlib_test/test.sh new file mode 100755 index 0000000..a650cb3 --- /dev/null +++ b/rustlib_test/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +function test_lib() { + if [ ! -d "build" ]; then + mkdir -p "build" + fi + + cargo build + + local rust_lib="target/debug/librustlib_test.a" + clang++ "main.cxx" "$rust_lib" -o "build/main" + + "./build/main" +} + +test_lib \ No newline at end of file