aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-14 21:42:41 +0200
committerTeddy Wing2018-10-14 21:42:41 +0200
commit2be00cdf66ab965bdb5edf5902b4ec8b83229704 (patch)
treefd5c1fd90110bc57f27094ba5a7d778e9ec21560
parentf23031e4b64acf962dd3d94efd99fe36dfb011b5 (diff)
downloaddome-key-map-2be00cdf66ab965bdb5edf5902b4ec8b83229704.tar.bz2
Compile and link 'libdome_key_event_source_simulator'
Turn this into a build dependency with Make. Use Vladimir Matveev (https://stackoverflow.com/users/788207/vladimir-matveev) and Shepmaster's (https://stackoverflow.com/users/155423/shepmaster) answer on Stack Overflow to sort out getting Cargo the search path for the static library: https://stackoverflow.com/questions/26246849/how-to-i-tell-rust-where-to-look-for-a-static-library/26254062#26254062 For some reason I wasn't able to get it to work by just putting the library into `./target/debug/deps/`. I had to explicitly tell Cargo to put that in the search path. Also, we need to use `std::env` instead of the `env!` macro to get the `PROFILE` environment variable, otherwise it won't be initialised at the right time, as described in the Rust docs: > Because these variables are not yet set when the build script is > compiled, the above example using env! won't work and instead you'll > need to retrieve the values when the build script is run (https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts)
-rw-r--r--Makefile14
-rw-r--r--build.rs10
2 files changed, 23 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index b4e76fa..67ae18e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,13 @@ SOURCE_FILES = $(shell find src -type f -name '*.rs')
LIB := target/debug/libdome_key_map.a
-$(LIB): $(SOURCE_FILES)
+DKESS_LIB_DEBUG := ~/Library/Developer/Xcode/DerivedData/dome_key_event_source_simulator-*/Build/Products/Debug/libdome_key_event_source_simulator.a
+DKESS_LOCAL_LIB_DEBUG := target/debug/deps/libdome_key_event_source_simulator.a
+
+.PHONY: build
+build: $(LIB)
+
+$(LIB): $(SOURCE_FILES) $(DKESS_LOCAL_LIB_DEBUG)
cargo build
includer: clean $(LIB)
@@ -14,3 +20,9 @@ moder: moder.c $(LIB)
.PHONY: clean
clean:
rm -f includer moder
+
+$(DKESS_LIB_DEBUG):
+ $(MAKE) -C lib/dome_key_event_source_simulator $@
+
+$(DKESS_LOCAL_LIB_DEBUG): $(DKESS_LIB_DEBUG)
+ cp -a $< $@
diff --git a/build.rs b/build.rs
index d2a0b5d..8c883f4 100644
--- a/build.rs
+++ b/build.rs
@@ -1,5 +1,7 @@
extern crate cbindgen;
+use std::env;
+
use cbindgen::Language;
fn main() {
@@ -15,4 +17,12 @@ fn main() {
.generate()
.expect("Unable to generate bindings")
.write_to_file("dome_key_map.h");
+
+
+ // Link libdome_key_event_source_simulator.a
+ println!("cargo:rustc-link-lib=static=dome_key_event_source_simulator");
+ println!(
+ "cargo:rustc-link-search=native=./target/{profile}/deps",
+ profile=env::var("PROFILE").unwrap(),
+ );
}