Improve windows support

This commit is contained in:
bjorn3 2021-06-18 13:38:50 +02:00
parent 0d6b3dab65
commit e5563b5077
4 changed files with 51 additions and 26 deletions

View file

@ -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")
}

View file

@ -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);

View file

@ -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);

View file

@ -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
}