Skip to content

Commit e5563b5

Browse files
committed
Improve windows support
1 parent 0d6b3da commit e5563b5

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

build_system/build_backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ pub(crate) fn build_backend(channel: &str) -> String {
3535
eprintln!("[BUILD] rustc_codegen_cranelift");
3636
crate::utils::spawn_and_wait(cmd);
3737

38-
crate::rustc_info::get_dylib_name("rustc_codegen_cranelift")
38+
crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
3939
}

build_system/build_sysroot.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::utils::spawn_and_wait;
2-
use crate::utils::try_hard_link;
3-
use crate::SysrootKind;
1+
use std::env;
42
use std::fs;
53
use std::path::Path;
64
use std::process::{self, Command};
75

6+
use crate::rustc_info::get_file_name;
7+
use crate::utils::{spawn_and_wait, try_hard_link};
8+
use crate::SysrootKind;
9+
810
pub(crate) fn build_sysroot(
911
channel: &str,
1012
sysroot_kind: SysrootKind,
@@ -22,15 +24,24 @@ pub(crate) fn build_sysroot(
2224
// Copy the backend
2325
for file in ["cg_clif", "cg_clif_build_sysroot"] {
2426
try_hard_link(
25-
Path::new("target").join(channel).join(file),
26-
target_dir.join("bin").join(file),
27+
Path::new("target").join(channel).join(get_file_name(file, "bin")),
28+
target_dir.join("bin").join(get_file_name(file, "bin")),
2729
);
2830
}
2931

30-
try_hard_link(
31-
Path::new("target").join(channel).join(&cg_clif_dylib),
32-
target_dir.join("lib").join(cg_clif_dylib),
33-
);
32+
if cfg!(windows) {
33+
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
34+
// binaries.
35+
try_hard_link(
36+
Path::new("target").join(channel).join(&cg_clif_dylib),
37+
target_dir.join("bin").join(cg_clif_dylib),
38+
);
39+
} else {
40+
try_hard_link(
41+
Path::new("target").join(channel).join(&cg_clif_dylib),
42+
target_dir.join("lib").join(cg_clif_dylib),
43+
);
44+
}
3445

3546
// Copy supporting files
3647
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)
141152
rustflags.push_str(" -Zmir-opt-level=3");
142153
}
143154
build_cmd.env("RUSTFLAGS", rustflags);
144-
build_cmd
145-
.env("RUSTC", target_dir.join("bin").join("cg_clif_build_sysroot").canonicalize().unwrap());
155+
build_cmd.env(
156+
"RUSTC",
157+
env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"),
158+
);
146159
// FIXME Enable incremental again once rust-lang/rust#74946 is fixed
147160
build_cmd.env("CARGO_INCREMENTAL", "0").env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
148161
spawn_and_wait(build_cmd);

build_system/prepare.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
use std::env;
12
use std::ffi::OsStr;
23
use std::ffi::OsString;
34
use std::fs;
45
use std::path::Path;
5-
use std::path::PathBuf;
66
use std::process::Command;
77

8-
use crate::rustc_info::get_rustc_path;
9-
use crate::utils::copy_dir_recursively;
10-
use crate::utils::spawn_and_wait;
8+
use crate::rustc_info::{get_file_name, get_rustc_path};
9+
use crate::utils::{copy_dir_recursively, spawn_and_wait};
1110

1211
pub(crate) fn prepare() {
1312
prepare_sysroot();
@@ -38,13 +37,18 @@ pub(crate) fn prepare() {
3837
let mut build_cmd = Command::new("cargo");
3938
build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer");
4039
spawn_and_wait(build_cmd);
41-
fs::copy("simple-raytracer/target/debug/main", "simple-raytracer/raytracer_cg_llvm").unwrap();
40+
fs::copy(
41+
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
42+
// FIXME use get_file_name here too once testing is migrated to rust
43+
"simple-raytracer/raytracer_cg_llvm",
44+
)
45+
.unwrap();
4246
}
4347

4448
fn prepare_sysroot() {
4549
let rustc_path = get_rustc_path();
4650
let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust");
47-
let sysroot_src = PathBuf::from("build_sysroot").canonicalize().unwrap().join("sysroot_src");
51+
let sysroot_src = env::current_dir().unwrap().join("build_sysroot").join("sysroot_src");
4852

4953
assert!(sysroot_src_orig.exists());
5054

@@ -114,7 +118,7 @@ fn get_patches(crate_name: &str) -> Vec<OsString> {
114118
fn apply_patches(crate_name: &str, target_dir: &Path) {
115119
for patch in get_patches(crate_name) {
116120
eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch);
117-
let patch_arg = Path::new("patches").join(patch).canonicalize().unwrap();
121+
let patch_arg = env::current_dir().unwrap().join("patches").join(patch);
118122
let mut apply_patch_cmd = Command::new("git");
119123
apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir);
120124
spawn_and_wait(apply_patch_cmd);

build_system/rustc_info.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,23 @@ pub(crate) fn get_default_sysroot() -> PathBuf {
3737
Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned()
3838
}
3939

40-
pub(crate) fn get_dylib_name(crate_name: &str) -> String {
41-
let dylib_name = Command::new("rustc")
40+
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
41+
let file_name = Command::new("rustc")
4242
.stderr(Stdio::inherit())
43-
.args(&["--crate-name", crate_name, "--crate-type", "dylib", "--print", "file-names", "-"])
43+
.args(&[
44+
"--crate-name",
45+
crate_name,
46+
"--crate-type",
47+
crate_type,
48+
"--print",
49+
"file-names",
50+
"-",
51+
])
4452
.output()
4553
.unwrap()
4654
.stdout;
47-
let dylib_name = String::from_utf8(dylib_name).unwrap().trim().to_owned();
48-
assert!(!dylib_name.contains('\n'));
49-
assert!(dylib_name.contains(crate_name));
50-
dylib_name
55+
let file_name = String::from_utf8(file_name).unwrap().trim().to_owned();
56+
assert!(!file_name.contains('\n'));
57+
assert!(file_name.contains(crate_name));
58+
file_name
5159
}

0 commit comments

Comments
 (0)