Skip to content

Commit ad67c72

Browse files
bors[bot]DiXNreitermarkus
authored
Merge #282
282: Add support for "x86_64-pc-windows-msvc". r=reitermarkus a=DiXN Co-authored-by: Michael Kaltschmid <[email protected]> Co-authored-by: Markus Reiter <[email protected]>
2 parents 31beb2e + bbfeae5 commit ad67c72

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

Cargo.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ libc = "0.2.18"
1616
rustc_version = "0.2.1"
1717
semver = "0.9.0"
1818
toml = "0.2.1"
19+
20+
[target.'cfg(windows)'.dependencies]
21+
winapi = { version = "0.3.7", features = ["winbase"] }

src/id.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
1+
#[cfg(not(target_os = "windows"))]
2+
use libc;
3+
#[cfg(not(target_os = "windows"))]
14
use std::ffi::CStr;
25

3-
use libc;
6+
#[cfg(target_os = "windows")]
7+
pub fn group() -> u32 {
8+
1000
9+
}
410

11+
#[cfg(not(target_os = "windows"))]
512
pub fn group() -> u32 {
613
unsafe { libc::getgid() }
714
}
815

16+
#[cfg(target_os = "windows")]
17+
pub fn user() -> u32 {
18+
1000
19+
}
20+
21+
#[cfg(not(target_os = "windows"))]
922
pub fn user() -> u32 {
1023
unsafe { libc::getuid() }
1124
}
1225

26+
#[cfg(target_os = "windows")]
27+
pub fn username() -> String {
28+
use std::ptr;
29+
30+
use winapi::um::winbase::GetUserNameW;
31+
32+
unsafe {
33+
let mut size = 0;
34+
GetUserNameW(ptr::null_mut(), &mut size);
35+
36+
if size == 0 {
37+
return "".to_owned()
38+
}
39+
40+
let mut username = Vec::with_capacity(size as usize);
41+
42+
if GetUserNameW(username.as_mut_ptr(), &mut size) == 0 {
43+
return "".to_owned();
44+
}
45+
46+
// Remove null terminator.
47+
username.set_len((size - 1) as usize);
48+
49+
String::from_utf16(&username).unwrap()
50+
}
51+
}
52+
53+
#[cfg(not(target_os = "windows"))]
1354
pub fn username() -> String {
1455
unsafe {
1556
CStr::from_ptr((*libc::getpwuid(user())).pw_name)

src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ extern crate rustc_version;
99
extern crate semver;
1010
extern crate toml;
1111

12+
#[cfg(target_os = "windows")]
13+
extern crate winapi;
14+
1215
mod cargo;
1316
mod cli;
1417
mod docker;
@@ -40,6 +43,9 @@ pub enum Host {
4043

4144
// Linux
4245
X86_64UnknownLinuxGnu,
46+
47+
// Windows MSVC
48+
X86_64PcWindowsMsvc
4349
}
4450

4551
impl Host {
@@ -51,6 +57,8 @@ impl Host {
5157
target.map(|t| t.triple() == "i686-apple-darwin" || t.needs_docker()).unwrap_or(false)
5258
} else if *self == Host::X86_64UnknownLinuxGnu {
5359
target.map(|t| t.needs_docker()).unwrap_or(true)
60+
} else if *self == Host::X86_64PcWindowsMsvc {
61+
target.map(|t| t.needs_docker()).unwrap_or(false)
5462
} else {
5563
false
5664
}
@@ -60,7 +68,8 @@ impl Host {
6068
match *self {
6169
Host::X86_64AppleDarwin => "x86_64-apple-darwin",
6270
Host::X86_64UnknownLinuxGnu => "x86_64-unknown-linux-gnu",
63-
Host::Other => unimplemented!(),
71+
Host::X86_64PcWindowsMsvc => "x86_64-pc-windows-msvc",
72+
Host::Other => unimplemented!()
6473
}
6574
}
6675
}
@@ -70,6 +79,7 @@ impl<'a> From<&'a str> for Host {
7079
match s {
7180
"x86_64-apple-darwin" => Host::X86_64AppleDarwin,
7281
"x86_64-unknown-linux-gnu" => Host::X86_64UnknownLinuxGnu,
82+
"x86_64-pc-windows-msvc" => Host::X86_64PcWindowsMsvc,
7383
_ => Host::Other,
7484
}
7585
}
@@ -161,7 +171,8 @@ impl From<Host> for Target {
161171
match host {
162172
Host::X86_64UnknownLinuxGnu => Target::new_built_in("x86_64-unknown-linux-gnu"),
163173
Host::X86_64AppleDarwin => Target::new_built_in("x86_64-apple-darwin"),
164-
Host::Other => unreachable!(),
174+
Host::X86_64PcWindowsMsvc => Target::new_built_in("x86_64-pc-windows-msvc"),
175+
Host::Other => unimplemented!(),
165176
}
166177
}
167178
}

0 commit comments

Comments
 (0)