Skip to content

Commit f3ebf4f

Browse files
authored
Rollup merge of #106000 - nikic:lld-build, r=Mark-Simulacrum
Make LLD build forward-compatible with LLVM 16 Switch to using the cmake module instead of llvm-config. I believe this also removes the need for llvm-config-wrapper.
2 parents db5280a + 6733a3f commit f3ebf4f

File tree

4 files changed

+8
-74
lines changed

4 files changed

+8
-74
lines changed

src/bootstrap/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ name = "sccache-plus-cl"
2929
path = "bin/sccache-plus-cl.rs"
3030
test = false
3131

32-
[[bin]]
33-
name = "llvm-config-wrapper"
34-
path = "bin/llvm-config-wrapper.rs"
35-
test = false
36-
3732
[dependencies]
3833
cmake = "0.1.38"
3934
fd-lock = "3.0.8"

src/bootstrap/bin/llvm-config-wrapper.rs

-24
This file was deleted.

src/bootstrap/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ impl Step for Bootstrap {
21372137
let tarball = Tarball::new(builder, "bootstrap", &target.triple);
21382138

21392139
let bootstrap_outdir = &builder.bootstrap_out;
2140-
for file in &["bootstrap", "llvm-config-wrapper", "rustc", "rustdoc", "sccache-plus-cl"] {
2140+
for file in &["bootstrap", "rustc", "rustdoc", "sccache-plus-cl"] {
21412141
tarball.add_file(bootstrap_outdir.join(exe(file, target)), "bootstrap/bin", 0o755);
21422142
}
21432143

src/bootstrap/native.rs

+7-44
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,12 @@ impl Step for Lld {
804804
let target = self.target;
805805

806806
let llvm_config = builder.ensure(Llvm { target: self.target });
807+
let mut llvm_cmake_dir = llvm_config;
808+
llvm_cmake_dir.pop();
809+
llvm_cmake_dir.pop();
810+
llvm_cmake_dir.push("lib");
811+
llvm_cmake_dir.push("cmake");
812+
llvm_cmake_dir.push("llvm");
807813

808814
let out_dir = builder.lld_out(target);
809815
let done_stamp = out_dir.join("lld-finished-building");
@@ -834,22 +840,6 @@ impl Step for Lld {
834840
configure_cmake(builder, target, &mut cfg, true, ldflags);
835841
configure_llvm(builder, target, &mut cfg);
836842

837-
// This is an awful, awful hack. Discovered when we migrated to using
838-
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
839-
// tree, will execute `llvm-config --cmakedir` and then tell CMake about
840-
// that directory for later processing. Unfortunately if this path has
841-
// forward slashes in it (which it basically always does on Windows)
842-
// then CMake will hit a syntax error later on as... something isn't
843-
// escaped it seems?
844-
//
845-
// Instead of attempting to fix this problem in upstream CMake and/or
846-
// LLVM/LLD we just hack around it here. This thin wrapper will take the
847-
// output from llvm-config and replace all instances of `\` with `/` to
848-
// ensure we don't hit the same bugs with escaping. It means that you
849-
// can't build on a system where your paths require `\` on Windows, but
850-
// there's probably a lot of reasons you can't do that other than this.
851-
let llvm_config_shim = env::current_exe().unwrap().with_file_name("llvm-config-wrapper");
852-
853843
// Re-use the same flags as llvm to control the level of debug information
854844
// generated for lld.
855845
let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
@@ -860,36 +850,9 @@ impl Step for Lld {
860850

861851
cfg.out_dir(&out_dir)
862852
.profile(profile)
863-
.env("LLVM_CONFIG_REAL", &llvm_config)
864-
.define("LLVM_CONFIG_PATH", llvm_config_shim)
853+
.define("LLVM_CMAKE_DIR", llvm_cmake_dir)
865854
.define("LLVM_INCLUDE_TESTS", "OFF");
866855

867-
// While we're using this horrible workaround to shim the execution of
868-
// llvm-config, let's just pile on more. I can't seem to figure out how
869-
// to build LLD as a standalone project and also cross-compile it at the
870-
// same time. It wants a natively executable `llvm-config` to learn
871-
// about LLVM, but then it learns about all the host configuration of
872-
// LLVM and tries to link to host LLVM libraries.
873-
//
874-
// To work around that we tell our shim to replace anything with the
875-
// build target with the actual target instead. This'll break parts of
876-
// LLD though which try to execute host tools, such as llvm-tblgen, so
877-
// we specifically tell it where to find those. This is likely super
878-
// brittle and will break over time. If anyone knows better how to
879-
// cross-compile LLD it would be much appreciated to fix this!
880-
if target != builder.config.build {
881-
cfg.env("LLVM_CONFIG_SHIM_REPLACE", &builder.config.build.triple)
882-
.env("LLVM_CONFIG_SHIM_REPLACE_WITH", &target.triple)
883-
.define(
884-
"LLVM_TABLEGEN_EXE",
885-
llvm_config.with_file_name("llvm-tblgen").with_extension(EXE_EXTENSION),
886-
);
887-
}
888-
889-
// Explicitly set C++ standard, because upstream doesn't do so
890-
// for standalone builds.
891-
cfg.define("CMAKE_CXX_STANDARD", "14");
892-
893856
cfg.build();
894857

895858
t!(File::create(&done_stamp));

0 commit comments

Comments
 (0)