Skip to content

Commit 9f85f8e

Browse files
Merge pull request #39 from Reim-developer/dev
Added Rust lib test # Change Log: commit 6f28482 (HEAD -> dev, origin/dev) Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:28:01 2025 +0700 Added Bash script helper for test FFI Rust -> C++ commit 067b4a9 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:24:06 2025 +0700 Fix: CMake syntax error in line `61` commit 6fee4e8 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:20:52 2025 +0700 Fix: Make syntax error on GitHub CI commit f011d11 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:15:09 2025 +0700 Added function test commit 5b93eae Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:15:00 2025 +0700 Added test case bingding Rust -> C++ calls. commit f35b31b Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:14:43 2025 +0700 Added `Cargo.toml` with package name `rustlib_test` & version info: `0.1.0`, with lib crate-type is `staticlib` commit 80111a1 Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:14:23 2025 +0700 Added `Cargo.lock` with package name `rustlib_test` & version info: `0.1.0` commit 60f450b Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:13:52 2025 +0700 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.) commit e082a4f Author: Reim-developer <contact.kaxtr@gmail.com> Date: Mon Jul 28 03:11:41 2025 +0700 Added Rust output binary `target` to Git ignore
2 parents 69dc0ec + 6f28482 commit 9f85f8e

9 files changed

Lines changed: 175 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ zClipboard-1.0.1
88
# AUR repo
99
aur
1010
__pycache__
11-
*.json
11+
*.json
12+
target

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,36 @@ target_link_libraries(
3636
PRIVATE Qt6::Gui
3737
PRIVATE Qt6::Network
3838
)
39+
40+
# We don't suggest enable this in production.
3941
if(Z_DEBUG)
4042
add_compile_definitions(${PROJECT_NAME} PRIVATE Z_DEBUG)
4143
endif()
4244

45+
# Enable all features, except to 'Z_DEBUG' flag.
46+
if(Z_ENABLE_ALL_FEATURES)
47+
add_compile_definitions(${PROJECT_NAME} PRIVATE Z_ENABLE_ALL_FEATURES)
48+
endif()
49+
50+
# Static linking mode. Beta.
51+
if(Z_STATIC_LINKING)
52+
add_compile_definitions(${PROJECT_NAME} PRIVATE Z_STATIC_LINKING)
53+
endif()
54+
55+
# Use it if you want use native notification
56+
# in Linux. (Suggested.)
57+
if(Z_USE_LIB_NOTIFY)
58+
if(NOT LINUX)
59+
message(FATAL_ERROR "Could not use 'LibNotify' in operating system outside of Linux")
60+
endif()
61+
62+
if(Z_STATIC_LINKING)
63+
message(FATAL_ERROR "Could not use 'LibNotify' if you want use static linking mode")
64+
endif()
65+
66+
add_compile_definitions(${PROJECT_NAME} PRIVATE Z_USE_LIB_NOTIFY)
67+
endif()
68+
4369
if(NOT WIN32)
4470
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::SODIUM)
4571
endif()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef SETTING_WINDOW_TRANSLATOR_HPP
2+
#define SETTING_WINDOW_TRANSLATOR_HPP
3+
#include "../../../../Utils/Include/Namespace_Macro.hpp"
4+
#include "../../../../Lib_Memory/Include/Memory.hpp"
5+
#include "../../../../GUI/Toolkit/Include/SettingWindow_Components.hpp"
6+
#include <QSettings>
7+
#include <QDialog>
8+
9+
using ZClipboard::Lib_Memory::PtrUnique;
10+
using ZClipboard::GUI::Toolkit::SettingWindowComponentsManager;
11+
12+
GUI_WINDOW_TRANSLATOR_NAMESPACE
13+
14+
class SettingWindowTranslator {
15+
private:
16+
using Settings = QSettings;
17+
using Components = SettingWindowComponentsManager;
18+
using Window = QDialog;
19+
20+
private:
21+
PtrUnique<Settings> settings;
22+
23+
private:
24+
void VietNameseTranslator(Window *window, Components *components);
25+
void EnglishTranslator(Window *window, Components *components);
26+
27+
public:
28+
void LoadTranslator(Window *window, Components *components);
29+
};
30+
31+
END_NAMESPACE
32+
33+
#endif // SETTING_WINDOW_TRANSLATOR_HPP
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "Include/SettingWindow_Translator.hpp"
2+
#include "../../../Language/Include/Language.hpp"
3+
4+
using ZClipboard::GUI::Windows::Translator::SettingWindowTranslator;
5+
using ZClipboard::Lib_Memory::MakePtr;
6+
7+
using Self = SettingWindowTranslator;
8+
9+
#if defined (Z_DEBUG)
10+
11+
#endif
12+
13+
void Self::VietNameseTranslator(Window *window, Components *components) {
14+
constexpr auto TITLE = SETTING_DIALOG_VI;
15+
16+
17+
window->setWindowTitle(TITLE);
18+
}
19+
20+
void Self::EnglishTranslator(Window *window, Components *components) {
21+
const auto TITLE = SETTING_DIALOG_EN;
22+
23+
window->setWindowTitle(TITLE);
24+
}
25+
26+
void Self::LoadTranslator(Window *window, Components *components) {
27+
if(!settings) {
28+
settings = MakePtr<Settings>();
29+
30+
31+
}
32+
33+
}

rustlib_test/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustlib_test/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "rustlib_test"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
crate-type = ["staticlib"]
8+
9+
[profile.dev]
10+
panic = "abort"

rustlib_test/main.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using std::cout;
5+
using std::endl;
6+
using std::string;
7+
8+
extern "C" {
9+
void greet();
10+
char *get_reim_name();
11+
void free_name(char *name);
12+
}
13+
14+
int main() {
15+
greet();
16+
17+
auto raw_name = get_reim_name();
18+
auto name_string = string(raw_name);
19+
free_name(raw_name);
20+
21+
cout << name_string << endl;
22+
}

rustlib_test/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![deny(clippy::all, clippy::pedantic, clippy::nursery, clippy::perf)]
2+
3+
use std::{ffi::CString, os::raw::c_char};
4+
use std::ptr::null_mut;
5+
6+
#[unsafe(no_mangle)]
7+
pub unsafe extern "C" fn greet() {
8+
println!("Hello World");
9+
}
10+
11+
#[unsafe(no_mangle)]
12+
pub extern "C" fn get_reim_name() -> *mut c_char {
13+
CString
14+
::new("REIM DEVELOPER")
15+
.map(|name| name.into_raw())
16+
.unwrap_or(null_mut())
17+
}
18+
19+
#[unsafe(no_mangle)]
20+
pub unsafe extern "C" fn free_name(c_string: *mut c_char) {
21+
if !c_string.is_null() {
22+
unsafe {
23+
let _ = CString::from_raw(c_string);
24+
}
25+
}
26+
}

rustlib_test/test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
function test_lib() {
4+
if [ ! -d "build" ]; then
5+
mkdir -p "build"
6+
fi
7+
8+
cargo build
9+
10+
local rust_lib="target/debug/librustlib_test.a"
11+
clang++ "main.cxx" "$rust_lib" -o "build/main"
12+
13+
"./build/main"
14+
}
15+
16+
test_lib

0 commit comments

Comments
 (0)