Skip to content

Commit

Permalink
Feature-gate gfx-rs/rspirv dependency
Browse files Browse the repository at this point in the history
Because our `spirv-builder-cli` can modify itself to comply with various
versions of `spirv-builder` from `rust-gpu`, then we also need to match
the version of `spirv` that we use to get `spirv::Capabilities`.

Namely that `rust-gpu <= v0.9.0` uses `spirv = "0.2.0"` and that
`rust-gpu >= "v0.9.0"` uses `spirv = "0.3.0".

Another solution to this could be to re-export `spirv` from `spirv-builder`.
But I'm not sure that would avoid compiling the entirety of `spirv-builder`
(which depends on specific Rust nightly versions), and besides, it's not
trivial to retroactively add re-exports to already-published version of
`rust-gpu`.
  • Loading branch information
tombh committed Jan 12, 2025
1 parent cfdf4ed commit 9414478
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/cargo-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build = "build.rs"

[dependencies]
anyhow.workspace = true
spirv-builder-cli = { path = "../spirv-builder-cli", default-features = false }
spirv-builder-cli = { path = "../spirv-builder-cli", default-features = false, features = ["rspirv-latest"] }
clap.workspace = true
directories.workspace = true
env_logger.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/spirv-builder-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions crates/spirv-builder-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ env_logger = "0.10"
log = "0.4"
serde = "1.0.214"
serde_json = "1.0.132"
spirv = { version = "0.3.0", features = [ "deserialize", "serialize" ] }
toml = "0.8.19"

[features]
default = ["spirv-builder-0_10"]
# The `spirv-builder` before `cargo gpu` existed. It has an incompatible `SpirvBuilder` interface.
spirv-builder-pre-cli = ["dep:spirv-builder-pre-cli"]
spirv-builder-pre-cli = ["dep:spirv-builder-pre-cli", "dep:spirv_0_2"]
# The first version that introduced `cargo gpu`. It has some extra `.builder()` args that make
# dynamically changing build dependencies easier.
spirv-builder-0_10 = ["dep:spirv-builder-0_10"]
spirv-builder-0_10 = ["dep:spirv-builder-0_10", "dep:spirv_0_3"]
#
rspirv-latest = ["dep:spirv_0_3"]

[dependencies.spirv_0_2]
package = "spirv"
version = "0.2.0"
features = [ "deserialize", "serialize" ]
optional = true

[dependencies.spirv_0_3]
package = "spirv"
version = "0.3.0"
features = [ "deserialize", "serialize" ]
optional = true

# NB: All the `${AUTO-REPLACE*}` tokens in each feature get replaced with the same values.
# This is because only one feature can ever be used at once and it makes it easier to just
Expand Down
6 changes: 6 additions & 0 deletions crates/spirv-builder-cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "spirv-builder-pre-cli")]
use spirv_0_2 as spirv;

#[cfg(any(feature = "spirv-builder-0_10", feature = "rspirv-latest"))]
use spirv_0_3 as spirv;

use std::str::FromStr as _;

#[derive(clap::Parser, Debug, serde::Deserialize, serde::Serialize)]
Expand Down
6 changes: 5 additions & 1 deletion crates/spirv-builder-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
pub mod args;

pub use spirv;
#[cfg(feature = "spirv-builder-pre-cli")]
pub use spirv_0_2 as spirv;

#[cfg(any(feature = "spirv-builder-0_10", feature = "rspirv-latest"))]
pub use spirv_0_3 as spirv;

/// Shader source and entry point that can be used to create shader linkage.
#[derive(serde::Serialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down

0 comments on commit 9414478

Please sign in to comment.