Skip to content

Commit

Permalink
Remove emscripten crate features (#3467)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Feb 15, 2023
1 parent c51edd3 commit e444520
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ jobs:
set -e
# build for Emscripten/WebGL
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features --features webgl,emscripten
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features
# build cube example
cargo clippy --target ${{ matrix.target }} --example cube --features webgl,emscripten
cargo clippy --target ${{ matrix.target }} --example cube
# build raw-gles example
cargo clippy --target ${{ matrix.target }} --example raw-gles --features webgl,emscripten
cargo clippy --target ${{ matrix.target }} --example raw-gles
- name: check native
if: matrix.kind == 'native'
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ workspace = true
features = ["dx11", "dx12"]

# We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows.
[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"))))'.dependencies.wgpu-core]
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"))))'.dependencies.wgpu-core]
workspace = true
features = ["vulkan"]
2 changes: 1 addition & 1 deletion player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ features = ["metal"]
workspace = true
features = ["dx11", "dx12"]

[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
workspace = true
features = ["vulkan"]

Expand Down
3 changes: 0 additions & 3 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ dx12 = ["hal/dx12"]
# https://renderdoc.org/
renderdoc = ["hal/renderdoc"]

# Compile for the Emscripten POSIX-in-a-web-page emulation environment.
emscripten = ["hal/emscripten"]

# Apply run-time checks, even in release builds. These are in addition
# to the validation carried out at public APIs in all builds.
strict_asserts = ["wgt/strict_asserts"]
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn is_valid_copy_dst_texture_format(
}

#[cfg_attr(
any(not(target_arch = "wasm32"), feature = "emscripten"),
any(not(target_arch = "wasm32"), target_os = "emscripten"),
allow(unused)
)]
pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Ok(())
}

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub fn queue_copy_external_image_to_texture<A: HalApi>(
&self,
queue_id: id::QueueId,
Expand Down
1 change: 0 additions & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ dx12 = ["naga/hlsl-out", "native", "bit-set", "range-alloc", "winapi/std", "wina
windows_rs = ["gpu-allocator"]
dxc_shader_compiler = ["hassle-rs"]
renderdoc = ["libloading", "renderdoc-sys"]
emscripten = ["gles"]

[[example]]
name = "halmark"
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/examples/raw-gles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Emscripten build:
//! 1. install emsdk
//! 2. build this example with cargo:
//! EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten --features emscripten,webgl
//! EMCC_CFLAGS="-g -s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry -s FULL_ES3=1" cargo build --example raw-gles --target wasm32-unknown-emscripten
//! 3. copy raw-gles.em.html into target directory and open it in browser:
//! cp wgpu-hal/examples/raw-gles.em.html target/wasm32-unknown-emscripten/debug/examples

Expand Down Expand Up @@ -66,7 +66,7 @@ fn main() {
});
}

