Skip to content

Commit f09372a

Browse files
authored
Rollup merge of #74787 - petrochenkov:rustllvm, r=cuviper
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`).
2 parents 97eb606 + 10d3f8a commit f09372a

17 files changed

+23
-27
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ __pycache__/
3333
/mingw-build/
3434
# Created by default with `src/ci/docker/run.sh`:
3535
/obj/
36-
/rustllvm/
3736
/unicode-downloads
3837
/target
3938
# Generated by compiletest for incremental:

compiler/rustc_codegen_llvm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rustc_fs_util = { path = "../rustc_fs_util" }
2525
rustc_hir = { path = "../rustc_hir" }
2626
rustc_incremental = { path = "../rustc_incremental" }
2727
rustc_index = { path = "../rustc_index" }
28-
rustc_llvm = { path = "../../src/librustc_llvm" }
28+
rustc_llvm = { path = "../rustc_llvm" }
2929
rustc_session = { path = "../rustc_session" }
3030
rustc_serialize = { path = "../rustc_serialize" }
3131
rustc_target = { path = "../rustc_target" }

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub enum DLLStorageClass {
9696
DllExport = 2, // Function to be accessible from DLL.
9797
}
9898

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

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

17101710
/// Opens an object file.
17111711
pub fn LLVMCreateObjectFile(

src/librustc_llvm/Cargo.toml compiler/rustc_llvm/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ name = "rustc_llvm"
44
version = "0.0.0"
55
edition = "2018"
66

7-
[lib]
8-
path = "lib.rs"
9-
107
[features]
118
static-libstdcpp = []
129
emscripten = []
@@ -15,5 +12,5 @@ emscripten = []
1512
libc = "0.2.73"
1613

1714
[build-dependencies]
18-
build_helper = { path = "../build_helper" }
15+
build_helper = { path = "../../src/build_helper" }
1916
cc = "1.0.58"

src/librustc_llvm/build.rs compiler/rustc_llvm/build.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ fn main() {
175175
cfg.debug(false);
176176
}
177177

178-
build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));
179-
cfg.file("../rustllvm/PassWrapper.cpp")
180-
.file("../rustllvm/RustWrapper.cpp")
181-
.file("../rustllvm/ArchiveWrapper.cpp")
182-
.file("../rustllvm/CoverageMappingWrapper.cpp")
183-
.file("../rustllvm/Linker.cpp")
178+
build_helper::rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper"));
179+
cfg.file("llvm-wrapper/PassWrapper.cpp")
180+
.file("llvm-wrapper/RustWrapper.cpp")
181+
.file("llvm-wrapper/ArchiveWrapper.cpp")
182+
.file("llvm-wrapper/CoverageMappingWrapper.cpp")
183+
.file("llvm-wrapper/Linker.cpp")
184184
.cpp(true)
185185
.cpp_link_stdlib(None) // we handle this below
186-
.compile("rustllvm");
186+
.compile("llvm-wrapper");
187187

188188
let (llvm_kind, llvm_link_arg) = detect_llvm_link();
189189

@@ -259,7 +259,7 @@ fn main() {
259259
}
260260

261261
// Some LLVM linker flags (-L and -l) may be needed even when linking
262-
// librustc_llvm, for example when using static libc++, we may need to
262+
// rustc_llvm, for example when using static libc++, we may need to
263263
// manually specify the library search path and -ldl -lpthread as link
264264
// dependencies.
265265
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
File renamed without changes.

src/rustllvm/ArchiveWrapper.cpp compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22

33
#include "llvm/Object/Archive.h"
44
#include "llvm/Object/ArchiveWriter.h"

src/rustllvm/CoverageMappingWrapper.cpp compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
33
#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
44
#include "llvm/ProfileData/InstrProf.h"
File renamed without changes.

src/rustllvm/Linker.cpp compiler/rustc_llvm/llvm-wrapper/Linker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "llvm/Linker/Linker.h"
22

3-
#include "rustllvm.h"
3+
#include "LLVMWrapper.h"
44

55
using namespace llvm;
66

src/rustllvm/PassWrapper.cpp compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44
#include <set>
55

6-
#include "rustllvm.h"
6+
#include "LLVMWrapper.h"
77

88
#include "llvm/Analysis/TargetLibraryInfo.h"
99
#include "llvm/Analysis/TargetTransformInfo.h"
File renamed without changes.

src/rustllvm/RustWrapper.cpp compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "rustllvm.h"
1+
#include "LLVMWrapper.h"
22
#include "llvm/IR/DebugInfoMetadata.h"
33
#include "llvm/IR/DiagnosticInfo.h"
44
#include "llvm/IR/DiagnosticPrinter.h"
File renamed without changes.

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# this flag will indicate that this version check should not be done.
4646
#version-check = true
4747

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

src/bootstrap/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ impl<'a> Builder<'a> {
812812
format!("CARGO_PROFILE_{}_{}", profile, name)
813813
};
814814

815-
// See comment in librustc_llvm/build.rs for why this is necessary, largely llvm-config
815+
// See comment in rustc_llvm/build.rs for why this is necessary, largely llvm-config
816816
// needs to not accidentally link to libLLVM in stage0/lib.
817817
cargo.env("REAL_LIBRARY_PATH_VAR", &util::dylib_path_var());
818818
if let Some(e) = env::var_os(util::dylib_path_var()) {
@@ -829,9 +829,9 @@ impl<'a> Builder<'a> {
829829
// scripts can do less work (i.e. not building/requiring LLVM).
830830
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
831831
// If we've not yet built LLVM, or it's stale, then bust
832-
// the librustc_llvm cache. That will always work, even though it
832+
// the rustc_llvm cache. That will always work, even though it
833833
// may mean that on the next non-check build we'll need to rebuild
834-
// librustc_llvm. But if LLVM is stale, that'll be a tiny amount
834+
// rustc_llvm. But if LLVM is stale, that'll be a tiny amount
835835
// of work comparitively, and we'd likely need to rebuild it anyway,
836836
// so that's okay.
837837
if crate::native::prebuilt_llvm_config(self, target).is_err() {

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
560560
}
561561

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

0 commit comments

Comments
 (0)