Skip to content

Commit

Permalink
Rollup merge of #74787 - petrochenkov:rustllvm, r=cuviper
Browse files Browse the repository at this point in the history
Move `rustllvm` into `compiler/rustc_llvm`

The `rustllvm` directory is not self-contained, it contains C++ code built by a build script of the `rustc_llvm` crate which is then linked into that crate.
So it makes sense to make `rustllvm` a part of `rustc_llvm` and move it into its directory.
I replaced `rustllvm` with more obvious `llvm-wrapper` as the subdirectory name, but something like `llvm-adapter` would work as well, other suggestions are welcome.

To make things more confusing, the Rust side of FFI functions defined in `rustllvm` can be found in `rustc_codegen_llvm` rather than in `rustc_llvm`. Perhaps they need to be moved as well, but this PR doesn't do that.

The presence of multiple LLVM-related directories in `src` (`llvm-project`, `rustllvm`, `librustc_llvm`, `librustc_codegen_llvm` and their predecessors) historically confused me and made me wonder about their purpose.
With this PR we will have LLVM itself (`llvm-project`), a FFI crate (`rustc_llvm`, kind of `llvm-sys`) and a codegen backend crate using LLVM through the FFI crate (`rustc_codegen_llvm`).
  • Loading branch information
tmandry committed Sep 10, 2020
2 parents 97eb606 + 10d3f8a commit f09372a
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 27 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ __pycache__/
/mingw-build/
# Created by default with `src/ci/docker/run.sh`:
/obj/
/rustllvm/
/unicode-downloads
/target
# Generated by compiletest for incremental:
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rustc_fs_util = { path = "../rustc_fs_util" }
rustc_hir = { path = "../rustc_hir" }
rustc_incremental = { path = "../rustc_incremental" }
rustc_index = { path = "../rustc_index" }
rustc_llvm = { path = "../../src/librustc_llvm" }
rustc_llvm = { path = "../rustc_llvm" }
rustc_session = { path = "../rustc_session" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_target = { path = "../rustc_target" }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub enum DLLStorageClass {
DllExport = 2, // Function to be accessible from DLL.
}

/// Matches LLVMRustAttribute in rustllvm.h
/// Matches LLVMRustAttribute in LLVMWrapper.h
/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
/// though it is not ABI compatible (since it's a C++ enum)
#[repr(C)]
Expand Down Expand Up @@ -1705,7 +1705,7 @@ extern "C" {
PM: &PassManager<'_>,
);

// Stuff that's in rustllvm/ because it's not upstream yet.
// Stuff that's in llvm-wrapper/ because it's not upstream yet.

/// Opens an object file.
pub fn LLVMCreateObjectFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ name = "rustc_llvm"
version = "0.0.0"
edition = "2018"

[lib]
path = "lib.rs"

[features]
static-libstdcpp = []
emscripten = []
Expand All @@ -15,5 +12,5 @@ emscripten = []
libc = "0.2.73"

[build-dependencies]
build_helper = { path = "../build_helper" }
build_helper = { path = "../../src/build_helper" }
cc = "1.0.58"
16 changes: 8 additions & 8 deletions src/librustc_llvm/build.rs → compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ fn main() {
cfg.debug(false);
}

build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));
cfg.file("../rustllvm/PassWrapper.cpp")
.file("../rustllvm/RustWrapper.cpp")
.file("../rustllvm/ArchiveWrapper.cpp")
.file("../rustllvm/CoverageMappingWrapper.cpp")
.file("../rustllvm/Linker.cpp")
build_helper::rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper"));
cfg.file("llvm-wrapper/PassWrapper.cpp")
.file("llvm-wrapper/RustWrapper.cpp")
.file("llvm-wrapper/ArchiveWrapper.cpp")
.file("llvm-wrapper/CoverageMappingWrapper.cpp")
.file("llvm-wrapper/Linker.cpp")
.cpp(true)
.cpp_link_stdlib(None) // we handle this below
.compile("rustllvm");
.compile("llvm-wrapper");

let (llvm_kind, llvm_link_arg) = detect_llvm_link();

Expand Down Expand Up @@ -259,7 +259,7 @@ fn main() {
}

// Some LLVM linker flags (-L and -l) may be needed even when linking
// librustc_llvm, for example when using static libc++, we may need to
// rustc_llvm, for example when using static libc++, we may need to
// manually specify the library search path and -ldl -lpthread as link
// dependencies.
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "rustllvm.h"
#include "LLVMWrapper.h"

#include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "rustllvm.h"
#include "LLVMWrapper.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
#include "llvm/ProfileData/InstrProf.h"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "llvm/Linker/Linker.h"

#include "rustllvm.h"
#include "LLVMWrapper.h"

using namespace llvm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>
#include <set>

#include "rustllvm.h"
#include "LLVMWrapper.h"

#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "rustllvm.h"
#include "LLVMWrapper.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# this flag will indicate that this version check should not be done.
#version-check = true

# Link libstdc++ statically into the librustc_llvm instead of relying on a
# Link libstdc++ statically into the rustc_llvm instead of relying on a
# dynamic version to be available.
#static-libstdcpp = false

Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl<'a> Builder<'a> {
format!("CARGO_PROFILE_{}_{}", profile, name)
};

// See comment in librustc_llvm/build.rs for why this is necessary, largely llvm-config
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
// needs to not accidentally link to libLLVM in stage0/lib.
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
if let Some(e) = env::var_os(util::dylib_path_var()) {
Expand All @@ -829,9 +829,9 @@ impl<'a> Builder<'a> {
// scripts can do less work (i.e. not building/requiring LLVM).
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
// If we've not yet built LLVM, or it's stale, then bust
// the librustc_llvm cache. That will always work, even though it
// the rustc_llvm cache. That will always work, even though it
// may mean that on the next non-check build we'll need to rebuild
// librustc_llvm. But if LLVM is stale, that'll be a tiny amount
// rustc_llvm. But if LLVM is stale, that'll be a tiny amount
// of work comparitively, and we'd likely need to rebuild it anyway,
// so that's okay.
if crate::native::prebuilt_llvm_config(self, target).is_err() {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
}

// Pass down configuration from the LLVM build into the build of
// librustc_llvm and librustc_codegen_llvm.
// rustc_llvm and rustc_codegen_llvm.
//
// Note that this is disabled if LLVM itself is disabled or we're in a check
// build. If we are in a check build we still go ahead here presuming we've
Expand All @@ -579,7 +579,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
cargo.env("CFG_LLVM_ROOT", s);
}
// Some LLVM linker flags (-L and -l) may be needed to link librustc_llvm.
// Some LLVM linker flags (-L and -l) may be needed to link rustc_llvm.
if let Some(ref s) = builder.config.llvm_ldflags {
cargo.env("LLVM_LINKER_FLAGS", s);
}
Expand Down

0 comments on commit f09372a

Please sign in to comment.