Skip to content

Commit f1ddd7a

Browse files
committed
change how to select bevy-glsl-to-spirv or shaderc (#1819)
`cfg` for `bevy-glsl-to-spirv` use now mimics https://github.com/cart/glsl-to-spirv/blob/master/Cargo.toml fixes #898 fixes #1348 fixes #1942 fixes #1078
1 parent 3eb828f commit f1ddd7a

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

crates/bevy_render/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ parking_lot = "0.11.0"
4444
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4545
spirv-reflect = "0.2.3"
4646

47-
[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32"), not(all(target_arch = "aarch64", target_os = "macos"))))'.dependencies]
47+
[target.'cfg(any(all(target_arch="x86_64", target_os="linux", target_env="gnu"), all(target_arch="x86_64", target_os="macos"), all(target_arch="aarch64", target_os="android"), all(target_arch="armv7", target_os="androidabi"), all(target_arch="x86_64", target_os="windows", target_env="msvc")))'.dependencies]
4848
bevy-glsl-to-spirv = "0.2.0"
4949

50-
[target.'cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))'.dependencies]
50+
[target.'cfg(not(any(target_arch = "wasm32", all(target_arch="x86_64", target_os="linux", target_env="gnu"), all(target_arch="x86_64", target_os="macos"), all(target_arch="aarch64", target_os="android"), all(target_arch="armv7", target_os="androidabi"), all(target_arch="x86_64", target_os="windows", target_env="msvc"))))'.dependencies]
5151
shaderc = "0.7.0"
5252

5353
[features]

crates/bevy_render/src/shader/shader.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,47 @@ pub enum ShaderError {
2727
#[error("Shader compilation error:\n{0}")]
2828
Compilation(String),
2929

30-
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
30+
#[cfg(not(any(
31+
target_arch = "wasm32",
32+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
33+
all(target_arch = "x86_64", target_os = "macos"),
34+
all(target_arch = "aarch64", target_os = "android"),
35+
all(target_arch = "armv7", target_os = "androidabi"),
36+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
37+
)))]
3138
/// shaderc error.
3239
#[error("shaderc error: {0}")]
3340
ShaderC(#[from] shaderc::Error),
3441

35-
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
42+
#[cfg(not(any(
43+
target_arch = "wasm32",
44+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
45+
all(target_arch = "x86_64", target_os = "macos"),
46+
all(target_arch = "aarch64", target_os = "android"),
47+
all(target_arch = "armv7", target_os = "androidabi"),
48+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
49+
)))]
3650
#[error("Error initializing shaderc Compiler")]
3751
ErrorInitializingShadercCompiler,
3852

39-
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
53+
#[cfg(not(any(
54+
target_arch = "wasm32",
55+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
56+
all(target_arch = "x86_64", target_os = "macos"),
57+
all(target_arch = "aarch64", target_os = "android"),
58+
all(target_arch = "armv7", target_os = "androidabi"),
59+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
60+
)))]
4061
#[error("Error initializing shaderc CompileOptions")]
4162
ErrorInitializingShadercCompileOptions,
4263
}
4364

44-
#[cfg(all(
45-
not(target_os = "ios"),
46-
not(target_arch = "wasm32"),
47-
not(all(target_arch = "aarch64", target_os = "macos"))
65+
#[cfg(any(
66+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
67+
all(target_arch = "x86_64", target_os = "macos"),
68+
all(target_arch = "aarch64", target_os = "android"),
69+
all(target_arch = "armv7", target_os = "androidabi"),
70+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
4871
))]
4972
impl From<ShaderStage> for bevy_glsl_to_spirv::ShaderType {
5073
fn from(s: ShaderStage) -> bevy_glsl_to_spirv::ShaderType {
@@ -56,10 +79,12 @@ impl From<ShaderStage> for bevy_glsl_to_spirv::ShaderType {
5679
}
5780
}
5881

59-
#[cfg(all(
60-
not(target_os = "ios"),
61-
not(target_arch = "wasm32"),
62-
not(all(target_arch = "aarch64", target_os = "macos"))
82+
#[cfg(any(
83+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
84+
all(target_arch = "x86_64", target_os = "macos"),
85+
all(target_arch = "aarch64", target_os = "android"),
86+
all(target_arch = "armv7", target_os = "androidabi"),
87+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
6388
))]
6489
pub fn glsl_to_spirv(
6590
glsl_source: &str,
@@ -70,7 +95,14 @@ pub fn glsl_to_spirv(
7095
.map_err(ShaderError::Compilation)
7196
}
7297

73-
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
98+
#[cfg(not(any(
99+
target_arch = "wasm32",
100+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
101+
all(target_arch = "x86_64", target_os = "macos"),
102+
all(target_arch = "aarch64", target_os = "android"),
103+
all(target_arch = "armv7", target_os = "androidabi"),
104+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
105+
)))]
74106
impl Into<shaderc::ShaderKind> for ShaderStage {
75107
fn into(self) -> shaderc::ShaderKind {
76108
match self {
@@ -81,7 +113,14 @@ impl Into<shaderc::ShaderKind> for ShaderStage {
81113
}
82114
}
83115

84-
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
116+
#[cfg(not(any(
117+
target_arch = "wasm32",
118+
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
119+
all(target_arch = "x86_64", target_os = "macos"),
120+
all(target_arch = "aarch64", target_os = "android"),
121+
all(target_arch = "armv7", target_os = "androidabi"),
122+
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
123+
)))]
85124
pub fn glsl_to_spirv(
86125
glsl_source: &str,
87126
stage: ShaderStage,

0 commit comments

Comments
 (0)