Skip to content

Commit 4ebd004

Browse files
committed
Get host tuple from rustc used for benchmarking/profiling, if possible
1 parent 8b605be commit 4ebd004

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

collector/src/bin/collector.rs

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -794,16 +794,54 @@ fn main_result() -> anyhow::Result<i32> {
794794
runtime: &runtime_benchmark_dir,
795795
};
796796

797-
let host_target_tuple =
798-
String::from_utf8(command_output(Command::new("rustc").arg("--print=host-tuple"))?.stdout)?
799-
.trim()
800-
.to_string();
797+
// We need to find the host tuple for a couple of things (several collector commands need it).
798+
// Probably the simplest way of determining it is asking rustc what is its host tuple.
799+
// However, where to get that rustc? We could just try using "rustc", but that is not always
800+
// available, e.g. on Rust's CI.
801+
// So we try to figure out if we have some rustc available from the command that is being
802+
// executed; such rustc should definitely be executable on this host.
803+
// If we don't, we'll simply fall back to `rustc`.
804+
let used_rustc: Option<String> = match &args.command {
805+
Commands::BinaryStats {
806+
mode: BinaryStatsMode::Compile(args),
807+
..
808+
} => Some(args.local.rustc.clone()),
809+
Commands::BenchRuntimeLocal { local, .. } => Some(local.rustc.clone()),
810+
Commands::ProfileRuntime { rustc, .. } => Some(rustc.clone()),
811+
Commands::CodegenDiff { rustc1, .. } => Some(rustc1.clone()),
812+
Commands::BenchLocal { local, .. } => Some(local.rustc.clone()),
813+
Commands::ProfileLocal { local, .. } => Some(local.rustc.clone()),
814+
Commands::BinaryStats {
815+
mode: BinaryStatsMode::Local(_),
816+
..
817+
}
818+
| Commands::BenchNext { .. }
819+
| Commands::BenchPublished { .. }
820+
| Commands::InstallNext { .. }
821+
| Commands::Download(_)
822+
| Commands::PurgeArtifact { .. }
823+
| Commands::BenchCmp { .. }
824+
| Commands::AddCollector { .. }
825+
| Commands::BenchmarkJobQueue { .. } => None,
826+
};
827+
828+
let host_target_tuple = match used_rustc {
829+
Some(rustc) => get_host_tuple_from_rustc(&rustc),
830+
None => get_host_tuple_from_rustc("rustc"),
831+
};
832+
// We only unwrap the host tuple in places where we actually need it, to avoid panicking if it
833+
// is missing, but we don't really need it.
834+
let require_host_target_tuple = || {
835+
host_target_tuple.expect(
836+
"Cannot determine host target tuple. Please make a `rustc` binary available in PATH.",
837+
)
838+
};
801839

