From e9f01bcf68b7f01c4b05422068adb3872f68cbaf Mon Sep 17 00:00:00 2001 From: Jeroen Bollen Date: Sat, 2 Sep 2017 23:44:21 +0200 Subject: Added a way to retrieve the key out of a HashMap when it's being replaced. --- src/libstd/collections/hash/map.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 16b0c709986..6eb6f892f80 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2161,6 +2161,36 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { fn take_key(&mut self) -> Option { self.key.take() } + + /// Replaces the entry, returning the old key and value. + /// + /// # Examples + /// + /// ``` + /// use std::collections::HashMap; + /// use std::collections::hash_map::Entry; + /// + /// let mut map: HashMap = HashMap::new(); + /// map.insert(String::from("poneyland"), 15); + /// + /// if let Entry::Occupied(entry) = map.entry(String::from("poneyland")) { + /// let (old_key, old_value): (String, u32) = entry.replace(16); + /// assert_eq!(old_key, "poneyland"); + /// assert_eq!(old_value, 15); + /// } + /// + /// assert_eq!(map.get("poneyland"), Some(&16)); + /// + /// ``` + #[stable(feature = "rust1", since = "1.20.0")] + pub fn replace(mut self, value: V) -> (K, V) { + let (old_key, old_value) = self.elem.read_mut(); + + let old_key = mem::replace(old_key, self.key.unwrap()); + let old_value = mem::replace(old_value, value); + + (old_key, old_value) + } } impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> { -- cgit 1.4.1-3-g733a5 From a312b4769808f69607377c8e00a5436c31edf67d Mon Sep 17 00:00:00 2001 From: Jeroen Bollen Date: Sun, 3 Sep 2017 20:16:20 +0200 Subject: Marked `Entry::replace` as unstable. --- src/libstd/collections/hash/map.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 6eb6f892f80..81d79493f08 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2167,6 +2167,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// # Examples /// /// ``` + /// # #![feature(map_entry_replace)] /// use std::collections::HashMap; /// use std::collections::hash_map::Entry; /// @@ -2182,7 +2183,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// assert_eq!(map.get("poneyland"), Some(&16)); /// /// ``` - #[stable(feature = "rust1", since = "1.20.0")] + #[unstable(feature = "map_entry_replace", issue = "44286")] pub fn replace(mut self, value: V) -> (K, V) { let (old_key, old_value) = self.elem.read_mut(); -- cgit 1.4.1-3-g733a5 From 4db499ff10c057f3ba4167594d2b3b57c5109ad3 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Fri, 8 Sep 2017 23:02:56 +0200 Subject: Add Duration::from_micros --- src/libstd/time/duration.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index d715a0d740b..8c37c38bbc8 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -13,7 +13,9 @@ use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign}; const NANOS_PER_SEC: u32 = 1_000_000_000; const NANOS_PER_MILLI: u32 = 1_000_000; +const NANOS_PER_MICROS: u32 = 1_000; const MILLIS_PER_SEC: u64 = 1_000; +const MICROS_PER_SEC: u64 = 1_000_000; /// A `Duration` type to represent a span of time, typically used for system /// timeouts. @@ -114,6 +116,27 @@ impl Duration { let secs = millis / MILLIS_PER_SEC; let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI; Duration { secs: secs, nanos: nanos } + + /// Creates a new `Duration` from the specified number of microseconds. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// let duration = Duration::from_micros(1_000_002); + /// + /// assert_eq!(1, duration.as_secs()); + /// assert_eq!(2000, duration.subsec_nanos()); + /// ``` + #[inline] + pub fn from_micros(micros: u64) -> Duration { + let secs = micros / MICROS_PER_SEC; + let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO; + Duration { + secs: secs, + nanos: nanos, + } } /// Returns the number of _whole_ seconds contained by this `Duration`. -- cgit 1.4.1-3-g733a5 From 376837b999dc4a6ec271080957cd46b59bb5cc32 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sat, 9 Sep 2017 11:46:58 +0200 Subject: from_micros: Inlined return for consistency --- src/libstd/time/duration.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 8c37c38bbc8..43cc2b880f7 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -133,10 +133,7 @@ impl Duration { pub fn from_micros(micros: u64) -> Duration { let secs = micros / MICROS_PER_SEC; let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO; - Duration { - secs: secs, - nanos: nanos, - } + Duration { secs: secs, nanos: nanos } } /// Returns the number of _whole_ seconds contained by this `Duration`. -- cgit 1.4.1-3-g733a5 From 2e6aed8f476f732cbc7f8d3bb21adb4b67fb688e Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sat, 9 Sep 2017 11:49:32 +0200 Subject: from_micros: Added unstable annotation --- src/libstd/time/duration.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 43cc2b880f7..baa86bfa133 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -129,6 +129,7 @@ impl Duration { /// assert_eq!(1, duration.as_secs()); /// assert_eq!(2000, duration.subsec_nanos()); /// ``` + #[unstable(feature = "", issue = "")] #[inline] pub fn from_micros(micros: u64) -> Duration { let secs = micros / MICROS_PER_SEC; -- cgit 1.4.1-3-g733a5 From abc53cc140a923340d4abf3ed8360d903866886a Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 Sep 2017 00:27:39 +0200 Subject: from_micros: Fix missing { --- src/libstd/time/duration.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index baa86bfa133..2612376704d 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -116,6 +116,7 @@ impl Duration { let secs = millis / MILLIS_PER_SEC; let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI; Duration { secs: secs, nanos: nanos } + } /// Creates a new `Duration` from the specified number of microseconds. /// -- cgit 1.4.1-3-g733a5 From a15c541a2afd08095d278249b345323c46ae23d3 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Sun, 10 Sep 2017 17:38:55 +0200 Subject: from_micros: added issue number and fixed typo --- src/libstd/time/duration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 2612376704d..9ef757076ba 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -13,7 +13,7 @@ use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign}; const NANOS_PER_SEC: u32 = 1_000_000_000; const NANOS_PER_MILLI: u32 = 1_000_000; -const NANOS_PER_MICROS: u32 = 1_000; +const NANOS_PER_MICRO: u32 = 1_000; const MILLIS_PER_SEC: u64 = 1_000; const MICROS_PER_SEC: u64 = 1_000_000; @@ -130,7 +130,7 @@ impl Duration { /// assert_eq!(1, duration.as_secs()); /// assert_eq!(2000, duration.subsec_nanos()); /// ``` - #[unstable(feature = "", issue = "")] + #[unstable(feature = "", issue = "44400")] #[inline] pub fn from_micros(micros: u64) -> Duration { let secs = micros / MICROS_PER_SEC; -- cgit 1.4.1-3-g733a5 From d3de465dc85638a6a77298638ebbbfab04b1844d Mon Sep 17 00:00:00 2001 From: Jeroen Bollen Date: Tue, 12 Sep 2017 15:32:10 +0200 Subject: Addressed @BurntSuchi's remarks regarding Entry::replace --- src/libstd/collections/hash/map.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 81d79493f08..48dad8bff5d 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2167,21 +2167,20 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> { /// # Examples /// /// ``` - /// # #![feature(map_entry_replace)] + /// #![feature(map_entry_replace)] /// use std::collections::HashMap; /// use std::collections::hash_map::Entry; /// /// let mut map: HashMap = HashMap::new(); - /// map.insert(String::from("poneyland"), 15); + /// map.insert("poneyland".to_string(), 15); /// - /// if let Entry::Occupied(entry) = map.entry(String::from("poneyland")) { + /// if let Entry::Occupied(entry) = map.entry("poneyland".to_string()) { /// let (old_key, old_value): (String, u32) = entry.replace(16); /// assert_eq!(old_key, "poneyland"); /// assert_eq!(old_value, 15); /// } /// /// assert_eq!(map.get("poneyland"), Some(&16)); - /// /// ``` #[unstable(feature = "map_entry_replace", issue = "44286")] pub fn replace(mut self, value: V) -> (K, V) { -- cgit 1.4.1-3-g733a5 From b40a9f4ecac2d0da2c96576e63e456a868026245 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Wed, 13 Sep 2017 13:21:20 +0200 Subject: from_micros: add feature name --- src/libstd/time/duration.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 9ef757076ba..86927ce322e 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -123,6 +123,7 @@ impl Duration { /// # Examples /// /// ``` + /// #![feature(duration_from_micros)] /// use std::time::Duration; /// /// let duration = Duration::from_micros(1_000_002); @@ -130,7 +131,7 @@ impl Duration { /// assert_eq!(1, duration.as_secs()); /// assert_eq!(2000, duration.subsec_nanos()); /// ``` - #[unstable(feature = "", issue = "44400")] + #[unstable(feature = "duration_from_micros", issue = "44400")] #[inline] pub fn from_micros(micros: u64) -> Duration { let secs = micros / MICROS_PER_SEC; -- cgit 1.4.1-3-g733a5 From e3910794961b820defedd909b11e69681803e0db Mon Sep 17 00:00:00 2001 From: Trevor Merrifield Date: Mon, 11 Sep 2017 20:02:44 -0400 Subject: Retain suid/sgid/sticky bits in Metadata.permissions Most users would expect set_permissions(Metadata.permissions()) to be non-destructive. While we can't guarantee this, we can at least pass the needed info to chmod. Also update the PermissionsExt documentation to disambiguate what it contains, and to refer to the underlying value as `st_mode` rather than its type `mode_t`. Closes #44147 --- src/libstd/sys/unix/ext/fs.rs | 4 ++-- src/libstd/sys/unix/fs.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index f44b9aa9615..96c0f4eab42 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -68,8 +68,8 @@ impl FileExt for fs::File { /// Unix-specific extensions to `Permissions` #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { - /// Returns the underlying raw `mode_t` bits that are the standard Unix - /// permissions for this file. + /// Returns the 12 least significant bits of `st_mode` which are the + /// standard Unix permissions for this file. /// /// # Examples /// diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 13112fc1fa5..e0ce02873f5 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -95,7 +95,7 @@ pub struct DirBuilder { mode: mode_t } impl FileAttr { pub fn size(&self) -> u64 { self.stat.st_size as u64 } pub fn perm(&self) -> FilePermissions { - FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 } + FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o7777 } } pub fn file_type(&self) -> FileType { -- cgit 1.4.1-3-g733a5 From a6ef99e9f43e70c36dc9744bc87374033b2dedba Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 15 Sep 2017 22:57:12 -0400 Subject: Indicate how ChildStd{in,out,err} FDs are closed. Fixes https://github.com/rust-lang/rust/issues/41452. --- src/libstd/process.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a3a7e91dd80..4dba9a4cb11 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -153,8 +153,12 @@ impl fmt::Debug for Child { /// /// This struct is used in the [`stdin`] field on [`Child`]. /// +/// When an instance of `ChildStdin` is [dropped], the `ChildStdin`'s underlying +/// file handle will be closed. +/// /// [`Child`]: struct.Child.html /// [`stdin`]: struct.Child.html#structfield.stdin +/// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdin { inner: AnonPipe @@ -196,8 +200,12 @@ impl fmt::Debug for ChildStdin { /// /// This struct is used in the [`stdout`] field on [`Child`]. /// +/// When an instance of `ChildStdout` is [dropped], the `ChildStdout`'s +/// underlying file handle will be closed. +/// /// [`Child`]: struct.Child.html /// [`stdout`]: struct.Child.html#structfield.stdout +/// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdout { inner: AnonPipe @@ -239,8 +247,12 @@ impl fmt::Debug for ChildStdout { /// /// This struct is used in the [`stderr`] field on [`Child`]. /// +/// When an instance of `ChildStderr` is [dropped], the `ChildStderr`'s +/// underlying file handle will be closed. +/// /// [`Child`]: struct.Child.html /// [`stderr`]: struct.Child.html#structfield.stderr +/// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStderr { inner: AnonPipe -- cgit 1.4.1-3-g733a5 From a1f9052be76c7d28fe2ee1ff7dcb2464237c2bfc Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 15 Sep 2017 23:02:50 -0400 Subject: Expand some of the std{in,out,err} usages. --- src/libstd/process.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 4dba9a4cb11..a70e632fe7c 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -106,15 +106,18 @@ use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; pub struct Child { handle: imp::Process, - /// The handle for writing to the child's stdin, if it has been captured + /// The handle for writing to the child's standard input (stdin), if it has + /// been captured. #[stable(feature = "process", since = "1.0.0")] pub stdin: Option, - /// The handle for reading from the child's stdout, if it has been captured + /// The handle for reading from the child's standard output (stdout), if it + /// has been captured. #[stable(feature = "process", since = "1.0.0")] pub stdout: Option, - /// The handle for reading from the child's stderr, if it has been captured + /// The handle for reading from the child's standard error (stderr), if it + /// has been captured. #[stable(feature = "process", since = "1.0.0")] pub stderr: Option, } @@ -149,7 +152,7 @@ impl fmt::Debug for Child { } } -/// A handle to a child process's stdin. +/// A handle to a child process's standard input (stdin). /// /// This struct is used in the [`stdin`] field on [`Child`]. /// @@ -196,7 +199,7 @@ impl fmt::Debug for ChildStdin { } } -/// A handle to a child process's stdout. +/// A handle to a child process's standard output (stdout). /// /// This struct is used in the [`stdout`] field on [`Child`]. /// @@ -546,7 +549,8 @@ impl Command { self } - /// Configuration for the child process's stdin handle (file descriptor 0). + /// Configuration for the child process's standard input (stdin) handle + /// (file descriptor 0). /// /// # Examples /// @@ -566,7 +570,8 @@ impl Command { self } - /// Configuration for the child process's stdout handle (file descriptor 1). + /// Configuration for the child process's standard output (stdout) handle + /// (file descriptor 1). /// /// # Examples /// @@ -586,7 +591,8 @@ impl Command { self } - /// Configuration for the child process's stderr handle (file descriptor 2). + /// Configuration for the child process's standard error (stderr) handle + /// (file descriptor 2). /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 04c01e0b1fc4830f4416c79d886c2f1a54986fe9 Mon Sep 17 00:00:00 2001 From: Trevor Merrifield Date: Sun, 17 Sep 2017 17:01:35 -0400 Subject: Add test case for unix permissions --- src/libstd/fs.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 2a916b819cc..99162766081 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -2160,6 +2160,27 @@ mod tests { check!(fs::remove_file(&filename)); } + #[test] + #[cfg(unix)] + fn set_get_unix_permissions() { + use os::unix::fs::PermissionsExt; + + let tmpdir = tmpdir(); + let filename = &tmpdir.join("set_get_unix_permissions"); + check!(fs::create_dir(filename)); + let mask = 0o7777; + + check!(fs::set_permissions(filename, + fs::Permissions::from_mode(0))); + let metadata0 = check!(fs::metadata(filename)); + assert_eq!(mask & metadata0.permissions().mode(), 0); + + check!(fs::set_permissions(filename, + fs::Permissions::from_mode(0o1777))); + let metadata1 = check!(fs::metadata(filename)); + assert_eq!(mask & metadata1.permissions().mode(), 0o1777); + } + #[test] #[cfg(windows)] fn file_test_io_seek_read_write() { -- cgit 1.4.1-3-g733a5 From 6ae9fc277287e4f207012ab65be24058f143d42d Mon Sep 17 00:00:00 2001 From: Trevor Merrifield Date: Sun, 17 Sep 2017 17:42:58 -0400 Subject: Remove st_mode mask --- src/libstd/sys/unix/ext/fs.rs | 4 ++-- src/libstd/sys/unix/fs.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 96c0f4eab42..3e631ad40ac 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -68,8 +68,8 @@ impl FileExt for fs::File { /// Unix-specific extensions to `Permissions` #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { - /// Returns the 12 least significant bits of `st_mode` which are the - /// standard Unix permissions for this file. + /// Returns the underlying raw `st_mode` bits that contain the standard + /// Unix permissions for this file. /// /// # Examples /// diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index e0ce02873f5..c4616c3b395 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -95,7 +95,7 @@ pub struct DirBuilder { mode: mode_t } impl FileAttr { pub fn size(&self) -> u64 { self.stat.st_size as u64 } pub fn perm(&self) -> FilePermissions { - FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o7777 } + FilePermissions { mode: (self.stat.st_mode as mode_t) } } pub fn file_type(&self) -> FileType { -- cgit 1.4.1-3-g733a5 From c9099ff11b1d44a4942f448750cafe8e5c2fd915 Mon Sep 17 00:00:00 2001 From: Jack O'Connor Date: Wed, 20 Sep 2017 01:25:47 -0400 Subject: fix an incorrect assertion in the doc example for `std::io::copy` --- src/libstd/io/util.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 88f4214296d..bff4e5caaa1 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -40,9 +40,10 @@ use mem; /// /// io::copy(&mut reader, &mut writer)?; /// -/// assert_eq!(reader, &writer[..]); +/// assert_eq!(&b"hello"[..], &writer[..]); /// # Ok(()) /// # } +/// # foo().unwrap(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn copy(reader: &mut R, writer: &mut W) -> io::Result -- cgit 1.4.1-3-g733a5 From 548686ff12322f948652ee6523074b2ce6d2bb06 Mon Sep 17 00:00:00 2001 From: Havvy Date: Sat, 16 Sep 2017 20:40:05 -0700 Subject: Document stable size_of primitives and pointer size guarantees --- src/libcore/mem.rs | 48 ++++++++++++++++++++++++++++++++++++++++++-- src/libstd/primitive_docs.rs | 8 ++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 3e24623dad8..e98dab739cb 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -177,15 +177,59 @@ pub fn forget(t: T) { /// Returns the size of a type in bytes. /// -/// More specifically, this is the offset in bytes between successive -/// items of the same type, including alignment padding. +/// More specifically, this is the offset in bytes between successive elements +/// in an array with that item type including alignment padding. Thus, for any +/// type `T` and length `n`, `[T; n]` has a size of `n * size_of::()`. +/// +/// In general, the size of a type is not stable across compilations, but +/// specific types such as primitives are. +/// +/// The following table gives the size for primitives. +/// +/// Type | size_of::\() +/// ---- | --------------- +/// () | 0 +/// u8 | 1 +/// u16 | 2 +/// u32 | 4 +/// u64 | 8 +/// i8 | 1 +/// i16 | 2 +/// i32 | 4 +/// i64 | 8 +/// f32 | 4 +/// f64 | 8 +/// char | 4 +/// +/// Furthermore, `usize` and `isize` have the same size. +/// +/// The types `*const T`, `&T`, `Box`, `Option<&T>`, and `Option>` all have +/// the same size. If `T` is Sized, all of those types have the same size as `usize`. +/// +/// The mutability of a pointer does not change its size. As such, `&T` and `&mut T` +/// have the same size. Likewise for `*const T` and `*mut T`. /// /// # Examples /// /// ``` /// use std::mem; /// +/// // Some primitives /// assert_eq!(4, mem::size_of::()); +/// assert_eq!(8, mem::size_of::()); +/// assert_eq!(0, mem::size_of::<()>()); +/// +/// // Some arrays +/// assert_eq!(8, mem::size_of::<[i32; 2]>()); +/// assert_eq!(12, mem::size_of::<[i32; 3]>()); +/// assert_eq!(0, mem::size_of::<[i32; 0]>()); +/// +/// +/// // Pointer size equality +/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::<*const i32>()); +/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::>()); +/// assert_eq!(mem::size_of::<&i32>(), mem::size_of::>()); +/// assert_eq!(mem::size_of::>(), mem::size_of::>>()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 76ef36cc9a7..1edb35d8fe7 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -710,6 +710,10 @@ mod prim_u128 { } // /// The pointer-sized signed integer type. /// +/// The size of this primitive is how many bytes it takes to reference any +/// location in memory. For example, on a 32 bit target, this is 4 bytes +/// and on a 64 bit target, this is 8 bytes. +/// /// *[See also the `std::isize` module](isize/index.html).* /// /// However, please note that examples are shared between primitive integer @@ -722,6 +726,10 @@ mod prim_isize { } // /// The pointer-sized unsigned integer type. /// +/// The size of this primitive is how many bytes it takes to reference any +/// location in memory. For example, on a 32 bit target, this is 4 bytes +/// and on a 64 bit target, this is 8 bytes. +/// /// *[See also the `std::usize` module](usize/index.html).* /// /// However, please note that examples are shared between primitive integer -- cgit 1.4.1-3-g733a5 From cf2bad8d4b6ffc98a1ea6378e83ad011c224ce80 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Thu, 21 Sep 2017 16:31:39 -0400 Subject: improve english in create_dir_all docs --- src/libstd/fs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 2a916b819cc..495f543c875 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1595,9 +1595,9 @@ pub fn create_dir>(path: P) -> io::Result<()> { /// /// Notable exception is made for situations where any of the directories /// specified in the `path` could not be created as it was being created concurrently. -/// Such cases are considered success. In other words: calling `create_dir_all` -/// concurrently from multiple threads or processes is guaranteed to not fail -/// due to race itself. +/// Such cases are considered to be successful. That is, calling `create_dir_all` +/// concurrently from multiple threads or processes is guaranteed not to fail +/// due to a race condition with itself. /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 5ee7db6a0ebe8803d420c591325605111a21a400 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 21 Sep 2017 21:01:51 -0400 Subject: Remove platform-specific terminology. --- src/libstd/process.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/process.rs b/src/libstd/process.rs index a70e632fe7c..33451a470d0 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -549,8 +549,7 @@ impl Command { self } - /// Configuration for the child process's standard input (stdin) handle - /// (file descriptor 0). + /// Configuration for the child process's standard input (stdin) handle. /// /// # Examples /// @@ -570,8 +569,7 @@ impl Command { self } - /// Configuration for the child process's standard output (stdout) handle - /// (file descriptor 1). + /// Configuration for the child process's standard output (stdout) handle. /// /// # Examples /// @@ -591,8 +589,7 @@ impl Command { self } - /// Configuration for the child process's standard error (stderr) handle - /// (file descriptor 2). + /// Configuration for the child process's standard error (stderr) handle. /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From 859ebef62fa0e7fcfc2af200dac11d2f899ea37f Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 21 Sep 2017 21:11:11 -0400 Subject: Add note about being blocked on input. --- src/libstd/process.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 33451a470d0..1869ad3ed70 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -157,7 +157,8 @@ impl fmt::Debug for Child { /// This struct is used in the [`stdin`] field on [`Child`]. /// /// When an instance of `ChildStdin` is [dropped], the `ChildStdin`'s underlying -/// file handle will be closed. +/// file handle will be closed. If the child process was blocked on input prior +/// to being dropped, it will become unblocked after dropping. /// /// [`Child`]: struct.Child.html /// [`stdin`]: struct.Child.html#structfield.stdin -- cgit 1.4.1-3-g733a5 From 9562981b0b6dc2d7ae6070732778623a59cfdd0a Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Thu, 21 Sep 2017 20:21:54 -0700 Subject: impl std::error::Error for convert::Infallible. --- src/libstd/error.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 401552a6ec4..5cb2b00334d 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -55,6 +55,7 @@ use alloc::allocator; use any::TypeId; use cell; use char; +use convert; use fmt::{self, Debug, Display}; use mem::transmute; use num; @@ -347,6 +348,12 @@ impl Error for char::ParseCharError { } } +#[unstable(feature = "try_from", issue = "33417")] +impl Error for convert::Infallible { + fn description(&self) -> &str { + "an error of this type can never exist" + } +} // copied from any.rs impl Error + 'static { -- cgit 1.4.1-3-g733a5 From f283875a780662f13d977e05de7ab5fe52604743 Mon Sep 17 00:00:00 2001 From: Lucas Morales Date: Fri, 22 Sep 2017 18:43:09 -0400 Subject: std::sync::RwLock docs improvement --- src/libstd/sync/rwlock.rs | 133 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 120 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 5c5231f4e84..4757faabfb8 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -24,19 +24,24 @@ use sys_common::rwlock as sys; /// of the underlying data (exclusive access) and the read portion of this lock /// typically allows for read-only access (shared access). /// +/// In comparison, a [`Mutex`] does not distinguish between readers or writers +/// that aquire the lock, therefore blocking any threads waiting for the lock to +/// become available. An `RwLock` will allow any number of readers to aquire the +/// lock as long as a writer is not holding the lock. +/// /// The priority policy of the lock is dependent on the underlying operating /// system's implementation, and this type does not guarantee that any /// particular policy will be used. /// /// The type parameter `T` represents the data that this lock protects. It is -/// required that `T` satisfies `Send` to be shared across threads and `Sync` to -/// allow concurrent access through readers. The RAII guards returned from the -/// locking methods implement `Deref` (and `DerefMut` for the `write` methods) -/// to allow access to the contained of the lock. +/// required that `T` satisfies [`Send`] to be shared across threads and +/// [`Sync`] to allow concurrent access through readers. The RAII guards +/// returned from the locking methods implement [`Deref`][] (and [`DerefMut`] +/// for the `write` methods) to allow access to the contained of the lock. /// /// # Poisoning /// -/// An `RwLock`, like `Mutex`, will become poisoned on a panic. Note, however, +/// An `RwLock`, like [`Mutex`], will become poisoned on a panic. Note, however, /// that an `RwLock` may only be poisoned if a panic occurs while it is locked /// exclusively (write mode). If a panic occurs in any reader, then the lock /// will not be poisoned. @@ -63,6 +68,12 @@ use sys_common::rwlock as sys; /// assert_eq!(*w, 6); /// } // write lock is dropped here /// ``` +/// +/// [`Deref`]: ../../std/ops/trait.Deref.html +/// [`DerefMut`]: ../../std/ops/trait.DerefMut.html +/// [`Send`]: ../../std/marker/trait.Send.html +/// [`Sync`]: ../../std/marker/trait.Sync.html +/// [`Mutex`]: struct.Mutex.html #[stable(feature = "rust1", since = "1.0.0")] pub struct RwLock { inner: Box, @@ -154,6 +165,24 @@ impl RwLock { /// # Panics /// /// This function might panic when called if the lock is already held by the current thread. + /// + /// # Examples + /// + /// ``` + /// use std::sync::{Arc, RwLock}; + /// use std::thread; + /// + /// let lock = Arc::new(RwLock::new(1)); + /// let c_lock = lock.clone(); + /// + /// let n = lock.read().unwrap(); + /// assert_eq!(*n, 1); + /// + /// thread::spawn(move || { + /// let r = c_lock.read(); + /// assert!(r.is_ok()); + /// }).join().unwrap(); + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn read(&self) -> LockResult> { @@ -180,6 +209,19 @@ impl RwLock { /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. + /// + /// # Examples + /// + /// ``` + /// use std::sync::RwLock; + /// + /// let lock = RwLock::new(1); + /// + /// match lock.try_read() { + /// Ok(n) => assert_eq!(*n, 1), + /// Err(_) => unreachable!(), + /// }; + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn try_read(&self) -> TryLockResult> { @@ -210,6 +252,19 @@ impl RwLock { /// # Panics /// /// This function might panic when called if the lock is already held by the current thread. + /// + /// # Examples + /// + /// ``` + /// use std::sync::RwLock; + /// + /// let lock = RwLock::new(1); + /// + /// let mut n = lock.write().unwrap(); + /// *n = 2; + /// + /// assert!(lock.try_read().is_err()); + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn write(&self) -> LockResult> { @@ -236,6 +291,19 @@ impl RwLock { /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. + /// + /// # Examples + /// + /// ``` + /// use std::sync::RwLock; + /// + /// let lock = RwLock::new(1); + /// + /// let n = lock.read().unwrap(); + /// assert_eq!(*n, 1); + /// + /// assert!(lock.try_write().is_err()); + /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn try_write(&self) -> TryLockResult> { @@ -253,6 +321,22 @@ impl RwLock { /// If another thread is active, the lock can still become poisoned at any /// time. You should not trust a `false` value for program correctness /// without additional synchronization. + /// + /// # Examples + /// + /// ``` + /// use std::sync::{Arc, RwLock}; + /// use std::thread; + /// + /// let lock = Arc::new(RwLock::new(0)); + /// let c_lock = lock.clone(); + /// + /// let _ = thread::spawn(move || { + /// let _lock = c_lock.write().unwrap(); + /// panic!(); // the lock gets poisoned + /// }).join(); + /// assert_eq!(lock.is_poisoned(), true); + /// ``` #[inline] #[stable(feature = "sync_poison", since = "1.2.0")] pub fn is_poisoned(&self) -> bool { @@ -267,6 +351,19 @@ impl RwLock { /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. + /// + /// # Examples + /// + /// ``` + /// use std::sync::RwLock; + /// + /// let lock = RwLock::new(String::new()); + /// { + /// let mut s = lock.write().unwrap(); + /// *s = "modified".to_owned(); + /// } + /// assert_eq!(lock.into_inner().unwrap(), "modified"); + /// ``` #[stable(feature = "rwlock_into_inner", since = "1.6.0")] pub fn into_inner(self) -> LockResult where T: Sized { // We know statically that there are no outstanding references to @@ -282,7 +379,7 @@ impl RwLock { (ptr::read(inner), ptr::read(poison), ptr::read(data)) }; mem::forget(self); - inner.destroy(); // Keep in sync with the `Drop` impl. + inner.destroy(); // Keep in sync with the `Drop` impl. drop(inner); poison::map_result(poison.borrow(), |_| data.into_inner()) @@ -300,6 +397,16 @@ impl RwLock { /// is poisoned whenever a writer panics while holding an exclusive lock. An /// error will only be returned if the lock would have otherwise been /// acquired. + /// + /// # Examples + /// + /// ``` + /// use std::sync::RwLock; + /// + /// let mut lock = RwLock::new(0); + /// *lock.get_mut().unwrap() = 10; + /// assert_eq!(*lock.read().unwrap(), 10); + /// ``` #[stable(feature = "rwlock_get_mut", since = "1.6.0")] pub fn get_mut(&mut self) -> LockResult<&mut T> { // We know statically that there are no other references to `self`, so @@ -486,7 +593,7 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result<(), _> = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move || { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -498,7 +605,7 @@ mod tests { let arc = Arc::new(RwLock::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _: Result<(), _> = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move || { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -510,7 +617,7 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result<(), _> = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move || { let _lock = arc2.read().unwrap(); panic!(); }).join(); @@ -521,7 +628,7 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result<(), _> = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move || { let _lock = arc2.read().unwrap(); panic!() }).join(); @@ -535,7 +642,7 @@ mod tests { let arc2 = arc.clone(); let (tx, rx) = channel(); - thread::spawn(move|| { + thread::spawn(move || { let mut lock = arc2.write().unwrap(); for _ in 0..10 { let tmp = *lock; @@ -550,7 +657,7 @@ mod tests { let mut children = Vec::new(); for _ in 0..5 { let arc3 = arc.clone(); - children.push(thread::spawn(move|| { + children.push(thread::spawn(move || { let lock = arc3.read().unwrap(); assert!(*lock >= 0); })); @@ -571,7 +678,7 @@ mod tests { fn test_rw_arc_access_in_unwind() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _ = thread::spawn(move|| -> () { + let _ = thread::spawn(move || -> () { struct Unwinder { i: Arc>, } -- cgit 1.4.1-3-g733a5 From 99c0c520aff7f9858340406631d9de763a743d41 Mon Sep 17 00:00:00 2001 From: Lucas Morales Date: Sat, 23 Sep 2017 18:28:08 -0400 Subject: docs improvement std::sync::{PoisonError, TryLockError} --- src/libstd/sys_common/poison.rs | 57 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys_common/poison.rs b/src/libstd/sys_common/poison.rs index 3c61593acc5..934ac3edbf1 100644 --- a/src/libstd/sys_common/poison.rs +++ b/src/libstd/sys_common/poison.rs @@ -65,6 +65,31 @@ pub struct Guard { /// each lock, but once a lock is poisoned then all future acquisitions will /// return this error. /// +/// # Examples +/// +/// ``` +/// use std::sync::{Arc, Mutex}; +/// use std::thread; +/// +/// let mutex = Arc::new(Mutex::new(1)); +/// +/// // poison the mutex +/// let c_mutex = mutex.clone(); +/// let _ = thread::spawn(move || { +/// let mut data = c_mutex.lock().unwrap(); +/// *data = 2; +/// panic!(); +/// }).join(); +/// +/// match mutex.lock() { +/// Ok(_) => unreachable!(), +/// Err(p_err) => { +/// let data = p_err.get_ref(); +/// println!("recovered: {}", data); +/// } +/// }; +/// ``` +/// /// [`Mutex`]: ../../std/sync/struct.Mutex.html /// [`RwLock`]: ../../std/sync/struct.RwLock.html #[stable(feature = "rust1", since = "1.0.0")] @@ -72,10 +97,16 @@ pub struct PoisonError { guard: T, } -/// An enumeration of possible errors which can occur while calling the -/// [`try_lock`] method. +/// An enumeration of possible errors associated with a [`TryLockResult`] which +/// can occur while trying to aquire a lock, from the [`try_lock`] method on a +/// [`Mutex`] or the [`try_read`] and [`try_write`] methods on an [`RwLock`]. /// +/// [`Mutex`]: struct.Mutex.html +/// [`RwLock`]: struct.RwLock.html +/// [`TryLockResult`]: type.TryLockResult.html /// [`try_lock`]: struct.Mutex.html#method.try_lock +/// [`try_read`]: struct.RwLock.html#method.try_read +/// [`try_write`]: struct.RwLock.html#method.try_write #[stable(feature = "rust1", since = "1.0.0")] pub enum TryLockError { /// The lock could not be acquired because another thread failed while holding @@ -148,6 +179,28 @@ impl PoisonError { /// Consumes this error indicating that a lock is poisoned, returning the /// underlying guard to allow access regardless. + /// + /// # Examples + /// + /// ``` + /// use std::collections::HashSet; + /// use std::sync::{Arc, Mutex}; + /// use std::thread; + /// + /// let mutex = Arc::new(Mutex::new(HashSet::new())); + /// + /// // poison the mutex + /// let c_mutex = mutex.clone(); + /// let _ = thread::spawn(move || { + /// let mut data = c_mutex.lock().unwrap(); + /// data.insert(10); + /// panic!(); + /// }).join(); + /// + /// let p_err = mutex.lock().unwrap_err(); + /// let data = p_err.into_inner(); + /// println!("recovered {} items", data.len()); + /// ``` #[stable(feature = "sync_poison", since = "1.2.0")] pub fn into_inner(self) -> T { self.guard } -- cgit 1.4.1-3-g733a5 From 4d2a8c527880a56db3b410450fa2b6cbf0cbe3a8 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sat, 23 Sep 2017 17:08:16 -0700 Subject: Simplify implementation of Display and Error for convert::Infallible. --- src/libcore/convert.rs | 5 +++-- src/libstd/error.rs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 6eb499ad8ab..e815d72d366 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -62,8 +62,9 @@ pub enum Infallible {} #[unstable(feature = "try_from", issue = "33417")] impl fmt::Display for Infallible { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - "an error of this type can never exist".fmt(f) + fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + match *self { + } } } /// A cheap reference-to-reference conversion. Used to convert a value to a diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 5cb2b00334d..6a4de4ecbff 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -351,7 +351,8 @@ impl Error for char::ParseCharError { #[unstable(feature = "try_from", issue = "33417")] impl Error for convert::Infallible { fn description(&self) -> &str { - "an error of this type can never exist" + match *self { + } } } -- cgit 1.4.1-3-g733a5 From bc43e1739234727ebddaf475c2851eab00353324 Mon Sep 17 00:00:00 2001 From: Ethan Dagner Date: Sat, 23 Sep 2017 11:47:21 -0600 Subject: Add doc example to HashMap::hasher --- src/libstd/collections/hash/map.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 96af2272578..f28577d257e 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -691,6 +691,17 @@ impl HashMap /// Returns a reference to the map's [`BuildHasher`]. /// /// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html + /// + /// # Examples + /// + /// ``` + /// use std::collections::HashMap; + /// use std::collections::hash_map::RandomState; + /// + /// let hasher = RandomState::new(); + /// let map: HashMap = HashMap::with_hasher(hasher); + /// let hasher: &RandomState = map.hasher(); + /// ``` #[stable(feature = "hashmap_public_hasher", since = "1.9.0")] pub fn hasher(&self) -> &S { &self.hash_builder -- cgit 1.4.1-3-g733a5 From 43cff131ddb0e34f7ebe361700dbd5c3c13519cb Mon Sep 17 00:00:00 2001 From: "P.Y. Laligand" Date: Fri, 15 Sep 2017 12:38:08 -0700 Subject: The Magenta kernel is now called Zircon. --- src/ci/docker/dist-fuchsia/build-toolchain.sh | 18 +- src/libstd/build.rs | 4 +- src/libstd/sys/unix/process/magenta.rs | 319 ------------------------- src/libstd/sys/unix/process/mod.rs | 2 +- src/libstd/sys/unix/process/process_fuchsia.rs | 76 +++--- src/libstd/sys/unix/process/zircon.rs | 319 +++++++++++++++++++++++++ src/libstd/sys/unix/rand.rs | 8 +- src/tools/tidy/src/deps.rs | 3 + 8 files changed, 376 insertions(+), 373 deletions(-) delete mode 100644 src/libstd/sys/unix/process/magenta.rs create mode 100644 src/libstd/sys/unix/process/zircon.rs (limited to 'src/libstd') diff --git a/src/ci/docker/dist-fuchsia/build-toolchain.sh b/src/ci/docker/dist-fuchsia/build-toolchain.sh index 10b285a5466..86430b48127 100755 --- a/src/ci/docker/dist-fuchsia/build-toolchain.sh +++ b/src/ci/docker/dist-fuchsia/build-toolchain.sh @@ -16,7 +16,7 @@ source shared.sh # Download sources SRCS=( - "https://fuchsia.googlesource.com/magenta magenta d17073dc8de344ead3b65e8cc6a12280dec38c84" + "https://fuchsia.googlesource.com/zircon zircon d17073dc8de344ead3b65e8cc6a12280dec38c84" "https://llvm.googlesource.com/llvm llvm 3f58a16d8eec385e2b3ebdfbb84ff9d3bf27e025" "https://llvm.googlesource.com/clang llvm/tools/clang 727ea63e6e82677f6e10e05e08bc7d6bdbae3111" "https://llvm.googlesource.com/lld llvm/tools/lld a31286c1366e5e89b8872803fded13805a1a084b" @@ -51,7 +51,7 @@ cd llvm mkdir build cd build hide_output cmake -GNinja \ - -DFUCHSIA_SYSROOT=${PWD}/../../magenta/third_party/ulib/musl \ + -DFUCHSIA_SYSROOT=${PWD}/../../zircon/third_party/ulib/musl \ -DLLVM_ENABLE_LTO=OFF \ -DCLANG_BOOTSTRAP_PASSTHROUGH=LLVM_ENABLE_LTO \ -C ../tools/clang/cmake/caches/Fuchsia.cmake \ @@ -62,21 +62,21 @@ cd ../.. # Build sysroot rm -rf llvm/runtimes/compiler-rt -./magenta/scripts/download-toolchain +./zircon/scripts/download-toolchain build_sysroot() { local arch="$1" case "${arch}" in - x86_64) tgt="magenta-pc-x86-64" ;; - aarch64) tgt="magenta-qemu-arm64" ;; + x86_64) tgt="zircon-pc-x86-64" ;; + aarch64) tgt="zircon-qemu-arm64" ;; esac - hide_output make -C magenta -j$(getconf _NPROCESSORS_ONLN) $tgt + hide_output make -C zircon -j$(getconf _NPROCESSORS_ONLN) $tgt dst=/usr/local/${arch}-unknown-fuchsia mkdir -p $dst - cp -r magenta/build-${tgt}/sysroot/include $dst/ - cp -r magenta/build-${tgt}/sysroot/lib $dst/ + cp -r zircon/build-${tgt}/sysroot/include $dst/ + cp -r zircon/build-${tgt}/sysroot/lib $dst/ cd llvm mkdir build-runtimes-${arch} @@ -112,7 +112,7 @@ build_sysroot() { build_sysroot "x86_64" build_sysroot "aarch64" -rm -rf magenta llvm +rm -rf zircon llvm for arch in x86_64 aarch64; do for tool in clang clang++; do diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 19ea25fc7df..b8061665aa1 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -68,8 +68,8 @@ fn main() { if cfg!(feature = "backtrace") { println!("cargo:rustc-link-lib=backtrace"); } - println!("cargo:rustc-link-lib=magenta"); - println!("cargo:rustc-link-lib=mxio"); + println!("cargo:rustc-link-lib=zircon"); + println!("cargo:rustc-link-lib=fdio"); println!("cargo:rustc-link-lib=launchpad"); // for std::process } } diff --git a/src/libstd/sys/unix/process/magenta.rs b/src/libstd/sys/unix/process/magenta.rs deleted file mode 100644 index bc20a74f114..00000000000 --- a/src/libstd/sys/unix/process/magenta.rs +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(non_camel_case_types)] - -use convert::TryInto; -use io; -use os::raw::c_char; -use u64; - -use libc::{c_int, c_void}; - -pub type mx_handle_t = i32; -pub type mx_vaddr_t = usize; -pub type mx_rights_t = u32; -pub type mx_status_t = i32; - -pub type mx_size_t = usize; - -pub const MX_HANDLE_INVALID: mx_handle_t = 0; - -pub type mx_time_t = u64; -pub const MX_TIME_INFINITE : mx_time_t = u64::MAX; - -pub type mx_signals_t = u32; - -pub const MX_OBJECT_SIGNAL_3 : mx_signals_t = 1 << 3; - -pub const MX_TASK_TERMINATED : mx_signals_t = MX_OBJECT_SIGNAL_3; - -pub const MX_RIGHT_SAME_RIGHTS : mx_rights_t = 1 << 31; - -pub type mx_object_info_topic_t = u32; - -pub const MX_INFO_PROCESS : mx_object_info_topic_t = 3; - -pub fn mx_cvt(t: T) -> io::Result where T: TryInto+Copy { - if let Ok(status) = TryInto::try_into(t) { - if status < 0 { - Err(io::Error::from_raw_os_error(status)) - } else { - Ok(t) - } - } else { - Err(io::Error::last_os_error()) - } -} - -// Safe wrapper around mx_handle_t -pub struct Handle { - raw: mx_handle_t, -} - -impl Handle { - pub fn new(raw: mx_handle_t) -> Handle { - Handle { - raw, - } - } - - pub fn raw(&self) -> mx_handle_t { - self.raw - } -} - -impl Drop for Handle { - fn drop(&mut self) { - unsafe { mx_cvt(mx_handle_close(self.raw)).expect("Failed to close mx_handle_t"); } - } -} - -// Common MX_INFO header -#[derive(Default)] -#[repr(C)] -pub struct mx_info_header_t { - pub topic: u32, // identifies the info struct - pub avail_topic_size: u16, // “native” size of the struct - pub topic_size: u16, // size of the returned struct (<=topic_size) - pub avail_count: u32, // number of records the kernel has - pub count: u32, // number of records returned (limited by buffer size) -} - -#[derive(Default)] -#[repr(C)] -pub struct mx_record_process_t { - pub return_code: c_int, -} - -// Returned for topic MX_INFO_PROCESS -#[derive(Default)] -#[repr(C)] -pub struct mx_info_process_t { - pub hdr: mx_info_header_t, - pub rec: mx_record_process_t, -} - -extern { - pub fn mx_job_default() -> mx_handle_t; - - pub fn mx_task_kill(handle: mx_handle_t) -> mx_status_t; - - pub fn mx_handle_close(handle: mx_handle_t) -> mx_status_t; - - pub fn mx_handle_duplicate(handle: mx_handle_t, rights: mx_rights_t, - out: *const mx_handle_t) -> mx_handle_t; - - pub fn mx_object_wait_one(handle: mx_handle_t, signals: mx_signals_t, timeout: mx_time_t, - pending: *mut mx_signals_t) -> mx_status_t; - - pub fn mx_object_get_info(handle: mx_handle_t, topic: u32, buffer: *mut c_void, - buffer_size: mx_size_t, actual_size: *mut mx_size_t, - avail: *mut mx_size_t) -> mx_status_t; -} - -// From `enum special_handles` in system/ulib/launchpad/launchpad.c -// HND_LOADER_SVC = 0 -// HND_EXEC_VMO = 1 -pub const HND_SPECIAL_COUNT: usize = 2; - -#[repr(C)] -pub struct launchpad_t { - argc: u32, - envc: u32, - args: *const c_char, - args_len: usize, - env: *const c_char, - env_len: usize, - - handles: *mut mx_handle_t, - handles_info: *mut u32, - handle_count: usize, - handle_alloc: usize, - - entry: mx_vaddr_t, - base: mx_vaddr_t, - vdso_base: mx_vaddr_t, - - stack_size: usize, - - special_handles: [mx_handle_t; HND_SPECIAL_COUNT], - loader_message: bool, -} - -extern { - pub fn launchpad_create(job: mx_handle_t, name: *const c_char, - lp: *mut *mut launchpad_t) -> mx_status_t; - - pub fn launchpad_go(lp: *mut launchpad_t, - proc_handle: *mut mx_handle_t, - err_msg: *mut *const c_char) -> mx_status_t; - - pub fn launchpad_destroy(lp: *mut launchpad_t); - - pub fn launchpad_set_args(lp: *mut launchpad_t, argc: c_int, - argv: *const *const c_char) -> mx_status_t; - - pub fn launchpad_set_environ(lp: *mut launchpad_t, envp: *const *const c_char) -> mx_status_t; - - pub fn launchpad_clone(lp: *mut launchpad_t, what: u32) -> mx_status_t; - - pub fn launchpad_clone_fd(lp: *mut launchpad_t, fd: c_int, target_fd: c_int) -> mx_status_t; - - pub fn launchpad_transfer_fd(lp: *mut launchpad_t, fd: c_int, target_fd: c_int) -> mx_status_t; - - pub fn launchpad_elf_load(lp: *mut launchpad_t, vmo: mx_handle_t) -> mx_status_t; - - pub fn launchpad_add_vdso_vmo(lp: *mut launchpad_t) -> mx_status_t; - - pub fn launchpad_load_vdso(lp: *mut launchpad_t, vmo: mx_handle_t) -> mx_status_t; - - pub fn launchpad_vmo_from_file(filename: *const c_char) -> mx_handle_t; -} - -// Launchpad clone constants - -pub const LP_CLONE_MXIO_ROOT: u32 = 0x0001; -pub const LP_CLONE_MXIO_CWD: u32 = 0x0002; -// LP_CLONE_MXIO_STDIO = 0x0004 -// LP_CLONE_MXIO_ALL = 0x00FF -// LP_CLONE_ENVIRON = 0x0100 -// LP_CLONE_DEFAULT_JOB = 0x0200 -// LP_CLONE_ALL = 0xFFFF - -// Errors - -#[allow(unused)] pub const ERR_INTERNAL: mx_status_t = -1; - -// ERR_NOT_SUPPORTED: The operation is not implemented, supported, -// or enabled. -#[allow(unused)] pub const ERR_NOT_SUPPORTED: mx_status_t = -2; - -// ERR_NO_RESOURCES: The system was not able to allocate some resource -// needed for the operation. -#[allow(unused)] pub const ERR_NO_RESOURCES: mx_status_t = -3; - -// ERR_NO_MEMORY: The system was not able to allocate memory needed -// for the operation. -#[allow(unused)] pub const ERR_NO_MEMORY: mx_status_t = -4; - -// ERR_CALL_FAILED: The second phase of mx_channel_call(; did not complete -// successfully. -#[allow(unused)] pub const ERR_CALL_FAILED: mx_status_t = -5; - -// ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be -// retried. This should not be seen outside of the VDSO. -#[allow(unused)] pub const ERR_INTERRUPTED_RETRY: mx_status_t = -6; - -// ======= Parameter errors ======= -// ERR_INVALID_ARGS: an argument is invalid, ex. null pointer -#[allow(unused)] pub const ERR_INVALID_ARGS: mx_status_t = -10; - -// ERR_BAD_HANDLE: A specified handle value does not refer to a handle. -#[allow(unused)] pub const ERR_BAD_HANDLE: mx_status_t = -11; - -// ERR_WRONG_TYPE: The subject of the operation is the wrong type to -// perform the operation. -// Example: Attempting a message_read on a thread handle. -#[allow(unused)] pub const ERR_WRONG_TYPE: mx_status_t = -12; - -// ERR_BAD_SYSCALL: The specified syscall number is invalid. -#[allow(unused)] pub const ERR_BAD_SYSCALL: mx_status_t = -13; - -// ERR_OUT_OF_RANGE: An argument is outside the valid range for this -// operation. -#[allow(unused)] pub const ERR_OUT_OF_RANGE: mx_status_t = -14; - -// ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for -// this operation. -#[allow(unused)] pub const ERR_BUFFER_TOO_SMALL: mx_status_t = -15; - -// ======= Precondition or state errors ======= -// ERR_BAD_STATE: operation failed because the current state of the -// object does not allow it, or a precondition of the operation is -// not satisfied -#[allow(unused)] pub const ERR_BAD_STATE: mx_status_t = -20; - -// ERR_TIMED_OUT: The time limit for the operation elapsed before -// the operation completed. -#[allow(unused)] pub const ERR_TIMED_OUT: mx_status_t = -21; - -// ERR_SHOULD_WAIT: The operation cannot be performed currently but -// potentially could succeed if the caller waits for a prerequisite -// to be satisfied, for example waiting for a handle to be readable -// or writable. -// Example: Attempting to read from a message pipe that has no -// messages waiting but has an open remote will return ERR_SHOULD_WAIT. -// Attempting to read from a message pipe that has no messages waiting -// and has a closed remote end will return ERR_REMOTE_CLOSED. -#[allow(unused)] pub const ERR_SHOULD_WAIT: mx_status_t = -22; - -// ERR_CANCELED: The in-progress operation (e.g. a wait) has been -// // canceled. -#[allow(unused)] pub const ERR_CANCELED: mx_status_t = -23; - -// ERR_PEER_CLOSED: The operation failed because the remote end -// of the subject of the operation was closed. -#[allow(unused)] pub const ERR_PEER_CLOSED: mx_status_t = -24; - -// ERR_NOT_FOUND: The requested entity is not found. -#[allow(unused)] pub const ERR_NOT_FOUND: mx_status_t = -25; - -// ERR_ALREADY_EXISTS: An object with the specified identifier -// already exists. -// Example: Attempting to create a file when a file already exists -// with that name. -#[allow(unused)] pub const ERR_ALREADY_EXISTS: mx_status_t = -26; - -// ERR_ALREADY_BOUND: The operation failed because the named entity -// is already owned or controlled by another entity. The operation -// could succeed later if the current owner releases the entity. -#[allow(unused)] pub const ERR_ALREADY_BOUND: mx_status_t = -27; - -// ERR_UNAVAILABLE: The subject of the operation is currently unable -// to perform the operation. -// Note: This is used when there's no direct way for the caller to -// observe when the subject will be able to perform the operation -// and should thus retry. -#[allow(unused)] pub const ERR_UNAVAILABLE: mx_status_t = -28; - -// ======= Permission check errors ======= -// ERR_ACCESS_DENIED: The caller did not have permission to perform -// the specified operation. -#[allow(unused)] pub const ERR_ACCESS_DENIED: mx_status_t = -30; - -// ======= Input-output errors ======= -// ERR_IO: Otherwise unspecified error occurred during I/O. -#[allow(unused)] pub const ERR_IO: mx_status_t = -40; - -// ERR_REFUSED: The entity the I/O operation is being performed on -// rejected the operation. -// Example: an I2C device NAK'ing a transaction or a disk controller -// rejecting an invalid command. -#[allow(unused)] pub const ERR_IO_REFUSED: mx_status_t = -41; - -// ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity -// check and is possibly corrupted. -// Example: CRC or Parity error. -#[allow(unused)] pub const ERR_IO_DATA_INTEGRITY: mx_status_t = -42; - -// ERR_IO_DATA_LOSS: The data in the operation is currently unavailable -// and may be permanently lost. -// Example: A disk block is irrecoverably damaged. -#[allow(unused)] pub const ERR_IO_DATA_LOSS: mx_status_t = -43; - -// Filesystem specific errors -#[allow(unused)] pub const ERR_BAD_PATH: mx_status_t = -50; -#[allow(unused)] pub const ERR_NOT_DIR: mx_status_t = -51; -#[allow(unused)] pub const ERR_NOT_FILE: mx_status_t = -52; -// ERR_FILE_BIG: A file exceeds a filesystem-specific size limit. -#[allow(unused)] pub const ERR_FILE_BIG: mx_status_t = -53; -// ERR_NO_SPACE: Filesystem or device space is exhausted. -#[allow(unused)] pub const ERR_NO_SPACE: mx_status_t = -54; diff --git a/src/libstd/sys/unix/process/mod.rs b/src/libstd/sys/unix/process/mod.rs index b50384d8eee..2a331069bc2 100644 --- a/src/libstd/sys/unix/process/mod.rs +++ b/src/libstd/sys/unix/process/mod.rs @@ -19,4 +19,4 @@ mod process_inner; #[path = "process_fuchsia.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] -mod magenta; +mod zircon; diff --git a/src/libstd/sys/unix/process/process_fuchsia.rs b/src/libstd/sys/unix/process/process_fuchsia.rs index 7d583cb3dfc..1a7f544f8e9 100644 --- a/src/libstd/sys/unix/process/process_fuchsia.rs +++ b/src/libstd/sys/unix/process/process_fuchsia.rs @@ -13,7 +13,7 @@ use libc; use mem; use ptr; -use sys::process::magenta::{Handle, mx_handle_t}; +use sys::process::zircon::{Handle, zx_handle_t}; use sys::process::process_common::*; //////////////////////////////////////////////////////////////////////////////// @@ -51,10 +51,10 @@ impl Command { } unsafe fn do_exec(&mut self, stdio: ChildPipes) - -> io::Result { - use sys::process::magenta::*; + -> io::Result { + use sys::process::zircon::*; - let job_handle = mx_job_default(); + let job_handle = zx_job_default(); let envp = match *self.get_envp() { Some(ref envp) => envp.as_ptr(), None => ptr::null(), @@ -67,39 +67,39 @@ impl Command { } // Duplicate the job handle - let mut job_copy: mx_handle_t = MX_HANDLE_INVALID; - mx_cvt(mx_handle_duplicate(job_handle, MX_RIGHT_SAME_RIGHTS, &mut job_copy))?; + let mut job_copy: zx_handle_t = zx_HANDLE_INVALID; + zx_cvt(zx_handle_duplicate(job_handle, zx_RIGHT_SAME_RIGHTS, &mut job_copy))?; // Create a launchpad let mut launchpad: *mut launchpad_t = ptr::null_mut(); - mx_cvt(launchpad_create(job_copy, self.get_argv()[0], &mut launchpad))?; + zx_cvt(launchpad_create(job_copy, self.get_argv()[0], &mut launchpad))?; let launchpad_destructor = LaunchpadDestructor(launchpad); // Set the process argv - mx_cvt(launchpad_set_args(launchpad, self.get_argv().len() as i32 - 1, + zx_cvt(launchpad_set_args(launchpad, self.get_argv().len() as i32 - 1, self.get_argv().as_ptr()))?; // Setup the environment vars - mx_cvt(launchpad_set_environ(launchpad, envp))?; - mx_cvt(launchpad_add_vdso_vmo(launchpad))?; + zx_cvt(launchpad_set_environ(launchpad, envp))?; + zx_cvt(launchpad_add_vdso_vmo(launchpad))?; // Load the executable - mx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?; - mx_cvt(launchpad_load_vdso(launchpad, MX_HANDLE_INVALID))?; - mx_cvt(launchpad_clone(launchpad, LP_CLONE_MXIO_ROOT | LP_CLONE_MXIO_CWD))?; + zx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?; + zx_cvt(launchpad_load_vdso(launchpad, zx_HANDLE_INVALID))?; + zx_cvt(launchpad_clone(launchpad, LP_CLONE_FDIO_ROOT | LP_CLONE_FDIO_CWD))?; // Clone stdin, stdout, and stderr if let Some(fd) = stdio.stdin.fd() { - mx_cvt(launchpad_transfer_fd(launchpad, fd, 0))?; + zx_cvt(launchpad_transfer_fd(launchpad, fd, 0))?; } else { - mx_cvt(launchpad_clone_fd(launchpad, 0, 0))?; + zx_cvt(launchpad_clone_fd(launchpad, 0, 0))?; } if let Some(fd) = stdio.stdout.fd() { - mx_cvt(launchpad_transfer_fd(launchpad, fd, 1))?; + zx_cvt(launchpad_transfer_fd(launchpad, fd, 1))?; } else { - mx_cvt(launchpad_clone_fd(launchpad, 1, 1))?; + zx_cvt(launchpad_clone_fd(launchpad, 1, 1))?; } if let Some(fd) = stdio.stderr.fd() { - mx_cvt(launchpad_transfer_fd(launchpad, fd, 2))?; + zx_cvt(launchpad_transfer_fd(launchpad, fd, 2))?; } else { - mx_cvt(launchpad_clone_fd(launchpad, 2, 2))?; + zx_cvt(launchpad_clone_fd(launchpad, 2, 2))?; } // We don't want FileDesc::drop to be called on any stdio. It would close their fds. The @@ -113,9 +113,9 @@ impl Command { // `launchpad_go` destroys the launchpad, so we must not mem::forget(launchpad_destructor); - let mut process_handle: mx_handle_t = 0; + let mut process_handle: zx_handle_t = 0; let mut err_msg: *const libc::c_char = ptr::null(); - mx_cvt(launchpad_go(launchpad, &mut process_handle, &mut err_msg))?; + zx_cvt(launchpad_go(launchpad, &mut process_handle, &mut err_msg))?; // FIXME: See if we want to do something with that err_msg Ok(process_handle) @@ -136,27 +136,27 @@ impl Process { } pub fn kill(&mut self) -> io::Result<()> { - use sys::process::magenta::*; + use sys::process::zircon::*; - unsafe { mx_cvt(mx_task_kill(self.handle.raw()))?; } + unsafe { zx_cvt(zx_task_kill(self.handle.raw()))?; } Ok(()) } pub fn wait(&mut self) -> io::Result { use default::Default; - use sys::process::magenta::*; + use sys::process::zircon::*; - let mut proc_info: mx_info_process_t = Default::default(); - let mut actual: mx_size_t = 0; - let mut avail: mx_size_t = 0; + let mut proc_info: zx_info_process_t = Default::default(); + let mut actual: zx_size_t = 0; + let mut avail: zx_size_t = 0; unsafe { - mx_cvt(mx_object_wait_one(self.handle.raw(), MX_TASK_TERMINATED, - MX_TIME_INFINITE, ptr::null_mut()))?; - mx_cvt(mx_object_get_info(self.handle.raw(), MX_INFO_PROCESS, + zx_cvt(zx_object_wait_one(self.handle.raw(), zx_TASK_TERMINATED, + zx_TIME_INFINITE, ptr::null_mut()))?; + zx_cvt(zx_object_get_info(self.handle.raw(), zx_INFO_PROCESS, &mut proc_info as *mut _ as *mut libc::c_void, - mem::size_of::(), &mut actual, + mem::size_of::(), &mut actual, &mut avail))?; } if actual != 1 { @@ -168,14 +168,14 @@ impl Process { pub fn try_wait(&mut self) -> io::Result> { use default::Default; - use sys::process::magenta::*; + use sys::process::zircon::*; - let mut proc_info: mx_info_process_t = Default::default(); - let mut actual: mx_size_t = 0; - let mut avail: mx_size_t = 0; + let mut proc_info: zx_info_process_t = Default::default(); + let mut actual: zx_size_t = 0; + let mut avail: zx_size_t = 0; unsafe { - let status = mx_object_wait_one(self.handle.raw(), MX_TASK_TERMINATED, + let status = zx_object_wait_one(self.handle.raw(), zx_TASK_TERMINATED, 0, ptr::null_mut()); match status { 0 => { }, // Success @@ -184,9 +184,9 @@ impl Process { }, _ => { panic!("Failed to wait on process handle: {}", status); }, } - mx_cvt(mx_object_get_info(self.handle.raw(), MX_INFO_PROCESS, + zx_cvt(zx_object_get_info(self.handle.raw(), zx_INFO_PROCESS, &mut proc_info as *mut _ as *mut libc::c_void, - mem::size_of::(), &mut actual, + mem::size_of::(), &mut actual, &mut avail))?; } if actual != 1 { diff --git a/src/libstd/sys/unix/process/zircon.rs b/src/libstd/sys/unix/process/zircon.rs new file mode 100644 index 00000000000..4dbcdb57663 --- /dev/null +++ b/src/libstd/sys/unix/process/zircon.rs @@ -0,0 +1,319 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(non_camel_case_types)] + +use convert::TryInto; +use io; +use os::raw::c_char; +use u64; + +use libc::{c_int, c_void}; + +pub type zx_handle_t = i32; +pub type zx_vaddr_t = usize; +pub type zx_rights_t = u32; +pub type zx_status_t = i32; + +pub type zx_size_t = usize; + +pub const zx_HANDLE_INVALID: zx_handle_t = 0; + +pub type zx_time_t = u64; +pub const zx_TIME_INFINITE : zx_time_t = u64::MAX; + +pub type zx_signals_t = u32; + +pub const zx_OBJECT_SIGNAL_3 : zx_signals_t = 1 << 3; + +pub const zx_TASK_TERMINATED : zx_signals_t = zx_OBJECT_SIGNAL_3; + +pub const zx_RIGHT_SAME_RIGHTS : zx_rights_t = 1 << 31; + +pub type zx_object_info_topic_t = u32; + +pub const zx_INFO_PROCESS : zx_object_info_topic_t = 3; + +pub fn zx_cvt(t: T) -> io::Result where T: TryInto+Copy { + if let Ok(status) = TryInto::try_into(t) { + if status < 0 { + Err(io::Error::from_raw_os_error(status)) + } else { + Ok(t) + } + } else { + Err(io::Error::last_os_error()) + } +} + +// Safe wrapper around zx_handle_t +pub struct Handle { + raw: zx_handle_t, +} + +impl Handle { + pub fn new(raw: zx_handle_t) -> Handle { + Handle { + raw, + } + } + + pub fn raw(&self) -> zx_handle_t { + self.raw + } +} + +impl Drop for Handle { + fn drop(&mut self) { + unsafe { zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t"); } + } +} + +// Common zx_INFO header +#[derive(Default)] +#[repr(C)] +pub struct zx_info_header_t { + pub topic: u32, // identifies the info struct + pub avail_topic_size: u16, // “native” size of the struct + pub topic_size: u16, // size of the returned struct (<=topic_size) + pub avail_count: u32, // number of records the kernel has + pub count: u32, // number of records returned (limited by buffer size) +} + +#[derive(Default)] +#[repr(C)] +pub struct zx_record_process_t { + pub return_code: c_int, +} + +// Returned for topic zx_INFO_PROCESS +#[derive(Default)] +#[repr(C)] +pub struct zx_info_process_t { + pub hdr: zx_info_header_t, + pub rec: zx_record_process_t, +} + +extern { + pub fn zx_job_default() -> zx_handle_t; + + pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t; + + pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t; + + pub fn zx_handle_duplicate(handle: zx_handle_t, rights: zx_rights_t, + out: *const zx_handle_t) -> zx_handle_t; + + pub fn zx_object_wait_one(handle: zx_handle_t, signals: zx_signals_t, timeout: zx_time_t, + pending: *mut zx_signals_t) -> zx_status_t; + + pub fn zx_object_get_info(handle: zx_handle_t, topic: u32, buffer: *mut c_void, + buffer_size: zx_size_t, actual_size: *mut zx_size_t, + avail: *mut zx_size_t) -> zx_status_t; +} + +// From `enum special_handles` in system/ulib/launchpad/launchpad.c +// HND_LOADER_SVC = 0 +// HND_EXEC_VMO = 1 +pub const HND_SPECIAL_COUNT: usize = 2; + +#[repr(C)] +pub struct launchpad_t { + argc: u32, + envc: u32, + args: *const c_char, + args_len: usize, + env: *const c_char, + env_len: usize, + + handles: *mut zx_handle_t, + handles_info: *mut u32, + handle_count: usize, + handle_alloc: usize, + + entry: zx_vaddr_t, + base: zx_vaddr_t, + vdso_base: zx_vaddr_t, + + stack_size: usize, + + special_handles: [zx_handle_t; HND_SPECIAL_COUNT], + loader_message: bool, +} + +extern { + pub fn launchpad_create(job: zx_handle_t, name: *const c_char, + lp: *mut *mut launchpad_t) -> zx_status_t; + + pub fn launchpad_go(lp: *mut launchpad_t, + proc_handle: *mut zx_handle_t, + err_msg: *mut *const c_char) -> zx_status_t; + + pub fn launchpad_destroy(lp: *mut launchpad_t); + + pub fn launchpad_set_args(lp: *mut launchpad_t, argc: c_int, + argv: *const *const c_char) -> zx_status_t; + + pub fn launchpad_set_environ(lp: *mut launchpad_t, envp: *const *const c_char) -> zx_status_t; + + pub fn launchpad_clone(lp: *mut launchpad_t, what: u32) -> zx_status_t; + + pub fn launchpad_clone_fd(lp: *mut launchpad_t, fd: c_int, target_fd: c_int) -> zx_status_t; + + pub fn launchpad_transfer_fd(lp: *mut launchpad_t, fd: c_int, target_fd: c_int) -> zx_status_t; + + pub fn launchpad_elf_load(lp: *mut launchpad_t, vmo: zx_handle_t) -> zx_status_t; + + pub fn launchpad_add_vdso_vmo(lp: *mut launchpad_t) -> zx_status_t; + + pub fn launchpad_load_vdso(lp: *mut launchpad_t, vmo: zx_handle_t) -> zx_status_t; + + pub fn launchpad_vmo_from_file(filename: *const c_char) -> zx_handle_t; +} + +// Launchpad clone constants + +pub const LP_CLONE_FDIO_ROOT: u32 = 0x0001; +pub const LP_CLONE_FDIO_CWD: u32 = 0x0002; +// LP_CLONE_FDIO_STDIO = 0x0004 +// LP_CLONE_FDIO_ALL = 0x00FF +// LP_CLONE_ENVIRON = 0x0100 +// LP_CLONE_DEFAULT_JOB = 0x0200 +// LP_CLONE_ALL = 0xFFFF + +// Errors + +#[allow(unused)] pub const ERR_INTERNAL: zx_status_t = -1; + +// ERR_NOT_SUPPORTED: The operation is not implemented, supported, +// or enabled. +#[allow(unused)] pub const ERR_NOT_SUPPORTED: zx_status_t = -2; + +// ERR_NO_RESOURCES: The system was not able to allocate some resource +// needed for the operation. +#[allow(unused)] pub const ERR_NO_RESOURCES: zx_status_t = -3; + +// ERR_NO_MEMORY: The system was not able to allocate memory needed +// for the operation. +#[allow(unused)] pub const ERR_NO_MEMORY: zx_status_t = -4; + +// ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete +// successfully. +#[allow(unused)] pub const ERR_CALL_FAILED: zx_status_t = -5; + +// ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be +// retried. This should not be seen outside of the VDSO. +#[allow(unused)] pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6; + +// ======= Parameter errors ======= +// ERR_INVALID_ARGS: an argument is invalid, ex. null pointer +#[allow(unused)] pub const ERR_INVALID_ARGS: zx_status_t = -10; + +// ERR_BAD_HANDLE: A specified handle value does not refer to a handle. +#[allow(unused)] pub const ERR_BAD_HANDLE: zx_status_t = -11; + +// ERR_WRONG_TYPE: The subject of the operation is the wrong type to +// perform the operation. +// Example: Attempting a message_read on a thread handle. +#[allow(unused)] pub const ERR_WRONG_TYPE: zx_status_t = -12; + +// ERR_BAD_SYSCALL: The specified syscall number is invalid. +#[allow(unused)] pub const ERR_BAD_SYSCALL: zx_status_t = -13; + +// ERR_OUT_OF_RANGE: An argument is outside the valid range for this +// operation. +#[allow(unused)] pub const ERR_OUT_OF_RANGE: zx_status_t = -14; + +// ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for +// this operation. +#[allow(unused)] pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15; + +// ======= Precondition or state errors ======= +// ERR_BAD_STATE: operation failed because the current state of the +// object does not allow it, or a precondition of the operation is +// not satisfied +#[allow(unused)] pub const ERR_BAD_STATE: zx_status_t = -20; + +// ERR_TIMED_OUT: The time limit for the operation elapsed before +// the operation completed. +#[allow(unused)] pub const ERR_TIMED_OUT: zx_status_t = -21; + +// ERR_SHOULD_WAIT: The operation cannot be performed currently but +// potentially could succeed if the caller waits for a prerequisite +// to be satisfied, for example waiting for a handle to be readable +// or writable. +// Example: Attempting to read from a message pipe that has no +// messages waiting but has an open remote will return ERR_SHOULD_WAIT. +// Attempting to read from a message pipe that has no messages waiting +// and has a closed remote end will return ERR_REMOTE_CLOSED. +#[allow(unused)] pub const ERR_SHOULD_WAIT: zx_status_t = -22; + +// ERR_CANCELED: The in-progress operation (e.g. a wait) has been +// // canceled. +#[allow(unused)] pub const ERR_CANCELED: zx_status_t = -23; + +// ERR_PEER_CLOSED: The operation failed because the remote end +// of the subject of the operation was closed. +#[allow(unused)] pub const ERR_PEER_CLOSED: zx_status_t = -24; + +// ERR_NOT_FOUND: The requested entity is not found. +#[allow(unused)] pub const ERR_NOT_FOUND: zx_status_t = -25; + +// ERR_ALREADY_EXISTS: An object with the specified identifier +// already exists. +// Example: Attempting to create a file when a file already exists +// with that name. +#[allow(unused)] pub const ERR_ALREADY_EXISTS: zx_status_t = -26; + +// ERR_ALREADY_BOUND: The operation failed because the named entity +// is already owned or controlled by another entity. The operation +// could succeed later if the current owner releases the entity. +#[allow(unused)] pub const ERR_ALREADY_BOUND: zx_status_t = -27; + +// ERR_UNAVAILABLE: The subject of the operation is currently unable +// to perform the operation. +// Note: This is used when there's no direct way for the caller to +// observe when the subject will be able to perform the operation +// and should thus retry. +#[allow(unused)] pub const ERR_UNAVAILABLE: zx_status_t = -28; + +// ======= Permission check errors ======= +// ERR_ACCESS_DENIED: The caller did not have permission to perform +// the specified operation. +#[allow(unused)] pub const ERR_ACCESS_DENIED: zx_status_t = -30; + +// ======= Input-output errors ======= +// ERR_IO: Otherwise unspecified error occurred during I/O. +#[allow(unused)] pub const ERR_IO: zx_status_t = -40; + +// ERR_REFUSED: The entity the I/O operation is being performed on +// rejected the operation. +// Example: an I2C device NAK'ing a transaction or a disk controller +// rejecting an invalid command. +#[allow(unused)] pub const ERR_IO_REFUSED: zx_status_t = -41; + +// ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity +// check and is possibly corrupted. +// Example: CRC or Parity error. +#[allow(unused)] pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42; + +// ERR_IO_DATA_LOSS: The data in the operation is currently unavailable +// and may be permanently lost. +// Example: A disk block is irrecoverably damaged. +#[allow(unused)] pub const ERR_IO_DATA_LOSS: zx_status_t = -43; + +// Filesystem specific errors +#[allow(unused)] pub const ERR_BAD_PATH: zx_status_t = -50; +#[allow(unused)] pub const ERR_NOT_DIR: zx_status_t = -51; +#[allow(unused)] pub const ERR_NOT_FILE: zx_status_t = -52; +// ERR_FILE_BIG: A file exceeds a filesystem-specific size limit. +#[allow(unused)] pub const ERR_FILE_BIG: zx_status_t = -53; +// ERR_NO_SPACE: Filesystem or device space is exhausted. +#[allow(unused)] pub const ERR_NO_SPACE: zx_status_t = -54; diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 1f56a299407..fd066c9cdbe 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -344,15 +344,15 @@ mod imp { use io; use rand::Rng; - #[link(name = "magenta")] + #[link(name = "zircon")] extern { - fn mx_cprng_draw(buffer: *mut u8, len: usize, actual: *mut usize) -> i32; + fn zx_cprng_draw(buffer: *mut u8, len: usize, actual: *mut usize) -> i32; } fn getrandom(buf: &mut [u8]) -> Result { unsafe { let mut actual = 0; - let status = mx_cprng_draw(buf.as_mut_ptr(), buf.len(), &mut actual); + let status = zx_cprng_draw(buf.as_mut_ptr(), buf.len(), &mut actual); if status == 0 { Ok(actual) } else { @@ -387,7 +387,7 @@ mod imp { let ret = getrandom(buf); match ret { Err(err) => { - panic!("kernel mx_cprng_draw call failed! (returned {}, buf.len() {})", + panic!("kernel zx_cprng_draw call failed! (returned {}, buf.len() {})", err, buf.len()) } Ok(actual) => { diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index e9e4b55402c..d4613d29a36 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -35,8 +35,11 @@ static EXCEPTIONS: &'static [&'static str] = &[ "thread-id", // Apache-2.0, mdbook "cssparser", // MPL-2.0, rustdoc "smallvec", // MPL-2.0, rustdoc + // TODO: remove magenta references when "everything" has moved over to using the zircon name. "magenta-sys", // BSD-3-Clause, rustdoc "magenta", // BSD-3-Clause, rustdoc + "zircon-sys", // BSD-3-Clause, rustdoc + "zircon", // BSD-3-Clause, rustdoc "cssparser-macros", // MPL-2.0, rustdoc "selectors", // MPL-2.0, rustdoc ]; -- cgit 1.4.1-3-g733a5 From cc4e82fe7a9126a068e27dcdfc251a1b4be1aa77 Mon Sep 17 00:00:00 2001 From: "P.Y. Laligand" Date: Fri, 15 Sep 2017 14:11:04 -0700 Subject: Fixed casing issues. --- src/libstd/sys/unix/process/process_fuchsia.rs | 16 ++++++++-------- src/libstd/sys/unix/process/zircon.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/process/process_fuchsia.rs b/src/libstd/sys/unix/process/process_fuchsia.rs index 1a7f544f8e9..6059acdd485 100644 --- a/src/libstd/sys/unix/process/process_fuchsia.rs +++ b/src/libstd/sys/unix/process/process_fuchsia.rs @@ -67,8 +67,8 @@ impl Command { } // Duplicate the job handle - let mut job_copy: zx_handle_t = zx_HANDLE_INVALID; - zx_cvt(zx_handle_duplicate(job_handle, zx_RIGHT_SAME_RIGHTS, &mut job_copy))?; + let mut job_copy: zx_handle_t = ZX_HANDLE_INVALID; + zx_cvt(zx_handle_duplicate(job_handle, ZX_RIGHT_SAME_RIGHTS, &mut job_copy))?; // Create a launchpad let mut launchpad: *mut launchpad_t = ptr::null_mut(); zx_cvt(launchpad_create(job_copy, self.get_argv()[0], &mut launchpad))?; @@ -82,7 +82,7 @@ impl Command { zx_cvt(launchpad_add_vdso_vmo(launchpad))?; // Load the executable zx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?; - zx_cvt(launchpad_load_vdso(launchpad, zx_HANDLE_INVALID))?; + zx_cvt(launchpad_load_vdso(launchpad, ZX_HANDLE_INVALID))?; zx_cvt(launchpad_clone(launchpad, LP_CLONE_FDIO_ROOT | LP_CLONE_FDIO_CWD))?; // Clone stdin, stdout, and stderr @@ -152,9 +152,9 @@ impl Process { let mut avail: zx_size_t = 0; unsafe { - zx_cvt(zx_object_wait_one(self.handle.raw(), zx_TASK_TERMINATED, - zx_TIME_INFINITE, ptr::null_mut()))?; - zx_cvt(zx_object_get_info(self.handle.raw(), zx_INFO_PROCESS, + zx_cvt(zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED, + ZX_TIME_INFINITE, ptr::null_mut()))?; + zx_cvt(zx_object_get_info(self.handle.raw(), ZX_INFO_PROCESS, &mut proc_info as *mut _ as *mut libc::c_void, mem::size_of::(), &mut actual, &mut avail))?; @@ -175,7 +175,7 @@ impl Process { let mut avail: zx_size_t = 0; unsafe { - let status = zx_object_wait_one(self.handle.raw(), zx_TASK_TERMINATED, + let status = zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED, 0, ptr::null_mut()); match status { 0 => { }, // Success @@ -184,7 +184,7 @@ impl Process { }, _ => { panic!("Failed to wait on process handle: {}", status); }, } - zx_cvt(zx_object_get_info(self.handle.raw(), zx_INFO_PROCESS, + zx_cvt(zx_object_get_info(self.handle.raw(), ZX_INFO_PROCESS, &mut proc_info as *mut _ as *mut libc::c_void, mem::size_of::(), &mut actual, &mut avail))?; diff --git a/src/libstd/sys/unix/process/zircon.rs b/src/libstd/sys/unix/process/zircon.rs index 4dbcdb57663..2a0fcabcf7f 100644 --- a/src/libstd/sys/unix/process/zircon.rs +++ b/src/libstd/sys/unix/process/zircon.rs @@ -24,22 +24,22 @@ pub type zx_status_t = i32; pub type zx_size_t = usize; -pub const zx_HANDLE_INVALID: zx_handle_t = 0; +pub const ZX_HANDLE_INVALID: zx_handle_t = 0; pub type zx_time_t = u64; -pub const zx_TIME_INFINITE : zx_time_t = u64::MAX; +pub const ZX_TIME_INFINITE : zx_time_t = u64::MAX; pub type zx_signals_t = u32; -pub const zx_OBJECT_SIGNAL_3 : zx_signals_t = 1 << 3; +pub const ZX_OBJECT_SIGNAL_3 : zx_signals_t = 1 << 3; -pub const zx_TASK_TERMINATED : zx_signals_t = zx_OBJECT_SIGNAL_3; +pub const ZX_TASK_TERMINATED : zx_signals_t = ZX_OBJECT_SIGNAL_3; -pub const zx_RIGHT_SAME_RIGHTS : zx_rights_t = 1 << 31; +pub const ZX_RIGHT_SAME_RIGHTS : zx_rights_t = 1 << 31; pub type zx_object_info_topic_t = u32; -pub const zx_INFO_PROCESS : zx_object_info_topic_t = 3; +pub const ZX_INFO_PROCESS : zx_object_info_topic_t = 3; pub fn zx_cvt(t: T) -> io::Result where T: TryInto+Copy { if let Ok(status) = TryInto::try_into(t) { @@ -76,7 +76,7 @@ impl Drop for Handle { } } -// Common zx_INFO header +// Common ZX_INFO header #[derive(Default)] #[repr(C)] pub struct zx_info_header_t { @@ -93,7 +93,7 @@ pub struct zx_record_process_t { pub return_code: c_int, } -// Returned for topic zx_INFO_PROCESS +// Returned for topic ZX_INFO_PROCESS #[derive(Default)] #[repr(C)] pub struct zx_info_process_t { -- cgit 1.4.1-3-g733a5 From d7a17fb3cf3bedd5efdda46a8412cdce097d1154 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Sun, 24 Sep 2017 14:31:50 -0700 Subject: LP_CLONE_FDIO_ROOT is now LP_CLONE_FDIO_NAMESPACE --- src/libstd/sys/unix/process/process_fuchsia.rs | 2 +- src/libstd/sys/unix/process/zircon.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/process/process_fuchsia.rs b/src/libstd/sys/unix/process/process_fuchsia.rs index 6059acdd485..5d34da04446 100644 --- a/src/libstd/sys/unix/process/process_fuchsia.rs +++ b/src/libstd/sys/unix/process/process_fuchsia.rs @@ -83,7 +83,7 @@ impl Command { // Load the executable zx_cvt(launchpad_elf_load(launchpad, launchpad_vmo_from_file(self.get_argv()[0])))?; zx_cvt(launchpad_load_vdso(launchpad, ZX_HANDLE_INVALID))?; - zx_cvt(launchpad_clone(launchpad, LP_CLONE_FDIO_ROOT | LP_CLONE_FDIO_CWD))?; + zx_cvt(launchpad_clone(launchpad, LP_CLONE_FDIO_NAMESPACE | LP_CLONE_FDIO_CWD))?; // Clone stdin, stdout, and stderr if let Some(fd) = stdio.stdin.fd() { diff --git a/src/libstd/sys/unix/process/zircon.rs b/src/libstd/sys/unix/process/zircon.rs index 2a0fcabcf7f..b5ec11b40fd 100644 --- a/src/libstd/sys/unix/process/zircon.rs +++ b/src/libstd/sys/unix/process/zircon.rs @@ -180,7 +180,7 @@ extern { // Launchpad clone constants -pub const LP_CLONE_FDIO_ROOT: u32 = 0x0001; +pub const LP_CLONE_FDIO_NAMESPACE: u32 = 0x0001; pub const LP_CLONE_FDIO_CWD: u32 = 0x0002; // LP_CLONE_FDIO_STDIO = 0x0004 // LP_CLONE_FDIO_ALL = 0x00FF -- cgit 1.4.1-3-g733a5 From 874124b2c73dc764aa83f7ba9711a4170c0aeffc Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Sep 2017 22:23:26 -0700 Subject: Backport libs stabilizations to 1.21 beta This includes the following stabilizations: - tcpstream_connect_timeout https://github.com/rust-lang/rust/pull/44563 - iterator_for_each https://github.com/rust-lang/rust/pull/44567 - ord_max_min https://github.com/rust-lang/rust/pull/44593 - compiler_fences https://github.com/rust-lang/rust/pull/44595 - needs_drop https://github.com/rust-lang/rust/pull/44639 - vec_splice https://github.com/rust-lang/rust/pull/44640 --- src/liballoc/vec.rs | 12 ++++++------ src/libcore/cmp.rs | 4 ++-- src/libcore/iter/iterator.rs | 2 +- src/libcore/mem.rs | 2 +- src/libcore/sync/atomic.rs | 2 +- src/libstd/net/tcp.rs | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/libstd') diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 7dd8895c1ae..725d3e15f4a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1950,7 +1950,7 @@ impl Vec { /// assert_eq!(u, &[1, 2]); /// ``` #[inline] - #[stable(feature = "vec_splice", since = "1.22.0")] + #[stable(feature = "vec_splice", since = "1.21.0")] pub fn splice(&mut self, range: R, replace_with: I) -> Splice where R: RangeArgument, I: IntoIterator { @@ -2553,13 +2553,13 @@ impl<'a, T> InPlace for PlaceBack<'a, T> { /// [`splice()`]: struct.Vec.html#method.splice /// [`Vec`]: struct.Vec.html #[derive(Debug)] -#[stable(feature = "vec_splice", since = "1.22.0")] +#[stable(feature = "vec_splice", since = "1.21.0")] pub struct Splice<'a, I: Iterator + 'a> { drain: Drain<'a, I::Item>, replace_with: I, } -#[stable(feature = "vec_splice", since = "1.22.0")] +#[stable(feature = "vec_splice", since = "1.21.0")] impl<'a, I: Iterator> Iterator for Splice<'a, I> { type Item = I::Item; @@ -2572,18 +2572,18 @@ impl<'a, I: Iterator> Iterator for Splice<'a, I> { } } -#[stable(feature = "vec_splice", since = "1.22.0")] +#[stable(feature = "vec_splice", since = "1.21.0")] impl<'a, I: Iterator> DoubleEndedIterator for Splice<'a, I> { fn next_back(&mut self) -> Option { self.drain.next_back() } } -#[stable(feature = "vec_splice", since = "1.22.0")] +#[stable(feature = "vec_splice", since = "1.21.0")] impl<'a, I: Iterator> ExactSizeIterator for Splice<'a, I> {} -#[stable(feature = "vec_splice", since = "1.22.0")] +#[stable(feature = "vec_splice", since = "1.21.0")] impl<'a, I: Iterator> Drop for Splice<'a, I> { fn drop(&mut self) { // exhaust drain first diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 6f86f8caad0..e012cbd76ff 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -456,7 +456,7 @@ pub trait Ord: Eq + PartialOrd { /// assert_eq!(2, 1.max(2)); /// assert_eq!(2, 2.max(2)); /// ``` - #[stable(feature = "ord_max_min", since = "1.22.0")] + #[stable(feature = "ord_max_min", since = "1.21.0")] fn max(self, other: Self) -> Self where Self: Sized { if other >= self { other } else { self } @@ -472,7 +472,7 @@ pub trait Ord: Eq + PartialOrd { /// assert_eq!(1, 1.min(2)); /// assert_eq!(2, 2.min(2)); /// ``` - #[stable(feature = "ord_max_min", since = "1.22.0")] + #[stable(feature = "ord_max_min", since = "1.21.0")] fn min(self, other: Self) -> Self where Self: Sized { if self <= other { self } else { other } diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 36bf9633b4a..e9e31065cf8 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -518,7 +518,7 @@ pub trait Iterator { /// .for_each(|(i, x)| println!("{}:{}", i, x)); /// ``` #[inline] - #[stable(feature = "iterator_for_each", since = "1.22.0")] + #[stable(feature = "iterator_for_each", since = "1.21.0")] fn for_each(self, mut f: F) where Self: Sized, F: FnMut(Self::Item), { diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 669b93120cf..c869054cee8 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -402,7 +402,7 @@ pub fn align_of_val(val: &T) -> usize { /// } /// ``` #[inline] -#[stable(feature = "needs_drop", since = "1.22.0")] +#[stable(feature = "needs_drop", since = "1.21.0")] pub fn needs_drop() -> bool { unsafe { intrinsics::needs_drop::() } } diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 3dd08e69710..2bb40cb672e 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -1752,7 +1752,7 @@ pub fn fence(order: Ordering) { /// [`Relaxed`]: enum.Ordering.html#variant.Relaxed /// [memory barriers]: https://www.kernel.org/doc/Documentation/memory-barriers.txt #[inline] -#[stable(feature = "compiler_fences", since = "1.22.0")] +#[stable(feature = "compiler_fences", since = "1.21.0")] pub fn compiler_fence(order: Ordering) { unsafe { match order { diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index aff9af66444..8d1e7882e5d 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -167,7 +167,7 @@ impl TcpStream { /// connection request. /// /// [`SocketAddr`]: ../../std/net/enum.SocketAddr.html - #[stable(feature = "tcpstream_connect_timeout", since = "1.22.0")] + #[stable(feature = "tcpstream_connect_timeout", since = "1.21.0")] pub fn connect_timeout(addr: &SocketAddr, timeout: Duration) -> io::Result { net_imp::TcpStream::connect_timeout(addr, timeout).map(TcpStream) } -- cgit 1.4.1-3-g733a5 From 7694ca419b3ade48e22982b69dec90eb45d8da73 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 22 Sep 2017 21:34:27 -0700 Subject: Update to the `cc` crate This is the name the `gcc` crate has moved to --- src/Cargo.lock | 20 +++-- src/Cargo.toml | 1 + src/bootstrap/Cargo.toml | 2 +- src/bootstrap/bin/sccache-plus-cl.rs | 4 +- src/bootstrap/cc.rs | 147 ----------------------------------- src/bootstrap/cc_detect.rs | 147 +++++++++++++++++++++++++++++++++++ src/bootstrap/lib.rs | 12 +-- src/bootstrap/native.rs | 4 +- src/bootstrap/tool.rs | 4 + src/liballoc_jemalloc/Cargo.toml | 2 +- src/liballoc_jemalloc/build.rs | 6 +- src/libprofiler_builtins/Cargo.toml | 2 +- src/libprofiler_builtins/build.rs | 4 +- src/librustc/session/config.rs | 28 +++---- src/librustc_llvm/Cargo.toml | 2 +- src/librustc_llvm/build.rs | 4 +- src/librustc_trans/Cargo.toml | 2 +- src/librustc_trans/back/link.rs | 2 +- src/librustc_trans/lib.rs | 2 +- src/librustdoc/Cargo.toml | 2 +- src/librustdoc/build.rs | 4 +- src/libstd/Cargo.toml | 2 +- src/libstd/build.rs | 4 +- 23 files changed, 208 insertions(+), 199 deletions(-) delete mode 100644 src/bootstrap/cc.rs create mode 100644 src/bootstrap/cc_detect.rs (limited to 'src/libstd') diff --git a/src/Cargo.lock b/src/Cargo.lock index a8def85baeb..c77be5154d3 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -42,8 +42,8 @@ dependencies = [ "alloc 0.0.0", "alloc_system 0.0.0", "build_helper 0.1.0", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "core 0.0.0", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.0.0", ] @@ -136,9 +136,9 @@ name = "bootstrap" version = "0.0.0" dependencies = [ "build_helper 0.1.0", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1221,8 +1221,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "profiler_builtins" version = "0.0.0" dependencies = [ + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "core 0.0.0", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1628,7 +1628,7 @@ version = "0.0.0" dependencies = [ "bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "build_helper 0.1.0", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", ] @@ -1759,8 +1759,8 @@ name = "rustc_trans" version = "0.0.0" dependencies = [ "bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "jobserver 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1786,7 +1786,7 @@ name = "rustc_trans_utils" version = "0.0.0" dependencies = [ "ar 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", @@ -1828,8 +1828,8 @@ name = "rustdoc" version = "0.0.0" dependencies = [ "build_helper 0.1.0", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "html-diff 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1998,10 +1998,10 @@ dependencies = [ "alloc_jemalloc 0.0.0", "alloc_system 0.0.0", "build_helper 0.1.0", + "cc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "collections 0.0.0", "compiler_builtins 0.0.0", "core 0.0.0", - "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.0.0", "panic_abort 0.0.0", "panic_unwind 0.0.0", @@ -2320,6 +2320,10 @@ name = "unicode-xid" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicødë" +version = "0.1.0" + [[package]] name = "unreachable" version = "0.1.1" diff --git a/src/Cargo.toml b/src/Cargo.toml index 2208f389638..f4b4189e01f 100644 --- a/src/Cargo.toml +++ b/src/Cargo.toml @@ -38,6 +38,7 @@ members = [ "tools/rls/test_data/infer_custom_bin", "tools/rls/test_data/infer_lib", "tools/rls/test_data/omit_init_build", + "tools/rls/test_data/unicødë", "tools/rls/test_data/workspace_symbol", ] diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 85e3b65c195..3f1d03b1872 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -34,7 +34,7 @@ cmake = "0.1.23" filetime = "0.1" num_cpus = "1.0" getopts = "0.2" -gcc = "0.3.54" +cc = "1.0" libc = "0.2" serde = "1.0.8" serde_derive = "1.0.8" diff --git a/src/bootstrap/bin/sccache-plus-cl.rs b/src/bootstrap/bin/sccache-plus-cl.rs index 266dffa5c92..8584014d48d 100644 --- a/src/bootstrap/bin/sccache-plus-cl.rs +++ b/src/bootstrap/bin/sccache-plus-cl.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate gcc; +extern crate cc; use std::env; use std::process::{self, Command}; @@ -18,7 +18,7 @@ fn main() { // Locate the actual compiler that we're invoking env::remove_var("CC"); env::remove_var("CXX"); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); cfg.cargo_metadata(false) .out_dir("/") .target(&target) diff --git a/src/bootstrap/cc.rs b/src/bootstrap/cc.rs deleted file mode 100644 index c77e609d70b..00000000000 --- a/src/bootstrap/cc.rs +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! C-compiler probing and detection. -//! -//! This module will fill out the `cc` and `cxx` maps of `Build` by looking for -//! C and C++ compilers for each target configured. A compiler is found through -//! a number of vectors (in order of precedence) -//! -//! 1. Configuration via `target.$target.cc` in `config.toml`. -//! 2. Configuration via `target.$target.android-ndk` in `config.toml`, if -//! applicable -//! 3. Special logic to probe on OpenBSD -//! 4. The `CC_$target` environment variable. -//! 5. The `CC` environment variable. -//! 6. "cc" -//! -//! Some of this logic is implemented here, but much of it is farmed out to the -//! `gcc` crate itself, so we end up having the same fallbacks as there. -//! Similar logic is then used to find a C++ compiler, just some s/cc/c++/ is -//! used. -//! -//! It is intended that after this module has run no C/C++ compiler will -//! ever be probed for. Instead the compilers found here will be used for -//! everything. - -use std::process::Command; -use std::iter; - -use build_helper::{cc2ar, output}; -use gcc; - -use Build; -use config::Target; -use cache::Interned; - -pub fn find(build: &mut Build) { - // For all targets we're going to need a C compiler for building some shims - // and such as well as for being a linker for Rust code. - for target in build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) { - let mut cfg = gcc::Build::new(); - cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false) - .target(&target).host(&build.build); - - let config = build.config.target_config.get(&target); - if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { - cfg.compiler(cc); - } else { - set_compiler(&mut cfg, "gcc", target, config, build); - } - - let compiler = cfg.get_compiler(); - let ar = cc2ar(compiler.path(), &target); - build.verbose(&format!("CC_{} = {:?}", &target, compiler.path())); - if let Some(ref ar) = ar { - build.verbose(&format!("AR_{} = {:?}", &target, ar)); - } - build.cc.insert(target, (compiler, ar)); - } - - // For all host triples we need to find a C++ compiler as well - for host in build.hosts.iter().cloned().chain(iter::once(build.build)) { - let mut cfg = gcc::Build::new(); - cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false).cpp(true) - .target(&host).host(&build.build); - let config = build.config.target_config.get(&host); - if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { - cfg.compiler(cxx); - } else { - set_compiler(&mut cfg, "g++", host, config, build); - } - let compiler = cfg.get_compiler(); - build.verbose(&format!("CXX_{} = {:?}", host, compiler.path())); - build.cxx.insert(host, compiler); - } -} - -fn set_compiler(cfg: &mut gcc::Build, - gnu_compiler: &str, - target: Interned, - config: Option<&Target>, - build: &Build) { - match &*target { - // When compiling for android we may have the NDK configured in the - // config.toml in which case we look there. Otherwise the default - // compiler already takes into account the triple in question. - t if t.contains("android") => { - if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { - let target = target.replace("armv7", "arm"); - let compiler = format!("{}-{}", target, gnu_compiler); - cfg.compiler(ndk.join("bin").join(compiler)); - } - } - - // The default gcc version from OpenBSD may be too old, try using egcc, - // which is a gcc version from ports, if this is the case. - t if t.contains("openbsd") => { - let c = cfg.get_compiler(); - if !c.path().ends_with(gnu_compiler) { - return - } - - let output = output(c.to_command().arg("--version")); - let i = match output.find(" 4.") { - Some(i) => i, - None => return, - }; - match output[i + 3..].chars().next().unwrap() { - '0' ... '6' => {} - _ => return, - } - let alternative = format!("e{}", gnu_compiler); - if Command::new(&alternative).output().is_ok() { - cfg.compiler(alternative); - } - } - - "mips-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mips-linux-musl-gcc"); - } - } - "mipsel-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mipsel-linux-musl-gcc"); - } - } - - t if t.contains("musl") => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { - cfg.compiler(guess); - } - } - } - - _ => {} - } -} diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs new file mode 100644 index 00000000000..08df65c7611 --- /dev/null +++ b/src/bootstrap/cc_detect.rs @@ -0,0 +1,147 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! C-compiler probing and detection. +//! +//! This module will fill out the `cc` and `cxx` maps of `Build` by looking for +//! C and C++ compilers for each target configured. A compiler is found through +//! a number of vectors (in order of precedence) +//! +//! 1. Configuration via `target.$target.cc` in `config.toml`. +//! 2. Configuration via `target.$target.android-ndk` in `config.toml`, if +//! applicable +//! 3. Special logic to probe on OpenBSD +//! 4. The `CC_$target` environment variable. +//! 5. The `CC` environment variable. +//! 6. "cc" +//! +//! Some of this logic is implemented here, but much of it is farmed out to the +//! `cc` crate itself, so we end up having the same fallbacks as there. +//! Similar logic is then used to find a C++ compiler, just some s/cc/c++/ is +//! used. +//! +//! It is intended that after this module has run no C/C++ compiler will +//! ever be probed for. Instead the compilers found here will be used for +//! everything. + +use std::process::Command; +use std::iter; + +use build_helper::{cc2ar, output}; +use cc; + +use Build; +use config::Target; +use cache::Interned; + +pub fn find(build: &mut Build) { + // For all targets we're going to need a C compiler for building some shims + // and such as well as for being a linker for Rust code. + for target in build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) { + let mut cfg = cc::Build::new(); + cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false) + .target(&target).host(&build.build); + + let config = build.config.target_config.get(&target); + if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { + cfg.compiler(cc); + } else { + set_compiler(&mut cfg, "gcc", target, config, build); + } + + let compiler = cfg.get_compiler(); + let ar = cc2ar(compiler.path(), &target); + build.verbose(&format!("CC_{} = {:?}", &target, compiler.path())); + if let Some(ref ar) = ar { + build.verbose(&format!("AR_{} = {:?}", &target, ar)); + } + build.cc.insert(target, (compiler, ar)); + } + + // For all host triples we need to find a C++ compiler as well + for host in build.hosts.iter().cloned().chain(iter::once(build.build)) { + let mut cfg = cc::Build::new(); + cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false).cpp(true) + .target(&host).host(&build.build); + let config = build.config.target_config.get(&host); + if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { + cfg.compiler(cxx); + } else { + set_compiler(&mut cfg, "g++", host, config, build); + } + let compiler = cfg.get_compiler(); + build.verbose(&format!("CXX_{} = {:?}", host, compiler.path())); + build.cxx.insert(host, compiler); + } +} + +fn set_compiler(cfg: &mut cc::Build, + gnu_compiler: &str, + target: Interned, + config: Option<&Target>, + build: &Build) { + match &*target { + // When compiling for android we may have the NDK configured in the + // config.toml in which case we look there. Otherwise the default + // compiler already takes into account the triple in question. + t if t.contains("android") => { + if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { + let target = target.replace("armv7", "arm"); + let compiler = format!("{}-{}", target, gnu_compiler); + cfg.compiler(ndk.join("bin").join(compiler)); + } + } + + // The default gcc version from OpenBSD may be too old, try using egcc, + // which is a gcc version from ports, if this is the case. + t if t.contains("openbsd") => { + let c = cfg.get_compiler(); + if !c.path().ends_with(gnu_compiler) { + return + } + + let output = output(c.to_command().arg("--version")); + let i = match output.find(" 4.") { + Some(i) => i, + None => return, + }; + match output[i + 3..].chars().next().unwrap() { + '0' ... '6' => {} + _ => return, + } + let alternative = format!("e{}", gnu_compiler); + if Command::new(&alternative).output().is_ok() { + cfg.compiler(alternative); + } + } + + "mips-unknown-linux-musl" => { + if cfg.get_compiler().path().to_str() == Some("gcc") { + cfg.compiler("mips-linux-musl-gcc"); + } + } + "mipsel-unknown-linux-musl" => { + if cfg.get_compiler().path().to_str() == Some("gcc") { + cfg.compiler("mipsel-linux-musl-gcc"); + } + } + + t if t.contains("musl") => { + if let Some(root) = build.musl_root(target) { + let guess = root.join("bin/musl-gcc"); + if guess.exists() { + cfg.compiler(guess); + } + } + } + + _ => {} + } +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 06c7c4c2faf..83aa08366df 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -126,7 +126,7 @@ extern crate lazy_static; extern crate serde_json; extern crate cmake; extern crate filetime; -extern crate gcc; +extern crate cc; extern crate getopts; extern crate num_cpus; extern crate toml; @@ -148,7 +148,7 @@ use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppresse use util::{exe, libdir, OutputFolder, CiEnv}; -mod cc; +mod cc_detect; mod channel; mod check; mod clean; @@ -241,9 +241,9 @@ pub struct Build { // Runtime state filled in later on // target -> (cc, ar) - cc: HashMap, (gcc::Tool, Option)>, + cc: HashMap, (cc::Tool, Option)>, // host -> (cc, ar) - cxx: HashMap, gcc::Tool>, + cxx: HashMap, cc::Tool>, crates: HashMap, Crate>, is_sudo: bool, ci_env: CiEnv, @@ -350,7 +350,7 @@ impl Build { } self.verbose("finding compilers"); - cc::find(self); + cc_detect::find(self); self.verbose("running sanity check"); sanity::check(self); // If local-rust is the same major.minor as the current version, then force a local-rebuild @@ -619,7 +619,7 @@ impl Build { /// specified. fn cflags(&self, target: Interned) -> Vec { // Filter out -O and /O (the optimization flags) that we picked up from - // gcc-rs because the build scripts will determine that for themselves. + // cc-rs because the build scripts will determine that for themselves. let mut base = self.cc[&target].0.args().iter() .map(|s| s.to_string_lossy().into_owned()) .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 99077d03dbe..29376ff25e4 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -27,7 +27,7 @@ use std::process::Command; use build_helper::output; use cmake; -use gcc; +use cc; use Build; use util; @@ -289,7 +289,7 @@ impl Step for TestHelpers { let _folder = build.fold_output(|| "build_test_helpers"); println!("Building test helpers"); t!(fs::create_dir_all(&dst)); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); // We may have found various cross-compilers a little differently due to our // extra configuration, so inform gcc of these compilers. Note, though, that diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 19879ab2ade..a05e58e6a22 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -126,6 +126,10 @@ pub fn prepare_tool_cargo( cargo.env("LIBZ_SYS_STATIC", "1"); } + // if tools are using lzma we want to force the build script to build its + // own copy + cargo.env("LZMA_API_STATIC", "1"); + cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel); cargo.env("CFG_VERSION", build.rust_version()); diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml index 94700cf4475..4042c4d2d4e 100644 --- a/src/liballoc_jemalloc/Cargo.toml +++ b/src/liballoc_jemalloc/Cargo.toml @@ -19,7 +19,7 @@ libc = { path = "../rustc/libc_shim" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.50" +cc = "1.0" [features] debug = [] diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index d89d3bcdb62..7dd85ddcc79 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -11,7 +11,7 @@ #![deny(warnings)] extern crate build_helper; -extern crate gcc; +extern crate cc; use std::env; use std::path::PathBuf; @@ -63,7 +63,7 @@ fn main() { _ => return, }; - let compiler = gcc::Build::new().get_compiler(); + let compiler = cc::Build::new().get_compiler(); // only msvc returns None for ar so unwrap is okay let ar = build_helper::cc2ar(compiler.path(), &target).unwrap(); let cflags = compiler.args() @@ -150,7 +150,7 @@ fn main() { // sure the symbols are available. if target.contains("androideabi") { println!("cargo:rerun-if-changed=pthread_atfork_dummy.c"); - gcc::Build::new() + cc::Build::new() .flag("-fvisibility=hidden") .file("pthread_atfork_dummy.c") .compile("libpthread_atfork_dummy.a"); diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml index a60db313679..eb31f5730d1 100644 --- a/src/libprofiler_builtins/Cargo.toml +++ b/src/libprofiler_builtins/Cargo.toml @@ -15,4 +15,4 @@ doc = false core = { path = "../libcore" } [build-dependencies] -gcc = "0.3.50" +cc = "1.0" diff --git a/src/libprofiler_builtins/build.rs b/src/libprofiler_builtins/build.rs index 41e92b33475..8508b2dae2c 100644 --- a/src/libprofiler_builtins/build.rs +++ b/src/libprofiler_builtins/build.rs @@ -12,14 +12,14 @@ //! //! See the build.rs for libcompiler_builtins crate for details. -extern crate gcc; +extern crate cc; use std::env; use std::path::Path; fn main() { let target = env::var("TARGET").expect("TARGET was not set"); - let cfg = &mut gcc::Build::new(); + let cfg = &mut cc::Build::new(); let mut profile_sources = vec!["GCDAProfiling.c", "InstrProfiling.c", diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index d3256357941..b1bf893cfd8 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1373,20 +1373,20 @@ pub fn rustc_optgroups() -> Vec { always = always colorize output; never = never colorize output", "auto|always|never"), - opt::flagopt("", "pretty", - "Pretty-print the input instead of compiling; - valid types are: `normal` (un-annotated source), - `expanded` (crates expanded), or - `expanded,identified` (fully parenthesized, AST nodes with IDs).", - "TYPE"), - opt::flagopt("", "unpretty", - "Present the input source, unstable (and less-pretty) variants; - valid types are any of the types for `--pretty`, as well as: - `flowgraph=` (graphviz formatted flowgraph for node), - `everybody_loops` (all function bodies replaced with `loop {}`), - `hir` (the HIR), `hir,identified`, or - `hir,typed` (HIR with types for each node).", - "TYPE"), + opt::opt("", "pretty", + "Pretty-print the input instead of compiling; + valid types are: `normal` (un-annotated source), + `expanded` (crates expanded), or + `expanded,identified` (fully parenthesized, AST nodes with IDs).", + "TYPE"), + opt::opt("", "unpretty", + "Present the input source, unstable (and less-pretty) variants; + valid types are any of the types for `--pretty`, as well as: + `flowgraph=` (graphviz formatted flowgraph for node), + `everybody_loops` (all function bodies replaced with `loop {}`), + `hir` (the HIR), `hir,identified`, or + `hir,typed` (HIR with types for each node).", + "TYPE"), ]); opts } diff --git a/src/librustc_llvm/Cargo.toml b/src/librustc_llvm/Cargo.toml index 1ed2cbab65f..de5add56b76 100644 --- a/src/librustc_llvm/Cargo.toml +++ b/src/librustc_llvm/Cargo.toml @@ -18,4 +18,4 @@ rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.50" +cc = "1.0" diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 393aa7fa43b..dde7a38efc7 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate gcc; +extern crate cc; extern crate build_helper; use std::process::Command; @@ -136,7 +136,7 @@ fn main() { let mut cmd = Command::new(&llvm_config); cmd.arg("--cxxflags"); let cxxflags = output(&mut cmd); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); cfg.warnings(false); for flag in cxxflags.split_whitespace() { // Ignore flags like `-m64` when we're doing a cross build diff --git a/src/librustc_trans/Cargo.toml b/src/librustc_trans/Cargo.toml index 6f1f5b4a123..482350d04b5 100644 --- a/src/librustc_trans/Cargo.toml +++ b/src/librustc_trans/Cargo.toml @@ -32,4 +32,4 @@ syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } [target."cfg(windows)".dependencies] -gcc = "0.3.50" +cc = "1.0" diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 1630e775991..39a9ccd8eb9 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -125,7 +125,7 @@ pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)> #[cfg(windows)] pub fn msvc_link_exe_cmd(sess: &Session) -> (Command, Vec<(OsString, OsString)>) { - use gcc::windows_registry; + use cc::windows_registry; let target = &sess.opts.target_triple; let tool = windows_registry::find_tool(target, "link.exe"); diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 8a2c478cea0..796dfd4417c 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -61,7 +61,7 @@ extern crate syntax_pos; extern crate rustc_errors as errors; extern crate serialize; #[cfg(windows)] -extern crate gcc; // Used to locate MSVC, not gcc :) +extern crate cc; // Used to locate MSVC pub use base::trans_crate; diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 61ac541e2c1..b295b414a03 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -18,4 +18,4 @@ html-diff = "0.0.4" [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.50" +cc = "1.0" diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs index 830492dec94..97c9ca1e2d2 100644 --- a/src/librustdoc/build.rs +++ b/src/librustdoc/build.rs @@ -9,12 +9,12 @@ // except according to those terms. extern crate build_helper; -extern crate gcc; +extern crate cc; fn main() { let src_dir = std::path::Path::new("../rt/hoedown/src"); build_helper::rerun_if_changed_anything_in_dir(src_dir); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); cfg.file("../rt/hoedown/src/autolink.c") .file("../rt/hoedown/src/buffer.c") .file("../rt/hoedown/src/document.c") diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 09c16816934..fb276448ffa 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -36,7 +36,7 @@ rustc_tsan = { path = "../librustc_tsan" } [build-dependencies] build_helper = { path = "../build_helper" } -gcc = "0.3.50" +cc = "1.0" [features] backtrace = [] diff --git a/src/libstd/build.rs b/src/libstd/build.rs index b8061665aa1..7ca762c801a 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -11,7 +11,7 @@ #![deny(warnings)] extern crate build_helper; -extern crate gcc; +extern crate cc; use std::env; use std::process::Command; @@ -77,7 +77,7 @@ fn main() { fn build_libbacktrace(host: &str, target: &str) -> Result<(), ()> { let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace", ".libs")?; - let compiler = gcc::Build::new().get_compiler(); + let compiler = cc::Build::new().get_compiler(); // only msvc returns None for ar so unwrap is okay let ar = build_helper::cc2ar(compiler.path(), target).unwrap(); let mut cflags = compiler.args().iter().map(|s| s.to_str().unwrap()) -- cgit 1.4.1-3-g733a5