about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-15 11:01:02 -0700
committerGitHub <noreply@github.com>2020-07-15 11:01:02 -0700
commitaf3d4cb936592ba53593ba869213c1af61b4166f (patch)
tree51d3b37f5a0d085af88b595b09ffa18539e79d0a /src/bootstrap
parent7e11379f3b4c376fbb9a6c4d44f3286ccc28d149 (diff)
parent933ba82266da94a812cc3052c6b91b7f8f5b4c35 (diff)
downloadrust-af3d4cb936592ba53593ba869213c1af61b4166f.tar.gz
rust-af3d4cb936592ba53593ba869213c1af61b4166f.zip
Rollup merge of #72973 - msizanoen1:riscv-host, r=pietroalbini
RISC-V GNU/Linux as host platform

This PR add a new builder named `dist-riscv64-linux` that builds the compiler toolchain for RISC-V 64-bit GNU/Linux.

r? @alexcrichton
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/native.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index ca0b3ddc920..b7c527f6712 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -112,6 +112,15 @@ impl Step for Llvm {
     /// Compile LLVM for `target`.
     fn run(self, builder: &Builder<'_>) -> PathBuf {
         let target = self.target;
+        let target_native = if self.target.starts_with("riscv") {
+            // RISC-V target triples in Rust is not named the same as C compiler target triples.
+            // This converts Rust RISC-V target triples to C compiler triples.
+            let idx = target.find('-').unwrap();
+
+            format!("riscv{}{}", &target[5..7], &target[idx..])
+        } else {
+            target.to_string()
+        };
 
         let Meta { stamp, build_llvm_config, out_dir, root } =
             match prebuilt_llvm_config(builder, target) {
@@ -165,8 +174,8 @@ impl Step for Llvm {
             .define("LLVM_ENABLE_BINDINGS", "OFF")
             .define("LLVM_ENABLE_Z3_SOLVER", "OFF")
             .define("LLVM_PARALLEL_COMPILE_JOBS", builder.jobs().to_string())
-            .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
-            .define("LLVM_DEFAULT_TARGET_TRIPLE", target);
+            .define("LLVM_TARGET_ARCH", target_native.split('-').next().unwrap())
+            .define("LLVM_DEFAULT_TARGET_TRIPLE", target_native);
 
         if !target.contains("netbsd") {
             cfg.define("LLVM_ENABLE_ZLIB", "ON");
@@ -213,6 +222,17 @@ impl Step for Llvm {
             }
         }
 
+        if target.starts_with("riscv") {
+            // In RISC-V, using C++ atomics require linking to `libatomic` but the LLVM build
+            // system check cannot detect this. Therefore it is set manually here.
+            if !builder.config.llvm_tools_enabled {
+                cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic");
+            } else {
+                cfg.define("CMAKE_EXE_LINKER_FLAGS", "-latomic -static-libstdc++");
+            }
+            cfg.define("CMAKE_SHARED_LINKER_FLAGS", "-latomic");
+        }
+
         if target.contains("msvc") {
             cfg.define("LLVM_USE_CRT_DEBUG", "MT");
             cfg.define("LLVM_USE_CRT_RELEASE", "MT");