First native windows bridge

This commit is contained in:
Federico Terzi 2019-08-30 14:33:40 +02:00
parent 39ec131ef9
commit 356c1c7a44
7 changed files with 90 additions and 2 deletions

42
Cargo.lock generated
View File

@ -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"

View File

@ -3,5 +3,12 @@ name = "espanso"
version = "0.1.0"
authors = ["Federico Terzi <federicoterzi96@gmail.com>"]
edition = "2018"
build="build.rs"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winuser"] }
[dependencies]
[build-dependencies]
cmake = "0.1.31"

10
build.rs Normal file
View File

@ -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");
}

View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.0)
project(libwinbridge)
add_library(winbridge STATIC bridge.cpp bridge.h)
install(TARGETS winbridge DESTINATION .)

View File

@ -0,0 +1 @@
#include "bridge.h"

View File

@ -0,0 +1,11 @@
#ifndef ESPANSO_BRIDGE_H
#define ESPANSO_BRIDGE_H
#include <stdio.h>
extern "C" void testcall(float value)
{
printf("Hello, world from C! Value passed: %f\n",value);
}
#endif //ESPANSO_BRIDGE_H

View File

@ -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);
};
}