Bladeren bron

refactor(cli): use `windows-sys` instead of `winapi` (#9603)

* refactor(cli): use `windows-sys` instead of `winapi`

* Update cli-windows-sys.md
Amr Bashir 1 jaar geleden
bovenliggende
commit
3f08054885

+ 5 - 0
.changes/cli-windows-sys.md

@@ -0,0 +1,5 @@
+---
+"tauri-cli": "patch:bug"
+---
+
+Use `windows-sys` crate instead of `winapi` which fixes installing the published cli from crates.io using `cargo install tauri-cli --version "^2.0.0-beta"`.

+ 40 - 34
tooling/cli/Cargo.lock

@@ -573,7 +573,7 @@ dependencies = [
  "num-traits",
  "serde",
  "wasm-bindgen",
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -4904,7 +4904,6 @@ dependencies = [
  "axum",
  "base64 0.22.0",
  "cargo-mobile2",
- "cc",
  "clap",
  "clap_complete",
  "colored",
@@ -4958,7 +4957,7 @@ dependencies = [
  "unicode-width",
  "ureq",
  "url",
- "winapi",
+ "windows-sys 0.52.0",
  "zeroize",
 ]
 
@@ -5928,7 +5927,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
 dependencies = [
  "windows-core 0.54.0",
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -5937,7 +5936,7 @@ version = "0.52.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
 dependencies = [
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -5947,16 +5946,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
 dependencies = [
  "windows-result",
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
 name = "windows-result"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cd19df78e5168dfb0aedc343d1d1b8d422ab2db6756d2dc3fef75035402a3f64"
+checksum = "749f0da9cc72d82e600d8d2e44cadd0b9eedb9038f71a1c58556ac1c5791813b"
 dependencies = [
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -5974,7 +5973,7 @@ version = "0.52.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
 dependencies = [
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -5994,17 +5993,18 @@ dependencies = [
 
 [[package]]
 name = "windows-targets"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
+checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
 dependencies = [
- "windows_aarch64_gnullvm 0.52.4",
- "windows_aarch64_msvc 0.52.4",
- "windows_i686_gnu 0.52.4",
- "windows_i686_msvc 0.52.4",
- "windows_x86_64_gnu 0.52.4",
- "windows_x86_64_gnullvm 0.52.4",
- "windows_x86_64_msvc 0.52.4",
+ "windows_aarch64_gnullvm 0.52.5",
+ "windows_aarch64_msvc 0.52.5",
+ "windows_i686_gnu 0.52.5",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc 0.52.5",
+ "windows_x86_64_gnu 0.52.5",
+ "windows_x86_64_gnullvm 0.52.5",
+ "windows_x86_64_msvc 0.52.5",
 ]
 
 [[package]]
@@ -6013,7 +6013,7 @@ version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "75aa004c988e080ad34aff5739c39d0312f4684699d6d71fc8a198d057b8b9b4"
 dependencies = [
- "windows-targets 0.52.4",
+ "windows-targets 0.52.5",
 ]
 
 [[package]]
@@ -6024,9 +6024,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
 
 [[package]]
 name = "windows_aarch64_gnullvm"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
+checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
 
 [[package]]
 name = "windows_aarch64_msvc"
@@ -6036,9 +6036,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
 
 [[package]]
 name = "windows_aarch64_msvc"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
+checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
 
 [[package]]
 name = "windows_i686_gnu"
@@ -6048,9 +6048,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
 
 [[package]]
 name = "windows_i686_gnu"
-version = "0.52.4"
+version = "0.52.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
+checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
 
 [[package]]
 name = "windows_i686_msvc"
@@ -6060,9 +6066,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
 
 [[package]]
 name = "windows_i686_msvc"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
+checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
 
 [[package]]
 name = "windows_x86_64_gnu"
@@ -6072,9 +6078,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
 
 [[package]]
 name = "windows_x86_64_gnu"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
+checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
 
 [[package]]
 name = "windows_x86_64_gnullvm"
@@ -6084,9 +6090,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
 
 [[package]]
 name = "windows_x86_64_gnullvm"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
+checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
 
 [[package]]
 name = "windows_x86_64_msvc"
@@ -6096,9 +6102,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
 
 [[package]]
 name = "windows_x86_64_msvc"
-version = "0.52.4"
+version = "0.52.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
+checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
 
 [[package]]
 name = "winnow"

+ 7 - 3
tooling/cli/Cargo.toml

@@ -96,9 +96,13 @@ resvg = "0.40.0"
 dunce = "1"
 glob = "0.3"
 
-[target."cfg(windows)".dependencies]
-winapi = { version = "0.3", features = [ "handleapi", "processenv", "winbase", "wincon", "winnt" ] }
-cc = "1"
+[target."cfg(windows)".dependencies.windows-sys]
+version = "0.52"
+features = [
+  "Win32_Storage_FileSystem",
+  "Win32_System_IO",
+  "Win32_System_Console"
+]
 
 [target."cfg(unix)".dependencies]
 libc = "0.2"

+ 25 - 19
tooling/cli/src/helpers/flock.rs

@@ -305,10 +305,10 @@ mod sys {
   use std::mem;
   use std::os::windows::io::AsRawHandle;
 
-  use winapi::shared::minwindef::DWORD;
-  use winapi::shared::winerror::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION};
-  use winapi::um::fileapi::{LockFileEx, UnlockFile};
-  use winapi::um::minwinbase::{LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY};
+  use windows_sys::Win32::Foundation::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION, HANDLE};
+  use windows_sys::Win32::Storage::FileSystem::{
+    LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY, LOCK_FILE_FLAGS,
+  };
 
   pub(super) fn lock_shared(file: &File) -> Result<()> {
     lock_file(file, 0)
@@ -339,25 +339,31 @@ mod sys {
   }
 
   pub(super) fn unlock(file: &File) -> Result<()> {
-    unsafe {
-      let ret = UnlockFile(file.as_raw_handle(), 0, 0, !0, !0);
-      if ret == 0 {
-        Err(Error::last_os_error())
-      } else {
-        Ok(())
-      }
+    let ret = unsafe { UnlockFile(file.as_raw_handle() as HANDLE, 0, 0, !0, !0) };
+    if ret == 0 {
+      Err(Error::last_os_error())
+    } else {
+      Ok(())
     }
   }
 
-  fn lock_file(file: &File, flags: DWORD) -> Result<()> {
-    unsafe {
+  fn lock_file(file: &File, flags: LOCK_FILE_FLAGS) -> Result<()> {
+    let ret = unsafe {
       let mut overlapped = mem::zeroed();
-      let ret = LockFileEx(file.as_raw_handle(), flags, 0, !0, !0, &mut overlapped);
-      if ret == 0 {
-        Err(Error::last_os_error())
-      } else {
-        Ok(())
-      }
+      LockFileEx(
+        file.as_raw_handle() as HANDLE,
+        flags,
+        0,
+        !0,
+        !0,
+        &mut overlapped,
+      )
+    };
+
+    if ret == 0 {
+      Err(Error::last_os_error())
+    } else {
+      Ok(())
     }
   }
 }

+ 10 - 8
tooling/cli/src/interface/rust/desktop.rs

@@ -446,12 +446,14 @@ mod terminal {
 #[cfg(windows)]
 mod terminal {
   use std::{cmp, mem, ptr};
-  use winapi::um::fileapi::*;
-  use winapi::um::handleapi::*;
-  use winapi::um::processenv::*;
-  use winapi::um::winbase::*;
-  use winapi::um::wincon::*;
-  use winapi::um::winnt::*;
+
+  use windows_sys::Win32::{
+    Foundation::{CloseHandle, GENERIC_READ, GENERIC_WRITE, INVALID_HANDLE_VALUE},
+    Storage::FileSystem::{CreateFileA, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING},
+    System::Console::{
+      GetConsoleScreenBufferInfo, GetStdHandle, CONSOLE_SCREEN_BUFFER_INFO, STD_ERROR_HANDLE,
+    },
+  };
 
   pub fn stderr_width() -> Option<usize> {
     unsafe {
@@ -465,13 +467,13 @@ mod terminal {
       // INVALID_HANDLE_VALUE. Use an alternate method which works
       // in that case as well.
       let h = CreateFileA(
-        "CONOUT$\0".as_ptr() as *const CHAR,
+        "CONOUT$\0".as_ptr(),
         GENERIC_READ | GENERIC_WRITE,
         FILE_SHARE_READ | FILE_SHARE_WRITE,
         ptr::null_mut(),
         OPEN_EXISTING,
         0,
-        ptr::null_mut(),
+        0,
       );
       if h == INVALID_HANDLE_VALUE {
         return None;