Skip to content

Commit 2587dba

Browse files
committed
target-spec: move query_rustc_version to *spirv-types
1 parent 358808d commit 2587dba

3 files changed

Lines changed: 23 additions & 18 deletions

File tree

crates/rustc_codegen_spirv-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
pub use rspirv::spirv::Capability;
44

55
mod compile_result;
6+
mod rustc_version;
67
mod target_spec;
78
pub use compile_result::*;
9+
pub use rustc_version::*;
810
pub use target_spec::*;
911

1012
// HACK(eddyb) allows downstream crates to access the correct version directly.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use semver::Version;
2+
use std::process::Command;
3+
4+
pub fn query_rustc_version(toolchain: Option<&str>) -> std::io::Result<Version> {
5+
let mut cmd = Command::new("rustc");
6+
if let Some(toolchain) = toolchain {
7+
cmd.arg(format!("+{toolchain}"));
8+
}
9+
cmd.arg("--version");
10+
let output = cmd.output()?;
11+
12+
let stdout = String::from_utf8(output.stdout).expect("stdout must be utf-8");
13+
let parse = |output: &str| {
14+
let output = output.strip_prefix("rustc ")?;
15+
let version = &output[..output.find(|c| !"0123456789.".contains(c))?];
16+
Version::parse(version).ok()
17+
};
18+
Ok(parse(&stdout)
19+
.unwrap_or_else(|| panic!("failed parsing `rustc --version` output `{stdout}`")))
20+
}

crates/spirv-builder/src/lib.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ use thiserror::Error;
9191
#[cfg(feature = "watch")]
9292
pub use self::watch::{SpirvWatcher, SpirvWatcherError};
9393
pub use rustc_codegen_spirv_types::Capability;
94+
use rustc_codegen_spirv_types::query_rustc_version;
9495
pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult, TargetSpecVersion};
9596

9697
#[derive(Debug, Error)]
@@ -1125,21 +1126,3 @@ fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> std::io::Resul
11251126
recurse(&deps_map, artifact.to_str().unwrap().into(), &mut handle);
11261127
Ok(())
11271128
}
1128-
1129-
pub fn query_rustc_version(toolchain: Option<&str>) -> std::io::Result<Version> {
1130-
let mut cmd = Command::new("rustc");
1131-
if let Some(toolchain) = toolchain {
1132-
cmd.arg(format!("+{toolchain}"));
1133-
}
1134-
cmd.arg("--version");
1135-
let output = cmd.output()?;
1136-
1137-
let stdout = String::from_utf8(output.stdout).expect("stdout must be utf-8");
1138-
let parse = |output: &str| {
1139-
let output = output.strip_prefix("rustc ")?;
1140-
let version = &output[..output.find(|c| !"0123456789.".contains(c))?];
1141-
Version::parse(version).ok()
1142-
};
1143-
Ok(parse(&stdout)
1144-
.unwrap_or_else(|| panic!("failed parsing `rustc --version` output `{stdout}`")))
1145-
}

0 commit comments

Comments
 (0)