diff --git a/Cargo.lock b/Cargo.lock index b72b3fc..4ce39df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,4 +1,46 @@ +[[package]] +name = "cc" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cmake" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "espanso" version = "0.1.0" +dependencies = [ + "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff" +"checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 3eea0a2..85a9141 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,12 @@ name = "espanso" version = "0.1.0" authors = ["Federico Terzi "] edition = "2018" +build="build.rs" + +[target.'cfg(windows)'.dependencies] +winapi = { version = "0.3", features = ["winuser"] } [dependencies] + +[build-dependencies] +cmake = "0.1.31" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..1c9611d --- /dev/null +++ b/build.rs @@ -0,0 +1,10 @@ +extern crate cmake; +use cmake::Config; + +fn main() +{ + let dst = Config::new("native/libwinbridge").build(); + + println!("cargo:rustc-link-search=native={}", dst.display()); + println!("cargo:rustc-link-lib=static=winbridge"); +} \ No newline at end of file diff --git a/native/libwinbridge/CMakeLists.txt b/native/libwinbridge/CMakeLists.txt new file mode 100644 index 0000000..6ac7b0b --- /dev/null +++ b/native/libwinbridge/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.0) +project(libwinbridge) + +add_library(winbridge STATIC bridge.cpp bridge.h) + +install(TARGETS winbridge DESTINATION .) \ No newline at end of file diff --git a/native/libwinbridge/bridge.cpp b/native/libwinbridge/bridge.cpp new file mode 100644 index 0000000..6de07b6 --- /dev/null +++ b/native/libwinbridge/bridge.cpp @@ -0,0 +1 @@ +#include "bridge.h" diff --git a/native/libwinbridge/bridge.h b/native/libwinbridge/bridge.h new file mode 100644 index 0000000..1420fb5 --- /dev/null +++ b/native/libwinbridge/bridge.h @@ -0,0 +1,11 @@ +#ifndef ESPANSO_BRIDGE_H +#define ESPANSO_BRIDGE_H + +#include + +extern "C" void testcall(float value) +{ + printf("Hello, world from C! Value passed: %f\n",value); +} + +#endif //ESPANSO_BRIDGE_H diff --git a/src/main.rs b/src/main.rs index e7a11a9..d8ac64a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,14 @@ -fn main() { - println!("Hello, world!"); +#[link(name="winbridge", kind="static")] +extern { + // this is rustified prototype of the function from our C library + fn testcall(v: f32); } + +fn main() { + println!("Hello, world from Rust!"); + + // calling the function from foo library + unsafe { + testcall(3.14159); + }; +} \ No newline at end of file