about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--build_system/build_backend.rs7
-rw-r--r--build_system/build_sysroot.rs32
-rw-r--r--config.txt8
-rwxr-xr-xy.rs4
4 files changed, 28 insertions, 23 deletions
diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs
index db046be1866..1df2bcc4541 100644
--- a/build_system/build_backend.rs
+++ b/build_system/build_backend.rs
@@ -1,9 +1,10 @@
 use std::env;
+use std::path::{Path, PathBuf};
 use std::process::Command;
 
-pub(crate) fn build_backend(channel: &str) -> String {
+pub(crate) fn build_backend(channel: &str, host_triple: &str) -> PathBuf {
     let mut cmd = Command::new("cargo");
-    cmd.arg("build");
+    cmd.arg("build").arg("--target").arg(host_triple);
 
     match channel {
         "debug" => {}
@@ -35,5 +36,5 @@ pub(crate) fn build_backend(channel: &str) -> String {
     eprintln!("[BUILD] rustc_codegen_cranelift");
     crate::utils::spawn_and_wait(cmd);
 
-    crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
+    Path::new("target").join(host_triple).join(channel)
 }
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index 00735ac1493..9fb88c27961 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -1,6 +1,6 @@
 use std::env;
 use std::fs;
-use std::path::Path;
+use std::path::{Path, PathBuf};
 use std::process::{self, Command};
 
 use crate::rustc_info::{get_file_name, get_rustc_version};
@@ -11,7 +11,7 @@ pub(crate) fn build_sysroot(
     channel: &str,
     sysroot_kind: SysrootKind,
     target_dir: &Path,
-    cg_clif_dylib: String,
+    cg_clif_build_dir: PathBuf,
     host_triple: &str,
     target_triple: &str,
 ) {
@@ -24,24 +24,24 @@ pub(crate) fn build_sysroot(
     // Copy the backend
     for file in ["cg_clif", "cg_clif_build_sysroot"] {
         try_hard_link(
-            Path::new("target").join(channel).join(get_file_name(file, "bin")),
+            cg_clif_build_dir.join(get_file_name(file, "bin")),
             target_dir.join("bin").join(get_file_name(file, "bin")),
         );
     }
 
-    if cfg!(windows) {
-        // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
-        // binaries.
-        try_hard_link(
-            Path::new("target").join(channel).join(&cg_clif_dylib),
-            target_dir.join("bin").join(cg_clif_dylib),
-        );
-    } else {
-        try_hard_link(
-            Path::new("target").join(channel).join(&cg_clif_dylib),
-            target_dir.join("lib").join(cg_clif_dylib),
-        );
-    }
+    let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
+    try_hard_link(
+        cg_clif_build_dir.join(&cg_clif_dylib),
+        target_dir
+            .join(if cfg!(windows) {
+                // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
+                // binaries.
+                "bin"
+            } else {
+                "lib"
+            })
+            .join(cg_clif_dylib),
+    );
 
     // Build and copy cargo wrapper
     let mut build_cargo_wrapper_cmd = Command::new("rustc");
diff --git a/config.txt b/config.txt
index c5fd7beb747..b14db27d620 100644
--- a/config.txt
+++ b/config.txt
@@ -1,9 +1,13 @@
 # This file allows configuring the build system.
 
-# The host triple
+# Which triple to produce a compiler toolchain for.
+#
+# Defaults to the default triple of rustc on the host system.
 #host = x86_64-unknown-linux-gnu
 
-# The target triple
+# Which triple to build libraries (core/alloc/std/test/proc_macro) for.
+#
+# Defaults to `host`.
 #target = x86_64-unknown-linux-gnu
 
 # Disables cleaning of the sysroot dir. This will cause old compiled artifacts to be re-used when
diff --git a/y.rs b/y.rs
index aeaac59fff0..43937588b48 100755
--- a/y.rs
+++ b/y.rs
@@ -141,12 +141,12 @@ fn main() {
         process::exit(1);
     }
 
-    let cg_clif_dylib = build_backend::build_backend(channel);
+    let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple);
     build_sysroot::build_sysroot(
         channel,
         sysroot_kind,
         &target_dir,
-        cg_clif_dylib,
+        cg_clif_build_dir,
         &host_triple,
         &target_triple,
     );