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

rustc: Link LLVM directly into rustc again #65703

Closed
Closed
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
19 changes: 19 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,25 @@ dependencies = [
name = "rustc_codegen_llvm"
version = "0.0.0"
dependencies = [
"bitflags",
"flate2",
"libc",
"log",
"rustc",
"rustc-demangle",
"rustc_codegen_ssa",
"rustc_codegen_utils",
"rustc_data_structures",
"rustc_errors",
"rustc_fs_util",
"rustc_incremental",
"rustc_index",
"rustc_llvm",
"rustc_target",
"smallvec 0.6.10",
"syntax",
"syntax_expand",
"syntax_pos",
]

[[package]]
Expand Down Expand Up @@ -3563,6 +3581,7 @@ dependencies = [
"once_cell",
"rustc",
"rustc-rayon 0.3.0",
"rustc_codegen_llvm",
"rustc_codegen_ssa",
"rustc_codegen_utils",
"rustc_data_structures",
Expand Down
3 changes: 0 additions & 3 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@
# and currently the only standard option supported is `"llvm"`
#codegen-backends = ["llvm"]
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm, this one still works? Or do I need to use llvm.enabled instead?

Copy link
Member

Choose a reason for hiding this comment

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

It would also be nice if this would automatically pass a feature flag for every item, even unknown ones, so adding a codegen backend is as easy as adding a few crate features, adding optional deps, and changing rustc_interface to recognize the -Zcodegen-backend value for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be the case that setting this to the empty array should work. I'll leave it to future PRs though to continue to tweak how multiple codegen backends work.


# This is the name of the directory in which codegen backends will get installed
#codegen-backends-dir = "codegen-backends"

# Indicates whether LLD will be compiled and made available in the sysroot for
# rustc to execute.
#lld = false
Expand Down
22 changes: 0 additions & 22 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ impl<'a> Builder<'a> {
Kind::Build => describe!(
compile::Std,
compile::Rustc,
compile::CodegenBackend,
compile::StartupObjects,
tool::BuildManifest,
tool::Rustbook,
Expand All @@ -364,7 +363,6 @@ impl<'a> Builder<'a> {
Kind::Check | Kind::Clippy | Kind::Fix => describe!(
check::Std,
check::Rustc,
check::CodegenBackend,
check::Rustdoc
),
Kind::Test => describe!(
Expand Down Expand Up @@ -631,11 +629,6 @@ impl<'a> Builder<'a> {
self.ensure(Libdir { compiler, target })
}

pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
self.sysroot_libdir(compiler, compiler.host)
.with_file_name(self.config.rust_codegen_backends_dir.clone())
}

/// Returns the compiler's libdir where it stores the dynamic libraries that
/// it itself links against.
///
Expand Down Expand Up @@ -706,15 +699,6 @@ impl<'a> Builder<'a> {
}
}

/// Gets the paths to all of the compiler's codegen backends.
fn codegen_backends(&self, compiler: Compiler) -> impl Iterator<Item = PathBuf> {
fs::read_dir(self.sysroot_codegen_backends(compiler))
.into_iter()
.flatten()
.filter_map(Result::ok)
.map(|entry| entry.path())
}

pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
self.ensure(tool::Rustdoc { compiler })
}
Expand Down Expand Up @@ -758,12 +742,6 @@ impl<'a> Builder<'a> {
let mut cargo = Command::new(&self.initial_cargo);
let out_dir = self.stage_out(compiler, mode);

// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
// so we need to explicitly clear out if they've been updated.
for backend in self.codegen_backends(compiler) {
self.clear_if_dirty(&out_dir, &backend);
}

if cmd == "doc" || cmd == "rustdoc" {
let my_out = match mode {
// This is the intended out directory for compiler documentation.
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ fn dist_with_same_targets_and_hosts() {
compiler: Compiler { host: a, stage: 1 },
target: b,
},
compile::Std {
compiler: Compiler { host: a, stage: 2 },
target: b,
},
]
);
assert_eq!(
Expand Down
66 changes: 3 additions & 63 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.

use crate::compile::{run_cargo, std_cargo, rustc_cargo, rustc_cargo_env,
add_to_sysroot};
use crate::compile::{run_cargo, std_cargo, rustc_cargo, add_to_sysroot};
use crate::builder::{RunConfig, Builder, Kind, ShouldRun, Step};
use crate::tool::{prepare_tool_cargo, SourceType};
use crate::{Compiler, Mode};
use crate::cache::{INTERNER, Interned};
use crate::cache::Interned;
use std::path::PathBuf;

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

let mut cargo = builder.cargo(compiler, Mode::Rustc, target,
cargo_subcommand(builder.kind));
rustc_cargo(builder, &mut cargo);
rustc_cargo(builder, &mut cargo, target);

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

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct CodegenBackend {
pub target: Interned<String>,
pub backend: Interned<String>,
}

impl Step for CodegenBackend {
type Output = ();
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.all_krates("rustc_codegen_llvm")
}

fn make_run(run: RunConfig<'_>) {
let backend = run.builder.config.rust_codegen_backends.get(0);
let backend = backend.cloned().unwrap_or_else(|| {
INTERNER.intern_str("llvm")
});
run.builder.ensure(CodegenBackend {
target: run.target,
backend,
});
}

fn run(self, builder: &Builder<'_>) {
let compiler = builder.compiler(0, builder.config.build);
let target = self.target;
let backend = self.backend;

builder.ensure(Rustc { target });

let mut cargo = builder.cargo(compiler, Mode::Codegen, target,
cargo_subcommand(builder.kind));
cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
rustc_cargo_env(builder, &mut cargo);

// We won't build LLVM if it's not available, as it shouldn't affect `check`.

run_cargo(builder,
cargo,
args(builder.kind),
&codegen_backend_stamp(builder, compiler, target, backend),
vec![],
true);
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Rustdoc {
pub target: Interned<String>,
Expand Down Expand Up @@ -231,16 +181,6 @@ pub fn librustc_stamp(
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
}

/// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
/// compiler for the specified target and backend.
fn codegen_backend_stamp(builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
backend: Interned<String>) -> PathBuf {
builder.cargo_out(compiler, Mode::Codegen, target)
.join(format!(".librustc_codegen_llvm-{}-check.stamp", backend))
}

/// Cargo's output path for rustdoc in a given stage, compiled by a particular
/// compiler for the specified target.
pub fn rustdoc_stamp(
Expand Down
Loading