diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68e13848d..1eb95f7f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,9 @@ jobs: - os: windows-2019 target: x86_64-pc-windows-msvc rustflags: -Ctarget-feature=+crt-static + - os: windows-2019 + target: aarch64-pc-windows-msvc + rustflags: -Ctarget-feature=+crt-static steps: - name: Clone repository uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index fc255b955..49f38ab50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1146,7 +1146,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio", "tower-service", "tracing", @@ -1184,7 +1184,7 @@ dependencies = [ "hyper 1.1.0", "hyper-util", "rustls 0.23.10", - "rustls-native-certs 0.7.0", + "rustls-native-certs", "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", @@ -1234,7 +1234,7 @@ dependencies = [ "http-body 1.0.0", "hyper 1.1.0", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio", "tower", "tower-service", @@ -1426,9 +1426,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "match_cfg" @@ -1682,9 +1682,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opendal" -version = "0.47.3" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac4826fe3d5482a49b92955b0f6b06ce45b46ec84484176588209bfbf996870" +checksum = "615d41187deea0ea7fab5b48e9afef6ae8fc742fdcfa248846ee3d92ff71e986" dependencies = [ "anyhow", "async-trait", @@ -1702,7 +1702,7 @@ dependencies = [ "md-5", "once_cell", "percent-encoding", - "quick-xml", + "quick-xml 0.36.1", "redis", "reqsign", "reqwest 0.12.5", @@ -1976,9 +1976,19 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quick-xml" -version = "0.31.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +checksum = "86e446ed58cef1bbfe847bc2fda0e2e4ea9f0e57b90c507d4781292590d72a4e" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quick-xml" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc" dependencies = [ "memchr", "serde", @@ -2026,7 +2036,7 @@ checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46" dependencies = [ "libc", "once_cell", - "socket2 0.5.5", + "socket2", "tracing", "windows-sys 0.52.0", ] @@ -2072,9 +2082,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.23.3" +version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f49cdc0bb3f412bf8e7d1bd90fe1d9eb10bc5c399ba90973c14662a27b3f8ba" +checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" dependencies = [ "arc-swap", "async-trait", @@ -2088,14 +2098,16 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rand", - "rustls 0.21.11", - "rustls-native-certs 0.6.3", + "rustls 0.22.4", + "rustls-native-certs", + "rustls-pemfile", + "rustls-pki-types", "ryu", "sha1_smol", - "socket2 0.4.10", + "socket2", "tokio", "tokio-retry", - "tokio-rustls 0.24.1", + "tokio-rustls 0.25.0", "tokio-util", "url", ] @@ -2151,9 +2163,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqsign" -version = "0.15.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70fe66d4cd0b5ed9b1abbfe639bf6baeaaf509f7da2d51b31111ba945be59286" +checksum = "03dd4ba7c3901dd43e6b8c7446a760d45bc1ea4301002e1a6fa48f97c3a796fa" dependencies = [ "anyhow", "async-trait", @@ -2169,7 +2181,7 @@ dependencies = [ "log", "once_cell", "percent-encoding", - "quick-xml", + "quick-xml 0.35.0", "rand", "reqwest 0.12.5", "rsa", @@ -2249,8 +2261,8 @@ dependencies = [ "pin-project-lite", "quinn", "rustls 0.23.10", - "rustls-native-certs 0.7.0", - "rustls-pemfile 2.1.2", + "rustls-native-certs", + "rustls-pemfile", "rustls-pki-types", "serde", "serde_json", @@ -2384,14 +2396,16 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.11" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", "ring", - "rustls-webpki 0.101.7", - "sct", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", ] [[package]] @@ -2403,23 +2417,11 @@ dependencies = [ "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.102.4", + "rustls-webpki", "subtle", "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" -dependencies = [ - "openssl-probe", - "rustls-pemfile 1.0.4", - "schannel", - "security-framework", -] - [[package]] name = "rustls-native-certs" version = "0.7.0" @@ -2427,21 +2429,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" dependencies = [ "openssl-probe", - "rustls-pemfile 2.1.2", + "rustls-pemfile", "rustls-pki-types", "schannel", "security-framework", ] -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] - [[package]] name = "rustls-pemfile" version = "2.1.2" @@ -2458,16 +2451,6 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" -[[package]] -name = "rustls-webpki" -version = "0.101.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "rustls-webpki" version = "0.102.4" @@ -2605,7 +2588,7 @@ dependencies = [ "version-compare", "walkdir", "which", - "winapi", + "windows-sys 0.52.0", "zip", "zstd", ] @@ -2636,16 +2619,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "sdd" version = "0.2.0" @@ -2844,16 +2817,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -3228,7 +3191,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -3267,11 +3230,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.24.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "rustls 0.21.11", + "rustls 0.22.4", + "rustls-pki-types", "tokio", ] @@ -3719,11 +3683,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 47f1090ab..9437e7369 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ mime = "0.3" num_cpus = "1.16" number_prefix = "0.4" once_cell = "1.19" -opendal = { version = "0.47.3", optional = true, default-features = false } +opendal = { version = "0.48.0", optional = true, default-features = false } openssl = { version = "0.10.64", optional = true } rand = "0.8.4" regex = "1.10.3" -reqsign = { version = "0.15.2", optional = true } +reqsign = { version = "0.16.0", optional = true } reqwest = { version = "0.12", features = [ "json", "blocking", @@ -140,16 +140,15 @@ daemonize = "0.5" optional = true version = "0.1.15" -[target.'cfg(windows)'.dependencies.winapi] +[target.'cfg(windows)'.dependencies.windows-sys] features = [ - "fileapi", - "handleapi", - "stringapiset", - "winnls", - "processenv", - "std", + "Win32_Foundation", + "Win32_Globalization", + "Win32_Storage_FileSystem", + "Win32_System_Threading", + "Win32_System_Console", ] -version = "0.3" +version = "0.52" [features] all = [ diff --git a/src/cache/azure.rs b/src/cache/azure.rs index 6faca3db1..59160b309 100644 --- a/src/cache/azure.rs +++ b/src/cache/azure.rs @@ -24,9 +24,9 @@ pub struct AzureBlobCache; impl AzureBlobCache { pub fn build(connection_string: &str, container: &str, key_prefix: &str) -> Result { - let mut builder = Azblob::from_connection_string(connection_string)?; - builder.container(container); - builder.root(key_prefix); + let builder = Azblob::from_connection_string(connection_string)? + .container(container) + .root(key_prefix); let op = Operator::new(builder)? .layer(LoggingLayer::default()) diff --git a/src/cache/gcs.rs b/src/cache/gcs.rs index 79fbbd4ce..cc5216d73 100644 --- a/src/cache/gcs.rs +++ b/src/cache/gcs.rs @@ -42,24 +42,24 @@ impl GCSCache { rw_mode: CacheMode, credential_url: Option<&str>, ) -> Result { - let mut builder = Gcs::default(); - builder.bucket(bucket); - builder.root(key_prefix); - builder.scope(rw_to_scope(rw_mode)); + let mut builder = Gcs::default() + .bucket(bucket) + .root(key_prefix) + .scope(rw_to_scope(rw_mode)); if let Some(service_account) = service_account { - builder.service_account(service_account); + builder = builder.service_account(service_account); } if let Some(path) = cred_path { - builder.credential_path(path); + builder = builder.credential_path(path); } if let Some(cred_url) = credential_url { let _ = Url::parse(cred_url) .map_err(|err| anyhow!("gcs credential url is invalid: {err:?}"))?; - builder.customed_token_loader(Box::new(TaskClusterTokenLoader { + builder = builder.customized_token_loader(Box::new(TaskClusterTokenLoader { scope: rw_to_scope(rw_mode).to_string(), url: cred_url.to_string(), })); diff --git a/src/cache/gha.rs b/src/cache/gha.rs index 8d8373430..28f6b3752 100644 --- a/src/cache/gha.rs +++ b/src/cache/gha.rs @@ -24,19 +24,19 @@ pub struct GHACache; impl GHACache { pub fn build(version: &str) -> Result { - let mut builder = Ghac::default(); - // This is the prefix of gha cache. - // From user side, cache key will be like `sccache/f/c/b/fcbxxx` - // - // User customization is theoretically supported, but I decided - // to see the community feedback first. - builder.root("/sccache"); + let mut builder = Ghac::default() + // This is the prefix of gha cache. + // From user side, cache key will be like `sccache/f/c/b/fcbxxx` + // + // User customization is theoretically supported, but I decided + // to see the community feedback first. + .root("/sccache"); - if version.is_empty() { - builder.version(&format!("sccache-v{VERSION}")); + builder = if version.is_empty() { + builder.version(&format!("sccache-v{VERSION}")) } else { - builder.version(&format!("sccache-v{VERSION}-{version}")); - } + builder.version(&format!("sccache-v{VERSION}-{version}")) + }; let op = Operator::new(builder)? .layer(LoggingLayer::default()) diff --git a/src/cache/memcached.rs b/src/cache/memcached.rs index b5735fc90..f01ca48bc 100644 --- a/src/cache/memcached.rs +++ b/src/cache/memcached.rs @@ -32,18 +32,18 @@ impl MemcachedCache { key_prefix: &str, expiration: u32, ) -> Result { - let mut builder = Memcached::default(); - builder.endpoint(url); + let mut builder = Memcached::default().endpoint(url); if let Some(username) = username { - builder.username(username); + builder = builder.username(username); } if let Some(password) = password { - builder.password(password); + builder = builder.password(password); } - builder.root(key_prefix); - builder.default_ttl(Duration::from_secs(expiration.into())); + builder = builder + .root(key_prefix) + .default_ttl(Duration::from_secs(expiration.into())); let op = Operator::new(builder)? .layer(LoggingLayer::default()) diff --git a/src/cache/oss.rs b/src/cache/oss.rs index e98e8ccc2..208179d17 100644 --- a/src/cache/oss.rs +++ b/src/cache/oss.rs @@ -26,18 +26,16 @@ impl OSSCache { endpoint: Option<&str>, no_credentials: bool, ) -> Result { - let mut builder = Oss::default(); - builder.bucket(bucket); - builder.root(key_prefix); + let mut builder = Oss::default().bucket(bucket).root(key_prefix); if let Some(endpoint) = endpoint { - builder.endpoint(endpoint); + builder = builder.endpoint(endpoint); } if no_credentials { // Allow anonymous access to OSS so that OpenDAL will not // throw error when no credentials are provided. - builder.allow_anonymous(); + builder = builder.allow_anonymous(); } let op = Operator::new(builder)? diff --git a/src/cache/redis.rs b/src/cache/redis.rs index 23c60b638..215bdc7ab 100644 --- a/src/cache/redis.rs +++ b/src/cache/redis.rs @@ -29,20 +29,20 @@ impl RedisCache { pub fn build_from_url(url: &str, key_prefix: &str, ttl: u64) -> Result { let parsed = Url::parse(url)?; - let mut builder = Redis::default(); - builder.endpoint(parsed.as_str()); - builder.username(parsed.username()); - builder.password(parsed.password().unwrap_or_default()); - builder.root(key_prefix); + let mut builder = Redis::default() + .endpoint(parsed.as_str()) + .username(parsed.username()) + .password(parsed.password().unwrap_or_default()) + .root(key_prefix); if ttl != 0 { - builder.default_ttl(Duration::from_secs(ttl)); + builder = builder.default_ttl(Duration::from_secs(ttl)); } let options: HashMap<_, _> = parsed .query_pairs() .map(|(k, v)| (k.to_string(), v.to_string())) .collect(); - builder.db(options + builder = builder.db(options .get("db") .map(|v| v.parse().unwrap_or_default()) .unwrap_or_default()); @@ -62,8 +62,7 @@ impl RedisCache { key_prefix: &str, ttl: u64, ) -> Result { - let mut builder = Redis::default(); - builder.endpoint(endpoint); + let builder = Redis::default().endpoint(endpoint); Self::build_common(builder, username, password, db, key_prefix, ttl) } @@ -77,8 +76,7 @@ impl RedisCache { key_prefix: &str, ttl: u64, ) -> Result { - let mut builder = Redis::default(); - builder.cluster_endpoints(endpoints); + let builder = Redis::default().cluster_endpoints(endpoints); Self::build_common(builder, username, password, db, key_prefix, ttl) } @@ -91,13 +89,14 @@ impl RedisCache { key_prefix: &str, ttl: u64, ) -> Result { - builder.username(username.unwrap_or_default()); - builder.password(password.unwrap_or_default()); - builder.root(key_prefix); + builder = builder + .username(username.unwrap_or_default()) + .password(password.unwrap_or_default()) + .db(db.into()) + .root(key_prefix); if ttl != 0 { - builder.default_ttl(Duration::from_secs(ttl)); + builder = builder.default_ttl(Duration::from_secs(ttl)); } - builder.db(db.into()); let op = Operator::new(builder)? .layer(LoggingLayer::default()) diff --git a/src/cache/s3.rs b/src/cache/s3.rs index 000c3213c..cd33b7846 100644 --- a/src/cache/s3.rs +++ b/src/cache/s3.rs @@ -30,33 +30,34 @@ impl S3Cache { use_ssl: Option, server_side_encryption: Option, ) -> Result { - let mut builder = S3::default(); - builder.http_client(set_user_agent()); - builder.bucket(bucket); - builder.root(key_prefix); + let mut builder = S3::default() + .http_client(set_user_agent()) + .bucket(bucket) + .root(key_prefix); if let Some(region) = region { - builder.region(region); + builder = builder.region(region); } if no_credentials { - builder.disable_config_load(); - // Disable EC2 metadata to avoid OpenDAL trying to load - // credentials from EC2 metadata. - // - // A.k.a, don't try to visit `http://169.254.169.254` - builder.disable_ec2_metadata(); - // Allow anonymous access to S3 so that OpenDAL will not - // throw error when no credentials are provided. - builder.allow_anonymous(); + builder = builder + .disable_config_load() + // Disable EC2 metadata to avoid OpenDAL trying to load + // credentials from EC2 metadata. + // + // A.k.a, don't try to visit `http://169.254.169.254` + .disable_ec2_metadata() + // Allow anonymous access to S3 so that OpenDAL will not + // throw error when no credentials are provided. + .allow_anonymous(); } if let Some(endpoint) = endpoint { - builder.endpoint(&endpoint_resolver(endpoint, use_ssl)?); + builder = builder.endpoint(&endpoint_resolver(endpoint, use_ssl)?); } if server_side_encryption.unwrap_or_default() { - builder.server_side_encryption_with_s3_key(); + builder = builder.server_side_encryption_with_s3_key(); } let op = Operator::new(builder)? diff --git a/src/cache/webdav.rs b/src/cache/webdav.rs index f9c0ea56f..a88cd17ce 100644 --- a/src/cache/webdav.rs +++ b/src/cache/webdav.rs @@ -27,18 +27,12 @@ impl WebdavCache { password: Option<&str>, token: Option<&str>, ) -> Result { - let mut builder = Webdav::default(); - builder.endpoint(endpoint); - builder.root(key_prefix); - if let Some(username) = username { - builder.username(username); - } - if let Some(password) = password { - builder.password(password); - } - if let Some(token) = token { - builder.token(token); - } + let builder = Webdav::default() + .endpoint(endpoint) + .root(key_prefix) + .username(username.unwrap_or_default()) + .password(password.unwrap_or_default()) + .token(token.unwrap_or_default()); let op = Operator::new(builder)? .layer(LoggingLayer::default()) diff --git a/src/commands.rs b/src/commands.rs index 33efb3727..967edc770 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -154,11 +154,10 @@ fn redirect_stderr(f: File) { #[cfg(windows)] fn redirect_stderr(f: File) { use std::os::windows::io::IntoRawHandle; - use winapi::um::processenv::SetStdHandle; - use winapi::um::winbase::STD_ERROR_HANDLE; + use windows_sys::Win32::System::Console::{SetStdHandle, STD_ERROR_HANDLE}; // Ignore errors here. unsafe { - SetStdHandle(STD_ERROR_HANDLE, f.into_raw_handle()); + SetStdHandle(STD_ERROR_HANDLE, f.into_raw_handle() as _); } } @@ -200,11 +199,10 @@ fn run_server_process( use std::ptr; use tokio::net::windows::named_pipe; use uuid::Uuid; - use winapi::shared::minwindef::{DWORD, FALSE, LPVOID, TRUE}; - use winapi::um::handleapi::CloseHandle; - use winapi::um::processthreadsapi::{CreateProcessW, PROCESS_INFORMATION, STARTUPINFOW}; - use winapi::um::winbase::{ - CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, CREATE_UNICODE_ENVIRONMENT, + use windows_sys::Win32::Foundation::CloseHandle; + use windows_sys::Win32::System::Threading::{ + CreateProcessW, CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW, CREATE_UNICODE_ENVIRONMENT, + PROCESS_INFORMATION, STARTUPINFOW, }; trace!("run_server_process"); @@ -256,26 +254,26 @@ fn run_server_process( // TODO: Expose `bInheritHandles` argument of `CreateProcessW` through the // standard library's `Command` type and then use that instead. let mut pi = PROCESS_INFORMATION { - hProcess: ptr::null_mut(), - hThread: ptr::null_mut(), + hProcess: 0, + hThread: 0, dwProcessId: 0, dwThreadId: 0, }; let mut si: STARTUPINFOW = unsafe { mem::zeroed() }; - si.cb = mem::size_of::() as DWORD; + si.cb = mem::size_of::() as _; if unsafe { CreateProcessW( exe.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), ptr::null_mut(), - FALSE, + 0, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, - envp.as_mut_ptr() as LPVOID, + envp.as_mut_ptr().cast(), workdir.as_ptr(), - &mut si, + &si, &mut pi, - ) == TRUE + ) != 0 } { unsafe { CloseHandle(pi.hProcess); diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 4ec7bf155..ccf77ce75 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -112,8 +112,10 @@ fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result { #[cfg(windows)] pub fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result { - let codepage = winapi::um::winnls::CP_OEMCP; - let flags = winapi::um::winnls::MB_ERR_INVALID_CHARS; + use windows_sys::Win32::Globalization::{MultiByteToWideChar, CP_OEMCP, MB_ERR_INVALID_CHARS}; + + let codepage = CP_OEMCP; + let flags = MB_ERR_INVALID_CHARS; // Empty string if multi_byte_str.is_empty() { @@ -121,7 +123,7 @@ pub fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result { } unsafe { // Get length of UTF-16 string - let len = winapi::um::stringapiset::MultiByteToWideChar( + let len = MultiByteToWideChar( codepage, flags, multi_byte_str.as_ptr() as _, @@ -132,7 +134,7 @@ pub fn from_local_codepage(multi_byte_str: &[u8]) -> io::Result { if len > 0 { // Convert to UTF-16 let mut wstr: Vec = Vec::with_capacity(len as usize); - let len = winapi::um::stringapiset::MultiByteToWideChar( + let len = MultiByteToWideChar( codepage, flags, multi_byte_str.as_ptr() as _, @@ -832,10 +834,10 @@ fn normpath(path: &str) -> String { use std::os::windows::ffi::OsStringExt; use std::os::windows::io::AsRawHandle; use std::ptr; - use winapi::um::fileapi::GetFinalPathNameByHandleW; + use windows_sys::Win32::Storage::FileSystem::GetFinalPathNameByHandleW; File::open(path) .and_then(|f| { - let handle = f.as_raw_handle(); + let handle = f.as_raw_handle() as _; let size = unsafe { GetFinalPathNameByHandleW(handle, ptr::null_mut(), 0, 0) }; if size == 0 { return Err(io::Error::last_os_error()); @@ -2582,7 +2584,7 @@ mod test { #[cfg(windows)] fn local_oem_codepage_conversions() { use crate::util::wide_char_to_multi_byte; - use winapi::um::winnls::GetOEMCP; + use windows_sys::Win32::Globalization::GetOEMCP; let current_oemcp = unsafe { GetOEMCP() }; // We don't control the local OEM codepage so test only if it is one of: diff --git a/src/util.rs b/src/util.rs index 1a2fffbe4..accc3d996 100644 --- a/src/util.rs +++ b/src/util.rs @@ -637,15 +637,19 @@ pub fn decode_path(bytes: &[u8]) -> std::io::Result { #[cfg(windows)] pub fn decode_path(bytes: &[u8]) -> std::io::Result { - let codepage = winapi::um::winnls::CP_OEMCP; - let flags = winapi::um::winnls::MB_ERR_INVALID_CHARS; + use windows_sys::Win32::Globalization::{CP_OEMCP, MB_ERR_INVALID_CHARS}; + + let codepage = CP_OEMCP; + let flags = MB_ERR_INVALID_CHARS; Ok(OsString::from_wide(&multi_byte_to_wide_char(codepage, flags, bytes)?).into()) } #[cfg(windows)] pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result> { - let codepage = winapi::um::winnls::CP_OEMCP; + use windows_sys::Win32::Globalization::{WideCharToMultiByte, CP_OEMCP}; + + let codepage = CP_OEMCP; let flags = 0; // Empty string if wide_char_str.is_empty() { @@ -653,7 +657,7 @@ pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result } unsafe { // Get length of multibyte string - let len = winapi::um::stringapiset::WideCharToMultiByte( + let len = WideCharToMultiByte( codepage, flags, wide_char_str.as_ptr(), @@ -667,7 +671,7 @@ pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result if len > 0 { // Convert from UTF-16 to multibyte let mut astr: Vec = Vec::with_capacity(len as usize); - let len = winapi::um::stringapiset::WideCharToMultiByte( + let len = WideCharToMultiByte( codepage, flags, wide_char_str.as_ptr(), @@ -696,19 +700,21 @@ pub fn wide_char_to_multi_byte(wide_char_str: &[u16]) -> std::io::Result /// See https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx /// for more details. pub fn multi_byte_to_wide_char( - codepage: winapi::shared::minwindef::DWORD, - flags: winapi::shared::minwindef::DWORD, + codepage: u32, + flags: u32, multi_byte_str: &[u8], ) -> std::io::Result> { + use windows_sys::Win32::Globalization::MultiByteToWideChar; + if multi_byte_str.is_empty() { return Ok(vec![]); } unsafe { // Get length of UTF-16 string - let len = winapi::um::stringapiset::MultiByteToWideChar( + let len = MultiByteToWideChar( codepage, flags, - multi_byte_str.as_ptr() as winapi::um::winnt::LPSTR, + multi_byte_str.as_ptr(), multi_byte_str.len() as i32, std::ptr::null_mut(), 0, @@ -716,10 +722,10 @@ pub fn multi_byte_to_wide_char( if len > 0 { // Convert to UTF-16 let mut wstr: Vec = Vec::with_capacity(len as usize); - let len = winapi::um::stringapiset::MultiByteToWideChar( + let len = MultiByteToWideChar( codepage, flags, - multi_byte_str.as_ptr() as winapi::um::winnt::LPSTR, + multi_byte_str.as_ptr(), multi_byte_str.len() as i32, wstr.as_mut_ptr(), len,