Skip to content

Commit 8903de3

Browse files
authored
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.
2 parents b92758a + 39ef149 commit 8903de3

30 files changed

+108
-96
lines changed

library/std/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ addr2line = { version = "0.21.0", optional = true, default-features = false }
3333
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
3434
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
3535

36-
[target.'cfg(all(windows, target_env = "msvc"))'.dependencies]
37-
libc = { version = "0.2.153", default-features = false }
38-
3936
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
4037
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
4138

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ extern crate alloc as alloc_crate;
435435
// so include it here even if it's unused.
436436
#[doc(masked)]
437437
#[allow(unused_extern_crates)]
438+
#[cfg(not(all(windows, target_env = "msvc")))]
438439
extern crate libc;
439440

440441
// We always need an unwinder currently for backtraces

library/std/src/os/raw/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(all(windows, target_env = "msvc")))]
2+
13
use crate::any::TypeId;
24

35
macro_rules! ok {

tests/incremental/foreign.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
// Test what happens we save incremental compilation state that makes
22
// use of foreign items. This used to ICE (#34991).
3-
//@ ignore-sgx no libc
4-
53
//@ revisions: rpass1
64

7-
#![feature(rustc_private)]
8-
9-
extern crate libc;
10-
115
use std::ffi::CString;
126

137
mod mlibc {
14-
use libc::{c_char, c_long, c_longlong};
15-
168
extern "C" {
17-
pub fn atol(x: *const c_char) -> c_long;
18-
pub fn atoll(x: *const c_char) -> c_longlong;
9+
// strlen is provided either by an external library or compiler-builtins as a fallback
10+
pub fn strlen(x: *const std::ffi::c_char) -> usize;
1911
}
2012
}
2113

22-
fn atol(s: String) -> isize {
23-
let c = CString::new(s).unwrap();
24-
unsafe { mlibc::atol(c.as_ptr()) as isize }
25-
}
26-
27-
fn atoll(s: String) -> i64 {
14+
fn strlen(s: String) -> usize {
2815
let c = CString::new(s).unwrap();
29-
unsafe { mlibc::atoll(c.as_ptr()) as i64 }
16+
unsafe { mlibc::strlen(c.as_ptr()) }
3017
}
3118

3219
pub fn main() {
33-
assert_eq!(atol("1024".to_string()) * 10, atol("10240".to_string()));
34-
assert_eq!(
35-
(atoll("11111111111111111".to_string()) * 10),
36-
atoll("111111111111111110".to_string())
37-
);
20+
assert_eq!(strlen("1024".to_string()), strlen("2048".to_string()));
3821
}

tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#![crate_type = "staticlib"]
22
#![feature(c_variadic)]
3-
#![feature(rustc_private)]
43

5-
extern crate libc;
6-
7-
use libc::{c_char, c_double, c_int, c_long, c_longlong};
4+
use std::ffi::{c_char, c_double, c_int, c_long, c_longlong};
85
use std::ffi::VaList;
96
use std::ffi::{CString, CStr};
107

tests/run-make/link-path-order/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#![feature(rustc_private)]
2-
3-
extern crate libc;
1+
use std::ffi::c_int;
42

53
#[link(name = "foo", kind = "static")]
64
extern "C" {
7-
fn should_return_one() -> libc::c_int;
5+
fn should_return_one() -> c_int;
86
}
97

108
fn main() {

tests/ui/env-null-vars.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1+
// Ensure that env::vars() does not panic if environ is null.
2+
// Regression test for rust-lang/rust#53200
13
//@ run-pass
24

3-
#![allow(unused_imports)]
4-
5-
//@ ignore-windows
6-
7-
// issue-53200
8-
95
#![feature(rustc_private)]
10-
extern crate libc;
11-
12-
use std::env;
136

147
// FIXME: more platforms?
158
#[cfg(target_os = "linux")]
169
fn main() {
10+
extern crate libc;
1711
unsafe { libc::clearenv(); }
18-
assert_eq!(env::vars().count(), 0);
12+
assert_eq!(std::env::vars().count(), 0);
1913
}
2014

2115
#[cfg(not(target_os = "linux"))]

tests/ui/error-codes/E0259.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#![feature(rustc_private)]
1+
#![feature(test)]
22

33
extern crate alloc;
44

5-
extern crate libc as alloc;
5+
extern crate test as alloc;
66
//~^ ERROR E0259
77

88
fn main() {}

tests/ui/error-codes/E0259.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ error[E0259]: the name `alloc` is defined multiple times
44
LL | extern crate alloc;
55
| ------------------- previous import of the extern crate `alloc` here
66
LL |
7-
LL | extern crate libc as alloc;
7+
LL | extern crate test as alloc;
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `alloc` reimported here
99
|
1010
= note: `alloc` must be defined only once in the type namespace of this module
1111
help: you can use `as` to change the binding name of the import
1212
|
13-
LL | extern crate libc as other_alloc;
13+
LL | extern crate test as other_alloc;
1414
|
1515

1616
error: aborting due to 1 previous error
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// gate-test-rustc_private
22

3-
extern crate libc; //~ ERROR use of unstable library feature 'rustc_private'
3+
extern crate cfg_if; //~ ERROR use of unstable library feature 'rustc_private'
44

55
fn main() {}

0 commit comments

Comments
 (0)