From 2c9d74515ebf19ef833a2f08d775be8e0e896376 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sun, 27 Feb 2022 17:03:04 +0000 Subject: [PATCH] link to libtaskchampion separately from the unity tests --- integration-tests/build.rs | 43 ++++++++++++++++++++++---------------- lib/Cargo.toml | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index b5217f5a0..0537507db 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -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( @@ -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"); @@ -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); } diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 564f28590..6f85b62b7 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -5,7 +5,7 @@ edition = "2018" [lib] name = "taskchampion" -crate-type = ["cdylib"] +crate-type = ["staticlib", "cdylib"] [dependencies] libc = "0.2.113"