Skip to content

Commit

Permalink
Add support for "x86_64-pc-windows-msvc".
Browse files Browse the repository at this point in the history
  • Loading branch information
DiXN committed Aug 20, 2019
1 parent 540dc4f commit d260d6c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
43 changes: 42 additions & 1 deletion src/id.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,6 +43,9 @@ pub enum Host {

// Linux
X86_64UnknownLinuxGnu,

// Windows MSVC
X86_64PcWindowsMsvc
}

impl Host {
Expand All @@ -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
}
Expand All @@ -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!()
}
}
}
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -161,7 +171,8 @@ impl From<Host> 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!(),
}
}
}
Expand Down

0 comments on commit d260d6c

Please sign in to comment.