diff --git a/Cargo.lock b/Cargo.lock index 986a90e8a..628fd6797 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "backtrace" version = "0.3.9" @@ -7,7 +9,7 @@ dependencies = [ "cfg-if 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -39,6 +41,7 @@ dependencies = [ "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -100,7 +103,7 @@ dependencies = [ [[package]] name = "winapi" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -131,6 +134,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" -"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index ad701702b..4c97aea42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,6 @@ libc = "0.2.18" rustc_version = "0.2.1" semver = "0.9.0" toml = "0.2.1" + +[target.'cfg(windows)'.dependencies] +winapi = { version = "0.3.7", features = ["winbase"] } \ No newline at end of file diff --git a/src/id.rs b/src/id.rs index 56f5f1a75..c4b3f4c56 100644 --- a/src/id.rs +++ b/src/id.rs @@ -1,15 +1,56 @@ +#[cfg(not(target_os = "windows"))] +use libc; +#[cfg(not(target_os = "windows"))] use std::ffi::CStr; -use libc; +#[cfg(target_os = "windows")] +pub fn group() -> u32 { + 1000 +} +#[cfg(not(target_os = "windows"))] pub fn group() -> u32 { unsafe { libc::getgid() } } +#[cfg(target_os = "windows")] +pub fn user() -> u32 { + 1000 +} + +#[cfg(not(target_os = "windows"))] pub fn user() -> u32 { unsafe { libc::getuid() } } +#[cfg(target_os = "windows")] +pub fn username() -> String { + use std::ptr; + + use winapi::um::winbase::GetUserNameW; + + unsafe { + let mut size = 0; + GetUserNameW(ptr::null_mut(), &mut size); + + if size == 0 { + return "".to_owned() + } + + let mut username = Vec::with_capacity(size as usize); + + if GetUserNameW(username.as_mut_ptr(), &mut size) == 0 { + return "".to_owned(); + } + + // Remove trailing space in user name. + username.set_len((size - 1) as usize); + + String::from_utf16(&username).unwrap() + } +} + +#[cfg(not(target_os = "windows"))] pub fn username() -> String { unsafe { CStr::from_ptr((*libc::getpwuid(user())).pw_name) diff --git a/src/main.rs b/src/main.rs index 402f68811..45b59f15d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,9 @@ extern crate rustc_version; extern crate semver; extern crate toml; +#[cfg(target_os = "windows")] +extern crate winapi; + mod cargo; mod cli; mod docker; @@ -40,6 +43,9 @@ pub enum Host { // Linux X86_64UnknownLinuxGnu, + + // Windows MSVC + X86_64PcWindowsMsvc } impl Host { @@ -51,6 +57,8 @@ impl Host { target.map(|t| t.triple() == "i686-apple-darwin" || t.needs_docker()).unwrap_or(false) } else if *self == Host::X86_64UnknownLinuxGnu { target.map(|t| t.needs_docker()).unwrap_or(true) + } else if *self == Host::X86_64PcWindowsMsvc { + target.map(|t| t.needs_docker()).unwrap_or(false) } else { false } @@ -60,7 +68,8 @@ impl Host { match *self { Host::X86_64AppleDarwin => "x86_64-apple-darwin", Host::X86_64UnknownLinuxGnu => "x86_64-unknown-linux-gnu", - Host::Other => unimplemented!(), + Host::X86_64PcWindowsMsvc => "x86_64-pc-windows-msvc", + Host::Other => unimplemented!() } } } @@ -70,6 +79,7 @@ impl<'a> From<&'a str> for Host { match s { "x86_64-apple-darwin" => Host::X86_64AppleDarwin, "x86_64-unknown-linux-gnu" => Host::X86_64UnknownLinuxGnu, + "x86_64-pc-windows-msvc" => Host::X86_64PcWindowsMsvc, _ => Host::Other, } } @@ -161,7 +171,8 @@ impl From for Target { match host { Host::X86_64UnknownLinuxGnu => Target::new_built_in("x86_64-unknown-linux-gnu"), Host::X86_64AppleDarwin => Target::new_built_in("x86_64-apple-darwin"), - Host::Other => unreachable!(), + Host::X86_64PcWindowsMsvc => Target::new_built_in("x86_64-pc-windows-msvc"), + Host::Other => unimplemented!(), } } }