Skip to content

Commit 7f23e6e

Browse files
alexcrichtonAaron1011
authored andcommitted
rustc: Link LLVM directly into rustc again
This commit builds on rust-lang#65501 continue to simplify the build system and compiler now that we no longer have multiple LLVM backends to ship by default. Here this switches the compiler back to what it once was long long ago, which is linking LLVM directly to the compiler rather than dynamically loading it at runtime. The `codegen-backends` directory of the sysroot no longer exists and all relevant support in the build system is removed. Note that `rustc` still supports a dynamically loaded codegen backend as it did previously, it just no longer supports dynamically loaded codegen backends in its own sysroot. Additionally as part of this the `librustc_codegen_llvm` crate now once again explicitly depends on all of its crates instead of implicitly loading them through the sysroot. This involved filling out its `Cargo.toml` and deleting all the now-unnecessary `extern crate` annotations in the header of the crate. (this in turn required adding a number of imports for names of macros too). The end results of this change are: * Rustbuild's build process for the compiler as all the "oh don't forget the codegen backend" checks can be easily removed. * Building `rustc_codegen_llvm` is much simpler since it's simply another compiler crate. * Managing the dependencies of `rustc_codegen_llvm` is much simpler since it's "just another `Cargo.toml` to edit" * The build process should be a smidge faster because there's more parallelism in the main rustc build step rather than splitting `librustc_codegen_llvm` out to its own step. * The compiler is expected to be slightly faster by default because the codegen backend does not need to be dynamically loaded. * Disabling LLVM as part of rustbuild is still supported, supporting multiple codegen backends is still supported, and dynamic loading of a codegen backend is still supported.
1 parent 033662d commit 7f23e6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+163
-415
lines changed

Cargo.lock

+23
Original file line numberDiff line numberDiff line change
@@ -3435,7 +3435,25 @@ dependencies = [
34353435
name = "rustc_codegen_llvm"
34363436
version = "0.0.0"
34373437
dependencies = [
3438+
"bitflags",
3439+
"flate2",
3440+
"libc",
3441+
"log",
3442+
"rustc",
3443+
"rustc-demangle",
3444+
"rustc_codegen_ssa",
3445+
"rustc_codegen_utils",
3446+
"rustc_data_structures",
3447+
"rustc_errors",
3448+
"rustc_fs_util",
3449+
"rustc_incremental",
3450+
"rustc_index",
34383451
"rustc_llvm",
3452+
"rustc_target",
3453+
"smallvec 0.6.10",
3454+
"syntax",
3455+
"syntax_expand",
3456+
"syntax_pos",
34393457
]
34403458

34413459
[[package]]
@@ -3596,7 +3614,12 @@ dependencies = [
35963614
"log",
35973615
"once_cell",
35983616
"rustc",
3617+
<<<<<<< HEAD
35993618
"rustc-rayon",
3619+
=======
3620+
"rustc-rayon 0.3.0",
3621+
"rustc_codegen_llvm",
3622+
>>>>>>> rustc: Link LLVM directly into rustc again
36003623
"rustc_codegen_ssa",
36013624
"rustc_codegen_utils",
36023625
"rustc_data_structures",

config.toml.example

-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,6 @@
379379
# and currently the only standard option supported is `"llvm"`
380380
#codegen-backends = ["llvm"]
381381

382-
# This is the name of the directory in which codegen backends will get installed
383-
#codegen-backends-dir = "codegen-backends"
384-
385382
# Indicates whether LLD will be compiled and made available in the sysroot for
386383
# rustc to execute.
387384
#lld = false

src/bootstrap/builder.rs

-22
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ impl<'a> Builder<'a> {
339339
Kind::Build => describe!(
340340
compile::Std,
341341
compile::Rustc,
342-
compile::CodegenBackend,
343342
compile::StartupObjects,
344343
tool::BuildManifest,
345344
tool::Rustbook,
@@ -364,7 +363,6 @@ impl<'a> Builder<'a> {
364363
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
365364
check::Std,
366365
check::Rustc,
367-
check::CodegenBackend,
368366
check::Rustdoc
369367
),
370368
Kind::Test => describe!(
@@ -632,11 +630,6 @@ impl<'a> Builder<'a> {
632630
self.ensure(Libdir { compiler, target })
633631
}
634632

635-
pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
636-
self.sysroot_libdir(compiler, compiler.host)
637-
.with_file_name(self.config.rust_codegen_backends_dir.clone())
638-
}
639-
640633
/// Returns the compiler's libdir where it stores the dynamic libraries that
641634
/// it itself links against.
642635
///
@@ -707,15 +700,6 @@ impl<'a> Builder<'a> {
707700
}
708701
}
709702

710-
/// Gets the paths to all of the compiler's codegen backends.
711-
fn codegen_backends(&self, compiler: Compiler) -> impl Iterator<Item = PathBuf> {
712-
fs::read_dir(self.sysroot_codegen_backends(compiler))
713-
.into_iter()
714-
.flatten()
715-
.filter_map(Result::ok)
716-
.map(|entry| entry.path())
717-
}
718-
719703
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
720704
self.ensure(tool::Rustdoc { compiler })
721705
}
@@ -759,12 +743,6 @@ impl<'a> Builder<'a> {
759743
let mut cargo = Command::new(&self.initial_cargo);
760744
let out_dir = self.stage_out(compiler, mode);
761745

762-
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
763-
// so we need to explicitly clear out if they've been updated.
764-
for backend in self.codegen_backends(compiler) {
765-
self.clear_if_dirty(&out_dir, &backend);
766-
}
767-
768746
if cmd == "doc" || cmd == "rustdoc" {
769747
let my_out = match mode {
770748
// This is the intended out directory for compiler documentation.

src/bootstrap/check.rs

+3-63
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::compile::{run_cargo, std_cargo, rustc_cargo, rustc_cargo_env,
4-
add_to_sysroot};
3+
use crate::compile::{run_cargo, std_cargo, rustc_cargo, add_to_sysroot};
54
use crate::builder::{RunConfig, Builder, Kind, ShouldRun, Step};
65
use crate::tool::{prepare_tool_cargo, SourceType};
76
use crate::{Compiler, Mode};
8-
use crate::cache::{INTERNER, Interned};
7+
use crate::cache::Interned;
98
use std::path::PathBuf;
109

1110
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -97,7 +96,7 @@ impl Step for Rustc {
9796

9897
let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
9998
cargo_subcommand(builder.kind));
100-
rustc_cargo(builder, &mut cargo);
99+
rustc_cargo(builder, &mut cargo, target);
101100

102101
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
103102
run_cargo(builder,
@@ -113,55 +112,6 @@ impl Step for Rustc {
113112
}
114113
}
115114

116-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
117-
pub struct CodegenBackend {
118-
pub target: Interned<String>,
119-
pub backend: Interned<String>,
120-
}
121-
122-
impl Step for CodegenBackend {
123-
type Output = ();
124-
const ONLY_HOSTS: bool = true;
125-
const DEFAULT: bool = true;
126-
127-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
128-
run.all_krates("rustc_codegen_llvm")
129-
}
130-
131-
fn make_run(run: RunConfig<'_>) {
132-
let backend = run.builder.config.rust_codegen_backends.get(0);
133-
let backend = backend.cloned().unwrap_or_else(|| {
134-
INTERNER.intern_str("llvm")
135-
});
136-
run.builder.ensure(CodegenBackend {
137-
target: run.target,
138-
backend,
139-
});
140-
}
141-
142-
fn run(self, builder: &Builder<'_>) {
143-
let compiler = builder.compiler(0, builder.config.build);
144-
let target = self.target;
145-
let backend = self.backend;
146-
147-
builder.ensure(Rustc { target });
148-
149-
let mut cargo = builder.cargo(compiler, Mode::Codegen, target,
150-
cargo_subcommand(builder.kind));
151-
cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
152-
rustc_cargo_env(builder, &mut cargo);
153-
154-
// We won't build LLVM if it's not available, as it shouldn't affect `check`.
155-
156-
run_cargo(builder,
157-
cargo,
158-
args(builder.kind),
159-
&codegen_backend_stamp(builder, compiler, target, backend),
160-
vec![],
161-
true);
162-
}
163-
}
164-
165115
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
166116
pub struct Rustdoc {
167117
pub target: Interned<String>,
@@ -231,16 +181,6 @@ pub fn librustc_stamp(
231181
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
232182
}
233183

234-
/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
235-
/// compiler for the specified target and backend.
236-
fn codegen_backend_stamp(builder: &Builder<'_>,
237-
compiler: Compiler,
238-
target: Interned<String>,
239-
backend: Interned<String>) -> PathBuf {
240-
builder.cargo_out(compiler, Mode::Codegen, target)
241-
.join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
242-
}
243-
244184
/// Cargo's output path for rustdoc in a given stage, compiled by a particular
245185
/// compiler for the specified target.
246186
pub fn rustdoc_stamp(

0 commit comments

Comments
 (0)