diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07c8f80730..5d1220f04a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,14 @@ jobs: - name: Additional core features run: cargo check --manifest-path wgpu-core/Cargo.toml --features trace --target ${{ env.TARGET }} + webgl_build: + name: Web Assembly + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - run: rustup target add wasm32-unknown-unknown + - run: cargo build --manifest-path wgpu-core/Cargo.toml --target wasm32-unknown-unknown + build: name: ${{ matrix.name }} runs-on: ${{ matrix.os }} diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 2d0c51a0d9..90e934229f 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -39,19 +39,22 @@ gpu-descriptor = { git = "https://github.com/zakarumych/gpu-descriptor", rev = " hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a" } gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a" } -[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies] gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a", features = ["naga"] } gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a", features = ["naga"] } -[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies] gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a", features = ["naga"] } gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a", optional = true } -[target.'cfg(windows)'.dependencies] +[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies] gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a" } gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a" } gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a" } +[target.'cfg(target_arch = "wasm32")'.dependencies] +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "0244e3401e9f127617cb8636397048584e7bfe8a", features = ["naga"] } + [dependencies.naga] git = "https://github.com/gfx-rs/naga" tag = "gfx-5" diff --git a/wgpu-core/build.rs b/wgpu-core/build.rs index 1a44cec6f2..2a5c02a8b3 100644 --- a/wgpu-core/build.rs +++ b/wgpu-core/build.rs @@ -6,13 +6,15 @@ fn main() { // Setup cfg aliases cfg_aliases::cfg_aliases! { // Vendors/systems + wasm: { target_arch = "wasm32" }, apple: { any(target_os = "ios", target_os = "macos") }, + unix_wo_apple: {all(unix, not(apple))}, // Backends - vulkan: { any(windows, all(unix, not(apple)), feature = "gfx-backend-vulkan") }, - metal: { apple }, - dx12: { windows }, - dx11: { windows }, - gl: { all(unix, not(apple)) }, + vulkan: { all(not(wasm), any(windows, unix_wo_apple, feature = "gfx-backend-vulkan")) }, + metal: { all(not(wasm), apple) }, + dx12: { all(not(wasm), windows) }, + dx11: { all(not(wasm), windows) }, + gl: { any(wasm, unix_wo_apple) }, } } diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 14dbd4d6cc..fc48d7eb49 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -230,15 +230,15 @@ macro_rules! gfx_select { // Note: For some reason the cfg aliases defined in build.rs don't succesfully apply in this // macro so we must specify their equivalents manually match $id.backend() { - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(all(not(target_arch = "wasm32"), any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan")))] wgt::Backend::Vulkan => $global.$method::<$crate::backend::Vulkan>( $($param),* ), - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))] wgt::Backend::Metal => $global.$method::<$crate::backend::Metal>( $($param),* ), - #[cfg(windows)] + #[cfg(all(not(target_arch = "wasm32"), windows))] wgt::Backend::Dx12 => $global.$method::<$crate::backend::Dx12>( $($param),* ), - #[cfg(windows)] + #[cfg(all(not(target_arch = "wasm32"), windows))] wgt::Backend::Dx11 => $global.$method::<$crate::backend::Dx11>( $($param),* ), - #[cfg(all(unix, not(any(target_os = "ios", target_os = "macos"))))] + #[cfg(any(target_arch = "wasm32", all(unix, not(any(target_os = "ios", target_os = "macos")))))] wgt::Backend::Gl => $global.$method::<$crate::backend::Gl>( $($param),+ ), other => panic!("Unexpected backend {:?}", other), }