Skip to content

Commit b83c2e9

Browse files
authored
Rollup merge of #71029 - Mark-Simulacrum:cargo-build, r=Mark-Simulacrum
Partial work on building with Cargo This cherry picks the commits I'm directly approving from #70999, I want to land them so that that PR is smaller.
2 parents 32fb4dc + 1864caa commit b83c2e9

File tree

18 files changed

+42
-31
lines changed

18 files changed

+42
-31
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,7 @@ dependencies = [
36943694
"indexmap",
36953695
"jobserver",
36963696
"lazy_static 1.4.0",
3697+
"libc",
36973698
"log",
36983699
"measureme",
36993700
"parking_lot 0.10.0",
@@ -3713,6 +3714,7 @@ version = "0.0.0"
37133714
dependencies = [
37143715
"env_logger 0.7.1",
37153716
"lazy_static 1.4.0",
3717+
"libc",
37163718
"log",
37173719
"rustc_ast",
37183720
"rustc_ast_pretty",
@@ -3867,6 +3869,7 @@ dependencies = [
38673869
name = "rustc_interface"
38683870
version = "0.0.0"
38693871
dependencies = [
3872+
"libc",
38703873
"log",
38713874
"once_cell",
38723875
"rustc-rayon",
@@ -3960,6 +3963,7 @@ name = "rustc_metadata"
39603963
version = "0.0.0"
39613964
dependencies = [
39623965
"flate2",
3966+
"libc",
39633967
"log",
39643968
"memmap",
39653969
"rustc_ast",
@@ -4197,6 +4201,7 @@ dependencies = [
41974201
name = "rustc_session"
41984202
version = "0.0.0"
41994203
dependencies = [
4204+
"getopts",
42004205
"log",
42014206
"num_cpus",
42024207
"rustc_ast",

src/bootstrap/compile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
186186
// `compiler-rt` is located.
187187
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
188188
let compiler_builtins_c_feature = if compiler_builtins_root.exists() {
189+
// Note that `libprofiler_builtins/build.rs` also computes this so if
190+
// you're changing something here please also change that.
189191
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
190192
" compiler-builtins-c".to_string()
191193
} else {

src/libprofiler_builtins/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ fn main() {
6363
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
6464
}
6565

66-
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
67-
let root = Path::new(&root);
66+
// Note that this should exist if we're going to run (otherwise we just
67+
// don't build profiler builtins at all).
68+
let root = Path::new("../llvm-project/compiler-rt");
6869

6970
let src_root = root.join("lib").join("profile");
7071
for src in profile_sources {

src/librustc_data_structures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2727
rustc_index = { path = "../librustc_index", package = "rustc_index" }
2828
bitflags = "1.2.1"
2929
measureme = "0.7.1"
30+
libc = "0.2"
3031

3132
[dependencies.parking_lot]
3233
version = "0.10"

src/librustc_data_structures/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
#[macro_use]
2828
extern crate log;
29-
#[cfg(unix)]
30-
extern crate libc;
3129
#[macro_use]
3230
extern crate cfg_if;
3331

src/librustc_driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ crate-type = ["dylib"]
1111

1212
[dependencies]
1313
lazy_static = "1.0"
14+
libc = "0.2"
1415
log = "0.4"
1516
env_logger = { version = "0.7", default-features = false }
1617
rustc_middle = { path = "../librustc_middle" }

src/librustc_driver/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#![feature(nll)]
99
#![recursion_limit = "256"]
1010

11-
pub extern crate getopts;
12-
#[cfg(unix)]
13-
extern crate libc;
1411
#[macro_use]
1512
extern crate log;
1613
#[macro_use]
@@ -37,6 +34,7 @@ use rustc_save_analysis::DumpHandler;
3734
use rustc_serialize::json::{self, ToJson};
3835
use rustc_session::config::nightly_options;
3936
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
37+
use rustc_session::getopts;
4038
use rustc_session::lint::{Lint, LintId};
4139
use rustc_session::{config, DiagnosticOutput, Session};
4240
use rustc_session::{early_error, early_warn};

src/librustc_interface/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13+
libc = "0.2"
1314
log = "0.4"
1415
rayon = { version = "0.3.0", package = "rustc-rayon" }
1516
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_interface/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#![feature(generators)]
77
#![recursion_limit = "256"]
88

9-
#[cfg(unix)]
10-
extern crate libc;
11-
129
mod callbacks;
1310
pub mod interface;
1411
mod passes;

src/librustc_interface/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate getopts;
2-
31
use crate::interface::parse_cfgspecs;
42

53
use rustc_data_structures::fx::FxHashSet;
@@ -9,6 +7,7 @@ use rustc_session::config::{build_configuration, build_session_options, to_crate
97
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
108
use rustc_session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
119
use rustc_session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
10+
use rustc_session::getopts;
1211
use rustc_session::lint::Level;
1312
use rustc_session::search_paths::SearchPath;
1413
use rustc_session::{build_session, Session};

src/librustc_llvm/build.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ fn main() {
2424
build_helper::restore_library_path();
2525

2626
let target = env::var("TARGET").expect("TARGET was not set");
27-
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from).unwrap_or_else(|| {
28-
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
29-
let to_test =
30-
dir.parent().unwrap().parent().unwrap().join(&target).join("llvm/bin/llvm-config");
31-
if Command::new(&to_test).output().is_ok() {
32-
return to_test;
27+
let llvm_config =
28+
env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
29+
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
30+
let to_test = dir
31+
.parent()
32+
.unwrap()
33+
.parent()
34+
.unwrap()
35+
.join(&target)
36+
.join("llvm/bin/llvm-config");
37+
if Command::new(&to_test).output().is_ok() {
38+
return Some(to_test);
39+
}
3340
}
34-
}
35-
PathBuf::from("llvm-config")
36-
});
41+
None
42+
});
43+
44+
if let Some(llvm_config) = &llvm_config {
45+
println!("cargo:rerun-if-changed={}", llvm_config.display());
46+
}
47+
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
3748

38-
println!("cargo:rerun-if-changed={}", llvm_config.display());
3949
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
4050

4151
// Test whether we're cross-compiling LLVM. This is a pretty rare case

src/librustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ doctest = false
1111

1212
[dependencies]
1313
flate2 = "1.0"
14+
libc = "0.2"
1415
log = "0.4"
1516
memmap = "0.7"
1617
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_metadata/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#![feature(stmt_expr_attributes)]
1111
#![recursion_limit = "256"]
1212

13-
extern crate libc;
1413
extern crate proc_macro;
1514

1615
#[macro_use]

src/librustc_session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name = "rustc_session"
99
path = "lib.rs"
1010

1111
[dependencies]
12+
getopts = "0.2"
1213
log = "0.4"
1314
rustc_errors = { path = "../librustc_errors" }
1415
rustc_feature = { path = "../librustc_feature" }

src/librustc_session/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#![feature(crate_visibility_modifier)]
2-
#![feature(test)]
3-
4-
// Use the test crate here so we depend on getopts through it. This allow tools to link to both
5-
// librustc_session and libtest.
6-
extern crate getopts;
7-
extern crate test as _;
82

93
pub mod cgu_reuse_tracker;
104
pub mod utils;
@@ -23,3 +17,5 @@ mod session;
2317
pub use session::*;
2418

2519
pub mod output;
20+
21+
pub use getopts;

src/librustdoc/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_session::config::{
1010
nightly_options,
1111
};
1212
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
13+
use rustc_session::getopts;
1314
use rustc_session::lint::Level;
1415
use rustc_session::search_paths::SearchPath;
1516
use rustc_span::edition::{Edition, DEFAULT_EDITION};

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![recursion_limit = "256"]
1616

1717
extern crate env_logger;
18-
extern crate getopts;
1918
extern crate rustc_ast;
2019
extern crate rustc_ast_pretty;
2120
extern crate rustc_attr;
@@ -51,6 +50,7 @@ use std::panic;
5150
use std::process;
5251

5352
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
53+
use rustc_session::getopts;
5454
use rustc_session::{early_error, early_warn};
5555

5656
#[macro_use]

src/libstd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] }
4747
wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false }
4848

4949
[features]
50-
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
50+
default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
5151

5252
backtrace = [
5353
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC

0 commit comments

Comments
 (0)