From ae91d4ed41da98bdfa16041dbc6cd30287920120 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 18:02:57 +0800 Subject: [PATCH 1/8] do some clean up --- Cargo.toml | 27 +++++++------------ crates/cargo-test-support/Cargo.toml | 2 +- crates/cargo-test-support/src/paths.rs | 2 +- crates/cargo-util/Cargo.toml | 2 +- crates/cargo-util/src/paths.rs | 5 ++-- crates/cargo-util/src/process_builder.rs | 8 +++--- crates/cargo-util/src/process_error.rs | 5 ++-- crates/cargo-util/src/read2.rs | 2 +- .../cargo-credential-wincred/Cargo.toml | 2 +- crates/home/Cargo.toml | 9 ++----- crates/home/src/lib.rs | 2 +- crates/home/src/windows.rs | 5 ++-- src/cargo/core/resolver/features.rs | 2 +- src/cargo/core/shell.rs | 19 ++++++++----- src/cargo/util/cpu.rs | 5 ++-- src/cargo/util/flock.rs | 22 ++++++++++----- src/cargo/util/job.rs | 17 +++++++----- 17 files changed, 69 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b28e425dcc4..9b96a75339c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,25 +84,16 @@ rustc-workspace-hack = "1.0.0" [target.'cfg(windows)'.dependencies] fwdansi = "1.1.0" -[target.'cfg(windows)'.dependencies.winapi] -version = "0.3" +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.45" features = [ - "basetsd", - "handleapi", - "jobapi", - "jobapi2", - "memoryapi", - "minwindef", - "ntdef", - "ntstatus", - "processenv", - "processthreadsapi", - "psapi", - "synchapi", - "winerror", - "winbase", - "wincon", - "winnt", + "Win32_Foundation", + "Win32_Storage_FileSystem", + "Win32_System_IO", + "Win32_System_Threading", + "Win32_System_JobObjects", + "Win32_Security", + "Win32_System_SystemServices" ] [dev-dependencies] diff --git a/crates/cargo-test-support/Cargo.toml b/crates/cargo-test-support/Cargo.toml index 653c5db4d61..89eb94a5ef7 100644 --- a/crates/cargo-test-support/Cargo.toml +++ b/crates/cargo-test-support/Cargo.toml @@ -29,7 +29,7 @@ toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] } url = "2.2.2" [target.'cfg(windows)'.dependencies] -winapi = "0.3" +windows-sys = { version = "0.45.0", features = ["Win32_Storage_FileSystem"] } [features] deny-warnings = [] diff --git a/crates/cargo-test-support/src/paths.rs b/crates/cargo-test-support/src/paths.rs index 6925597a1da..ef1fddb7003 100644 --- a/crates/cargo-test-support/src/paths.rs +++ b/crates/cargo-test-support/src/paths.rs @@ -305,7 +305,7 @@ pub fn windows_reserved_names_are_allowed() -> bool { use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; use std::ptr; - use winapi::um::fileapi::GetFullPathNameW; + use windows_sys::Win32::Storage::FileSystem::GetFullPathNameW; let test_file_name: Vec<_> = OsStr::new("aux.rs").encode_wide().collect(); diff --git a/crates/cargo-util/Cargo.toml b/crates/cargo-util/Cargo.toml index ff47587b3c7..7c9d89df12a 100644 --- a/crates/cargo-util/Cargo.toml +++ b/crates/cargo-util/Cargo.toml @@ -25,4 +25,4 @@ core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] } [target.'cfg(windows)'.dependencies] miow = "0.5.0" -winapi = { version = "0.3.9", features = ["consoleapi", "minwindef"] } +windows-sys = { version = "0.45.0", features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_Console"] } diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs index d0ac2a79a08..69df7a2096c 100644 --- a/crates/cargo-util/src/paths.rs +++ b/crates/cargo-util/src/paths.rs @@ -701,8 +701,9 @@ fn exclude_from_content_indexing(path: &Path) { { use std::iter::once; use std::os::windows::prelude::OsStrExt; - use winapi::um::fileapi::{GetFileAttributesW, SetFileAttributesW}; - use winapi::um::winnt::FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; + use windows_sys::Win32::Storage::FileSystem::{ + GetFileAttributesW, SetFileAttributesW, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, + }; let path: Vec = path.as_os_str().encode_wide().chain(once(0)).collect(); unsafe { diff --git a/crates/cargo-util/src/process_builder.rs b/crates/cargo-util/src/process_builder.rs index be8a5fca3b3..76392f2564b 100644 --- a/crates/cargo-util/src/process_builder.rs +++ b/crates/cargo-util/src/process_builder.rs @@ -606,10 +606,10 @@ mod imp { use super::{ProcessBuilder, ProcessError}; use anyhow::Result; use std::io; - use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE}; - use winapi::um::consoleapi::SetConsoleCtrlHandler; + use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE}; + use windows_sys::Win32::System::Console::SetConsoleCtrlHandler; - unsafe extern "system" fn ctrlc_handler(_: DWORD) -> BOOL { + unsafe extern "system" fn ctrlc_handler(_: u32) -> BOOL { // Do nothing; let the child process handle it. TRUE } @@ -626,7 +626,7 @@ mod imp { } pub fn command_line_too_big(err: &io::Error) -> bool { - use winapi::shared::winerror::ERROR_FILENAME_EXCED_RANGE; + use windows_sys::Win32::Foundation::ERROR_FILENAME_EXCED_RANGE; err.raw_os_error() == Some(ERROR_FILENAME_EXCED_RANGE as i32) } } diff --git a/crates/cargo-util/src/process_error.rs b/crates/cargo-util/src/process_error.rs index e8607d6614d..9b4a38cb5e3 100644 --- a/crates/cargo-util/src/process_error.rs +++ b/crates/cargo-util/src/process_error.rs @@ -140,11 +140,10 @@ pub fn exit_status_to_string(status: ExitStatus) -> String { #[cfg(windows)] fn status_to_string(status: ExitStatus) -> String { - use winapi::shared::minwindef::DWORD; - use winapi::um::winnt::*; + use windows_sys::Win32::Foundation::*; let mut base = status.to_string(); - let extra = match status.code().unwrap() as DWORD { + let extra = match status.code().unwrap() as i32 { STATUS_ACCESS_VIOLATION => "STATUS_ACCESS_VIOLATION", STATUS_IN_PAGE_ERROR => "STATUS_IN_PAGE_ERROR", STATUS_INVALID_HANDLE => "STATUS_INVALID_HANDLE", diff --git a/crates/cargo-util/src/read2.rs b/crates/cargo-util/src/read2.rs index 53322a51d70..742dc1daa60 100644 --- a/crates/cargo-util/src/read2.rs +++ b/crates/cargo-util/src/read2.rs @@ -84,7 +84,7 @@ mod imp { use miow::iocp::{CompletionPort, CompletionStatus}; use miow::pipe::NamedPipe; use miow::Overlapped; - use winapi::shared::winerror::ERROR_BROKEN_PIPE; + use windows_sys::Win32::Foundation::ERROR_BROKEN_PIPE; struct Pipe<'a> { dst: &'a mut Vec, diff --git a/crates/credential/cargo-credential-wincred/Cargo.toml b/crates/credential/cargo-credential-wincred/Cargo.toml index b612c26fe7a..d17b1afa04c 100644 --- a/crates/credential/cargo-credential-wincred/Cargo.toml +++ b/crates/credential/cargo-credential-wincred/Cargo.toml @@ -8,4 +8,4 @@ description = "A Cargo credential process that stores tokens with Windows Creden [dependencies] cargo-credential = { version = "0.2.0", path = "../cargo-credential" } -winapi = { version = "0.3.9", features = ["wincred", "winerror", "impl-default"] } +windows-sys = { version = "0.45", features = [] } diff --git a/crates/home/Cargo.toml b/crates/home/Cargo.toml index 052b6193215..f2797db9c4f 100644 --- a/crates/home/Cargo.toml +++ b/crates/home/Cargo.toml @@ -16,10 +16,5 @@ readme = "README.md" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" -[target."cfg(windows)".dependencies.winapi] -version = "0.3" -features = [ - "shlobj", - "std", - "winerror", -] +[target."cfg(windows)".dependencies] +windows-sys = { version = "0.45.0", features = ["Win32_Foundation", "Win32_UI_Shell"] } diff --git a/crates/home/src/lib.rs b/crates/home/src/lib.rs index ad254ca3bb1..2dd22883be0 100644 --- a/crates/home/src/lib.rs +++ b/crates/home/src/lib.rs @@ -30,7 +30,7 @@ pub mod env; -#[cfg(windows)] +#[cfg(target_os(windows))] mod windows; use std::io; diff --git a/crates/home/src/windows.rs b/crates/home/src/windows.rs index 4e0cd8ec513..65b5ec725bc 100644 --- a/crates/home/src/windows.rs +++ b/crates/home/src/windows.rs @@ -4,9 +4,8 @@ use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; -use winapi::shared::minwindef::MAX_PATH; -use winapi::shared::winerror::S_OK; -use winapi::um::shlobj::{SHGetFolderPathW, CSIDL_PROFILE}; +use windows_sys::Win32::Foundation::{MAX_PATH, S_OK}; +use windows_sys::Win32::UI::Shell::{SHGetFolderPathW, CSIDL_PROFILE}; pub fn home_dir_inner() -> Option { env::var_os("USERPROFILE") diff --git a/src/cargo/core/resolver/features.rs b/src/cargo/core/resolver/features.rs index e2f2bd5c50c..564be05873c 100644 --- a/src/cargo/core/resolver/features.rs +++ b/src/cargo/core/resolver/features.rs @@ -812,7 +812,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> { true }) .flat_map(|dep| { - // Each `dep`endency can be built for multiple targets. For one, it + // Each dependency can be built for multiple targets. For one, it // may be a library target which is built as initially configured // by `fk`. If it appears as build dependency, it must be built // for the host. diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index d1f413adb8f..84a16f75594 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -557,12 +557,17 @@ mod imp { #[cfg(windows)] mod imp { 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::core::PCSTR; + use windows_sys::Win32::Foundation::CloseHandle; + use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; + use windows_sys::Win32::Storage::FileSystem::{ + CreateFileA, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING, + }; + use windows_sys::Win32::System::Console::{ + GetConsoleScreenBufferInfo, GetStdHandle, CONSOLE_SCREEN_BUFFER_INFO, STD_ERROR_HANDLE, + }; + use windows_sys::Win32::System::SystemServices::{GENERIC_READ, GENERIC_WRITE}; pub(super) use super::{default_err_erase_line as err_erase_line, TtyWidth}; @@ -578,7 +583,7 @@ mod imp { // 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() as PCSTR, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, ptr::null_mut(), diff --git a/src/cargo/util/cpu.rs b/src/cargo/util/cpu.rs index 3fe50d372da..6ebb01b8ea1 100644 --- a/src/cargo/util/cpu.rs +++ b/src/cargo/util/cpu.rs @@ -190,8 +190,9 @@ mod imp { mod imp { use std::io; use std::mem; - use winapi::shared::minwindef::*; - use winapi::um::processthreadsapi::*; + + use windows_sys::Win32::Foundation::FILETIME; + use windows_sys::Win32::System::Threading::GetSystemTimes; pub struct State { idle: FILETIME, diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 0cdd9434495..295eb1e140b 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -437,10 +437,11 @@ 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::HANDLE; + use windows_sys::Win32::Foundation::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION}; + use windows_sys::Win32::Storage::FileSystem::{ + LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY, + }; pub(super) fn lock_shared(file: &File) -> Result<()> { lock_file(file, 0) @@ -470,7 +471,7 @@ mod sys { pub(super) fn unlock(file: &File) -> Result<()> { unsafe { - let ret = UnlockFile(file.as_raw_handle(), 0, 0, !0, !0); + let ret = UnlockFile(file.as_raw_handle() as HANDLE, 0, 0, !0, !0); if ret == 0 { Err(Error::last_os_error()) } else { @@ -479,10 +480,17 @@ mod sys { } } - fn lock_file(file: &File, flags: DWORD) -> Result<()> { + fn lock_file(file: &File, flags: u32) -> Result<()> { unsafe { let mut overlapped = mem::zeroed(); - let ret = LockFileEx(file.as_raw_handle(), flags, 0, !0, !0, &mut overlapped); + let ret = LockFileEx( + file.as_raw_handle() as HANDLE, + flags, + 0, + !0, + !0, + &mut overlapped, + ); if ret == 0 { Err(Error::last_os_error()) } else { diff --git a/src/cargo/util/job.rs b/src/cargo/util/job.rs index 7a9cd1bcaed..1f2d11281fc 100644 --- a/src/cargo/util/job.rs +++ b/src/cargo/util/job.rs @@ -47,12 +47,15 @@ mod imp { use log::info; - use winapi::shared::minwindef::*; - use winapi::um::handleapi::*; - use winapi::um::jobapi2::*; - use winapi::um::processthreadsapi::*; - use winapi::um::winnt::HANDLE; - use winapi::um::winnt::*; + use windows_sys::Win32::Foundation::CloseHandle; + use windows_sys::Win32::Foundation::HANDLE; + use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; + use windows_sys::Win32::System::JobObjects::AssignProcessToJobObject; + use windows_sys::Win32::System::JobObjects::CreateJobObjectW; + use windows_sys::Win32::System::JobObjects::JobObjectExtendedLimitInformation; + use windows_sys::Win32::System::JobObjects::SetInformationJobObject; + use windows_sys::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION; + use windows_sys::Win32::System::Threading::GetCurrentProcess; pub struct Setup { job: Handle, @@ -77,7 +80,7 @@ mod imp { // we're otherwise part of someone else's job object in this case. let job = CreateJobObjectW(ptr::null_mut(), ptr::null()); - if job.is_null() { + if job == INVALID_HANDLE_VALUE { return None; } let job = Handle { inner: job }; From d46273ae362abdb2415925595727a1773e00d36e Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 18:03:59 +0800 Subject: [PATCH 2/8] more --- src/cargo/util/job.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cargo/util/job.rs b/src/cargo/util/job.rs index 1f2d11281fc..49335366f01 100644 --- a/src/cargo/util/job.rs +++ b/src/cargo/util/job.rs @@ -55,6 +55,7 @@ mod imp { use windows_sys::Win32::System::JobObjects::JobObjectExtendedLimitInformation; use windows_sys::Win32::System::JobObjects::SetInformationJobObject; use windows_sys::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION; + use windows_sys::Win32::System::JobObjects::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; use windows_sys::Win32::System::Threading::GetCurrentProcess; pub struct Setup { From a592060fbf0d9dbefac79b2428a4fef4f3ce1974 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 18:24:13 +0800 Subject: [PATCH 3/8] fix --- src/cargo/core/shell.rs | 2 +- src/cargo/util/job.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 84a16f75594..79f09e6f9ce 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -589,7 +589,7 @@ mod imp { ptr::null_mut(), OPEN_EXISTING, 0, - ptr::null_mut(), + 0, ); if h == INVALID_HANDLE_VALUE { return TtyWidth::NoTty; diff --git a/src/cargo/util/job.rs b/src/cargo/util/job.rs index 49335366f01..9ff9b53042d 100644 --- a/src/cargo/util/job.rs +++ b/src/cargo/util/job.rs @@ -44,6 +44,7 @@ mod imp { use std::io; use std::mem; use std::ptr; + use std::ptr::addr_of; use log::info; @@ -96,8 +97,8 @@ mod imp { let r = SetInformationJobObject( job.inner, JobObjectExtendedLimitInformation, - &mut info as *mut _ as LPVOID, - mem::size_of_val(&info) as DWORD, + addr_of!(info) as *const _, + mem::size_of_val(&info) as u32, ); if r == 0 { return None; @@ -120,13 +121,13 @@ mod imp { // processes. The destructor here configures our job object to // **not** kill everything on close, then closes the job object. unsafe { - let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION; + let info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION; info = mem::zeroed(); let r = SetInformationJobObject( self.job.inner, JobObjectExtendedLimitInformation, - &mut info as *mut _ as LPVOID, - mem::size_of_val(&info) as DWORD, + addr_of!(info) as *const _, + mem::size_of_val(&info) as u32, ); if r == 0 { info!("failed to configure job object to defaults: {}", last_err()); From d9537b8187114cf948a51c6357da3a979cda356e Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 19:14:45 +0800 Subject: [PATCH 4/8] fix --- crates/home/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/home/src/lib.rs b/crates/home/src/lib.rs index 2dd22883be0..306026e4010 100644 --- a/crates/home/src/lib.rs +++ b/crates/home/src/lib.rs @@ -30,7 +30,7 @@ pub mod env; -#[cfg(target_os(windows))] +#[cfg(target_os = "windows")] mod windows; use std::io; From 8342c1e9f2a0716bd6f490d35abafc56bcdf51ec Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 20:12:58 +0800 Subject: [PATCH 5/8] more --- .../cargo-credential-wincred/Cargo.toml | 2 +- .../cargo-credential-wincred/src/main.rs | 53 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/crates/credential/cargo-credential-wincred/Cargo.toml b/crates/credential/cargo-credential-wincred/Cargo.toml index d17b1afa04c..83c38e80dbb 100644 --- a/crates/credential/cargo-credential-wincred/Cargo.toml +++ b/crates/credential/cargo-credential-wincred/Cargo.toml @@ -8,4 +8,4 @@ description = "A Cargo credential process that stores tokens with Windows Creden [dependencies] cargo-credential = { version = "0.2.0", path = "../cargo-credential" } -windows-sys = { version = "0.45", features = [] } +windows-sys = { version = "0.45", features = ["Win32_Foundation", "Win32_Security_Credentials"] } diff --git a/crates/credential/cargo-credential-wincred/src/main.rs b/crates/credential/cargo-credential-wincred/src/main.rs index 8661d28b80b..de39dc26dc7 100644 --- a/crates/credential/cargo-credential-wincred/src/main.rs +++ b/crates/credential/cargo-credential-wincred/src/main.rs @@ -3,10 +3,17 @@ use cargo_credential::{Credential, Error}; use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; -use winapi::shared::minwindef::{DWORD, FILETIME, LPBYTE, TRUE}; -use winapi::shared::winerror; -use winapi::um::wincred; -use winapi::um::winnt::LPWSTR; + +use windows_sys::core::PWSTR; +use windows_sys::Win32::Foundation::ERROR_NOT_FOUND; +use windows_sys::Win32::Foundation::FILETIME; +use windows_sys::Win32::Foundation::TRUE; +use windows_sys::Win32::Security::Credentials::CredDeleteW; +use windows_sys::Win32::Security::Credentials::CredReadW; +use windows_sys::Win32::Security::Credentials::CredWriteW; +use windows_sys::Win32::Security::Credentials::CREDENTIALW; +use windows_sys::Win32::Security::Credentials::CRED_PERSIST_LOCAL_MACHINE; +use windows_sys::Win32::Security::Credentials::CRED_TYPE_GENERIC; struct WindowsCredential; @@ -31,13 +38,13 @@ impl Credential for WindowsCredential { fn get(&self, index_url: &str) -> Result { let target_name = target_name(index_url); - let mut p_credential: wincred::PCREDENTIALW = std::ptr::null_mut(); + let mut p_credential: CREDENTIALW = std::ptr::null_mut(); unsafe { - if wincred::CredReadW( + if CredReadW( target_name.as_ptr(), - wincred::CRED_TYPE_GENERIC, + CRED_TYPE_GENERIC, 0, - &mut p_credential, + &mut p_credential as *mut _, ) != TRUE { return Err( @@ -45,8 +52,8 @@ impl Credential for WindowsCredential { ); } let bytes = std::slice::from_raw_parts( - (*p_credential).CredentialBlob, - (*p_credential).CredentialBlobSize as usize, + p_credential.CredentialBlob, + p_credential.CredentialBlobSize as usize, ); String::from_utf8(bytes.to_vec()).map_err(|_| "failed to convert token to UTF8".into()) } @@ -59,21 +66,24 @@ impl Credential for WindowsCredential { Some(name) => wstr(&format!("Cargo registry token for {}", name)), None => wstr("Cargo registry token"), }; - let mut credential = wincred::CREDENTIALW { + let mut credential = CREDENTIALW { Flags: 0, - Type: wincred::CRED_TYPE_GENERIC, - TargetName: target_name.as_ptr() as LPWSTR, - Comment: comment.as_ptr() as LPWSTR, - LastWritten: FILETIME::default(), - CredentialBlobSize: token.len() as DWORD, - CredentialBlob: token.as_ptr() as LPBYTE, - Persist: wincred::CRED_PERSIST_LOCAL_MACHINE, + Type: CRED_TYPE_GENERIC, + TargetName: target_name.as_ptr() as PWSTR, + Comment: comment.as_ptr() as PWSTR, + LastWritten: FILETIME { + dwLowDateTime: 0, + dwHighDateTime: 0, + }, + CredentialBlobSize: token.len() as u32, + CredentialBlob: token.as_ptr() as *mut u8, + Persist: CRED_PERSIST_LOCAL_MACHINE, AttributeCount: 0, Attributes: std::ptr::null_mut(), TargetAlias: std::ptr::null_mut(), UserName: std::ptr::null_mut(), }; - let result = unsafe { wincred::CredWriteW(&mut credential, 0) }; + let result = unsafe { CredWriteW(&mut credential, 0) }; if result != TRUE { let err = std::io::Error::last_os_error(); return Err(format!("failed to store token: {}", err).into()); @@ -83,11 +93,10 @@ impl Credential for WindowsCredential { fn erase(&self, index_url: &str) -> Result<(), Error> { let target_name = target_name(index_url); - let result = - unsafe { wincred::CredDeleteW(target_name.as_ptr(), wincred::CRED_TYPE_GENERIC, 0) }; + let result = unsafe { CredDeleteW(target_name.as_ptr(), CRED_TYPE_GENERIC, 0) }; if result != TRUE { let err = std::io::Error::last_os_error(); - if err.raw_os_error() == Some(winerror::ERROR_NOT_FOUND as i32) { + if err.raw_os_error() == Some(ERROR_NOT_FOUND as i32) { eprintln!("not currently logged in to `{}`", index_url); return Ok(()); } From f89e58f300e169df8f6de92b55329648128aff9f Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 22:40:28 +0800 Subject: [PATCH 6/8] MORE --- crates/credential/cargo-credential-wincred/src/main.rs | 8 ++++---- crates/home/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/credential/cargo-credential-wincred/src/main.rs b/crates/credential/cargo-credential-wincred/src/main.rs index de39dc26dc7..8ae48f34899 100644 --- a/crates/credential/cargo-credential-wincred/src/main.rs +++ b/crates/credential/cargo-credential-wincred/src/main.rs @@ -38,13 +38,13 @@ impl Credential for WindowsCredential { fn get(&self, index_url: &str) -> Result { let target_name = target_name(index_url); - let mut p_credential: CREDENTIALW = std::ptr::null_mut(); + let p_credential: *mut CREDENTIALW = std::ptr::null_mut() as *mut _; unsafe { if CredReadW( target_name.as_ptr(), CRED_TYPE_GENERIC, 0, - &mut p_credential as *mut _, + p_credential as *mut _ as *mut _, ) != TRUE { return Err( @@ -52,8 +52,8 @@ impl Credential for WindowsCredential { ); } let bytes = std::slice::from_raw_parts( - p_credential.CredentialBlob, - p_credential.CredentialBlobSize as usize, + (*p_credential).CredentialBlob, + (*p_credential).CredentialBlobSize as usize, ); String::from_utf8(bytes.to_vec()).map_err(|_| "failed to convert token to UTF8".into()) } diff --git a/crates/home/Cargo.toml b/crates/home/Cargo.toml index f2797db9c4f..18459dfef1b 100644 --- a/crates/home/Cargo.toml +++ b/crates/home/Cargo.toml @@ -16,5 +16,5 @@ readme = "README.md" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" -[target."cfg(windows)".dependencies] +[target.'cfg(windows)'.dependencies] windows-sys = { version = "0.45.0", features = ["Win32_Foundation", "Win32_UI_Shell"] } From bf10d8d36b083a89f1231feb3db809e2e8d1e5a9 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 31 Jan 2023 23:16:12 +0800 Subject: [PATCH 7/8] more --- crates/home/src/windows.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/home/src/windows.rs b/crates/home/src/windows.rs index 65b5ec725bc..a35dc9c5719 100644 --- a/crates/home/src/windows.rs +++ b/crates/home/src/windows.rs @@ -2,7 +2,6 @@ use std::env; use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; -use std::ptr; use windows_sys::Win32::Foundation::{MAX_PATH, S_OK}; use windows_sys::Win32::UI::Shell::{SHGetFolderPathW, CSIDL_PROFILE}; @@ -17,14 +16,8 @@ pub fn home_dir_inner() -> Option { #[cfg(not(target_vendor = "uwp"))] fn home_dir_crt() -> Option { unsafe { - let mut path: Vec = Vec::with_capacity(MAX_PATH); - match SHGetFolderPathW( - ptr::null_mut(), - CSIDL_PROFILE, - ptr::null_mut(), - 0, - path.as_mut_ptr(), - ) { + let mut path: Vec = Vec::with_capacity(MAX_PATH as usize); + match SHGetFolderPathW(0, CSIDL_PROFILE as i32, 0, 0, path.as_mut_ptr()) { S_OK => { let len = wcslen(path.as_ptr()); path.set_len(len); From a199718e07fd4d1a1941274c24ac1a4a74313c56 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Wed, 1 Feb 2023 09:14:56 +0800 Subject: [PATCH 8/8] revert --- src/cargo/core/resolver/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/resolver/features.rs b/src/cargo/core/resolver/features.rs index 564be05873c..e2f2bd5c50c 100644 --- a/src/cargo/core/resolver/features.rs +++ b/src/cargo/core/resolver/features.rs @@ -812,7 +812,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> { true }) .flat_map(|dep| { - // Each dependency can be built for multiple targets. For one, it + // Each `dep`endency can be built for multiple targets. For one, it // may be a library target which is built as initially configured // by `fk`. If it appears as build dependency, it must be built // for the host.