Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ wgpu = { version = "29.0.0", path = "./wgpu", default-features = false, features
"vulkan-portability",
"angle",
"static-dxc",
"noop", # This should be removed if we ever have non-test crates that depend on wgpu
] }
wgpu-core = { version = "29.0.0", path = "./wgpu-core" }
wgpu-hal = { version = "29.0.0", path = "./wgpu-hal" }
Expand Down
34 changes: 28 additions & 6 deletions tests/tests/wgpu-dependency/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn check_feature_dependency(requirement: Requirement) {
println!("Checking: {}", requirement.human_readable_name);

let mut args = Vec::new();
args.extend(["tree", "--target", requirement.target]);
args.extend(["tree", "--edges", "no-dev", "--target", requirement.target]);

for package in requirement.packages {
args.push("--package");
Expand All @@ -43,11 +43,15 @@ fn check_feature_dependency(requirement: Requirement) {

println!("$ cargo {}", args.join(" "));

let output = Command::new("cargo")
.args(&args)
.output()
.expect("Failed to run cargo tree")
.stdout;
let output = match Command::new("cargo").args(&args).output() {
Ok(o) if o.status.success() => o.stdout,
Ok(o) => panic!(
"cargo tree failed ({}):\n{}",
o.status,
String::from_utf8_lossy(&o.stderr)
),
Err(e) => panic!("Failed to run cargo tree: {e}"),
};
let output = String::from_utf8(output).expect("Output is not valid UTF-8");

let mut any_failed = false;
Expand Down Expand Up @@ -117,6 +121,15 @@ fn wasm32_without_webgl_or_noop_does_not_depend_on_wgpu_core() {
default_features: false,
search_terms: &[Search::Negative("wgpu-core")],
});

check_feature_dependency(Requirement {
human_readable_name: "wasm32 with only `webgpu` feature does not depend on `wgpu-core`",
target: "wasm32-unknown-unknown",
packages: &["wgpu-examples"],
features: &["webgpu"],
default_features: false,
search_terms: &[Search::Negative("wgpu-core")],
});
}

#[test]
Expand All @@ -129,6 +142,15 @@ fn wasm32_with_webgpu_and_wgsl_does_not_depend_on_naga() {
default_features: false,
search_terms: &[Search::Negative("naga")],
});

check_feature_dependency(Requirement {
human_readable_name: "wasm32 with only `webgpu` feature does not depend on `naga`",
target: "wasm32-unknown-unknown",
packages: &["wgpu-examples"],
features: &["webgpu"],
default_features: false,
search_terms: &[Search::Negative("naga")],
});
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde = ["dep:serde", "bitflags/serde"]
# Enables some internal instrumentation for debugging purposes.
counters = []
# Enables variants of `Trace` other than `Trace::Off`
trace = ["std"]
trace = ["std", "serde/std"]
# Enable web-specific dependencies for wasm.
web = ["dep:js-sys", "dep:web-sys"]
exhaust = ["dep:exhaust"]
Expand Down
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ strict_asserts = ["wgpu-core?/strict_asserts", "wgpu-types/strict_asserts"]
## Enables serialization via `serde` on common wgpu types.
serde = ["wgpu-core?/serde", "wgpu-types/serde"]

# ## Allow writing of trace capture files. See [`Adapter::request_device`].
trace = ["serde", "wgpu-core?/trace"]
## Allow writing of trace capture files. See [`Adapter::request_device`].
trace = ["serde", "wgpu-core?/trace", "wgpu-types/trace"]

#! ### External libraries
# --------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/api/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};
use core::{
error, fmt,
num::NonZero,
ops::{Bound, Deref, Range, RangeBounds},
ops::{Bound, Range, RangeBounds},
};

use crate::util::Mutex;
Expand Down Expand Up @@ -287,7 +287,7 @@ impl Buffer {
#[cfg(wgpu_core)]
pub unsafe fn as_hal<A: hal::Api>(
&self,
) -> Option<impl Deref<Target = A::Buffer> + WasmNotSendSync> {
) -> Option<impl core::ops::Deref<Target = A::Buffer> + WasmNotSendSync> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't seem to have anything to do with this PR? I like it, but it's not in the PR description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When wgpu_core is removed from the build, the module-scope core::ops::Deref import becomes unused in WebGPU-only builds. I made this change to resolve that warning. (Although I did not check whether the warning is enforced in CI, maybe this configuration is an exception?).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. In that case, I would consider doing one of these three instead:

#[allow(unused_imports)]
use core::ops::Deref;
#[cfg_attr(not(wgpu_core)), expect(unused_imports))]
use core::ops::Deref;
use core::ops;
// ... use all ops items as ops::Foo 

I would consider all of these superior to making the import style inconsistent in an undocumented way. But that’s my opinion, not wgpu project style.

let buffer = self.inner.as_core_opt()?;
unsafe { buffer.context.buffer_as_hal::<A>(buffer) }
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/api/queue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::boxed::Box;
use core::ops::{Deref, RangeBounds};
use core::ops::RangeBounds;

use crate::{api::DeferredCommandBufferActions, *};

Expand Down Expand Up @@ -338,7 +338,7 @@ impl Queue {
#[cfg(wgpu_core)]
pub unsafe fn as_hal<A: hal::Api>(
&self,
) -> Option<impl Deref<Target = A::Queue> + WasmNotSendSync> {
) -> Option<impl core::ops::Deref<Target = A::Queue> + WasmNotSendSync> {
let queue = self.inner.as_core_opt()?;
unsafe { queue.context.queue_as_hal::<A>(queue) }
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ pub trait QueueWriteBufferInterface: CommonTraits {
}

pub trait BufferMappedRangeInterface: CommonTraits {
// Used only in wgpu_core's `impl QueueWriteBufferInterface`
#[cfg_attr(not(wgpu_core), expect(unused))]
fn len(&self) -> usize;

/// # Safety
Expand Down
1 change: 1 addition & 0 deletions wgpu/src/macros/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Convenience macros
#![cfg_attr(not(wgpu_core), expect(unused_macros, unused_imports))]

#[cfg(doc)]
use crate::{VertexAttribute, VertexBufferLayout, VertexFormat};
Expand Down
Loading