diff options
| author | Teddy Wing | 2018-10-14 21:42:41 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-10-14 21:42:41 +0200 |
| commit | 2be00cdf66ab965bdb5edf5902b4ec8b83229704 (patch) | |
| tree | fd5c1fd90110bc57f27094ba5a7d778e9ec21560 | |
| parent | f23031e4b64acf962dd3d94efd99fe36dfb011b5 (diff) | |
| download | dome-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-- | Makefile | 14 | ||||
| -rw-r--r-- | build.rs | 10 |
2 files changed, 23 insertions, 1 deletions
@@ -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 $< $@ @@ -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(), + ); } |
