Start work on Cross-FFI functions

This commit is contained in:
Michael Mikovsky
2025-11-05 15:17:31 -07:00
parent a8432f66be
commit f601c3a58e
17 changed files with 612 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "libloading"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [
"cfg-if",
"windows-link",
]
[[package]]
name = "log"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
[[package]]
name = "unshell-logger"
version = "0.1.0"
dependencies = [
"log",
]
[[package]]
name = "unshell-module-test"
version = "0.1.0"
dependencies = [
"log",
"unshell-logger",
"unshell-modules",
]
[[package]]
name = "unshell-modules"
version = "0.1.0"
dependencies = [
"libloading",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+24
View File
@@ -0,0 +1,24 @@
[package]
name = "unshell-module-test"
version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["cdylib"]
[profile.release]
strip = true # Strip symbols from the binary
# strip = "debuginfo"
opt-level = "s" # Optimize for size
lto = true
codegen-units = 1
panic = "abort"
debug = false
[dependencies]
log = "0.4.28"
unshell-logger = {path = "../unshell-logger"}
unshell-modules = {path = "../unshell-modules"}
# log = "0.4.28"
+12
View File
@@ -0,0 +1,12 @@
# RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \
# rustup run nightly cargo build --release
# rustup run nightly cargo build \
# --release \
# --no-default-features \
# -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
# -Zbuild-std-features="panic_immediate_abort"
# RUSTFLAGS="-Z build-std" \
rustup run nightly cargo build --release
+48
View File
@@ -0,0 +1,48 @@
#![no_main]
#[macro_use]
extern crate log;
pub use unshell_logger::setup_logger;
use unshell_modules::{module, module_interface};
// #[unsafe(no_mangle)]
extern "C" fn test1() {
warn!("Test1 called");
}
// #[unsafe(no_mangle)]
extern "C" fn test2() {
warn!("Test2 called");
}
// #[unsafe(no_mangle)]
extern "C" fn test3() {
warn!("Test3 called");
}
module_interface! {
Interface {
fn test1();
fn test2();
fn test3();
}
}
#[unsafe(no_mangle)]
pub fn test() {
info!("Module loaded");
}
#[unsafe(no_mangle)]
pub fn functions() -> Interface {
info!("Module loaded");
// let m = TestModule::new();
let i = unsafe { Interface::from_raw(test1, test2, test3) };
i.test1();
i
}
#[unsafe(no_mangle)]
pub fn testfunc() {
info!("testfunc called");
}