Rollup merge of #124050 - saethlin:less-sysroot-libc, r=ChrisDenton
Remove libc from MSVC targets ``@ChrisDenton`` started working on a project to remove libc from Windows MSVC targets. I'm completing that work here. The primary change is to cfg out the dependency in `library/`. And then there's a lot of test patching. Happy to separate this more if people want.
This commit is contained in:
commit
8903de31ca
30 changed files with 108 additions and 96 deletions
|
@ -33,9 +33,6 @@ addr2line = { version = "0.21.0", optional = true, default-features = false }
|
|||
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
|
||||
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
|
||||
|
||||
[target.'cfg(all(windows, target_env = "msvc"))'.dependencies]
|
||||
libc = { version = "0.2.153", default-features = false }
|
||||
|
||||
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
|
||||
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
|
||||
|
||||
|
|
|
@ -435,6 +435,7 @@ extern crate alloc as alloc_crate;
|
|||
// so include it here even if it's unused.
|
||||
#[doc(masked)]
|
||||
#[allow(unused_extern_crates)]
|
||||
#[cfg(not(all(windows, target_env = "msvc")))]
|
||||
extern crate libc;
|
||||
|
||||
// We always need an unwinder currently for backtraces
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg(not(all(windows, target_env = "msvc")))]
|
||||
|
||||
use crate::any::TypeId;
|
||||
|
||||
macro_rules! ok {
|
||||
|
|
|
@ -1,38 +1,21 @@
|
|||
// Test what happens we save incremental compilation state that makes
|
||||
// use of foreign items. This used to ICE (#34991).
|
||||
//@ ignore-sgx no libc
|
||||
|
||||
//@ revisions: rpass1
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
mod mlibc {
|
||||
use libc::{c_char, c_long, c_longlong};
|
||||
|
||||
extern "C" {
|
||||
pub fn atol(x: *const c_char) -> c_long;
|
||||
pub fn atoll(x: *const c_char) -> c_longlong;
|
||||
// strlen is provided either by an external library or compiler-builtins as a fallback
|
||||
pub fn strlen(x: *const std::ffi::c_char) -> usize;
|
||||
}
|
||||
}
|
||||
|
||||
fn atol(s: String) -> isize {
|
||||
fn strlen(s: String) -> usize {
|
||||
let c = CString::new(s).unwrap();
|
||||
unsafe { mlibc::atol(c.as_ptr()) as isize }
|
||||
}
|
||||
|
||||
fn atoll(s: String) -> i64 {
|
||||
let c = CString::new(s).unwrap();
|
||||
unsafe { mlibc::atoll(c.as_ptr()) as i64 }
|
||||
unsafe { mlibc::strlen(c.as_ptr()) }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
|
||||
assert_eq!(
|
||||
(atoll("11111111111111111".to_string()) * 10),
|
||||
atoll("111111111111111110".to_string())
|
||||
);
|
||||
assert_eq!(strlen("1024".to_string()), strlen("2048".to_string()));
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#![crate_type = "staticlib"]
|
||||
#![feature(c_variadic)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use libc::{c_char, c_double, c_int, c_long, c_longlong};
|
||||
use std::ffi::{c_char, c_double, c_int, c_long, c_longlong};
|
||||
use std::ffi::VaList;
|
||||
use std::ffi::{CString, CStr};
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
use std::ffi::c_int;
|
||||
|
||||
#[link(name = "foo", kind = "static")]
|
||||
extern "C" {
|
||||
fn should_return_one() -> libc::c_int;
|
||||
fn should_return_one() -> c_int;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
// Ensure that env::vars() does not panic if environ is null.
|
||||
// Regression test for rust-lang/rust#53200
|
||||
//@ run-pass
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
//@ ignore-windows
|
||||
|
||||
// issue-53200
|
||||
|
||||
#![feature(rustc_private)]
|
||||
extern crate libc;
|
||||
|
||||
use std::env;
|
||||
|
||||
// FIXME: more platforms?
|
||||
#[cfg(target_os = "linux")]
|
||||
fn main() {
|
||||
extern crate libc;
|
||||
unsafe { libc::clearenv(); }
|
||||
assert_eq!(env::vars().count(), 0);
|
||||
assert_eq!(std::env::vars().count(), 0);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#![feature(rustc_private)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
extern crate libc as alloc;
|
||||
extern crate test as alloc;
|
||||
//~^ ERROR E0259
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -4,13 +4,13 @@ error[E0259]: the name `alloc` is defined multiple times
|
|||
LL | extern crate alloc;
|
||||
| ------------------- previous import of the extern crate `alloc` here
|
||||
LL |
|
||||
LL | extern crate libc as alloc;
|
||||
LL | extern crate test as alloc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `alloc` reimported here
|
||||
|
|
||||
= note: `alloc` must be defined only once in the type namespace of this module
|
||||
help: you can use `as` to change the binding name of the import
|
||||
|
|
||||
LL | extern crate libc as other_alloc;
|
||||
LL | extern crate test as other_alloc;
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// gate-test-rustc_private
|
||||
|
||||
extern crate libc; //~ ERROR use of unstable library feature 'rustc_private'
|
||||
extern crate cfg_if; //~ ERROR use of unstable library feature 'rustc_private'
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
|
||||
--> $DIR/rustc-private.rs:3:1
|
||||
|
|
||||
LL | extern crate libc;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | extern crate cfg_if;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
|
||||
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
//@ run-pass
|
||||
//@ ignore-sgx no libc
|
||||
|
||||
// Ensure no false positive on "unused extern crate" lint
|
||||
#![deny(unused_extern_crates)]
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
use std::ffi::CString;
|
||||
|
||||
mod mlibc {
|
||||
use libc::{c_char, size_t};
|
||||
use std::ffi::c_char;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "strlen"]
|
||||
pub fn my_strlen(str: *const c_char) -> size_t;
|
||||
pub fn my_strlen(str: *const c_char) -> usize;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
//@ run-pass
|
||||
#![allow(dead_code)]
|
||||
//@ pretty-expanded FIXME #23616
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
#![allow(dead_code)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
mod bar {
|
||||
extern "C" {}
|
||||
|
@ -13,14 +12,37 @@ mod zed {
|
|||
extern "C" {}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
mod mlibc {
|
||||
use libc::{c_int, c_void, size_t, ssize_t};
|
||||
extern crate libc;
|
||||
use self::libc::{c_int, c_void, size_t, ssize_t};
|
||||
|
||||
extern "C" {
|
||||
pub fn write(fd: c_int, buf: *const c_void, count: size_t) -> ssize_t;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
mod mlibc {
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::ffi::c_void;
|
||||
|
||||
pub type BOOL = i32;
|
||||
pub type HANDLE = *mut c_void;
|
||||
|
||||
#[link(name = "ntdll")]
|
||||
extern "system" {
|
||||
pub fn WriteFile(
|
||||
hfile: HANDLE,
|
||||
lpbuffer: *const u8,
|
||||
nnumberofbytestowrite: u32,
|
||||
lpnumberofbyteswritten: *mut u32,
|
||||
lpoverlapped: *mut c_void,
|
||||
) -> BOOL;
|
||||
}
|
||||
}
|
||||
|
||||
mod baz {
|
||||
extern "C" {}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
extern crate libc; //~ ERROR use of unstable
|
||||
use libc::*; //~ ERROR unresolved import
|
||||
extern crate test; //~ ERROR use of unstable
|
||||
use test::*; //~ ERROR unresolved import
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
error[E0432]: unresolved import `libc`
|
||||
error[E0432]: unresolved import `test`
|
||||
--> $DIR/issue-37887.rs:3:9
|
||||
|
|
||||
LL | use libc::*;
|
||||
| ^^^^ maybe a missing crate `libc`?
|
||||
LL | use test::*;
|
||||
| ^^^^ maybe a missing crate `test`?
|
||||
|
|
||||
= help: consider adding `extern crate libc` to use the `libc` crate
|
||||
= help: consider adding `extern crate test` to use the `test` crate
|
||||
|
||||
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
|
||||
error[E0658]: use of unstable library feature 'test'
|
||||
--> $DIR/issue-37887.rs:2:5
|
||||
|
|
||||
LL | extern crate libc;
|
||||
LL | extern crate test;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
|
||||
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
|
||||
= note: see issue #50297 <https://github.com/rust-lang/rust/issues/50297> for more information
|
||||
= help: add `#![feature(test)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
//@ edition:2018
|
||||
|
||||
#![deny(unused_extern_crates)]
|
||||
#![feature(test, rustc_private)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate libc;
|
||||
extern crate core;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
extern crate libc as x;
|
||||
extern crate core as x;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
|
||||
|
@ -28,11 +28,11 @@ mod foo {
|
|||
|
||||
pub(super) extern crate alloc as d;
|
||||
|
||||
extern crate libc;
|
||||
extern crate core;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
|
||||
extern crate libc as x;
|
||||
extern crate core as x;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
|
||||
|
@ -41,11 +41,11 @@ mod foo {
|
|||
pub extern crate test as y;
|
||||
|
||||
mod bar {
|
||||
extern crate libc;
|
||||
extern crate core;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
|
||||
extern crate libc as x;
|
||||
extern crate core as x;
|
||||
//~^ ERROR unused extern crate
|
||||
//~| HELP remove
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:6:1
|
||||
|
|
||||
LL | extern crate libc;
|
||||
LL | extern crate core;
|
||||
| ^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
|
||||
note: the lint level is defined here
|
||||
|
@ -13,31 +13,31 @@ LL | #![deny(unused_extern_crates)]
|
|||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:9:1
|
||||
|
|
||||
LL | extern crate libc as x;
|
||||
LL | extern crate core as x;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
||||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:31:5
|
||||
|
|
||||
LL | extern crate libc;
|
||||
LL | extern crate core;
|
||||
| ^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
||||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:35:5
|
||||
|
|
||||
LL | extern crate libc as x;
|
||||
LL | extern crate core as x;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
||||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:44:9
|
||||
|
|
||||
LL | extern crate libc;
|
||||
LL | extern crate core;
|
||||
| ^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
||||
error: unused extern crate
|
||||
--> $DIR/unnecessary-extern-crate.rs:48:9
|
||||
|
|
||||
LL | extern crate libc as x;
|
||||
LL | extern crate core as x;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Test that `download-rustc` doesn't put duplicate copies of libc in the sysroot.
|
||||
//@ check-pass
|
||||
//@ ignore-windows doesn't necessarily have the libc crate
|
||||
#![crate_type = "lib"]
|
||||
#![no_std]
|
||||
#![feature(rustc_private)]
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate libc;
|
||||
|
||||
use std::process::{Command, Stdio};
|
||||
use std::env;
|
||||
use std::ffi::c_int;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
#[cfg(unix)]
|
||||
unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
|
||||
|
@ -36,14 +38,14 @@ unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
|
|||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn assert_fd_is_valid(fd: libc::c_int) {
|
||||
fn assert_fd_is_valid(fd: c_int) {
|
||||
if unsafe { libc::fcntl(fd, libc::F_GETFD) == -1 } {
|
||||
panic!("file descriptor {} is not valid: {}", fd, io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn assert_fd_is_valid(_fd: libc::c_int) {}
|
||||
fn assert_fd_is_valid(_fd: c_int) {}
|
||||
|
||||
#[cfg(windows)]
|
||||
unsafe fn without_stdio<R, F: FnOnce() -> R>(f: F) -> R {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//@ run-pass
|
||||
//@ aux-build:sigpipe-utils.rs
|
||||
//@ compile-flags: -Zon-broken-pipe=error
|
||||
//@ only-unix because SIGPIPE is a unix thing
|
||||
|
||||
fn main() {
|
||||
extern crate sigpipe_utils;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
//@ aux-bin: assert-inherit-sig_ign.rs
|
||||
//@ run-pass
|
||||
//@ compile-flags: -Zon-broken-pipe=kill
|
||||
//@ only-unix because SIGPIPE is a unix thing
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//@ run-pass
|
||||
//@ aux-build:sigpipe-utils.rs
|
||||
//@ compile-flags: -Zon-broken-pipe=kill
|
||||
//@ only-unix because SIGPIPE is a unix thing
|
||||
|
||||
fn main() {
|
||||
extern crate sigpipe_utils;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//@ run-pass
|
||||
//@ aux-build:sigpipe-utils.rs
|
||||
//@ only-unix because SIGPIPE is a unix thing
|
||||
|
||||
fn main() {
|
||||
extern crate sigpipe_utils;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//@ run-pass
|
||||
//@ aux-build:sigpipe-utils.rs
|
||||
//@ compile-flags: -Zon-broken-pipe=kill
|
||||
//@ only-unix because SIGPIPE is a unix thing
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
|
|
|
@ -8,21 +8,16 @@
|
|||
//@ ignore-fuchsia must translate zircon signal to SIGABRT, FIXME (#58590)
|
||||
//@ ignore-nto no stack overflow handler used (no alternate stack available)
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#[cfg(unix)]
|
||||
extern crate libc;
|
||||
|
||||
use std::env;
|
||||
use std::hint::black_box;
|
||||
use std::process::Command;
|
||||
use std::thread;
|
||||
|
||||
// Inlining to avoid llvm turning the recursive functions into tail calls,
|
||||
// which doesn't consume stack.
|
||||
#[inline(always)]
|
||||
pub fn black_box<T>(dummy: T) { std::intrinsics::black_box(dummy); }
|
||||
|
||||
fn silent_recurse() {
|
||||
let buf = [0u8; 1000];
|
||||
black_box(buf);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//@ run-pass
|
||||
//@ check-run-results
|
||||
//@ ignore-emscripten
|
||||
//@ only-unix
|
||||
|
||||
// Emscripten doesn't flush its own stdout buffers on exit, which would fail
|
||||
// this test. So this test is disabled on this platform.
|
20
tests/ui/runtime/stdout-during-shutdown-windows.rs
Normal file
20
tests/ui/runtime/stdout-during-shutdown-windows.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
//@ run-pass
|
||||
//@ check-run-results
|
||||
//@ only-windows
|
||||
|
||||
struct Bye;
|
||||
|
||||
impl Drop for Bye {
|
||||
fn drop(&mut self) {
|
||||
print!(", world!");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
thread_local!{
|
||||
static BYE: Bye = Bye;
|
||||
}
|
||||
BYE.with(|_| {
|
||||
print!("hello");
|
||||
});
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
hello, world!
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
// The output from "ps -A -o pid,ppid,args" should look like this:
|
||||
|
@ -28,6 +26,7 @@ use std::process::Command;
|
|||
|
||||
#[cfg(unix)]
|
||||
fn find_zombies() {
|
||||
extern crate libc;
|
||||
let my_pid = unsafe { libc::getpid() };
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
|
||||
|
|
Loading…
Add table
Reference in a new issue