Add rustc-check-cfg for ffmpeg_x_y features (#70)

* sys: Add check-cfg statements

* Add rustc-check-cfg in main crate

The sys build script sets an environment variable for every
feature that needs to be added to rustc-check-cfg.
This commit is contained in:
FreezyLemon 2024-07-20 00:35:19 +02:00 committed by GitHub
parent 820afa79bb
commit 3239649dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -2,7 +2,14 @@ use std::env;
fn main() { fn main() {
for (name, _value) in env::vars() { for (name, _value) in env::vars() {
if name.starts_with("DEP_FFMPEG_") { println!("{name}");
if name.starts_with("DEP_FFMPEG_CHECK_") {
println!(
r#"cargo:rustc-check-cfg=cfg(feature, values("{}"))"#,
name["DEP_FFMPEG_CHECK_".len()..name.len()].to_lowercase()
);
} else if name.starts_with("DEP_FFMPEG_") {
println!( println!(
r#"cargo:rustc-cfg=feature="{}""#, r#"cargo:rustc-cfg=feature="{}""#,
name["DEP_FFMPEG_".len()..name.len()].to_lowercase() name["DEP_FFMPEG_".len()..name.len()].to_lowercase()

View File

@ -851,6 +851,10 @@ fn check_features(include_paths: &[PathBuf]) {
.expect("Unable to find the version for lib{lib}"); .expect("Unable to find the version for lib{lib}");
for &(ffmpeg_version_flag, lavc_version_major, lavc_version_minor) in &ffmpeg_lavc_versions { for &(ffmpeg_version_flag, lavc_version_major, lavc_version_minor) in &ffmpeg_lavc_versions {
// Every possible feature needs an unconditional check-cfg to prevent warnings
println!(r#"cargo:rustc-check-cfg=cfg(feature, values("{}"))"#, ffmpeg_version_flag);
println!(r#"cargo:check_{}=true"#, ffmpeg_version_flag);
if lavc_version >= (lavc_version_major, lavc_version_minor) { if lavc_version >= (lavc_version_major, lavc_version_minor) {
println!(r#"cargo:rustc-cfg=feature="{}""#, ffmpeg_version_flag); println!(r#"cargo:rustc-cfg=feature="{}""#, ffmpeg_version_flag);
println!(r#"cargo:{}=true"#, ffmpeg_version_flag); println!(r#"cargo:{}=true"#, ffmpeg_version_flag);