Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial work on building with Cargo #71029

Merged
merged 5 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3694,6 +3694,7 @@ dependencies = [
"indexmap",
"jobserver",
"lazy_static 1.4.0",
"libc",
"log",
"measureme",
"parking_lot 0.10.0",
Expand All @@ -3713,6 +3714,7 @@ version = "0.0.0"
dependencies = [
"env_logger 0.7.1",
"lazy_static 1.4.0",
"libc",
"log",
"rustc_ast",
"rustc_ast_pretty",
Expand Down Expand Up @@ -3867,6 +3869,7 @@ dependencies = [
name = "rustc_interface"
version = "0.0.0"
dependencies = [
"libc",
"log",
"once_cell",
"rustc-rayon",
Expand Down Expand Up @@ -3960,6 +3963,7 @@ name = "rustc_metadata"
version = "0.0.0"
dependencies = [
"flate2",
"libc",
"log",
"memmap",
"rustc_ast",
Expand Down Expand Up @@ -4197,6 +4201,7 @@ dependencies = [
name = "rustc_session"
version = "0.0.0"
dependencies = [
"getopts",
"log",
"num_cpus",
"rustc_ast",
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
// `compiler-rt` is located.
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
let compiler_builtins_c_feature = if compiler_builtins_root.exists() {
// Note that `libprofiler_builtins/build.rs` also computes this so if
// you're changing something here please also change that.
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
" compiler-builtins-c".to_string()
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/libprofiler_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ fn main() {
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
}

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

let src_root = root.join("lib").join("profile");
for src in profile_sources {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_index = { path = "../librustc_index", package = "rustc_index" }
bitflags = "1.2.1"
measureme = "0.7.1"
libc = "0.2"

[dependencies.parking_lot]
version = "0.10"
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#[macro_use]
extern crate log;
#[cfg(unix)]
extern crate libc;
#[macro_use]
extern crate cfg_if;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["dylib"]

[dependencies]
lazy_static = "1.0"
libc = "0.2"
log = "0.4"
env_logger = { version = "0.7", default-features = false }
rustc_middle = { path = "../librustc_middle" }
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#![feature(nll)]
#![recursion_limit = "256"]

pub extern crate getopts;
#[cfg(unix)]
extern crate libc;
#[macro_use]
extern crate log;
#[macro_use]
Expand All @@ -37,6 +34,7 @@ use rustc_save_analysis::DumpHandler;
use rustc_serialize::json::{self, ToJson};
use rustc_session::config::nightly_options;
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
use rustc_session::getopts;
use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, DiagnosticOutput, Session};
use rustc_session::{early_error, early_warn};
Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ path = "lib.rs"
doctest = false

[dependencies]
libc = "0.2"
log = "0.4"
rayon = { version = "0.3.0", package = "rustc-rayon" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_interface/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#![feature(generators)]
#![recursion_limit = "256"]

#[cfg(unix)]
extern crate libc;

mod callbacks;
pub mod interface;
mod passes;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate getopts;

use crate::interface::parse_cfgspecs;

use rustc_data_structures::fx::FxHashSet;
Expand All @@ -9,6 +7,7 @@ use rustc_session::config::{build_configuration, build_session_options, to_crate
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
use rustc_session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
use rustc_session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
use rustc_session::getopts;
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_session::{build_session, Session};
Expand Down
30 changes: 20 additions & 10 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@ fn main() {
build_helper::restore_library_path();

let target = env::var("TARGET").expect("TARGET was not set");
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from).unwrap_or_else(|| {
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
let to_test =
dir.parent().unwrap().parent().unwrap().join(&target).join("llvm/bin/llvm-config");
if Command::new(&to_test).output().is_ok() {
return to_test;
let llvm_config =
env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
let to_test = dir
.parent()
.unwrap()
.parent()
.unwrap()
.join(&target)
.join("llvm/bin/llvm-config");
if Command::new(&to_test).output().is_ok() {
return Some(to_test);
}
}
}
PathBuf::from("llvm-config")
});
None
});

if let Some(llvm_config) = &llvm_config {
println!("cargo:rerun-if-changed={}", llvm_config.display());
}
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));

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

// Test whether we're cross-compiling LLVM. This is a pretty rare case
Expand Down
1 change: 1 addition & 0 deletions src/librustc_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ doctest = false

[dependencies]
flate2 = "1.0"
libc = "0.2"
log = "0.4"
memmap = "0.7"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#![feature(stmt_expr_attributes)]
#![recursion_limit = "256"]

extern crate libc;
extern crate proc_macro;

#[macro_use]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ name = "rustc_session"
path = "lib.rs"

[dependencies]
getopts = "0.2"
log = "0.4"
rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" }
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_session/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#![feature(crate_visibility_modifier)]
#![feature(test)]

// Use the test crate here so we depend on getopts through it. This allow tools to link to both
// librustc_session and libtest.
extern crate getopts;
extern crate test as _;
Comment on lines -2 to -7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this broke rustfmt and rls in #71059 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right link-related extern crates still exist in rustc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error:

error[E0464]: multiple matching crates for `getopts`
 --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_session-651.0.0/lib.rs:6:1
  |
6 | extern crate getopts;
  | ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: candidates:
          crate `getopts`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-2a6246002b81ef60.rlib
          crate `getopts`: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-c6adfde1f127313e.rlib

error[E0463]: can't find crate for `getopts`
 --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_session-651.0.0/lib.rs:6:1
  |
6 | extern crate getopts;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 2 previous errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems likely, but I'm pretty sure that once y'all bump the autopublished librustc_session crate then things should work. If not, please do let me know, we can re-add this here as needed.


pub mod cgu_reuse_tracker;
pub mod utils;
Expand All @@ -23,3 +17,5 @@ mod session;
pub use session::*;

pub mod output;

pub use getopts;
1 change: 1 addition & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_session::config::{
nightly_options,
};
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
use rustc_session::getopts;
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_span::edition::{Edition, DEFAULT_EDITION};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![recursion_limit = "256"]

extern crate env_logger;
extern crate getopts;
extern crate rustc_ast;
extern crate rustc_ast_pretty;
extern crate rustc_attr;
Expand Down Expand Up @@ -51,6 +50,7 @@ use std::panic;
use std::process;

use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
use rustc_session::getopts;
use rustc_session::{early_error, early_warn};

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] }
wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false }

[features]
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat surprising to me, what's the explanation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to link to some panic runtime for std to build and I believe bootstrap always builds std with panic-unwind linked in today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this negatively affect some -Zbuild-std uses?


backtrace = [
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC
Expand Down