Auto merge of #125144 - fmease:rollup-4uft293, r=fmease
Rollup of 6 pull requests Successful merges: - #124307 (Optimize character escaping.) - #124975 (Use an helper to move the files) - #125027 (Migrate `run-make/c-link-to-rust-staticlib` to `rmake`) - #125038 (Invert comparison in `uN::checked_sub`) - #125104 (Migrate `run-make/no-cdylib-as-rdylib` to `rmake`) - #125137 (MIR operators: clarify Shl/Shr handling of negative offsets) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
ade234d574
@ -1480,13 +1480,17 @@ pub enum BinOp {
|
|||||||
BitOr,
|
BitOr,
|
||||||
/// The `<<` operator (shift left)
|
/// The `<<` operator (shift left)
|
||||||
///
|
///
|
||||||
/// The offset is truncated to the size of the first operand and made unsigned before shifting.
|
/// The offset is (uniquely) determined as follows:
|
||||||
|
/// - it is "equal modulo LHS::BITS" to the RHS
|
||||||
|
/// - it is in the range `0..LHS::BITS`
|
||||||
Shl,
|
Shl,
|
||||||
/// Like `Shl`, but is UB if the RHS >= LHS::BITS or RHS < 0
|
/// Like `Shl`, but is UB if the RHS >= LHS::BITS or RHS < 0
|
||||||
ShlUnchecked,
|
ShlUnchecked,
|
||||||
/// The `>>` operator (shift right)
|
/// The `>>` operator (shift right)
|
||||||
///
|
///
|
||||||
/// The offset is truncated to the size of the first operand and made unsigned before shifting.
|
/// The offset is (uniquely) determined as follows:
|
||||||
|
/// - it is "equal modulo LHS::BITS" to the RHS
|
||||||
|
/// - it is in the range `0..LHS::BITS`
|
||||||
///
|
///
|
||||||
/// This is an arithmetic shift if the LHS is signed
|
/// This is an arithmetic shift if the LHS is signed
|
||||||
/// and a logical shift if the LHS is unsigned.
|
/// and a logical shift if the LHS is unsigned.
|
||||||
|
@ -91,17 +91,21 @@
|
|||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn escape_default(c: u8) -> EscapeDefault {
|
pub fn escape_default(c: u8) -> EscapeDefault {
|
||||||
let mut data = [Char::Null; 4];
|
EscapeDefault::new(c)
|
||||||
let range = escape::escape_ascii_into(&mut data, c);
|
|
||||||
EscapeDefault(escape::EscapeIterInner::new(data, range))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EscapeDefault {
|
impl EscapeDefault {
|
||||||
pub(crate) fn empty() -> Self {
|
#[inline]
|
||||||
let data = [Char::Null; 4];
|
pub(crate) const fn new(c: u8) -> Self {
|
||||||
EscapeDefault(escape::EscapeIterInner::new(data, 0..0))
|
Self(escape::EscapeIterInner::ascii(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn empty() -> Self {
|
||||||
|
Self(escape::EscapeIterInner::empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub(crate) fn as_str(&self) -> &str {
|
pub(crate) fn as_str(&self) -> &str {
|
||||||
self.0.as_str()
|
self.0.as_str()
|
||||||
}
|
}
|
||||||
|
@ -449,10 +449,10 @@ pub(crate) fn escape_debug_ext(self, args: EscapeDebugExtArgs) -> EscapeDebug {
|
|||||||
'\"' if args.escape_double_quote => EscapeDebug::backslash(ascii::Char::QuotationMark),
|
'\"' if args.escape_double_quote => EscapeDebug::backslash(ascii::Char::QuotationMark),
|
||||||
'\'' if args.escape_single_quote => EscapeDebug::backslash(ascii::Char::Apostrophe),
|
'\'' if args.escape_single_quote => EscapeDebug::backslash(ascii::Char::Apostrophe),
|
||||||
_ if args.escape_grapheme_extended && self.is_grapheme_extended() => {
|
_ if args.escape_grapheme_extended && self.is_grapheme_extended() => {
|
||||||
EscapeDebug::from_unicode(self.escape_unicode())
|
EscapeDebug::unicode(self)
|
||||||
}
|
}
|
||||||
_ if is_printable(self) => EscapeDebug::printable(self),
|
_ if is_printable(self) => EscapeDebug::printable(self),
|
||||||
_ => EscapeDebug::from_unicode(self.escape_unicode()),
|
_ => EscapeDebug::unicode(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,9 +555,9 @@ pub fn escape_default(self) -> EscapeDefault {
|
|||||||
'\t' => EscapeDefault::backslash(ascii::Char::SmallT),
|
'\t' => EscapeDefault::backslash(ascii::Char::SmallT),
|
||||||
'\r' => EscapeDefault::backslash(ascii::Char::SmallR),
|
'\r' => EscapeDefault::backslash(ascii::Char::SmallR),
|
||||||
'\n' => EscapeDefault::backslash(ascii::Char::SmallN),
|
'\n' => EscapeDefault::backslash(ascii::Char::SmallN),
|
||||||
'\\' | '\'' | '"' => EscapeDefault::backslash(self.as_ascii().unwrap()),
|
'\\' | '\'' | '\"' => EscapeDefault::backslash(self.as_ascii().unwrap()),
|
||||||
'\x20'..='\x7e' => EscapeDefault::printable(self.as_ascii().unwrap()),
|
'\x20'..='\x7e' => EscapeDefault::printable(self.as_ascii().unwrap()),
|
||||||
_ => EscapeDefault::from_unicode(self.escape_unicode()),
|
_ => EscapeDefault::unicode(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +152,9 @@ pub const fn from_digit(num: u32, radix: u32) -> Option<char> {
|
|||||||
pub struct EscapeUnicode(escape::EscapeIterInner<10>);
|
pub struct EscapeUnicode(escape::EscapeIterInner<10>);
|
||||||
|
|
||||||
impl EscapeUnicode {
|
impl EscapeUnicode {
|
||||||
fn new(chr: char) -> Self {
|
#[inline]
|
||||||
let mut data = [ascii::Char::Null; 10];
|
const fn new(c: char) -> Self {
|
||||||
let range = escape::escape_unicode_into(&mut data, chr);
|
Self(escape::EscapeIterInner::unicode(c))
|
||||||
Self(escape::EscapeIterInner::new(data, range))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,18 +218,19 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
pub struct EscapeDefault(escape::EscapeIterInner<10>);
|
pub struct EscapeDefault(escape::EscapeIterInner<10>);
|
||||||
|
|
||||||
impl EscapeDefault {
|
impl EscapeDefault {
|
||||||
fn printable(chr: ascii::Char) -> Self {
|
#[inline]
|
||||||
let data = [chr];
|
const fn printable(c: ascii::Char) -> Self {
|
||||||
Self(escape::EscapeIterInner::from_array(data))
|
Self(escape::EscapeIterInner::ascii(c.to_u8()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backslash(chr: ascii::Char) -> Self {
|
#[inline]
|
||||||
let data = [ascii::Char::ReverseSolidus, chr];
|
const fn backslash(c: ascii::Char) -> Self {
|
||||||
Self(escape::EscapeIterInner::from_array(data))
|
Self(escape::EscapeIterInner::backslash(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_unicode(esc: EscapeUnicode) -> Self {
|
#[inline]
|
||||||
Self(esc.0)
|
const fn unicode(c: char) -> Self {
|
||||||
|
Self(escape::EscapeIterInner::unicode(c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,23 +304,24 @@ enum EscapeDebugInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EscapeDebug {
|
impl EscapeDebug {
|
||||||
fn printable(chr: char) -> Self {
|
#[inline]
|
||||||
|
const fn printable(chr: char) -> Self {
|
||||||
Self(EscapeDebugInner::Char(chr))
|
Self(EscapeDebugInner::Char(chr))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backslash(chr: ascii::Char) -> Self {
|
#[inline]
|
||||||
let data = [ascii::Char::ReverseSolidus, chr];
|
const fn backslash(c: ascii::Char) -> Self {
|
||||||
let iter = escape::EscapeIterInner::from_array(data);
|
Self(EscapeDebugInner::Bytes(escape::EscapeIterInner::backslash(c)))
|
||||||
Self(EscapeDebugInner::Bytes(iter))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_unicode(esc: EscapeUnicode) -> Self {
|
#[inline]
|
||||||
Self(EscapeDebugInner::Bytes(esc.0))
|
const fn unicode(c: char) -> Self {
|
||||||
|
Self(EscapeDebugInner::Bytes(escape::EscapeIterInner::unicode(c)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
let bytes = escape::EscapeIterInner::from_array([]);
|
self.0 = EscapeDebugInner::Bytes(escape::EscapeIterInner::empty());
|
||||||
self.0 = EscapeDebugInner::Bytes(bytes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,6 +340,7 @@ fn next(&mut self) -> Option<char> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let n = self.len();
|
let n = self.len();
|
||||||
(n, Some(n))
|
(n, Some(n))
|
||||||
|
@ -6,56 +6,79 @@
|
|||||||
|
|
||||||
const HEX_DIGITS: [ascii::Char; 16] = *b"0123456789abcdef".as_ascii().unwrap();
|
const HEX_DIGITS: [ascii::Char; 16] = *b"0123456789abcdef".as_ascii().unwrap();
|
||||||
|
|
||||||
/// Escapes a byte into provided buffer; returns length of escaped
|
#[inline]
|
||||||
/// representation.
|
const fn backslash<const N: usize>(a: ascii::Char) -> ([ascii::Char; N], Range<u8>) {
|
||||||
pub(crate) fn escape_ascii_into(output: &mut [ascii::Char; 4], byte: u8) -> Range<u8> {
|
const { assert!(N >= 2) };
|
||||||
#[inline]
|
|
||||||
fn backslash(a: ascii::Char) -> ([ascii::Char; 4], u8) {
|
|
||||||
([ascii::Char::ReverseSolidus, a, ascii::Char::Null, ascii::Char::Null], 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
let (data, len) = match byte {
|
let mut output = [ascii::Char::Null; N];
|
||||||
|
|
||||||
|
output[0] = ascii::Char::ReverseSolidus;
|
||||||
|
output[1] = a;
|
||||||
|
|
||||||
|
(output, 0..2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Escapes an ASCII character.
|
||||||
|
///
|
||||||
|
/// Returns a buffer and the length of the escaped representation.
|
||||||
|
const fn escape_ascii<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>) {
|
||||||
|
const { assert!(N >= 4) };
|
||||||
|
|
||||||
|
match byte {
|
||||||
b'\t' => backslash(ascii::Char::SmallT),
|
b'\t' => backslash(ascii::Char::SmallT),
|
||||||
b'\r' => backslash(ascii::Char::SmallR),
|
b'\r' => backslash(ascii::Char::SmallR),
|
||||||
b'\n' => backslash(ascii::Char::SmallN),
|
b'\n' => backslash(ascii::Char::SmallN),
|
||||||
b'\\' => backslash(ascii::Char::ReverseSolidus),
|
b'\\' => backslash(ascii::Char::ReverseSolidus),
|
||||||
b'\'' => backslash(ascii::Char::Apostrophe),
|
b'\'' => backslash(ascii::Char::Apostrophe),
|
||||||
b'\"' => backslash(ascii::Char::QuotationMark),
|
b'\"' => backslash(ascii::Char::QuotationMark),
|
||||||
_ => {
|
byte => {
|
||||||
if let Some(a) = byte.as_ascii()
|
let mut output = [ascii::Char::Null; N];
|
||||||
|
|
||||||
|
if let Some(c) = byte.as_ascii()
|
||||||
&& !byte.is_ascii_control()
|
&& !byte.is_ascii_control()
|
||||||
{
|
{
|
||||||
([a, ascii::Char::Null, ascii::Char::Null, ascii::Char::Null], 1)
|
output[0] = c;
|
||||||
|
(output, 0..1)
|
||||||
} else {
|
} else {
|
||||||
let hi = HEX_DIGITS[usize::from(byte >> 4)];
|
let hi = HEX_DIGITS[(byte >> 4) as usize];
|
||||||
let lo = HEX_DIGITS[usize::from(byte & 0xf)];
|
let lo = HEX_DIGITS[(byte & 0xf) as usize];
|
||||||
([ascii::Char::ReverseSolidus, ascii::Char::SmallX, hi, lo], 4)
|
|
||||||
|
output[0] = ascii::Char::ReverseSolidus;
|
||||||
|
output[1] = ascii::Char::SmallX;
|
||||||
|
output[2] = hi;
|
||||||
|
output[3] = lo;
|
||||||
|
|
||||||
|
(output, 0..4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
*output = data;
|
|
||||||
0..len
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Escapes a character into provided buffer using `\u{NNNN}` representation.
|
/// Escapes a character `\u{NNNN}` representation.
|
||||||
pub(crate) fn escape_unicode_into(output: &mut [ascii::Char; 10], ch: char) -> Range<u8> {
|
///
|
||||||
|
/// Returns a buffer and the length of the escaped representation.
|
||||||
|
const fn escape_unicode<const N: usize>(c: char) -> ([ascii::Char; N], Range<u8>) {
|
||||||
|
const { assert!(N >= 10 && N < u8::MAX as usize) };
|
||||||
|
|
||||||
|
let c = u32::from(c);
|
||||||
|
|
||||||
|
// OR-ing `1` ensures that for `c == 0` the code computes that
|
||||||
|
// one digit should be printed.
|
||||||
|
let start = (c | 1).leading_zeros() as usize / 4 - 2;
|
||||||
|
|
||||||
|
let mut output = [ascii::Char::Null; N];
|
||||||
|
output[3] = HEX_DIGITS[((c >> 20) & 15) as usize];
|
||||||
|
output[4] = HEX_DIGITS[((c >> 16) & 15) as usize];
|
||||||
|
output[5] = HEX_DIGITS[((c >> 12) & 15) as usize];
|
||||||
|
output[6] = HEX_DIGITS[((c >> 8) & 15) as usize];
|
||||||
|
output[7] = HEX_DIGITS[((c >> 4) & 15) as usize];
|
||||||
|
output[8] = HEX_DIGITS[((c >> 0) & 15) as usize];
|
||||||
output[9] = ascii::Char::RightCurlyBracket;
|
output[9] = ascii::Char::RightCurlyBracket;
|
||||||
|
output[start + 0] = ascii::Char::ReverseSolidus;
|
||||||
|
output[start + 1] = ascii::Char::SmallU;
|
||||||
|
output[start + 2] = ascii::Char::LeftCurlyBracket;
|
||||||
|
|
||||||
let ch = ch as u32;
|
(output, (start as u8)..(N as u8))
|
||||||
output[3] = HEX_DIGITS[((ch >> 20) & 15) as usize];
|
|
||||||
output[4] = HEX_DIGITS[((ch >> 16) & 15) as usize];
|
|
||||||
output[5] = HEX_DIGITS[((ch >> 12) & 15) as usize];
|
|
||||||
output[6] = HEX_DIGITS[((ch >> 8) & 15) as usize];
|
|
||||||
output[7] = HEX_DIGITS[((ch >> 4) & 15) as usize];
|
|
||||||
output[8] = HEX_DIGITS[((ch >> 0) & 15) as usize];
|
|
||||||
|
|
||||||
// or-ing 1 ensures that for ch==0 the code computes that one digit should
|
|
||||||
// be printed.
|
|
||||||
let start = (ch | 1).leading_zeros() as usize / 4 - 2;
|
|
||||||
const UNICODE_ESCAPE_PREFIX: &[ascii::Char; 3] = b"\\u{".as_ascii().unwrap();
|
|
||||||
output[start..][..3].copy_from_slice(UNICODE_ESCAPE_PREFIX);
|
|
||||||
|
|
||||||
(start as u8)..10
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An iterator over an fixed-size array.
|
/// An iterator over an fixed-size array.
|
||||||
@ -65,45 +88,63 @@
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct EscapeIterInner<const N: usize> {
|
pub(crate) struct EscapeIterInner<const N: usize> {
|
||||||
// The element type ensures this is always ASCII, and thus also valid UTF-8.
|
// The element type ensures this is always ASCII, and thus also valid UTF-8.
|
||||||
pub(crate) data: [ascii::Char; N],
|
data: [ascii::Char; N],
|
||||||
|
|
||||||
// Invariant: alive.start <= alive.end <= N.
|
// Invariant: `alive.start <= alive.end <= N`
|
||||||
pub(crate) alive: Range<u8>,
|
alive: Range<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> EscapeIterInner<N> {
|
impl<const N: usize> EscapeIterInner<N> {
|
||||||
pub fn new(data: [ascii::Char; N], alive: Range<u8>) -> Self {
|
pub const fn backslash(c: ascii::Char) -> Self {
|
||||||
const { assert!(N < 256) };
|
let (data, range) = backslash(c);
|
||||||
debug_assert!(alive.start <= alive.end && usize::from(alive.end) <= N, "{alive:?}");
|
Self { data, alive: range }
|
||||||
Self { data, alive }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_array<const M: usize>(array: [ascii::Char; M]) -> Self {
|
pub const fn ascii(c: u8) -> Self {
|
||||||
const { assert!(M <= N) };
|
let (data, range) = escape_ascii(c);
|
||||||
|
Self { data, alive: range }
|
||||||
let mut data = [ascii::Char::Null; N];
|
|
||||||
data[..M].copy_from_slice(&array);
|
|
||||||
Self::new(data, 0..M as u8)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn unicode(c: char) -> Self {
|
||||||
|
let (data, range) = escape_unicode(c);
|
||||||
|
Self { data, alive: range }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub const fn empty() -> Self {
|
||||||
|
Self { data: [ascii::Char::Null; N], alive: 0..0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn as_ascii(&self) -> &[ascii::Char] {
|
pub fn as_ascii(&self) -> &[ascii::Char] {
|
||||||
&self.data[usize::from(self.alive.start)..usize::from(self.alive.end)]
|
// SAFETY: `self.alive` is guaranteed to be a valid range for indexing `self.data`.
|
||||||
|
unsafe {
|
||||||
|
self.data.get_unchecked(usize::from(self.alive.start)..usize::from(self.alive.end))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn as_str(&self) -> &str {
|
pub fn as_str(&self) -> &str {
|
||||||
self.as_ascii().as_str()
|
self.as_ascii().as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
usize::from(self.alive.end - self.alive.start)
|
usize::from(self.alive.end - self.alive.start)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) -> Option<u8> {
|
pub fn next(&mut self) -> Option<u8> {
|
||||||
self.alive.next().map(|i| self.data[usize::from(i)].to_u8())
|
let i = self.alive.next()?;
|
||||||
|
|
||||||
|
// SAFETY: `i` is guaranteed to be a valid index for `self.data`.
|
||||||
|
unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_back(&mut self) -> Option<u8> {
|
pub fn next_back(&mut self) -> Option<u8> {
|
||||||
self.alive.next_back().map(|i| self.data[usize::from(i)].to_u8())
|
let i = self.alive.next_back()?;
|
||||||
|
|
||||||
|
// SAFETY: `i` is guaranteed to be a valid index for `self.data`.
|
||||||
|
unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
|
pub fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
|
||||||
|
@ -584,11 +584,11 @@ pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
|
|||||||
// Thus, rather than using `overflowing_sub` that produces a wrapping
|
// Thus, rather than using `overflowing_sub` that produces a wrapping
|
||||||
// subtraction, check it ourself so we can use an unchecked one.
|
// subtraction, check it ourself so we can use an unchecked one.
|
||||||
|
|
||||||
if self >= rhs {
|
if self < rhs {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
// SAFETY: just checked this can't overflow
|
// SAFETY: just checked this can't overflow
|
||||||
Some(unsafe { intrinsics::unchecked_sub(self, rhs) })
|
Some(unsafe { intrinsics::unchecked_sub(self, rhs) })
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@
|
|||||||
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
|
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
|
||||||
use crate::core::config::TargetSelection;
|
use crate::core::config::TargetSelection;
|
||||||
use crate::utils::channel::{self, Info};
|
use crate::utils::channel::{self, Info};
|
||||||
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
|
use crate::utils::helpers::{
|
||||||
|
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
|
||||||
|
};
|
||||||
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
|
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
|
||||||
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
|
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
|
||||||
|
|
||||||
@ -2024,7 +2026,7 @@ fn filter(contents: &str, marker: &str) -> String {
|
|||||||
builder.run(&mut cmd);
|
builder.run(&mut cmd);
|
||||||
|
|
||||||
if !builder.config.dry_run() {
|
if !builder.config.dry_run() {
|
||||||
t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
|
t!(move_file(exe.join(&filename), distdir(builder).join(&filename)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
use build_helper::stage0_parser::VersionMetadata;
|
use build_helper::stage0_parser::VersionMetadata;
|
||||||
use xz2::bufread::XzDecoder;
|
use xz2::bufread::XzDecoder;
|
||||||
|
|
||||||
use crate::utils::helpers::{check_run, exe, program_out_of_date};
|
use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date};
|
||||||
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
|
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
|
||||||
use crate::{t, Config};
|
use crate::{t, Config};
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
|
|||||||
None => panic!("no protocol in {url}"),
|
None => panic!("no protocol in {url}"),
|
||||||
}
|
}
|
||||||
t!(
|
t!(
|
||||||
std::fs::rename(&tempfile, dest_path),
|
move_file(&tempfile, dest_path),
|
||||||
format!("failed to rename {tempfile:?} to {dest_path:?}")
|
format!("failed to rename {tempfile:?} to {dest_path:?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ fn unpack(&self, tarball: &Path, dst: &Path, pattern: &str) {
|
|||||||
if src_path.is_dir() && dst_path.exists() {
|
if src_path.is_dir() && dst_path.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
t!(fs::rename(src_path, dst_path));
|
t!(move_file(src_path, dst_path));
|
||||||
}
|
}
|
||||||
let dst_dir = dst.join(directory_prefix);
|
let dst_dir = dst.join(directory_prefix);
|
||||||
if dst_dir.exists() {
|
if dst_dir.exists() {
|
||||||
|
@ -150,6 +150,21 @@ fn symlink_dir_inner(target: &Path, junction: &Path) -> io::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rename a file if from and to are in the same filesystem or
|
||||||
|
/// copy and remove the file otherwise
|
||||||
|
pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
|
||||||
|
match fs::rename(&from, &to) {
|
||||||
|
// FIXME: Once `ErrorKind::CrossesDevices` is stabilized use
|
||||||
|
// if e.kind() == io::ErrorKind::CrossesDevices {
|
||||||
|
#[cfg(unix)]
|
||||||
|
Err(e) if e.raw_os_error() == Some(libc::EXDEV) => {
|
||||||
|
std::fs::copy(&from, &to)?;
|
||||||
|
std::fs::remove_file(&from)
|
||||||
|
}
|
||||||
|
r => r,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn forcing_clang_based_tests() -> bool {
|
pub fn forcing_clang_based_tests() -> bool {
|
||||||
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
|
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
|
||||||
match &var.to_string_lossy().to_lowercase()[..] {
|
match &var.to_string_lossy().to_lowercase()[..] {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
use crate::core::builder::Builder;
|
use crate::core::builder::Builder;
|
||||||
use crate::core::{build_steps::dist::distdir, builder::Kind};
|
use crate::core::{build_steps::dist::distdir, builder::Kind};
|
||||||
use crate::utils::channel;
|
use crate::utils::channel;
|
||||||
use crate::utils::helpers::t;
|
use crate::utils::helpers::{move_file, t};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub(crate) enum OverlayKind {
|
pub(crate) enum OverlayKind {
|
||||||
@ -284,7 +284,7 @@ pub(crate) fn bare(self) -> GeneratedTarball {
|
|||||||
// name, not "image". We rename the image directory just before passing
|
// name, not "image". We rename the image directory just before passing
|
||||||
// into rust-installer.
|
// into rust-installer.
|
||||||
let dest = self.temp_dir.join(self.package_name());
|
let dest = self.temp_dir.join(self.package_name());
|
||||||
t!(std::fs::rename(&self.image_dir, &dest));
|
t!(move_file(&self.image_dir, &dest));
|
||||||
|
|
||||||
self.run(|this, cmd| {
|
self.run(|this, cmd| {
|
||||||
let distdir = distdir(this.builder);
|
let distdir = distdir(this.builder);
|
||||||
|
@ -8,7 +8,6 @@ run-make/branch-protection-check-IBT/Makefile
|
|||||||
run-make/c-dynamic-dylib/Makefile
|
run-make/c-dynamic-dylib/Makefile
|
||||||
run-make/c-dynamic-rlib/Makefile
|
run-make/c-dynamic-rlib/Makefile
|
||||||
run-make/c-link-to-rust-dylib/Makefile
|
run-make/c-link-to-rust-dylib/Makefile
|
||||||
run-make/c-link-to-rust-staticlib/Makefile
|
|
||||||
run-make/c-static-dylib/Makefile
|
run-make/c-static-dylib/Makefile
|
||||||
run-make/c-static-rlib/Makefile
|
run-make/c-static-rlib/Makefile
|
||||||
run-make/c-unwind-abi-catch-lib-panic/Makefile
|
run-make/c-unwind-abi-catch-lib-panic/Makefile
|
||||||
@ -179,7 +178,6 @@ run-make/native-link-modifier-whole-archive/Makefile
|
|||||||
run-make/no-alloc-shim/Makefile
|
run-make/no-alloc-shim/Makefile
|
||||||
run-make/no-builtins-attribute/Makefile
|
run-make/no-builtins-attribute/Makefile
|
||||||
run-make/no-builtins-lto/Makefile
|
run-make/no-builtins-lto/Makefile
|
||||||
run-make/no-cdylib-as-rdylib/Makefile
|
|
||||||
run-make/no-duplicate-libs/Makefile
|
run-make/no-duplicate-libs/Makefile
|
||||||
run-make/no-intermediate-extras/Makefile
|
run-make/no-intermediate-extras/Makefile
|
||||||
run-make/obey-crate-type-flag/Makefile
|
run-make/obey-crate-type-flag/Makefile
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
# This test checks that C linking with Rust does not encounter any errors, with static libraries.
|
|
||||||
# See https://github.com/rust-lang/rust/issues/10434
|
|
||||||
|
|
||||||
# ignore-cross-compile
|
|
||||||
include ../tools.mk
|
|
||||||
|
|
||||||
# ignore-freebsd
|
|
||||||
# FIXME
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTC) foo.rs
|
|
||||||
$(CC) bar.c $(call STATICLIB,foo) $(call OUT_EXE,bar) \
|
|
||||||
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
|
|
||||||
$(call RUN,bar)
|
|
||||||
rm $(call STATICLIB,foo)
|
|
||||||
$(call RUN,bar)
|
|
15
tests/run-make/c-link-to-rust-staticlib/rmake.rs
Normal file
15
tests/run-make/c-link-to-rust-staticlib/rmake.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// This test checks that C linking with Rust does not encounter any errors, with a static library.
|
||||||
|
// See https://github.com/rust-lang/rust/issues/10434
|
||||||
|
|
||||||
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
|
use run_make_support::{cc, extra_c_flags, run, rustc, static_lib};
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
rustc().input("foo.rs").run();
|
||||||
|
cc().input("bar.c").input(static_lib("foo")).out_exe("bar").args(&extra_c_flags()).run();
|
||||||
|
run("bar");
|
||||||
|
fs::remove_file(static_lib("foo"));
|
||||||
|
run("bar");
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
# ignore-cross-compile
|
|
||||||
include ../tools.mk
|
|
||||||
|
|
||||||
# Test that rustc will not attempt to link against a cdylib as if
|
|
||||||
# it is a rust dylib when an rlib for the same crate is available.
|
|
||||||
# Previously rustc didn't actually check if any further formats of
|
|
||||||
# a crate which has been loaded are of the same version and if
|
|
||||||
# they are actually valid. This caused a cdylib to be interpreted
|
|
||||||
# as rust dylib as soon as the corresponding rlib was loaded. As
|
|
||||||
# cdylibs don't export any rust symbols, linking would fail if
|
|
||||||
# rustc decides to link against the cdylib rather than the rlib.
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTC) bar.rs --crate-type=rlib --crate-type=cdylib
|
|
||||||
$(RUSTC) foo.rs -C prefer-dynamic
|
|
||||||
$(call RUN,foo)
|
|
16
tests/run-make/no-cdylib-as-rdylib/rmake.rs
Normal file
16
tests/run-make/no-cdylib-as-rdylib/rmake.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// This test produces an rlib and a cdylib from bar.rs.
|
||||||
|
// Then, foo.rs attempts to link to the bar library.
|
||||||
|
// If the test passes, that means rustc favored the rlib and ignored the cdylib.
|
||||||
|
// If the test fails, that is because the cdylib was picked, which does not export
|
||||||
|
// any Rust symbols.
|
||||||
|
// See https://github.com/rust-lang/rust/pull/113695
|
||||||
|
|
||||||
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
|
use run_make_support::{run, rustc};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
rustc().input("bar.rs").crate_type("rlib").crate_type("cdylib").run();
|
||||||
|
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||||
|
run("foo");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user