about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-09-25 22:34:51 +0200
committerGitHub <noreply@github.com>2018-09-25 22:34:51 +0200
commitcc9dea43be5ab201421b41dbb027f6ba36973cac (patch)
tree898f79af831dc3687a9693814cbe7674c81d7283
parent4ceeec09efa468700768a21d71bb92d733728887 (diff)
parentf4b4939f3e024c53355d4f99c0762135a613dae0 (diff)
downloadrust-cc9dea43be5ab201421b41dbb027f6ba36973cac.tar.gz
rust-cc9dea43be5ab201421b41dbb027f6ba36973cac.zip
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.
-rw-r--r--config.toml.example5
-rw-r--r--src/bootstrap/config.rs6
-rwxr-xr-xsrc/bootstrap/configure.py6
-rw-r--r--src/bootstrap/lib.rs23
4 files changed, 38 insertions, 2 deletions
diff --git a/config.toml.example b/config.toml.example
index 3159c19528a..66eaab236f7 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -322,6 +322,7 @@
 
 # Flag indicating whether codegen tests will be run or not. If you get an error
 # saying that the FileCheck executable is missing, you may want to disable this.
+# Also see the target's llvm-filecheck option.
 #codegen-tests = true
 
 # Flag indicating whether git info will be retrieved from .git automatically.
@@ -416,6 +417,10 @@
 # target.
 #llvm-config = "../path/to/llvm/root/bin/llvm-config"
 
+# Normally the build system can find LLVM's FileCheck utility, but if
+# not, you can specify an explicit file name for it.
+#llvm-filecheck = "/path/to/FileCheck"
+
 # Path to the custom jemalloc static library to link into the standard library
 # by default. This is only used if jemalloc is still enabled above
 #jemalloc = "/path/to/jemalloc/libjemalloc_pic.a"
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index cc6d76c76f2..3a4bc526d03 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -162,6 +162,8 @@ pub struct Config {
 pub struct Target {
     /// Some(path to llvm-config) if using an external LLVM.
     pub llvm_config: Option<PathBuf>,
+    /// Some(path to FileCheck) if one was specified.
+    pub llvm_filecheck: Option<PathBuf>,
     pub jemalloc: Option<PathBuf>,
     pub cc: Option<PathBuf>,
     pub cxx: Option<PathBuf>,
@@ -330,6 +332,7 @@ struct Rust {
 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
 struct TomlTarget {
     llvm_config: Option<String>,
+    llvm_filecheck: Option<String>,
     jemalloc: Option<String>,
     cc: Option<String>,
     cxx: Option<String>,
@@ -583,6 +586,9 @@ impl Config {
                 if let Some(ref s) = cfg.llvm_config {
                     target.llvm_config = Some(config.src.join(s));
                 }
+                if let Some(ref s) = cfg.llvm_filecheck {
+                    target.llvm_filecheck = Some(config.src.join(s));
+                }
                 if let Some(ref s) = cfg.jemalloc {
                     target.jemalloc = Some(config.src.join(s));
                 }
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index cf7f78eeba0..75831dbe262 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -95,6 +95,8 @@ v("docdir", "install.docdir", "install documentation in PATH")
 v("bindir", "install.bindir", "install binaries")
 
 v("llvm-root", None, "set LLVM root")
+v("llvm-config", None, "set path to llvm-config")
+v("llvm-filecheck", None, "set path to LLVM's FileCheck utility")
 v("python", "build.python", "set path to python")
 v("jemalloc-root", None, "set directory where libjemalloc_pic.a is located")
 v("android-cross-path", "target.arm-linux-androideabi.android-ndk",
@@ -323,6 +325,10 @@ for key in known_args:
         set('build.cargo', value + '/bin/cargo')
     elif option.name == 'llvm-root':
         set('target.{}.llvm-config'.format(build()), value + '/bin/llvm-config')
+    elif option.name == 'llvm-config':
+        set('target.{}.llvm-config'.format(build()), value)
+    elif option.name == 'llvm-filecheck':
+        set('target.{}.llvm-filecheck'.format(build()), value)
     elif option.name == 'jemalloc-root':
         set('target.{}.jemalloc'.format(build()), value + '/libjemalloc_pic.a')
     elif option.name == 'tools':
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 6b88516bacd..75c18cd2dd4 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -641,9 +641,28 @@ impl Build {
     /// Returns the path to `FileCheck` binary for the specified target
     fn llvm_filecheck(&self, target: Interned<String>) -> PathBuf {
         let target_config = self.config.target_config.get(&target);
-        if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
+        if let Some(s) = target_config.and_then(|c| c.llvm_filecheck.as_ref()) {
+            s.to_path_buf()
+        } else if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
             let llvm_bindir = output(Command::new(s).arg("--bindir"));
-            Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target))
+            let filecheck = Path::new(llvm_bindir.trim()).join(exe("FileCheck", &*target));
+            if filecheck.exists() {
+                filecheck
+            } else {
+                // On Fedora the system LLVM installs FileCheck in the
+                // llvm subdirectory of the libdir.
+                let llvm_libdir = output(Command::new(s).arg("--libdir"));
+                let lib_filecheck = Path::new(llvm_libdir.trim())
+                    .join("llvm").join(exe("FileCheck", &*target));
+                if lib_filecheck.exists() {
+                    lib_filecheck
+                } else {
+                    // Return the most normal file name, even though
+                    // it doesn't exist, so that any error message
+                    // refers to that.
+                    filecheck
+                }
+            }
         } else {
             let base = self.llvm_out(self.config.build).join("build");
             let base = if !self.config.ninja && self.config.build.contains("msvc") {