Skip to content

Commit

Permalink
link to libtaskchampion separately from the unity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Feb 27, 2022
1 parent 17ccaea commit 2c9d745
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
43 changes: 25 additions & 18 deletions integration-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ use std::env;
use std::fs;
use std::path::Path;

fn build_libtaskchampion(suites: &[&'static str]) {
// This crate has taskchampion-lib in its build-dependencies, so
// libtaskchampion.so should be built already. Hopefully it's in target/$PROFILE, and hopefully
// it's named libtaskchampion.so and not something else
let mut libtaskchampion = env::current_dir().unwrap();
libtaskchampion.pop();
libtaskchampion.push("target");
libtaskchampion.push(env::var("PROFILE").unwrap());
libtaskchampion.push("deps");
libtaskchampion.push(if cfg!(target_os = "macos") {
"libtaskchampion.dylib"
} else {
"libtaskchampion.so"
});
/// Link to the libtaskchampion library produced by the `taskchampion-lib` crate. This is done as
/// a build dependency, rather than a cargo dependency, for unclear reasons. TODO
fn link_libtaskchampion() {
// This crate has taskchampion-lib in its build-dependencies, so libtaskchampion.so should be
// built already.
//
// Shared libraries (crate-type=cdylib) appear to be placed in target/$PROFILE/deps.
let mut libtc_dir = env::current_dir().unwrap();
libtc_dir.pop();
libtc_dir.push("target");
libtc_dir.push(env::var("PROFILE").unwrap());
libtc_dir.push("deps");

let libtc_dir = libtc_dir.to_str().expect("path is valid utf-8");
println!("cargo:rustc-link-search={}", libtc_dir);
println!("cargo:rustc-link-lib=dylib=taskchampion");
}

/// Build the Unity-based C test suite in `src/bindings_tests`, linking the result with this
/// package's library crate.
fn build_bindings_tests(suites: &[&'static str]) {
let mut build = cc::Build::new();
build.shared_flag(true);
build.object(libtaskchampion);
build.include("../lib");
build.include("../lib"); // include path for taskchampion.h
build.include("src/bindings_tests/unity");
build.define("UNITY_OUTPUT_CHAR", "test_output");
build.define(
Expand All @@ -41,6 +45,8 @@ fn build_libtaskchampion(suites: &[&'static str]) {
build.compile("bindings-tests");
}

/// Make `bindings_test_suites.rs` listing all of the test suites, for use in building the
/// bindings-test binary.
fn make_suite_file(suites: &[&'static str]) {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("bindings_test_suites.rs");
Expand All @@ -55,6 +61,7 @@ fn main() {
println!("cargo:rerun-if-changed=build.rs");

let suites = &["uuid", "string", "task", "replica"];
build_libtaskchampion(suites);
link_libtaskchampion();
build_bindings_tests(suites);
make_suite_file(suites);
}
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"

[lib]
name = "taskchampion"
crate-type = ["cdylib"]
crate-type = ["staticlib", "cdylib"]

[dependencies]
libc = "0.2.113"
Expand Down

0 comments on commit 2c9d745

Please sign in to comment.