about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-06-18 13:38:50 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2021-06-19 13:58:32 +0200
commite5563b50772e45dc2ad9111769f48d216570af71 (patch)
treef94c19f4bf3833949c6ecacf93ae86b2c3823c28
parent0d6b3dab658d76078741cc78b0bda1682b43a7ec (diff)
downloadrust-e5563b50772e45dc2ad9111769f48d216570af71.tar.gz
rust-e5563b50772e45dc2ad9111769f48d216570af71.zip
Improve windows support
-rw-r--r--build_system/build_backend.rs2
-rw-r--r--build_system/build_sysroot.rs35
-rw-r--r--build_system/prepare.rs18
-rw-r--r--build_system/rustc_info.rs22
4 files changed, 51 insertions, 26 deletions
diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs
index 81c47fa8358..db046be1866 100644
--- a/build_system/build_backend.rs
+++ b/build_system/build_backend.rs
@@ -35,5 +35,5 @@ pub(crate) fn build_backend(channel: &str) -> String {
     eprintln!("[BUILD] rustc_codegen_cranelift");
     crate::utils::spawn_and_wait(cmd);
 
-    crate::rustc_info::get_dylib_name("rustc_codegen_cranelift")
+    crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
 }
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index fb34875f50f..547159438e9 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -1,10 +1,12 @@
-use crate::utils::spawn_and_wait;
-use crate::utils::try_hard_link;
-use crate::SysrootKind;
+use std::env;
 use std::fs;
 use std::path::Path;
 use std::process::{self, Command};
 
+use crate::rustc_info::get_file_name;
+use crate::utils::{spawn_and_wait, try_hard_link};
+use crate::SysrootKind;
+
 pub(crate) fn build_sysroot(
     channel: &str,
     sysroot_kind: SysrootKind,
@@ -22,15 +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(file),
-            target_dir.join("bin").join(file),
+            Path::new("target").join(channel).join(get_file_name(file, "bin")),
+            target_dir.join("bin").join(get_file_name(file, "bin")),
         );
     }
 
-    try_hard_link(
-        Path::new("target").join(channel).join(&cg_clif_dylib),
-        target_dir.join("lib").join(cg_clif_dylib),
-    );
+    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),
+        );
+    }
 
     // Copy supporting files
     try_hard_link("rust-toolchain", target_dir.join("rust-toolchain"));
@@ -141,8 +152,10 @@ fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str)
         rustflags.push_str(" -Zmir-opt-level=3");
     }
     build_cmd.env("RUSTFLAGS", rustflags);
-    build_cmd
-        .env("RUSTC", target_dir.join("bin").join("cg_clif_build_sysroot").canonicalize().unwrap());
+    build_cmd.env(
+        "RUSTC",
+        env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"),
+    );
     // FIXME Enable incremental again once rust-lang/rust#74946 is fixed
     build_cmd.env("CARGO_INCREMENTAL", "0").env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
     spawn_and_wait(build_cmd);
diff --git a/build_system/prepare.rs b/build_system/prepare.rs
index b5011ceb159..d26f24f8856 100644
--- a/build_system/prepare.rs
+++ b/build_system/prepare.rs
@@ -1,13 +1,12 @@
+use std::env;
 use std::ffi::OsStr;
 use std::ffi::OsString;
 use std::fs;
 use std::path::Path;
-use std::path::PathBuf;
 use std::process::Command;
 
-use crate::rustc_info::get_rustc_path;
-use crate::utils::copy_dir_recursively;
-use crate::utils::spawn_and_wait;
+use crate::rustc_info::{get_file_name, get_rustc_path};
+use crate::utils::{copy_dir_recursively, spawn_and_wait};
 
 pub(crate) fn prepare() {
     prepare_sysroot();
@@ -38,13 +37,18 @@ pub(crate) fn prepare() {
     let mut build_cmd = Command::new("cargo");
     build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer");
     spawn_and_wait(build_cmd);
-    fs::copy("simple-raytracer/target/debug/main", "simple-raytracer/raytracer_cg_llvm").unwrap();
+    fs::copy(
+        Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
+        // FIXME use get_file_name here too once testing is migrated to rust
+        "simple-raytracer/raytracer_cg_llvm",
+    )
+    .unwrap();
 }
 
 fn prepare_sysroot() {
     let rustc_path = get_rustc_path();
     let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust");
-    let sysroot_src = PathBuf::from("build_sysroot").canonicalize().unwrap().join("sysroot_src");
+    let sysroot_src = env::current_dir().unwrap().join("build_sysroot").join("sysroot_src");
 
     assert!(sysroot_src_orig.exists());
 
@@ -114,7 +118,7 @@ fn get_patches(crate_name: &str) -> Vec<OsString> {
 fn apply_patches(crate_name: &str, target_dir: &Path) {
     for patch in get_patches(crate_name) {
         eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch);
-        let patch_arg = Path::new("patches").join(patch).canonicalize().unwrap();
+        let patch_arg = env::current_dir().unwrap().join("patches").join(patch);
         let mut apply_patch_cmd = Command::new("git");
         apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir);
         spawn_and_wait(apply_patch_cmd);
diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs
index f7f5d42fe09..3bf86d9a114 100644
--- a/build_system/rustc_info.rs
+++ b/build_system/rustc_info.rs
@@ -37,15 +37,23 @@ pub(crate) fn get_default_sysroot() -> PathBuf {
     Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned()
 }
 
-pub(crate) fn get_dylib_name(crate_name: &str) -> String {
-    let dylib_name = Command::new("rustc")
+pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
+    let file_name = Command::new("rustc")
         .stderr(Stdio::inherit())
-        .args(&["--crate-name", crate_name, "--crate-type", "dylib", "--print", "file-names", "-"])
+        .args(&[
+            "--crate-name",
+            crate_name,
+            "--crate-type",
+            crate_type,
+            "--print",
+            "file-names",
+            "-",
+        ])
         .output()
         .unwrap()
         .stdout;
-    let dylib_name = String::from_utf8(dylib_name).unwrap().trim().to_owned();
-    assert!(!dylib_name.contains('\n'));
-    assert!(dylib_name.contains(crate_name));
-    dylib_name
+    let file_name = String::from_utf8(file_name).unwrap().trim().to_owned();
+    assert!(!file_name.contains('\n'));
+    assert!(file_name.contains(crate_name));
+    file_name
 }