feature-gate vcpkg

This commit is contained in:
Ruifeng Xie 2021-12-25 16:34:35 +08:00
parent 5354ba8b04
commit 59b67c14c0
No known key found for this signature in database
GPG Key ID: 17A512702D99B3B8
3 changed files with 17 additions and 16 deletions

View File

@ -136,17 +136,23 @@ jobs:
- name: docking feature
run: cargo test --workspace --all-targets --features docking
- name: freetype feature
- name: freetype feature (non-Windows, pkg-config)
if: matrix.os != 'windows-latest'
run: cargo test --workspace --all-targets --features freetype
- name: all features
- name: freetype and docking (non-Windows, pkg-config)
if: matrix.os != 'windows-latest'
run: cargo test --workspace --all-targets --features docking,freetype
run: cargo test --workspace --all-targets --features freetype,docking
- name: doc tests
run: cargo test --workspace --doc
- name: freetype feature (Windows, vcpkg)
if: matrix.os == 'windows-latest'
run: cargo test --workspace --all-targets --features freetype,use-vcpkg
- name: freetype and docking (Windows, vcpkg)
if: matrix.os == 'windows-latest'
run: cargo test --workspace --all-targets --features freetype,docking,use-vcpkg
- run: cargo test --workspace --doc
# run to check for lint problems
- name: build documentation
run: cargo doc

View File

@ -39,4 +39,5 @@ vcpkg = { version="0.2.15", optional=true }
default = []
wasm = []
docking = []
freetype = ["pkg-config", "vcpkg"]
freetype = ["pkg-config"]
use-vcpkg = ["vcpkg"]

View File

@ -11,22 +11,16 @@ const DEFINES: &[(&str, Option<&str>)] = &[
#[cfg(feature = "freetype")]
fn find_freetype() -> Vec<impl AsRef<std::path::Path>> {
let err_pkg_config;
let err_vcpkg;
#[cfg(not(feature = "use-vcpkg"))]
match pkg_config::Config::new().find("freetype2") {
Ok(freetype) => return freetype.include_paths,
Err(err) => err_pkg_config = err,
Err(err) => panic!("cannot find freetype: {}", err),
}
#[cfg(feature = "use-vcpkg")]
match vcpkg::find_package("freetype") {
Ok(freetype) => return freetype.include_paths,
Err(err) => err_vcpkg = err,
Err(err) => panic!("cannot find freetype: {}", err),
}
panic!(
"cannot find freetype:\n\
- pkg-config failed with: {}\n\
- vcpkg failed with: {}",
err_pkg_config, err_vcpkg
);
}
// Output define args for compiler