From fbcbc5ef7cb5e3a69e3c23d6af24c8d340ae5f6b Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 30 Jul 2024 00:58:26 +0900 Subject: [PATCH] chore: emit rustc-check-cfg for rust 1.80 (#10392) * chore: emit rustc-check-cfg for rust 1.80 * build: add lints.rust.unexpected_cfgs to suppress false positive warnings --- .changes/rustc-check-cfg.md | 8 ++++++++ core/tauri-build/Cargo.toml | 4 ++++ core/tauri-build/src/lib.rs | 1 + core/tauri-runtime-wry/build.rs | 1 + core/tauri-runtime/Cargo.toml | 4 ++++ core/tauri-runtime/build.rs | 1 + core/tauri/Cargo.toml | 4 ++++ core/tauri/build.rs | 1 + 8 files changed, 24 insertions(+) create mode 100644 .changes/rustc-check-cfg.md diff --git a/.changes/rustc-check-cfg.md b/.changes/rustc-check-cfg.md new file mode 100644 index 000000000000..98d42942edfa --- /dev/null +++ b/.changes/rustc-check-cfg.md @@ -0,0 +1,8 @@ +--- +"tauri": patch:changes +"tauri-build": patch:changes +"tauri-runtime": patch:changes +"tauri-runtime-wry": patch:changes +--- + +Emit `cargo:rustc-check-cfg` instruction so Cargo validates custom cfg attributes on Rust 1.80 (or nightly-2024-05-05). diff --git a/core/tauri-build/Cargo.toml b/core/tauri-build/Cargo.toml index c526ad69a818..32b366bd5c2a 100644 --- a/core/tauri-build/Cargo.toml +++ b/core/tauri-build/Cargo.toml @@ -16,6 +16,10 @@ readme = "README.md" all-features = true rustdoc-args = [ "--cfg", "doc_cfg" ] +[lints.rust] +# cfg(doc_cfg) is used for docs.rs detection. see above +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] } + [dependencies] anyhow = "1" quote = { version = "1", optional = true } diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 045011dfe4e1..57071d1eb424 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -200,6 +200,7 @@ fn has_feature(feature: &str) -> bool { // creates a cfg alias if `has_feature` is true. // `alias` must be a snake case string. fn cfg_alias(alias: &str, has_feature: bool) { + println!("cargo:rustc-check-cfg=cfg({alias})"); if has_feature { println!("cargo:rustc-cfg={alias}"); } diff --git a/core/tauri-runtime-wry/build.rs b/core/tauri-runtime-wry/build.rs index 2ccb32962447..cf348318d093 100644 --- a/core/tauri-runtime-wry/build.rs +++ b/core/tauri-runtime-wry/build.rs @@ -5,6 +5,7 @@ // creates a cfg alias if `has_feature` is true. // `alias` must be a snake case string. fn alias(alias: &str, has_feature: bool) { + println!("cargo:rustc-check-cfg=cfg({alias})"); if has_feature { println!("cargo:rustc-cfg={alias}"); } diff --git a/core/tauri-runtime/Cargo.toml b/core/tauri-runtime/Cargo.toml index 80b7494faaa1..96a3500a77f5 100644 --- a/core/tauri-runtime/Cargo.toml +++ b/core/tauri-runtime/Cargo.toml @@ -22,6 +22,10 @@ targets = [ "x86_64-apple-darwin" ] +[lints.rust] +# cfg(doc_cfg) is used for docs.rs detection. see above +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] } + [dependencies] serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" diff --git a/core/tauri-runtime/build.rs b/core/tauri-runtime/build.rs index 2ccb32962447..cf348318d093 100644 --- a/core/tauri-runtime/build.rs +++ b/core/tauri-runtime/build.rs @@ -5,6 +5,7 @@ // creates a cfg alias if `has_feature` is true. // `alias` must be a snake case string. fn alias(alias: &str, has_feature: bool) { + println!("cargo:rustc-check-cfg=cfg({alias})"); if has_feature { println!("cargo:rustc-cfg={alias}"); } diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 8ac68a4086ce..0c4c591699a4 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -45,6 +45,10 @@ targets = [ "x86_64-apple-darwin" ] +[lints.rust] +# cfg(doc_cfg) is used for docs.rs detection. see above +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(doc_cfg)'] } + [package.metadata.cargo-udeps.ignore] normal = [ "reqwest", "nix" ] diff --git a/core/tauri/build.rs b/core/tauri/build.rs index bd095e6b06fc..94e10853c73a 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -30,6 +30,7 @@ fn has_feature(feature: &str) -> bool { // creates a cfg alias if `has_feature` is true. // `alias` must be a snake case string. fn alias(alias: &str, has_feature: bool) { + println!("cargo:rustc-check-cfg=cfg({alias})"); if has_feature { println!("cargo:rustc-cfg={alias}"); }