Explorar el Código

Merge branch '1.x' into feat/1.x-edition-2024

Tillmann hace 1 año
padre
commit
41f518115d

+ 8 - 0
.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).

+ 4 - 0
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 }

+ 1 - 0
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}");
   }

+ 1 - 0
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}");
   }

+ 4 - 0
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"

+ 1 - 0
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}");
   }

+ 8 - 8
core/tauri-utils/src/config/parse.rs

@@ -175,7 +175,7 @@ pub fn is_configuration_file(path: &Path) -> bool {
 /// - `tauri.macos.conf.json[5]` on macOS
 /// - `tauri.linux.conf.json[5]` on Linux
 /// - `tauri.windows.conf.json[5]` on Windows
-/// Merging the configurations using [JSON Merge Patch (RFC 7396)].
+///   Merging the configurations using [JSON Merge Patch (RFC 7396)].
 ///
 /// [JSON Merge Patch (RFC 7396)]: https://datatracker.ietf.org/doc/html/rfc7396.
 pub fn read_from(root_dir: PathBuf) -> Result<Value, ConfigError> {
@@ -224,15 +224,15 @@ pub fn does_supported_file_name_exist(path: impl Into<PathBuf>) -> bool {
 ///
 /// Hierarchy:
 /// 1. Check if `tauri.conf.json` exists
-///   a. Parse it with `serde_json`
-///   b. Parse it with `json5` if `serde_json` fails
-///   c. Return original `serde_json` error if all above steps failed
+///     a. Parse it with `serde_json`
+///     b. Parse it with `json5` if `serde_json` fails
+///     c. Return original `serde_json` error if all above steps failed
 /// 2. Check if `tauri.conf.json5` exists
-///   a. Parse it with `json5`
-///   b. Return error if all above steps failed
+///     a. Parse it with `json5`
+///     b. Return error if all above steps failed
 /// 3. Check if `Tauri.json` exists
-///   a. Parse it with `toml`
-///   b. Return error if all above steps failed
+///     a. Parse it with `toml`
+///     b. Return error if all above steps failed
 /// 4. Return error if all above steps failed
 pub fn parse(path: impl Into<PathBuf>) -> Result<(Config, PathBuf), ConfigError> {
   do_parse(path.into())

+ 4 - 0
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" ]
 

+ 1 - 0
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}");
   }

+ 2 - 2
core/tauri/src/api/notification.rs

@@ -61,8 +61,8 @@ pub enum Sound {
   ///   if `ms-winsoundevent:Notification.Looping.Alarm2`, you would use `Alarm2`.
   ///   Windows 7 is not supported, if a sound is provided, it will play the default sound, otherwise it will be silent.
   /// - **macOS**: you can specify the name of the sound you'd like to play when the notification is shown.
-  /// Any of the default sounds (under System Preferences > Sound) can be used, in addition to custom sound files.
-  /// Be sure that the sound file is under one of the following locations:
+  ///   Any of the default sounds (under System Preferences > Sound) can be used, in addition to custom sound files.
+  ///   Be sure that the sound file is under one of the following locations:
   ///   - `~/Library/Sounds`
   ///   - `/Library/Sounds`
   ///   - `/Network/Library/Sounds`

+ 2 - 0
core/tauri/src/endpoints/dialog.rs

@@ -52,6 +52,7 @@ pub struct DialogFilter {
 /// The options for the open dialog API.
 #[derive(Debug, Clone, Deserialize)]
 #[serde(rename_all = "camelCase")]
+#[cfg_attr(not(dialog_open), allow(dead_code))]
 pub struct OpenDialogOptions {
   /// The title of the dialog window.
   pub title: Option<String>,
@@ -75,6 +76,7 @@ pub struct OpenDialogOptions {
 /// The options for the save dialog API.
 #[derive(Debug, Clone, Deserialize)]
 #[serde(rename_all = "camelCase")]
+#[cfg_attr(not(dialog_save), allow(dead_code))]
 pub struct SaveDialogOptions {
   /// The title of the dialog window.
   pub title: Option<String>,

+ 1 - 1
core/tauri/src/lib.rs

@@ -20,7 +20,7 @@
 //! - **custom-protocol**: Feature managed by the Tauri CLI. When enabled, Tauri assumes a production environment instead of a development one.
 //! - **updater**: Enables the application auto updater. Enabled by default if the `updater` config is defined on the `tauri.conf.json` file.
 //! - **devtools**: Enables the developer tools (Web inspector) and [`Window::open_devtools`]. Enabled by default on debug builds.
-//! On macOS it uses private APIs, so you can't enable it if your app will be published to the App Store.
+//!   On macOS it uses private APIs, so you can't enable it if your app will be published to the App Store.
 //! - **shell-open-api**: Enables the [`api::shell`] module.
 //! - **http-api**: Enables the [`api::http`] module.
 //! - **http-multipart**: Adds support to `multipart/form-data` requests.

+ 3 - 3
core/tauri/src/window.rs

@@ -1713,7 +1713,7 @@ impl<R: Runtime> Window<R> {
   /// ## Platform-specific
   ///
   /// - **macOS:** Only supported on macOS 10.15+.
-  /// This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
+  ///   This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
   ///
   /// # Examples
   ///
@@ -1738,7 +1738,7 @@ impl<R: Runtime> Window<R> {
   /// ## Platform-specific
   ///
   /// - **macOS:** Only supported on macOS 10.15+.
-  /// This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
+  ///   This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
   /// - **Windows:** Unsupported.
   ///
   /// # Examples
@@ -1771,7 +1771,7 @@ impl<R: Runtime> Window<R> {
   /// ## Platform-specific
   ///
   /// - **macOS:** Only supported on macOS 10.15+.
-  /// This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
+  ///   This is a private API on macOS, so you cannot use this if your application will be published on the App Store.
   /// - **Windows:** Unsupported.
   ///
   /// # Examples