Skip to content

Commit 836aa5d

Browse files
authored
Support using pkg-config to query shaderc dylib path (#160)
1 parent 0d9a871 commit 836aa5d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ are passed through to shaderc-sys when building shaderc-rs:
8989
static shaderc library.
9090
1. If the `VULKAN_SDK` environment variable is set, then `$VULKAN_SDK/lib` will
9191
be searched for native dynamic or static shaderc library.
92+
1. If `pkg-config` is available, use it to find the path to search for libraries.
9293
1. On Linux, system library paths like `/usr/lib/` will additionally be searched
9394
for native dynamic or shaderc library, if the `SHADERC_LIB_DIR` is not set.
9495
1. Building from source, if the native shaderc library is not found via the
9596
above steps.
9697

9798
For each library directory, the build script will try to find and link to the
98-
dynamic native shaderc library `shaderc_shared` first and the static native
99-
shaderc library `shaderc_combined` next. To prefer searching for the static
100-
library first and the dynamic library next, the option
99+
dynamic native shaderc library `shaderc`/`shaderc_shared` first and the static
100+
native shaderc library `shaderc_combined` next. To prefer searching for the
101+
static library first and the dynamic library next, the option
101102
`--features prefer-static-linking` may be used.
102103

103104
Building from Source

shaderc-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ link-cplusplus = "1.0"
2424

2525
[build-dependencies]
2626
cmake = "^0.1.37"
27+
pkg-config = "0.3"
2728
roxmltree = "0.20"

shaderc-sys/build/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ fn main() {
211211
};
212212
}
213213

214+
if search_dir.is_none() {
215+
search_dir = if let Ok(pkg_lib) = pkg_config::Config::new().probe(SHADERC_SHARED_LIB0) {
216+
let pkg_dir = pkg_lib.link_paths[0].as_path().to_string_lossy();
217+
println!("cargo:warning=shaderc: searching native shaderc libraries in '{pkg_dir}' from pkg-config");
218+
Some(pkg_dir.to_string())
219+
} else {
220+
None
221+
};
222+
}
223+
214224
// If no explicit path is set and no explicit request is made to build from
215225
// source, check known system locations before falling back to build from source.
216226
// This set `search_dir` for later usage.

0 commit comments

Comments
 (0)