#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
fn main() {
env_logger::init();

Expand Down Expand Up @@ -116,7 +116,7 @@ fn main() {
fill_screen(&exposed, 640, 400);
}

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
fn main() {}

fn fill_screen(exposed: &hal::ExposedAdapter<hal::api::Gles>, width: u32, height: u32) {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl crate::CommandEncoder<Api> for Encoder {

unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &Resource, dst: &Resource, regions: T) {}

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
unsafe fn copy_external_image_to_texture<T>(
&mut self,
src: &wgt::ImageCopyExternalImage,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
}
}

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
unsafe fn copy_external_image_to_texture<T>(
&mut self,
src: &wgt::ImageCopyExternalImage,
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl super::Device {
/// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the texture. If `drop_guard` is
/// [`Some`], the texture must be valid until the drop implementation
/// of the drop guard is called.
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
pub unsafe fn texture_from_raw(
&self,
name: std::num::NonZeroU32,
Expand Down Expand Up @@ -125,7 +125,7 @@ impl super::Device {
/// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the renderbuffer. If `drop_guard` is
/// [`Some`], the renderbuffer must be valid until the drop implementation
/// of the drop guard is called.
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
pub unsafe fn texture_from_raw_renderbuffer(
&self,
name: std::num::NonZeroU32,
Expand Down
31 changes: 17 additions & 14 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type WlDisplayConnectFun =

type WlDisplayDisconnectFun = unsafe extern "system" fn(display: *const raw::c_void);

#[cfg(not(feature = "emscripten"))]
#[cfg(not(target_os = "emscripten"))]
type EglInstance = egl::DynamicInstance<egl::EGL1_4>;

#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
type EglInstance = egl::Instance<egl::Static>;

type WlEglWindowCreateFun = unsafe extern "system" fn(
Expand Down Expand Up @@ -423,7 +423,7 @@ struct Inner {
version: (i32, i32),
supports_native_window: bool,
config: egl::Config,
#[cfg_attr(feature = "emscripten", allow(dead_code))]
#[cfg_attr(target_os = "emscripten", allow(dead_code))]
wl_display: Option<*mut raw::c_void>,
/// Method by which the framebuffer should support srgb
srgb_kind: SrgbFrameBufferKind,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl Inner {
// and creating dummy pbuffer surface if not.
let pbuffer = if version >= (1, 5)
|| display_extensions.contains("EGL_KHR_surfaceless_context")
|| cfg!(feature = "emscripten")
|| cfg!(target_os = "emscripten")
{
log::info!("\tEGL context: +surfaceless");
None
Expand Down Expand Up @@ -624,10 +624,10 @@ unsafe impl Sync for Instance {}

impl crate::Instance<super::Api> for Instance {
unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> {
#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
let egl_result: Result<EglInstance, egl::Error> = Ok(egl::Instance::new(egl::Static));

#[cfg(not(feature = "emscripten"))]
#[cfg(not(target_os = "emscripten"))]
let egl_result = if cfg!(windows) {
unsafe {
egl::DynamicInstance::<egl::EGL1_4>::load_required_from_filename("libEGL.dll")
Expand Down Expand Up @@ -674,10 +674,10 @@ impl crate::Instance<super::Api> for Instance {
None
};

#[cfg(not(feature = "emscripten"))]
#[cfg(not(target_os = "emscripten"))]
let egl1_5 = egl.upcast::<egl::EGL1_5>();

#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
let egl1_5: Option<&Arc<EglInstance>> = Some(&egl);

let (display, wsi_library, wsi_kind) = if let (Some(library), Some(egl)) =
Expand Down Expand Up @@ -776,7 +776,10 @@ impl crate::Instance<super::Api> for Instance {
) -> Result<Surface, crate::InstanceError> {
use raw_window_handle::RawWindowHandle as Rwh;

#[cfg_attr(any(target_os = "android", feature = "emscripten"), allow(unused_mut))]
#[cfg_attr(
any(target_os = "android", target_os = "emscripten"),
allow(unused_mut)
)]
let mut inner = self.inner.lock();

match (window_handle, display_handle) {
Expand All @@ -801,7 +804,7 @@ impl crate::Instance<super::Api> for Instance {
return Err(crate::InstanceError);
}
}
#[cfg(not(feature = "emscripten"))]
#[cfg(not(target_os = "emscripten"))]
(Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => {
if inner
.wl_display
Expand Down Expand Up @@ -841,7 +844,7 @@ impl crate::Instance<super::Api> for Instance {
drop(old_inner);
}
}
#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
(Rwh::Web(_), _) => {}
other => {
log::error!("Unsupported window: {:?}", other);
Expand Down Expand Up @@ -1087,7 +1090,7 @@ impl crate::Surface<super::Api> for Surface {
wl_window = Some(window);
window
}
#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
(WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void,
(WindowKind::Unknown, Rwh::Win32(handle)) => handle.hwnd,
(WindowKind::Unknown, Rwh::AppKit(handle)) => {
Expand Down Expand Up @@ -1140,10 +1143,10 @@ impl crate::Surface<super::Api> for Surface {
}
attributes.push(egl::ATTRIB_NONE as i32);

#[cfg(not(feature = "emscripten"))]
#[cfg(not(target_os = "emscripten"))]
let egl1_5 = self.egl.instance.upcast::<egl::EGL1_5>();

#[cfg(feature = "emscripten")]
#[cfg(target_os = "emscripten")]
let egl1_5: Option<&Arc<EglInstance>> = Some(&self.egl.instance);

// Careful, we can still be in 1.4 version even if `upcast` succeeds
Expand Down
14 changes: 7 additions & 7 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ To address this, we invalidate the vertex buffers based on:
*/

///cbindgen:ignore
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
mod egl;
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
mod web;

mod adapter;
Expand All @@ -70,14 +70,14 @@ mod queue;

use crate::{CopyExtent, TextureDescriptor};

#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
pub use self::egl::{AdapterContext, AdapterContextLock};
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
use self::egl::{Instance, Surface};

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub use self::web::AdapterContext;
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
use self::web::{Instance, Surface};

use arrayvec::ArrayVec;
Expand Down Expand Up @@ -680,7 +680,7 @@ enum Command {
dst_target: BindTarget,
copy: crate::BufferCopy,
},
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
CopyExternalImageToTexture {
src: wgt::ImageCopyExternalImage,
dst: glow::Texture,
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl super::Queue {
unsafe { gl.bind_buffer(copy_dst_target, None) };
}
}
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
C::CopyExternalImageToTexture {
ref src,
dst,
Expand Down Expand Up @@ -1554,10 +1554,10 @@ impl crate::Queue<super::Api> for super::Queue {
surface: &mut super::Surface,
texture: super::Texture,
) -> Result<(), crate::SurfaceError> {
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
let gl = unsafe { &self.shared.context.get_without_egl_lock() };

#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
let gl = &self.shared.context.glow_context;

unsafe { surface.present(texture, gl) }
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub trait CommandEncoder<A: Api>: Send + Sync + fmt::Debug {
/// Works with a single array layer.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// Note: the copy extent is in physical size (rounded to the block size)
#[cfg(all(target_arch = "wasm32", not(feature = "emscripten")))]
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
unsafe fn copy_external_image_to_texture<T>(
&mut self,
src: &wgt::ImageCopyExternalImage,
Expand Down
7 changes: 1 addition & 6 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ trace = ["serde", "wgc/trace"]
replay = ["serde", "wgc/replay"]
angle = ["wgc/angle"]
webgl = ["hal", "wgc"]
emscripten = ["webgl"]
vulkan-portability = ["wgc/vulkan"]
expose-ids = []

Expand Down Expand Up @@ -128,14 +127,10 @@ workspace = true
features = ["dx11", "dx12"]

# We want the wgpu-core Vulkan backend on Unix (but not Emscripten) and Windows.
[target.'cfg(any(windows, all(unix, not(target_arch = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
workspace = true
features = ["vulkan"]

[target.'cfg(target_os = "emscripten")'.dependencies.wgc]
workspace = true
features = ["emscripten"]

[dependencies.wgt]
workspace = true

Expand Down
Loading

0 comments on commit e444520

Please sign in to comment.