diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a0735ad61..1d370d487e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ env: RUST_LOG: debug RUST_BACKTRACE: full PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work + # XXX TODO CONFIGURE THIS PER JOB - NOT ALL JOBS SHOULD FAIL WITH CARGO WARNINGS RUSTFLAGS: -D warnings RUSTDOCFLAGS: -D warnings WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes @@ -175,6 +176,13 @@ jobs: tier: 2 kind: no_std + # XXX TODO MOVE INTO SEPARATE CI JOB: + - name: no-std feature test - Linux x86_64 + os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + tier: 1 + kind: no-std-feature-test + name: Clippy ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -282,9 +290,12 @@ jobs: run: | set -e - # check with no features + # check with no features - wgpu-types cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features + # check with no features - naga + cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features + # XXX TODO SIMILAR SUB-STEP for naga with all features possible with no-std (once this is supported) # Check with all features except "std". cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features --features strict_asserts,fragile-send-sync-non-atomic-wasm,serde,counters @@ -304,6 +315,20 @@ jobs: # build docs cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps + # XXX TODO MOVE INTO SEPARATE CI JOB - MAY SHOW UP AS A "Clippy" job in GitHub CI + - name: no-std feature test + if: matrix.kind == 'no-std-feature-test' + shell: bash + run: | + set -e + + # no-std feature test with no features - naga + cargo test --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p naga --no-default-features + + # XXX TODO FIX & TEST MULTIPLE naga features for no-std + # no-std test with multiple features - naga + # cargo test [...] + - name: check private item docs if: matrix.kind == 'native' shell: bash diff --git a/CHANGELOG.md b/CHANGELOG.md index b6faa5575c..405b80bfe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ Bottom level categories: ## Unreleased +### Major changes + +#### no-std support in naga + +XXX TODO + ### New Features #### Naga diff --git a/Cargo.lock b/Cargo.lock index 507e2b1be8..88192426a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2049,6 +2049,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + [[package]] name = "libredox" version = "0.1.3" @@ -2255,6 +2261,7 @@ dependencies = [ "indexmap", "itertools 0.13.0", "log", + "num-traits", "petgraph 0.7.1", "pp-rs", "ron", @@ -2427,6 +2434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 01c5f4a77c..823014b325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,9 +74,12 @@ wgpu-types = { version = "24.0.0", path = "./wgpu-types" } anyhow = "1.0.95" argh = "0.1.13" -arrayvec = "0.7" +arrayvec = { version = "0.7", default-features = false } +# XXX TODO MOVE ITEM IN SEPARATE PR: approx approx = "0.5" bincode = "1" +# XXX RESOLVE WHERE TO KEEP ITEM: bit-set - ??? +bit-set = { version = "0.8", default-features = false } bit-vec = "0.8" bitflags = "2.7" bytemuck = { version = "1.21", features = ["derive", "min_const_generics"] } @@ -99,7 +102,7 @@ hashbrown = { version = "0.15.2", default-features = false, features = [ ] } heck = "0.5.0" image = { version = "0.24", default-features = false, features = ["png"] } -indexmap = "2" +indexmap = { version = "2", default-features = false } itertools = { version = "0.13.0" } ktx2 = "0.3" libc = "0.2" @@ -135,10 +138,10 @@ serde_json = "1.0.137" serde = { version = "1", default-features = false } smallvec = "1" static_assertions = "1.1.0" -strum = { version = "0.26.0", features = ["derive"] } +strum = { version = "0.26", default-features = false, features = ["derive"] } trybuild = "1" tracy-client = "0.17" -thiserror = "2" +thiserror = { version = "2", default-features = false } winit = { version = "0.29", features = ["android-native-activity"] } # Metal dependencies @@ -154,7 +157,6 @@ gpu-alloc = "0.6" gpu-descriptor = "0.3" # DX12 dependencies -bit-set = "0.8" gpu-allocator = { version = "0.27", default-features = false } range-alloc = "0.1" mach-dxcompiler-rs = { version = "0.1.4", default-features = false } diff --git a/naga/Cargo.toml b/naga/Cargo.toml index a207e5b92b..c90d396904 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -25,9 +25,24 @@ path = "tests/root.rs" all-features = true [features] -default = [] +default = ["std"] + +# XXX TBD ADD DESCRIPTION HERE (???) +std = [ + "dep:codespan-reporting", + # XXX TBD does strum need to be gated on std ??? + "dep:strum", + "dep:termcolor", + "indexmap/std", + # XXX TBD IS / WHY IS THIS NEEDED ??? + "strum/std", +] + +# XXX TODO ALL FEATURES BELOW REQUIRE std feature to build - NEED TO SPECIFY THIS +# XXX TODO DETERMINE which features may or may not be able to work with no-std + dot-out = [] -glsl-in = ["dep:pp-rs"] +glsl-in = ["std", "dep:pp-rs"] glsl-out = [] ## Enables outputting to the Metal Shading Language (MSL). @@ -72,16 +87,20 @@ arbitrary = { version = "1.4", features = ["derive"], optional = true } arrayvec.workspace = true bitflags.workspace = true bit-set.workspace = true -termcolor = { version = "1.4.1" } -# remove termcolor dep when updating to the next version of codespan-reporting +# XXX TODO RAISE SEPARATE PR FOR UPDATE RE: remove termcolor dep [...] +# remove termcolor from here when updating to the next version of codespan-reporting # termcolor minimum version was wrong and was fixed in # https://github.com/brendanzab/codespan/commit/e99c867339a877731437e7ee6a903a3d03b5439e -codespan-reporting = { version = "0.11.0" } +termcolor = { version = "1.4.1", optional = true } +codespan-reporting = { version = "0.11.0", optional = true } hashbrown.workspace = true rustc-hash.workspace = true indexmap.workspace = true log = "0.4" -strum.workspace = true +num-traits = { version = "0.2.19", default-features = false, features = [ + "libm", +] } +strum = { workspace = true, optional = true } spirv = { version = "0.3", optional = true } thiserror.workspace = true serde = { version = "1.0.217", features = [ diff --git a/naga/src/arena/handle.rs b/naga/src/arena/handle.rs index d486d6e054..6be5ae5bce 100644 --- a/naga/src/arena/handle.rs +++ b/naga/src/arena/handle.rs @@ -5,6 +5,9 @@ //! [`Arena`]: super::Arena //! [`UniqueArena`]: super::UniqueArena +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use std::{cmp::Ordering, fmt, hash, marker::PhantomData}; /// An unique index in the arena array that a handle points to. diff --git a/naga/src/arena/handle_set.rs b/naga/src/arena/handle_set.rs index f2ce058d12..4c2efb993d 100644 --- a/naga/src/arena/handle_set.rs +++ b/naga/src/arena/handle_set.rs @@ -1,5 +1,8 @@ //! The [`HandleSet`] type and associated definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, Handle, UniqueArena}; /// A set of `Handle` values. diff --git a/naga/src/arena/handlevec.rs b/naga/src/arena/handlevec.rs index 2ddb65c9a4..8106ec244b 100644 --- a/naga/src/arena/handlevec.rs +++ b/naga/src/arena/handlevec.rs @@ -1,5 +1,8 @@ //! The [`HandleVec`] type and associated definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use super::handle::Handle; use std::marker::PhantomData; diff --git a/naga/src/arena/mod.rs b/naga/src/arena/mod.rs index 8bd3fb84cf..76d3d9e45f 100644 --- a/naga/src/arena/mod.rs +++ b/naga/src/arena/mod.rs @@ -31,6 +31,9 @@ pub(crate) use handlevec::HandleVec; pub use range::{BadRangeError, Range}; pub use unique_arena::UniqueArena; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::Span; use handle::Index; diff --git a/naga/src/arena/range.rs b/naga/src/arena/range.rs index b448f83c8c..9e9787a1a5 100644 --- a/naga/src/arena/range.rs +++ b/naga/src/arena/range.rs @@ -5,6 +5,9 @@ //! //! [`Arena`]: super::Arena +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use super::{ handle::{Handle, Index}, Arena, diff --git a/naga/src/arena/unique_arena.rs b/naga/src/arena/unique_arena.rs index c64bb302eb..40dca78c3c 100644 --- a/naga/src/arena/unique_arena.rs +++ b/naga/src/arena/unique_arena.rs @@ -1,5 +1,8 @@ //! The [`UniqueArena`] type and supporting definitions. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{FastIndexSet, Span}; use super::handle::{BadHandle, Handle, Index}; diff --git a/naga/src/back/mod.rs b/naga/src/back/mod.rs index e839853008..35812fcaef 100644 --- a/naga/src/back/mod.rs +++ b/naga/src/back/mod.rs @@ -3,6 +3,9 @@ Backend functions that export shader [`Module`](super::Module)s into binary and */ #![allow(dead_code)] // can be dead if none of the enabled backends need it +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::proc::ExpressionKindTracker; #[cfg(dot_out)] diff --git a/naga/src/block.rs b/naga/src/block.rs index 2e86a928f1..9cbd1d51e2 100644 --- a/naga/src/block.rs +++ b/naga/src/block.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{Span, Statement}; + use std::ops::{Deref, DerefMut, RangeBounds}; /// A code block is a vector of statements, with maybe a vector of spans. diff --git a/naga/src/common/wgsl.rs b/naga/src/common/wgsl.rs index 07459d7f34..3b73504343 100644 --- a/naga/src/common/wgsl.rs +++ b/naga/src/common/wgsl.rs @@ -2,6 +2,9 @@ use std::fmt::{self, Display, Formatter}; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::diagnostic_filter::{ FilterableTriggeringRule, Severity, StandardFilterableTriggeringRule, }; diff --git a/naga/src/diagnostic_filter.rs b/naga/src/diagnostic_filter.rs index 2fa5464cdf..336b5f9eb8 100644 --- a/naga/src/diagnostic_filter.rs +++ b/naga/src/diagnostic_filter.rs @@ -1,5 +1,8 @@ //! [`DiagnosticFilter`]s and supporting functionality. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + #[cfg(feature = "wgsl-in")] use crate::Span; use crate::{Arena, Handle}; diff --git a/naga/src/error.rs b/naga/src/error.rs index 21c1a13d3c..34dbc06223 100644 --- a/naga/src/error.rs +++ b/naga/src/error.rs @@ -1,4 +1,12 @@ -use std::{error::Error, fmt}; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + +#[cfg(feature = "std")] +use std::error::Error; + +// XXX TODO ADD & IMPROVE NOTE: multiple features below only working with std at this point +#[cfg(feature = "std")] +use std::fmt; #[derive(Clone, Debug)] pub struct ShaderError { @@ -32,6 +40,8 @@ impl fmt::Display for ShaderError { write!(f, "\nShader '{label}' parsing {string}") } } +// XXX TBD FIX for no-std ??? +#[cfg(feature = "std")] impl fmt::Display for ShaderError> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use codespan_reporting::{files::SimpleFile, term}; @@ -49,6 +59,9 @@ impl fmt::Display for ShaderError ) } } + +// XXX TODO ADD NOTE WITH TODO: supporting core::error::Error would be a nice feature but may affect core MSRV +#[cfg(feature = "std")] impl Error for ShaderError where ShaderError: fmt::Display, diff --git a/naga/src/front/mod.rs b/naga/src/front/mod.rs index 11c8aa047e..8d2f708c36 100644 --- a/naga/src/front/mod.rs +++ b/naga/src/front/mod.rs @@ -14,6 +14,9 @@ pub mod spv; #[cfg(feature = "wgsl-in")] pub mod wgsl; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{Arena, Handle, HandleVec, UniqueArena}, proc::{ResolveContext, ResolveError, TypeResolution}, diff --git a/naga/src/front/type_gen.rs b/naga/src/front/type_gen.rs index 737c456bbd..4065c3b6cf 100644 --- a/naga/src/front/type_gen.rs +++ b/naga/src/front/type_gen.rs @@ -2,6 +2,9 @@ Type generators. */ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, span::Span}; impl crate::Module { diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 498abd526a..0126d9fea0 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -16,6 +16,8 @@ use crate::{Arena, FastIndexSet, Handle, ShaderStage, Span}; pub mod ast; pub mod conv; +// XXX TBD ENABLE OR ENABLE PARTIALLY for no-std ??? +#[cfg(feature = "std")] pub mod directive; pub mod lexer; pub mod number; diff --git a/naga/src/lib.rs b/naga/src/lib.rs index 04f3f52bba..3a73a5b74b 100644 --- a/naga/src/lib.rs +++ b/naga/src/lib.rs @@ -249,6 +249,60 @@ An override expression can be evaluated at pipeline creation time. clippy::todo ) )] +// XXX TODO ADD SOME COMMENTS FOR THIS: +#![cfg_attr(not(feature = "std"), no_std)] + +// XXX TBD WHERE TO PUT THIS MOD - ??? - XXX TBD SEPARATE SOURCE FILE ??? +#[cfg(not(feature = "std"))] +pub(crate) mod aliases { + pub(crate) mod external { + pub(crate) extern crate alloc; + } + + pub(crate) mod std { + pub(crate) mod prelude { + pub(crate) mod v1 { + pub(crate) use crate::aliases::std::{ + // XXX XXX TBD COMBINE LINES ??? + boxed::Box, + format, + string::String, + string::ToString, + vec, + vec::Vec, + }; + } + } + + pub(crate) use core::{ + // XXX XXX TBD COMBINE LINES ??? + any, + cmp, + convert, + fmt, + hash, + iter, + marker, + mem, + num, + ops, + slice, + }; + + pub(crate) use super::external::alloc::{ + // XXX XXX TBD COMBINE LINES ??? + borrow, + boxed, + format, + string, + vec, + }; + } + pub(crate) use std::prelude::v1::*; +} + +#[cfg(not(feature = "std"))] +use crate::aliases::*; mod arena; pub mod back; diff --git a/naga/src/non_max_u32.rs b/naga/src/non_max_u32.rs index 2ad402e497..80c422b700 100644 --- a/naga/src/non_max_u32.rs +++ b/naga/src/non_max_u32.rs @@ -16,6 +16,9 @@ //! [`NonZeroU32`]: std::num::NonZeroU32 #![allow(dead_code)] +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use std::num::NonZeroU32; /// An unsigned 32-bit value known not to be [`u32::MAX`]. diff --git a/naga/src/proc/constant_evaluator.rs b/naga/src/proc/constant_evaluator.rs index c8911077b7..0f185e03e8 100644 --- a/naga/src/proc/constant_evaluator.rs +++ b/naga/src/proc/constant_evaluator.rs @@ -1,3 +1,13 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + +// XXX TBD ??? ??? - IGNORING unused_imports warning HERE - XXX TBD COMBINE WITH ALIASES ??? +#[allow(unused_imports)] +#[cfg(not(feature = "std"))] +use num_traits::real::*; + +// XXX TBD MOVE IMPORTS ??? + use std::iter; use arrayvec::ArrayVec; @@ -1189,14 +1199,25 @@ impl<'a> ConstantEvaluator<'a> { if f == 0.5 { if i & 1 == 1 { // -1.5, 1.5, 3.5, ... - (x.abs() + 0.5).copysign(x) + with_sign(x.abs() + 0.5, x.is_sign_negative()) } else { - (x.abs() - 0.5).copysign(x) + with_sign(x.abs() - 0.5, x.is_sign_positive()) } } else { x.round() } } + // Additional helper shamelessly adapted, based on: + // - https://github.com/rust-num/num-traits/blob/num-traits-0.2.19/src/float.rs#L1905 + // (with compatible licensing as well) + #[inline] + fn with_sign(magnitude: f64, with_negative_sign: bool) -> f64 { + if with_negative_sign { + -magnitude.abs() + } else { + magnitude.abs() + } + } component_wise_float(self, span, [arg], |e| match e { Float::Abstract([e]) => Ok(Float::Abstract([round_ties_even(e)])), Float::F32([e]) => Ok(Float::F32([(round_ties_even(e as f64) as f32)])), @@ -2473,6 +2494,9 @@ impl TryFromAbstract for u64 { mod tests { use std::vec; + #[cfg(not(feature = "std"))] + use crate::aliases::*; + use crate::{ Arena, Constant, Expression, Literal, ScalarKind, Type, TypeInner, UnaryOperator, UniqueArena, VectorSize, diff --git a/naga/src/proc/layouter.rs b/naga/src/proc/layouter.rs index 82b1be094a..ba4ee8be6d 100644 --- a/naga/src/proc/layouter.rs +++ b/naga/src/proc/layouter.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Handle, HandleVec}; + use std::{fmt::Display, num::NonZeroU32, ops}; /// A newtype struct where its only valid values are powers of 2 diff --git a/naga/src/proc/mod.rs b/naga/src/proc/mod.rs index a6a19f70ed..2cb92d5ece 100644 --- a/naga/src/proc/mod.rs +++ b/naga/src/proc/mod.rs @@ -11,6 +11,9 @@ mod terminator; mod type_methods; mod typifier; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + pub use constant_evaluator::{ ConstantEvaluator, ConstantEvaluatorError, ExpressionKind, ExpressionKindTracker, }; diff --git a/naga/src/proc/namer.rs b/naga/src/proc/namer.rs index 8afacb593d..7d065cc1fb 100644 --- a/naga/src/proc/namer.rs +++ b/naga/src/proc/namer.rs @@ -1,4 +1,8 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, FastHashMap, FastHashSet}; + use std::borrow::Cow; use std::hash::{Hash, Hasher}; diff --git a/naga/src/proc/typifier.rs b/naga/src/proc/typifier.rs index 1359289900..0ca22137a1 100644 --- a/naga/src/proc/typifier.rs +++ b/naga/src/proc/typifier.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, Handle, UniqueArena}; use thiserror::Error; diff --git a/naga/src/span.rs b/naga/src/span.rs index 0256e19dc4..02afd1eb85 100644 --- a/naga/src/span.rs +++ b/naga/src/span.rs @@ -1,5 +1,11 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; use crate::{Arena, Handle, UniqueArena}; -use std::{error::Error, fmt, ops::Range}; + +#[cfg(feature = "std")] +use std::error::Error; + +use std::{fmt, ops::Range}; /// A source code span, used for error reporting. #[derive(Clone, Copy, Debug, PartialEq, Default)] @@ -152,6 +158,8 @@ where } } +// XXX TODO ADD NOTE WITH TODO: supporting core::error::Error would be a nice feature but may affect core MSRV +#[cfg(feature = "std")] impl Error for WithSpan where E: Error, @@ -239,6 +247,7 @@ impl WithSpan { Some(self.spans[0].0.location(source)) } + #[cfg(feature = "std")] pub(crate) fn diagnostic(&self) -> codespan_reporting::diagnostic::Diagnostic<()> where E: Error, @@ -266,6 +275,7 @@ impl WithSpan { } /// Emits a summary of the error to standard error stream. + #[cfg(feature = "std")] pub fn emit_to_stderr(&self, source: &str) where E: Error, @@ -274,6 +284,7 @@ impl WithSpan { } /// Emits a summary of the error to standard error stream. + #[cfg(feature = "std")] pub fn emit_to_stderr_with_path(&self, source: &str, path: &str) where E: Error, @@ -288,7 +299,9 @@ impl WithSpan { .expect("cannot write error"); } + // XXX TBD FIX FOR no-std - ??? /// Emits a summary of the error to a string. + #[cfg(feature = "std")] pub fn emit_to_string(&self, source: &str) -> String where E: Error, @@ -297,6 +310,7 @@ impl WithSpan { } /// Emits a summary of the error to a string. + #[cfg(feature = "std")] pub fn emit_to_string_with_path(&self, source: &str, path: &str) -> String where E: Error, diff --git a/naga/src/valid/analyzer.rs b/naga/src/valid/analyzer.rs index 8417bf77be..16f7ce6bfb 100644 --- a/naga/src/valid/analyzer.rs +++ b/naga/src/valid/analyzer.rs @@ -6,12 +6,17 @@ //! - expression reference counts use super::{ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags}; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::diagnostic_filter::{DiagnosticFilterNode, StandardFilterableTriggeringRule}; use crate::span::{AddSpan as _, WithSpan}; use crate::{ arena::{Arena, Handle}, proc::{ResolveContext, TypeResolution}, }; + use std::ops; pub type NonUniformResult = Option>; diff --git a/naga/src/valid/expression.rs b/naga/src/valid/expression.rs index 9ef3a9edfb..88beca4bf9 100644 --- a/naga/src/valid/expression.rs +++ b/naga/src/valid/expression.rs @@ -1,4 +1,9 @@ use super::{compose::validate_compose, FunctionInfo, ModuleInfo, ShaderStages, TypeFlags}; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + +// XXX TODO COMBINE with arena::Handle import below: use crate::arena::UniqueArena; use crate::{ diff --git a/naga/src/valid/function.rs b/naga/src/valid/function.rs index 9f92e708ce..787b572529 100644 --- a/naga/src/valid/function.rs +++ b/naga/src/valid/function.rs @@ -1,3 +1,6 @@ +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Arena, UniqueArena}; use crate::arena::{Handle, HandleSet}; @@ -7,6 +10,8 @@ use super::{ analyzer::{UniformityDisruptor, UniformityRequirements}, ExpressionError, FunctionInfo, ModuleInfo, }; + +// XXX TODO MOVE THESE CLOSER TO OTHER use::crate::... imports use crate::span::WithSpan; use crate::span::{AddSpan as _, MapErrWithSpan as _}; diff --git a/naga/src/valid/handles.rs b/naga/src/valid/handles.rs index 260d442c79..54c976f9cd 100644 --- a/naga/src/valid/handles.rs +++ b/naga/src/valid/handles.rs @@ -1,5 +1,8 @@ //! Implementation of `Validator::validate_module_handles`. +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{BadHandle, BadRangeError}, diagnostic_filter::DiagnosticFilterNode, diff --git a/naga/src/valid/interface.rs b/naga/src/valid/interface.rs index a6fff61d82..4d36dc6ac8 100644 --- a/naga/src/valid/interface.rs +++ b/naga/src/valid/interface.rs @@ -2,9 +2,14 @@ use super::{ analyzer::{FunctionInfo, GlobalUse}, Capabilities, Disalignment, FunctionError, ModuleInfo, }; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::arena::{Handle, UniqueArena}; use crate::span::{AddSpan as _, MapErrWithSpan as _, SpanProvider as _, WithSpan}; + use bit_set::BitSet; const MAX_WORKGROUP_SIZE: u32 = 0x4000; diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index 906d449362..9992f56d4f 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -10,18 +10,24 @@ mod handles; mod interface; mod r#type; +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{ arena::{Handle, HandleSet}, proc::{ExpressionKindTracker, LayoutError, Layouter, TypeResolution}, FastHashSet, }; + use bit_set::BitSet; use std::ops; //TODO: analyze the model at the same time as we validate it, // merge the corresponding matches over expressions and statements. +// XXX TODO MOVE THIS CRATE IMPORT use crate::span::{AddSpan as _, WithSpan}; + pub use analyzer::{ExpressionInfo, FunctionInfo, GlobalUse, Uniformity, UniformityRequirements}; pub use compose::ComposeError; pub use expression::{check_literal_value, LiteralError}; diff --git a/naga/src/valid/type.rs b/naga/src/valid/type.rs index 8c6825b842..595aba26d5 100644 --- a/naga/src/valid/type.rs +++ b/naga/src/valid/type.rs @@ -1,4 +1,8 @@ use super::Capabilities; + +#[cfg(not(feature = "std"))] +use crate::aliases::*; + use crate::{arena::Handle, proc::Alignment}; bitflags::bitflags! { diff --git a/naga/tests/snapshots.rs b/naga/tests/snapshots.rs index 829019d99b..96c5c89c91 100644 --- a/naga/tests/snapshots.rs +++ b/naga/tests/snapshots.rs @@ -30,6 +30,7 @@ bitflags::bitflags! { } } +// XXX TBD add cfg condition - ??? #[derive(serde::Deserialize)] struct SpvOutVersion(u8, u8); impl Default for SpvOutVersion { @@ -38,8 +39,9 @@ impl Default for SpvOutVersion { } } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] struct SpirvOutParameters { version: SpvOutVersion, capabilities: naga::FastHashSet, @@ -52,14 +54,17 @@ struct SpirvOutParameters { binding_map: naga::back::spv::BindingMap, } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] struct WgslOutParameters { explicit_types: bool, } -#[derive(Default, serde::Deserialize)] -#[serde(default)] +#[derive(Default)] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +#[cfg_attr(feature = "deserialize", serde(default))] +// #[serde(default)] struct Parameters { // -- GOD MODE -- god_mode: bool, @@ -235,6 +240,7 @@ impl Input { } /// Return this input's parameter file, parsed. + #[cfg(feature = "deserialize")] fn read_parameters(&self) -> Parameters { let mut param_path = self.input_path(); param_path.set_extension("param.ron"); @@ -266,6 +272,7 @@ type FragmentEntryPoint<'a> = naga::back::hlsl::FragmentEntryPoint<'a>; type FragmentEntryPoint<'a> = (); #[allow(unused_variables)] +#[cfg(feature = "deserialize")] fn check_targets( input: &Input, module: &mut naga::Module, diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index bba28939f7..3007a2b2df 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -2,7 +2,6 @@ use super::{conv, RawTlasInstance}; use arrayvec::ArrayVec; use ash::{khr, vk}; -use hashbrown::hash_map::Entry; use parking_lot::Mutex; use crate::TlasInstance; @@ -16,6 +15,9 @@ use std::{ sync::Arc, }; +// XXX TODO MOVE THIS IMPORT NOW RESTORED: +use hashbrown::hash_map::Entry; + impl super::DeviceShared { /// Set the name of `object` to `name`. ///