Skip to content

Commit a9c36bd

Browse files
committed
target declaration refactor
1 parent a64583d commit a9c36bd

File tree

6 files changed

+607
-100
lines changed

6 files changed

+607
-100
lines changed

crates/rustc_codegen_spirv-types/src/target.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fmt::{Debug, Formatter};
22
use thiserror::Error;
33

4+
pub const SPIRV_VENDOR: &str = "unknown";
5+
pub const SPIRV_ARCH: &str = "spirv";
46
pub const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-";
57

68
/// A well-formed rust-gpu target.

crates/rustc_codegen_spirv/src/builder_spirv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::builder;
55
use crate::codegen_cx::CodegenCx;
66
use crate::spirv_type::SpirvType;
77
use crate::symbols::Symbols;
8-
use crate::target::SpirvTarget;
8+
use crate::target::{SpirvTarget, SpirvTargetVariant, SpirvVersion};
99
use crate::target_feature::TargetFeature;
1010
use rspirv::dr::{Builder, Instruction, Module, Operand};
1111
use rspirv::spirv::{
@@ -492,7 +492,7 @@ impl<'tcx> BuilderSpirv<'tcx> {
492492

493493
add_cap(&mut builder, &mut enabled_capabilities, Capability::Shader);
494494
if memory_model == MemoryModel::Vulkan {
495-
if version < (1, 5) {
495+
if version < SpirvVersion::V1_5 {
496496
add_ext(&mut builder, sym.spv_khr_vulkan_memory_model);
497497
}
498498
add_cap(

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use crate::builder_spirv::{
1010
use crate::custom_decorations::{CustomDecoration, SrcLocDecoration, ZombieDecoration};
1111
use crate::spirv_type::{SpirvType, SpirvTypePrinter, TypeCache};
1212
use crate::symbols::Symbols;
13-
use crate::target::SpirvTarget;
1413

1514
// HACK(eddyb) avoids rewriting all of the imports (see `lib.rs` and `build.rs`).
1615
use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
1716

17+
use crate::target::SpirvTarget;
1818
use itertools::Itertools as _;
1919
use rspirv::dr::{Module, Operand};
2020
use rspirv::spirv::{Decoration, LinkageType, Word};
@@ -99,7 +99,7 @@ impl<'tcx> CodegenCx<'tcx> {
9999
pub fn new(tcx: TyCtxt<'tcx>, codegen_unit: &'tcx CodegenUnit<'tcx>) -> Self {
100100
// Validate the target spec, as the backend doesn't control `--target`.
101101
let target_tuple = tcx.sess.opts.target_triple.tuple();
102-
let target: SpirvTarget = target_tuple.parse().unwrap_or_else(|_| {
102+
let target = SpirvTarget::parse(target_tuple).unwrap_or_else(|_| {
103103
let qualifier = if !target_tuple.starts_with("spirv-") {
104104
"non-SPIR-V "
105105
} else {

crates/rustc_codegen_spirv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod linker;
136136
mod spirv_type;
137137
mod spirv_type_constraints;
138138
mod symbols;
139-
mod target;
139+
pub mod target;
140140
mod target_feature;
141141

142142
use builder::Builder;

crates/rustc_codegen_spirv/src/linker/test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::sync::{Arc, Mutex};
1313
// We need to construct an emitter as yet another workaround,
1414
// see https://github.com/rust-lang/rust/pull/102992.
1515
extern crate termcolor;
16+
use crate::target::SpirvTarget;
1617
use termcolor::{ColorSpec, WriteColor};
1718

1819
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
@@ -130,10 +131,7 @@ fn link_with_linker_opts(
130131
.unwrap();
131132
let sopts = rustc_session::config::build_session_options(&mut early_dcx, &matches);
132133

133-
let target = "spirv-unknown-spv1.0"
134-
.parse::<crate::target::SpirvTarget>()
135-
.unwrap()
136-
.rustc_target();
134+
let target = SpirvTarget::UNIVERSAL_1_0.rustc_target();
137135
let sm_inputs = rustc_span::source_map::SourceMapInputs {
138136
file_loader: Box::new(rustc_span::source_map::RealFileLoader),
139137
path_mapping: sopts.file_path_mapping(),

0 commit comments

Comments
 (0)