Skip to content

Commit cc9dea4

Browse files
authored
Rollup merge of #54558 - tromey:find-filecheck, r=nikomatsakis
Improvements to finding LLVM's FileCheck This patch adds a few improvements to how the build system finds LLVM's FileCheck program. * On Fedora, the system LLVM installs FileCheck in the "llvm" subdirectory of the LLVM libdir. This patch teaches the build system to look there. * This adds a configure option to specify which llvm-config executable to use. This is handy on systems that can parallel install multiple versions of LLVM; for example I can now: ./configure --llvm-config=/bin/llvm-config-5.0-64 ... to build against LLVM 5, rather than whatever the default llvm-config might be. * Finally, this adds a configure- and config.toml- option to set the path to FileCheck. This is handy when building against an LLVM where FileCheck was not installed. This happens on compatibility installs of LLVM on Fedora.
2 parents 4ceeec0 + f4b4939 commit cc9dea4

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

config.toml.example

+5
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322

323323
# Flag indicating whether codegen tests will be run or not. If you get an error
324324
# saying that the FileCheck executable is missing, you may want to disable this.
325+
# Also see the target's llvm-filecheck option.
325326
#codegen-tests = true
326327

327328
# Flag indicating whether git info will be retrieved from .git automatically.
@@ -416,6 +417,10 @@
416417
# target.
417418
#llvm-config = "../path/to/llvm/root/bin/llvm-config"
418419

420+
# Normally the build system can find LLVM's FileCheck utility, but if
421+
# not, you can specify an explicit file name for it.
422+
#llvm-filecheck = "/path/to/FileCheck"
423+
419424
# Path to the custom jemalloc static library to link into the standard library
420425
# by default. This is only used if jemalloc is still enabled above
421426
#jemalloc = "/path/to/jemalloc/libjemalloc_pic.a"

src/bootstrap/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pub struct Config {
162162
pub struct Target {
163163
/// Some(path to llvm-config) if using an external LLVM.
164164
pub llvm_config: Option<PathBuf>,
165+
/// Some(path to FileCheck) if one was specified.
166+
pub llvm_filecheck: Option<PathBuf>,
165167
pub jemalloc: Option<PathBuf>,
166168
pub cc: Option<PathBuf>,
167169
pub cxx: Option<PathBuf>,
@@ -330,6 +332,7 @@ struct Rust {
330332
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
331333
struct TomlTarget {
332334
llvm_config: Option<String>,
335+
llvm_filecheck: Option<String>,
333336
jemalloc: Option<String>,
334337
cc: Option<String>,
335338
cxx: Option<String>,
@@ -583,6 +586,9 @@ impl Config {
583586
if let Some(ref s) = cfg.llvm_config {
584587
target.llvm_config = Some(config.src.join(s));
585588
}
589+
if let Some(ref s) = cfg.llvm_filecheck {
590+
target.llvm_filecheck = Some(config.src.join(s));
591+
}
586592
if let Some(ref s) = cfg.jemalloc {
587593
target.jemalloc = Some(config.src.join(s));
588594
}

src/bootstrap/configure.py

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def v(*args):
9595
v("bindir", "install.bindir", "install binaries")
9696

9797
v("llvm-root", None, "set LLVM root")
98+
v("llvm-config", None, "set path to llvm-config")
99+
v("llvm-filecheck", None, "set path to LLVM's FileCheck utility")
98100
v("python", "build.python", "set path to python")
99101
v("jemalloc-root", None, "set directory where libjemalloc_pic.a is located")
100102
v("android-cross-path", "target.arm-linux-androideabi.android-ndk",
@@ -323,6 +325,10 @@ def set(key, value):
323325
set('build.cargo', value + '/bin/cargo')
324326
elif option.name == 'llvm-root':
325327
set('target.{}.llvm-config'.format(build()), value + '/bin/llvm-config')
328+
elif option.name == 'llvm-config':
329+
set('target.{}.llvm-config'.format(build()), value)
330+
elif option.name == 'llvm-filecheck':
331+
set('target.{}.llvm-filecheck'.format(build()), value)
326332
elif option.name == 'jemalloc-root':
327333
set('target.{}.jemalloc'.format(build()), value + '/libjemalloc_pic.a')
328334
elif option.name == 'tools':

src/bootstrap/lib.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,28 @@ impl Build {
641641
/// Returns the path to `FileCheck` binary for the specified target
642642
fn llvm_filecheck(&self, target: Interned<String>) -> PathBuf {
643643
let target_config = self.config.target_config.get(&target);
644-
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
644+
if let Some(s) = target_config.and_then(|c| c.llvm_filecheck.as_ref()) {
645+
s.to_path_buf()
646+
} else if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
645647
let llvm_bindir = output(Command::new(s).arg("--bindir"));
646-
Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target))
648+
let filecheck = Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target));
649+
if filecheck.exists() {
650+
filecheck
651+
} else {
652+
// On Fedora the system LLVM installs FileCheck in the
653+
// llvm subdirectory of the libdir.
654+
let llvm_libdir = output(Command::new(s).arg("--libdir"));
655+
let lib_filecheck = Path::new(llvm_libdir.trim())
656+
.join("llvm").join(exe("FileCheck", &*target));
657+
if lib_filecheck.exists() {
658+
lib_filecheck
659+
} else {
660+
// Return the most normal file name, even though
661+
// it doesn't exist, so that any error message
662+
// refers to that.
663+
filecheck
664+
}
665+
}
647666
} else {
648667
let base = self.llvm_out(self.config.build).join("build");
649668
let base = if !self.config.ninja && self.config.build.contains("msvc") {

0 commit comments

Comments
 (0)