Skip to content

[hal] Do not expose dependency on metal and objc crates #7649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Apr 29, 2025

Connections
Allows #5641 to not contain breaking changes.

Description
wgpu-hal's dependency on the metal and objc crates is currently indirectly exposed via. the parameter types on hal::metal::Surface::from_view, hal::metal::Surface::from_layer and hal::metal::Instance::create_surface_from_layer.

This is unfortunate, since it ties wgpu-hal to specific dependencies, and specific versions of said dependencies. Instead, this PR changes these methods to use NonNull<c_void>, and prefers to instead document which type the user is expected to pass here. This mirrors the top-level API already exposed in Instance::create_surface_metal.

Additionally, this PR removes metal::Instance::create_surface_from_layer, since it was only a simple wrapper, and splits metal::Surface::from_view into from_ns_view and from_ui_view to make it clearer/easier to document what the requirements are for the given type. This matches raw_window_metal::Layer's methods.

Testing
Tested using:

# macOS
cargo run --bin wgpu-examples -- cube

# iOS on Mac Catalyst using Cargo Bundle
echo "[package.metadata.bundle]" >> examples/features/Cargo.toml
cargo bundle --format=ios --target=aarch64-apple-ios-macabi --bin wgpu-examples
./target/aarch64-apple-ios-macabi/debug/bundle/ios/wgpu-examples.app/wgpu-examples cube

I believe this should suffice, as this mostly modifies the entry point to surface creation.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@madsmtm madsmtm force-pushed the metal-hal-no-expose-deps branch from 1ffe038 to 3b5ebf9 Compare April 29, 2025 14:06
@madsmtm madsmtm mentioned this pull request Apr 29, 2025
4 tasks
@madsmtm madsmtm marked this pull request as ready for review April 29, 2025 14:08
@madsmtm madsmtm requested a review from a team as a code owner April 29, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants