Skip to content

Commit adfda1f

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 f6840f3 commit adfda1f

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

+159
-415
lines changed

Cargo.lock

+19
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,25 @@ dependencies = [
34963496
name = "rustc_codegen_llvm"
34973497
version = "0.0.0"
34983498
dependencies = [
3499+
"bitflags",
3500+
"flate2",
3501+
"libc",
3502+
"log",
3503+
"rustc",
3504+
"rustc-demangle",
3505+
"rustc_codegen_ssa",
3506+
"rustc_codegen_utils",
3507+
"rustc_data_structures",
3508+
"rustc_errors",
3509+
"rustc_fs_util",
3510+
"rustc_incremental",
3511+
"rustc_index",
34993512
"rustc_llvm",
3513+
"rustc_target",
3514+
"smallvec 0.6.10",
3515+
"syntax",
3516+
"syntax_expand",
3517+
"syntax_pos",
35003518
]
35013519

35023520
[[package]]
@@ -3658,6 +3676,7 @@ dependencies = [
36583676
"once_cell",
36593677
"rustc",
36603678
"rustc-rayon 0.3.0",
3679+
"rustc_codegen_llvm",
36613680
"rustc_codegen_ssa",
36623681
"rustc_codegen_utils",
36633682
"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!(
@@ -631,11 +629,6 @@ impl<'a> Builder<'a> {
631629
self.ensure(Libdir { compiler, target })
632630
}
633631

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

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

761-
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
762-
// so we need to explicitly clear out if they've been updated.
763-
for backend in self.codegen_backends(compiler) {
764-
self.clear_if_dirty(&out_dir, &backend);
765-
}
766-
767745
if cmd == "doc" || cmd == "rustdoc" {
768746
let my_out = match mode {
769747
// 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)