Skip to content

Commit 5347882

Browse files
committed
Refactor cg_clif building
1 parent 0d531c3 commit 5347882

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

build_system/build_backend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::env;
2+
use std::path::{Path, PathBuf};
23
use std::process::Command;
34

4-
pub(crate) fn build_backend(channel: &str) -> String {
5+
pub(crate) fn build_backend(channel: &str, host_triple: &str) -> PathBuf {
56
let mut cmd = Command::new("cargo");
6-
cmd.arg("build");
7+
cmd.arg("build").arg("--target").arg(host_triple);
78

89
match channel {
910
"debug" => {}
@@ -35,5 +36,5 @@ pub(crate) fn build_backend(channel: &str) -> String {
3536
eprintln!("[BUILD] rustc_codegen_cranelift");
3637
crate::utils::spawn_and_wait(cmd);
3738

38-
crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib")
39+
Path::new("target").join(host_triple).join(channel)
3940
}

build_system/build_sysroot.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::fs;
3-
use std::path::Path;
3+
use std::path::{Path, PathBuf};
44
use std::process::{self, Command};
55

66
use crate::rustc_info::{get_file_name, get_rustc_version};
@@ -11,7 +11,7 @@ pub(crate) fn build_sysroot(
1111
channel: &str,
1212
sysroot_kind: SysrootKind,
1313
target_dir: &Path,
14-
cg_clif_dylib: String,
14+
cg_clif_build_dir: PathBuf,
1515
host_triple: &str,
1616
target_triple: &str,
1717
) {
@@ -24,24 +24,24 @@ pub(crate) fn build_sysroot(
2424
// Copy the backend
2525
for file in ["cg_clif", "cg_clif_build_sysroot"] {
2626
try_hard_link(
27-
Path::new("target").join(channel).join(get_file_name(file, "bin")),
27+
cg_clif_build_dir.join(get_file_name(file, "bin")),
2828
target_dir.join("bin").join(get_file_name(file, "bin")),
2929
);
3030
}
3131

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-
}
32+
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
33+
try_hard_link(
34+
cg_clif_build_dir.join(&cg_clif_dylib),
35+
target_dir
36+
.join(if cfg!(windows) {
37+
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
38+
// binaries.
39+
"bin"
40+
} else {
41+
"lib"
42+
})
43+
.join(cg_clif_dylib),
44+
);
4545

4646
// Build and copy cargo wrapper
4747
let mut build_cargo_wrapper_cmd = Command::new("rustc");

config.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# This file allows configuring the build system.
22

3-
# The host triple
3+
# Which triple to produce a compiler toolchain for.
4+
#
5+
# Defaults to the default triple of rustc on the host system.
46
#host = x86_64-unknown-linux-gnu
57

6-
# The target triple
8+
# Which triple to build libraries (core/alloc/std/test/proc_macro) for.
9+
#
10+
# Defaults to `host`.
711
#target = x86_64-unknown-linux-gnu
812

913
# Disables cleaning of the sysroot dir. This will cause old compiled artifacts to be re-used when

y.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ fn main() {
141141
process::exit(1);
142142
}
143143

144-
let cg_clif_dylib = build_backend::build_backend(channel);
144+
let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple);
145145
build_sysroot::build_sysroot(
146146
channel,
147147
sysroot_kind,
148148
&target_dir,
149-
cg_clif_dylib,
149+
cg_clif_build_dir,
150150
&host_triple,
151151
&target_triple,
152152
);

0 commit comments

Comments
 (0)