diff --git a/README.md b/README.md index 9e80e5f..a0557fc 100644 --- a/README.md +++ b/README.md @@ -94,9 +94,11 @@ are passed through to shaderc-sys when building shaderc-rs: 1. Building from source, if the native shaderc library is not found via the above steps. -For each library directory, the build script will try to fine and link to the +For each library directory, the build script will try to find and link to the dynamic native shaderc library `shaderc_shared` first and the static native -shaderc library `shaderc_combined` next. +shaderc library `shaderc_combined` next. To prefer searching for the static +library first and the dynamic library next, the option +`--features prefer-static-linking` may be used. Building from Source -------------------- diff --git a/shaderc-rs/Cargo.toml b/shaderc-rs/Cargo.toml index efc5907..9ce4677 100644 --- a/shaderc-rs/Cargo.toml +++ b/shaderc-rs/Cargo.toml @@ -21,3 +21,4 @@ assert_matches = "1.5" [features] build-from-source = ["shaderc-sys/build-from-source"] +prefer-static-linking = ["shaderc-sys/prefer-static-linking"] diff --git a/shaderc-sys/Cargo.toml b/shaderc-sys/Cargo.toml index ee6c88c..632983e 100644 --- a/shaderc-sys/Cargo.toml +++ b/shaderc-sys/Cargo.toml @@ -16,6 +16,7 @@ name = "shaderc_sys" [features] build-from-source = [] +prefer-static-linking = [] [dependencies] libc = "0.2" diff --git a/shaderc-sys/build/build.rs b/shaderc-sys/build/build.rs index 3f3b6ed..70b506e 100644 --- a/shaderc-sys/build/build.rs +++ b/shaderc-sys/build/build.rs @@ -169,6 +169,7 @@ fn main() { let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); let config_build_from_source = env::var("CARGO_FEATURE_BUILD_FROM_SOURCE").is_ok(); + let config_prefer_static_linking = env::var("CARGO_FEATURE_PREFER_STATIC_LINKING").is_ok(); let has_explicit_set_search_dir = env::var("SHADERC_LIB_DIR").is_ok(); // Initialize explicit shaderc search directory first. @@ -275,12 +276,17 @@ fn main() { let dylib_path = search_dir.join(dylib_name); if let Some((lib_name, lib_kind)) = { - if dylib_path.exists() { - Some((SHADERC_SHARED_LIB, "dylib")) - } else if static_lib_path.exists() { - Some((SHADERC_STATIC_LIB, "static")) - } else { - None + match ( + dylib_path.exists(), + static_lib_path.exists(), + config_prefer_static_linking, + ) { + // If dylib not exist OR prefer static lib and static lib exist, static. + (false, true, _) | (_, true, true) => Some((SHADERC_STATIC_LIB, "static")), + // Otherwise, if dylib exist, dynamic. + (true, _, _) => Some((SHADERC_SHARED_LIB, "dylib")), + // Neither dylib nor static lib exist. + _ => None, } } { match (target_os.as_str(), target_env.as_str()) {