802840
match args.command {
803841
Commands::BinaryStats { mode, symbols } => {
804842
match mode {
805843
BinaryStatsMode::Compile(args) => {
806-
binary_stats_compile(args, symbols, &host_target_tuple)?;
844+
binary_stats_compile(args, symbols, &require_host_target_tuple())?;
807845
}
808846
BinaryStatsMode::Local(args) => {
809847
binary_stats_local(args, symbols)?;
@@ -822,7 +860,8 @@ fn main_result() -> anyhow::Result<i32> {
822860
purge,
823861
} => {
824862
log_db(&db);
825-
let toolchain = get_local_toolchain_for_runtime_benchmarks(&local, &host_target_tuple)?;
863+
let toolchain =
864+
get_local_toolchain_for_runtime_benchmarks(&local, &require_host_target_tuple())?;
826865
let pool = Pool::open(&db.db);
827866

828867
let isolation_mode = if no_isolate {
@@ -871,6 +910,7 @@ fn main_result() -> anyhow::Result<i32> {
871910
rustc2,
872911
benchmark,
873912
} => {
913+
let host_target_tuple = require_host_target_tuple();
874914
let get_suite = |rustc: &str, id: &str| {
875915
let toolchain = get_local_toolchain(
876916
&[Profile::Opt],
@@ -928,6 +968,7 @@ fn main_result() -> anyhow::Result<i32> {
928968
rustc1: rustc,
929969
rustc2,
930970
} => {
971+
let host_target_tuple = require_host_target_tuple();
931972
let get_toolchain = |rustc: &str, id: &str| {
932973
let toolchain = get_local_toolchain(
933974
&[Profile::Opt],
@@ -978,7 +1019,7 @@ fn main_result() -> anyhow::Result<i32> {
9781019
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
9791020
.id(local.id.as_deref()),
9801021
"",
981-
host_target_tuple,
1022+
require_host_target_tuple(),
9821023
)?;
9831024

9841025
let mut benchmarks = get_compile_benchmarks(&compile_benchmark_dir, (&local).into())?;
@@ -1047,8 +1088,10 @@ fn main_result() -> anyhow::Result<i32> {
10471088

10481089
match next {
10491090
NextArtifact::Release(tag) => {
1050-
let toolchain =
1051-
create_toolchain_from_published_version(&tag, &host_target_tuple)?;
1091+
let toolchain = create_toolchain_from_published_version(
1092+
&tag,
1093+
&require_host_target_tuple(),
1094+
)?;
10521095
let conn = rt.block_on(pool.connection());
10531096
rt.block_on(bench_published_artifact(
10541097
conn,
@@ -1097,7 +1140,7 @@ fn main_result() -> anyhow::Result<i32> {
10971140
.block_on(Sysroot::install(
10981141
Path::new(TOOLCHAIN_CACHE_DIRECTORY),
10991142
sha.clone(),
1100-
&host_target_tuple,
1143+
&require_host_target_tuple(),
11011144
&backends,
11021145
))
11031146
.map_err(SysrootDownloadError::as_anyhow_error)
@@ -1180,7 +1223,7 @@ fn main_result() -> anyhow::Result<i32> {
11801223
let rt = build_async_runtime();
11811224
let conn = rt.block_on(pool.connection());
11821225
let toolchain =
1183-
create_toolchain_from_published_version(&toolchain, &host_target_tuple)?;
1226+
create_toolchain_from_published_version(&toolchain, &require_host_target_tuple())?;
11841227
rt.block_on(bench_published_artifact(
11851228
conn,
11861229
toolchain,
@@ -1221,6 +1264,7 @@ fn main_result() -> anyhow::Result<i32> {
12211264
.build_global()
12221265
.unwrap();
12231266

1267+
let host_target_tuple = require_host_target_tuple();
12241268
let mut get_toolchain_and_profile =
12251269
|rustc: &str, suffix: &str| -> anyhow::Result<String> {
12261270
let toolchain = get_local_toolchain(
@@ -1295,7 +1339,7 @@ fn main_result() -> anyhow::Result<i32> {
12951339
.block_on(Sysroot::install(
12961340
Path::new(TOOLCHAIN_CACHE_DIRECTORY),
12971341
commit.sha,
1298-
&host_target_tuple,
1342+
&require_host_target_tuple(),
12991343
&codegen_backends.0,
13001344
))
13011345
.map_err(SysrootDownloadError::as_anyhow_error)?;
@@ -1407,6 +1451,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
14071451
)
14081452
})?;
14091453

1454+
let host_target_tuple = require_host_target_tuple();
14101455
if collector_config.target().as_str() != host_target_tuple {
14111456
return Err(anyhow::anyhow!(
14121457
"The collector `{collector_name}` is configured for target `{}`, but the current host target seems to be `{host_target_tuple}`",
@@ -1437,6 +1482,14 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
14371482
}
14381483
}
14391484

1485+
fn get_host_tuple_from_rustc(rustc: &str) -> anyhow::Result<String> {
1486+
Ok(
1487+
String::from_utf8(command_output(Command::new(rustc).arg("--print=host-tuple"))?.stdout)?
1488+
.trim()
1489+
.to_string(),
1490+
)
1491+
}
1492+
14401493
/// Maximum number of failures before a job will be marked as failed.
14411494
const MAX_JOB_FAILS: u32 = 3;
14421495

0 commit comments

Comments
 (0)