diff --git a/src/lib.rs b/src/lib.rs index efac203..5b465ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,7 +113,8 @@ use std::fs; use std::io::Read; use std::path::{Path, PathBuf}; use std::str::FromStr; -use strum_macros::EnumString; +use strum::IntoEnumIterator; +use strum_macros::{EnumIter, EnumString}; use thiserror::Error; use version_compare::VersionCompare; @@ -177,6 +178,7 @@ impl BuildInternalClosureError { } // enums representing the environment variables user can define to tune system-deps +#[derive(Debug, PartialEq, EnumIter)] enum EnvVariable { Lib(String), LibFramework(String), @@ -561,6 +563,26 @@ impl Config { } } + // Export cargo:rerun-if-env-changed instructions for all env variables affecting system-deps behaviour + flags.add(BuildFlag::RerunIfEnvChanged( + EnvVariable::new_build_internal(None), + )); + + for (name, _lib) in libraries.iter() { + for var in EnvVariable::iter() { + let var = match var { + EnvVariable::Lib(_) => EnvVariable::new_lib(name), + EnvVariable::LibFramework(_) => EnvVariable::new_lib_framework(name), + EnvVariable::SearchNative(_) => EnvVariable::new_search_native(name), + EnvVariable::SearchFramework(_) => EnvVariable::new_search_framework(name), + EnvVariable::Include(_) => EnvVariable::new_include(name), + EnvVariable::NoPkgConfig(_) => EnvVariable::new_no_pkg_config(name), + EnvVariable::BuildInternal(_) => EnvVariable::new_build_internal(Some(name)), + }; + flags.add(BuildFlag::RerunIfEnvChanged(var)); + } + } + Ok(flags) } @@ -722,6 +744,7 @@ enum BuildFlag { SearchFramework(String), Lib(String), LibFramework(String), + RerunIfEnvChanged(EnvVariable), } impl fmt::Display for BuildFlag { @@ -732,6 +755,7 @@ impl fmt::Display for BuildFlag { BuildFlag::SearchFramework(lib) => write!(f, "rustc-link-search=framework={}", lib), BuildFlag::Lib(lib) => write!(f, "rustc-link-lib={}", lib), BuildFlag::LibFramework(lib) => write!(f, "rustc-link-lib=framework={}", lib), + BuildFlag::RerunIfEnvChanged(env) => write!(f, "rerun-if-env-changed={}", env), } } } diff --git a/src/test.rs b/src/test.rs index 6a067e4..393b851 100644 --- a/src/test.rs +++ b/src/test.rs @@ -73,6 +73,21 @@ cargo:rustc-link-search=framework=/usr/lib/x86_64-linux-gnu cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -213,6 +228,21 @@ cargo:rustc-link-search=framework=/usr/lib/x86_64-linux-gnu cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -234,6 +264,21 @@ cargo:rustc-link-search=framework=/custom/path cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -256,6 +301,21 @@ cargo:rustc-link-lib=overrided-test cargo:rustc-link-lib=other-test cargo:rustc-link-lib=framework=someframework cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -277,6 +337,21 @@ cargo:rustc-link-search=framework=/usr/lib/x86_64-linux-gnu cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=overrided-framework cargo:include=/usr/include/testlib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -298,6 +373,21 @@ cargo:rustc-link-search=framework=/usr/lib/x86_64-linux-gnu cargo:rustc-link-lib=test cargo:rustc-link-lib=framework=someframework cargo:include=/other/include +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL "#, ); } @@ -322,7 +412,25 @@ fn override_unset() { assert_eq!(testlib.frameworks, Vec::::new()); assert_eq!(testlib.include_paths, Vec::::new()); - assert_flags(flags, ""); + assert_flags( + flags, + r"cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL +", + ); } #[test] @@ -342,7 +450,26 @@ fn override_no_pkg_config() { assert_eq!(testlib.frameworks, Vec::::new()); assert_eq!(testlib.include_paths, Vec::::new()); - assert_flags(flags, "cargo:rustc-link-lib=custom-lib\n"); + assert_flags( + flags, + r"cargo:rustc-link-lib=custom-lib +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_INCLUDE +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_LIB_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_NO_PKG_CONFIG +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_FRAMEWORK +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_SEARCH_NATIVE +cargo:rerun-if-env-changed=SYSTEM_DEPS_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTLIB_BUILD_INTERNAL +cargo:rerun-if-env-changed=SYSTEM_DEPS_TESTDATA_BUILD_INTERNAL +", + ); } #[test]