mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
arch: add support for building on Windows
This commit is contained in:
parent
3969b431a9
commit
5d241da7ca
6 changed files with 90 additions and 44 deletions
|
@ -6,7 +6,6 @@ build = "build.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
unix = [
|
unix = [
|
||||||
"arch",
|
|
||||||
"chgrp",
|
"chgrp",
|
||||||
"chmod",
|
"chmod",
|
||||||
"chown",
|
"chown",
|
||||||
|
@ -44,7 +43,6 @@ unix = [
|
||||||
# all utilities in that feature.
|
# all utilities in that feature.
|
||||||
fuchsia = [
|
fuchsia = [
|
||||||
# unix utilities
|
# unix utilities
|
||||||
"arch",
|
|
||||||
"chgrp",
|
"chgrp",
|
||||||
"chmod",
|
"chmod",
|
||||||
"chown",
|
"chown",
|
||||||
|
@ -67,6 +65,7 @@ fuchsia = [
|
||||||
"generic"
|
"generic"
|
||||||
]
|
]
|
||||||
generic = [
|
generic = [
|
||||||
|
"arch",
|
||||||
"cat",
|
"cat",
|
||||||
"hashsum",
|
"hashsum",
|
||||||
"join",
|
"join",
|
||||||
|
|
|
@ -19,7 +19,7 @@ static LONG_HELP: &'static str = "";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
new_coreopts!(SYNTAX, SUMMARY, LONG_HELP).parse(args);
|
new_coreopts!(SYNTAX, SUMMARY, LONG_HELP).parse(args);
|
||||||
let uts = Uname::new();
|
let uts = return_if_err!(1, Uname::new());
|
||||||
println!("{}", uts.machine().trim());
|
println!("{}", uts.machine().trim());
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
.get_matches_from(&args);
|
.get_matches_from(&args);
|
||||||
|
|
||||||
let argc = args.len();
|
let argc = args.len();
|
||||||
let uname = Uname::new();
|
let uname = return_if_err!(1, Uname::new());
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
|
|
||||||
if matches.is_present(OPT_KERNELNAME) || matches.is_present(OPT_ALL) || argc == 1 {
|
if matches.is_present(OPT_KERNELNAME) || matches.is_present(OPT_ALL) || argc == 1 {
|
||||||
|
|
|
@ -8,6 +8,7 @@ getopts = "0.2.14"
|
||||||
time = { version = "0.1.38", optional = true }
|
time = { version = "0.1.38", optional = true }
|
||||||
data-encoding = { version = "^1.1", optional = true }
|
data-encoding = { version = "^1.1", optional = true }
|
||||||
libc = { version = "0.2.34", optional = true }
|
libc = { version = "0.2.34", optional = true }
|
||||||
|
winapi = { version = "0.3", features = ["sysinfoapi"], optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
fs = ["libc"]
|
fs = ["libc"]
|
||||||
|
@ -20,7 +21,7 @@ process = ["libc"]
|
||||||
signals = []
|
signals = []
|
||||||
entries = ["libc"]
|
entries = ["libc"]
|
||||||
wide = []
|
wide = []
|
||||||
utsname = ["libc"]
|
utsname = ["libc", "winapi"]
|
||||||
default = ["fs", "libc", "utf8", "utsname", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"]
|
default = ["fs", "libc", "utf8", "utsname", "encoding", "parse_time", "mode", "utmpx", "process", "entries", "signals", "wide"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#[cfg(feature = "libc")]
|
#[cfg(feature = "libc")]
|
||||||
pub extern crate libc;
|
pub extern crate libc;
|
||||||
|
#[cfg(feature = "winapi")]
|
||||||
|
pub extern crate winapi;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -22,7 +24,7 @@ pub mod parse_time;
|
||||||
pub mod mode;
|
pub mod mode;
|
||||||
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))]
|
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "utmpx"))]
|
||||||
pub mod utmpx;
|
pub mod utmpx;
|
||||||
#[cfg(all(unix, feature = "utsname"))]
|
#[cfg(feature = "utsname")]
|
||||||
pub mod utsname;
|
pub mod utsname;
|
||||||
#[cfg(all(unix, feature = "entries"))]
|
#[cfg(all(unix, feature = "entries"))]
|
||||||
pub mod entries;
|
pub mod entries;
|
||||||
|
|
|
@ -6,47 +6,91 @@
|
||||||
// that was distributed with this source code.
|
// that was distributed with this source code.
|
||||||
//
|
//
|
||||||
|
|
||||||
use super::libc::{uname, utsname};
|
pub use self::platform::*;
|
||||||
use ::std::mem;
|
|
||||||
use ::std::ffi::CStr;
|
|
||||||
use ::std::borrow::Cow;
|
|
||||||
|
|
||||||
macro_rules! cstr2cow {
|
#[cfg(unix)]
|
||||||
($v:expr) => (
|
mod platform {
|
||||||
unsafe { CStr::from_ptr($v.as_ref().as_ptr()).to_string_lossy() }
|
use super::libc::{uname, utsname};
|
||||||
)
|
use ::std::mem;
|
||||||
}
|
use ::std::ffi::CStr;
|
||||||
|
use ::std::borrow::Cow;
|
||||||
|
use ::std::io;
|
||||||
|
|
||||||
pub struct Uname {
|
macro_rules! cstr2cow {
|
||||||
inner: utsname,
|
($v:expr) => (
|
||||||
}
|
unsafe { CStr::from_ptr($v.as_ref().as_ptr()).to_string_lossy() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
impl Uname {
|
pub struct Uname {
|
||||||
pub fn new() -> Self {
|
inner: utsname,
|
||||||
unsafe {
|
}
|
||||||
let mut uts: utsname = mem::uninitialized();
|
|
||||||
uname(&mut uts);
|
impl Uname {
|
||||||
Uname { inner: uts }
|
pub fn new() -> io::Result<Self> {
|
||||||
|
unsafe {
|
||||||
|
let mut uts: utsname = mem::uninitialized();
|
||||||
|
if uname(&mut uts) == 0 {
|
||||||
|
Ok(Uname { inner: uts })
|
||||||
|
} else {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sysname(&self) -> Cow<str> {
|
||||||
|
cstr2cow!(self.inner.sysname)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn nodename(&self) -> Cow<str> {
|
||||||
|
cstr2cow!(self.inner.nodename)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn release(&self) -> Cow<str> {
|
||||||
|
cstr2cow!(self.inner.release)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn version(&self) -> Cow<str> {
|
||||||
|
cstr2cow!(self.inner.version)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn machine(&self) -> Cow<str> {
|
||||||
|
cstr2cow!(self.inner.machine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sysname(&self) -> Cow<str> {
|
|
||||||
cstr2cow!(self.inner.sysname)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn nodename(&self) -> Cow<str> {
|
|
||||||
cstr2cow!(self.inner.nodename)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn release(&self) -> Cow<str> {
|
|
||||||
cstr2cow!(self.inner.release)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn version(&self) -> Cow<str> {
|
|
||||||
cstr2cow!(self.inner.version)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn machine(&self) -> Cow<str> {
|
|
||||||
cstr2cow!(self.inner.machine)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
mod platform {
|
||||||
|
use ::winapi::um::sysinfoapi::{SYSTEM_INFO, GetSystemInfo};
|
||||||
|
use ::winapi::um::winnt::*;
|
||||||
|
use ::std::mem;
|
||||||
|
use ::std::borrow::Cow;
|
||||||
|
use ::std::io;
|
||||||
|
|
||||||
|
pub struct Uname {
|
||||||
|
inner: SYSTEM_INFO
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Uname {
|
||||||
|
pub fn new() -> io::Result<Uname> {
|
||||||
|
unsafe {
|
||||||
|
let mut info = mem::uninitialized();
|
||||||
|
GetSystemInfo(&mut info);
|
||||||
|
Ok(Uname { inner: info })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: need to implement more architectures (e.g. ARM)
|
||||||
|
pub fn machine(&self) -> Cow<str> {
|
||||||
|
let arch = unsafe {
|
||||||
|
match self.inner.u.s().wProcessorArchitecture {
|
||||||
|
PROCESSOR_ARCHITECTURE_AMD64 => "x86_64",
|
||||||
|
PROCESSOR_ARCHITECTURE_INTEL => "x86",
|
||||||
|
_ => unimplemented!()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Cow::from(arch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue