Skip to content
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

macOS Sonoma (14.0) / Xcode 15.0 — Compatibility Fixes + Docs #9905

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

coreh
Copy link
Contributor

@coreh coreh commented Sep 23, 2023

Objective

Improve compatibility with macOS Sonoma and Xcode 15.0.

Solution

  • Adds the workaround by @ptxmac to ignore the invalid window sizes provided by winit on macOS 14.0
    • This still provides a slightly wrong content size when resizing (it fails to account for the window title bar, so some content gets clipped at the bottom) but it's much better than crashing.
  • Adds docs on how to work around the bindgen bug on Xcode 15.0.

Related Issues:


Changelog

  • Added a workaround for a winit-related crash under macOS Sonoma (14.0)

@Vrixyz
Copy link
Member

Vrixyz commented Sep 23, 2023

Is there a follow up issue to track when this « hack » + « slightly wrong » resizing can be fixed ?

Maybe next version of winit will help ? In the meantime that PR sounds great 👍

@coreh
Copy link
Contributor Author

coreh commented Sep 23, 2023

The fix for it is already merged to winit. However, there hasn't been a new release with it yet.

It should will be included in 0.29, so perhaps we could just use your PR (#8745) to track that? (By removing the workaround on your branch)

@Vrixyz Vrixyz mentioned this pull request Sep 23, 2023
11 tasks
@Vrixyz
Copy link
Member

Vrixyz commented Sep 23, 2023

I’d rather avoid my PR to be a tracking issue for this fix, because:

I added a link though, so we’re not forgetting it, I’ll create a standalone issue or PR after we’re done with #8745 if need be.

@rparrett
Copy link
Contributor

The fix for it is already merged to winit. However, there hasn't been a new release with it yet.

The fix seems relatively simple -- I wonder if they would be willing to backport it for a minor 0.28 release.

Comment on lines 9 to 31
Xcode 15.x introduces a few `clang` changes that can cause the build to fail due an identifier format not expected by older versions of `bindgen`. The error looks like this:

```
error: failed to run custom build command for `coreaudio-sys v0.2.10`

Caused by:
process didn't exit successfully: `<path to your project>/target/debug/build/coreaudio-sys-7e0a7d7c97b2ec33/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=COREAUDIO_SDK_PATH
cargo:rustc-link-lib=framework=AudioUnit
cargo:rustc-link-lib=framework=CoreAudio
cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS

--- stderr
thread 'main' panicked at '"enum_(unnamed_at_/Applications/Xcode_app/Contents/Developer/Platforms/MacOSX_platform/Developer/SDKs/MacOSX14_0_sdk/usr/include/MacTypes_h_382_1)" is not a valid Ident', <path to your user folder>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.56/src/fallback.rs:811:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

There's an upstream [issue](https://github.com/RustAudio/coreaudio-sys/issues/85) in `coreaudio-sys` to update `bindgen`. In the mean time you can work around this by installing clang from [Homebrew](https://brew.sh):

```sh
brew install llvm@15
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for being late to see the coreaudio-sys issue. A new minor version of coreaudio-sys has been published with an updated version of bindgen so this work around shouldn't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, that's even better!

Thanks for updating it, I'll update the PR bumping the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually scratch that, I forgot that Cargo.lock is not tracked for libraries, so there's no need to update anything 🥳

I just removed the special instructions

@mockersf mockersf added P-Crash A sudden unexpected crash O-MacOS Specific to the MacOS (Apple) desktop operating system P-High This is particularly urgent, and deserves immediate attention labels Sep 27, 2023
@mockersf mockersf added this to the 0.11.3 milestone Sep 27, 2023
mockersf pushed a commit to mockersf/bevy that referenced this pull request Sep 27, 2023
mockersf pushed a commit to mockersf/bevy that referenced this pull request Sep 27, 2023
Co-Authored-By: Marco Buono <418473+coreh@users.noreply.github.com>
@cart cart added this pull request to the merge queue Sep 27, 2023
Merged via the queue into bevyengine:main with commit 20ed3e0 Sep 27, 2023
24 checks passed
@n-raine
Copy link

n-raine commented Sep 28, 2023

FWIW it looks like winit's maintainers have just backported the fix and released it as 0.28.7 (see the last comments on the linked issue), so hopefully this can be fixed properly now?

ameknite added a commit to ameknite/bevy that referenced this pull request Oct 1, 2023
github-merge-queue bot pushed a commit that referenced this pull request Oct 2, 2023
ameknite added a commit to ameknite/bevy that referenced this pull request Oct 3, 2023
ameknite added a commit to ameknite/bevy that referenced this pull request Oct 3, 2023
regnarock pushed a commit to regnarock/bevy that referenced this pull request Oct 13, 2023
github-merge-queue bot pushed a commit that referenced this pull request Dec 21, 2023
# Objective

- Update winit dependency to 0.29

## Changelog

### KeyCode changes

- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.

KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.

In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.

### Other changes
- Use `web-time` rather than `instant` crate.
(rust-windowing/winit#2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: emilk/egui#1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(#10702 (comment))

## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
rust-windowing/winit#2945
- (windows) Window content doesn't refresh at all when resizing. By
reading rust-windowing/winit#2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait rust-windowing/winit#3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔

## Follow up 

I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(#10702 (comment))
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
rust-windowing/winit#3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
#10702 (review)
- #9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
  - blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
#10702 (comment)
- remove `instant` dependency, [replaced
by](rust-windowing/winit#2836) `web_time`), we'd
need to update to :
  - fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
    - [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](#8745 (comment))
  - we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](#8745 (comment))
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- #10689 (comment)
## Migration Guide

This PR should have one.
@Vrixyz Vrixyz mentioned this pull request Dec 21, 2023
23 tasks
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
…gine#9905)

# Objective

Improve compatibility with macOS Sonoma and Xcode 15.0.

## Solution

- Adds the workaround by @ptxmac to ignore the invalid window sizes
provided by `winit` on macOS 14.0
- This still provides a slightly wrong content size when resizing (it
fails to account for the window title bar, so some content gets clipped
at the bottom) but it's _much better_ than crashing.
- Adds docs on how to work around the `bindgen` bug on Xcode 15.0.

## Related Issues:

- RustAudio/coreaudio-sys#85
- rust-windowing/winit#2876

---

## Changelog

- Added a workaround for a `winit`-related crash under macOS Sonoma
(14.0)

---------

Co-authored-by: Peter Kristensen <peter@ptx.dk>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
Subserial pushed a commit to Subserial/bevy_winit_hook that referenced this pull request Feb 20, 2024
# Objective

- Update winit dependency to 0.29

## Changelog

### KeyCode changes

- Removed `ScanCode`, as it was [replaced by
KeyCode](https://github.com/rust-windowing/winit/blob/master/CHANGELOG.md#0292).
- `ReceivedCharacter.char` is now a `SmolStr`, [relevant
doc](https://docs.rs/winit/latest/winit/event/struct.KeyEvent.html#structfield.text).
- Changed most `KeyCode` values, and added more.

KeyCode has changed meaning. With this PR, it refers to physical
position on keyboard rather than the printed letter on keyboard keys.

In practice this means:
- On QWERTY keyboard layouts, nothing changes
- On any other keyboard layout, `KeyCode` no longer reflects the label
on key.
- This is "good". In bevy 0.12, when you used WASD for movement, users
with non-QWERTY keyboards couldn't play your game! This was especially
bad for non-latin keyboards. Now, WASD represents the physical keys. A
French player will press the ZQSD keys, which are near each other,
Kyrgyz players will use "Цфыв".
- This is "bad" as well. You can't know in advance what the label of the
key for input is. Your UI says "press WASD to move", even if in reality,
they should be pressing "ZQSD" or "Цфыв". You also no longer can use
`KeyCode` for text inputs. In any case, it was a pretty bad API for text
input. You should use `ReceivedCharacter` now instead.

### Other changes
- Use `web-time` rather than `instant` crate.
(rust-windowing/winit#2836)
- winit did split `run_return` in `run_onDemand` and `pump_events`, I
did the same change in bevy_winit and used `pump_events`.
- Removed `return_from_run` from `WinitSettings` as `winit::run` now
returns on supported platforms.
- I left the example "return_after_run" as I think it's still useful.
- This winit change is done partly to allow to create a new window after
quitting all windows: emilk/egui#1918 ; this
PR doesn't address.
- added `width` and `height` properties in the `canvas` from wasm
example
(bevyengine/bevy#10702 (comment))

## Known regressions (important follow ups?)
- Provide an API for reacting when a specific key from current layout
was released.
- possible solutions: use winit::Key from winit::KeyEvent ; mapping
between KeyCode and Key ; or .
- We don't receive characters through alt+numpad (e.g. alt + 151 = "ù")
anymore ; reproduced on winit example "ime". maybe related to
rust-windowing/winit#2945
- (windows) Window content doesn't refresh at all when resizing. By
reading rust-windowing/winit#2900 ; I suspect
we should just fire a `window.request_redraw();` from `AboutToWait`, and
handle actual redrawing within `RedrawRequested`. I'm not sure how to
move all that code so I'd appreciate it to be a follow up.
- (windows) unreleased winit fix for using set_control_flow in
AboutToWait rust-windowing/winit#3215 ; ⚠️ I'm
not sure what the implications are, but that feels bad 🤔

## Follow up 

I'd like to avoid bloating this PR, here are a few follow up tasks
worthy of a separate PR, or new issue to track them once this PR is
closed, as they would either complicate reviews, or at risk of being
controversial:
- remove CanvasParentResizePlugin
(bevyengine/bevy#10702 (comment))
- avoid mentionning explicitly winit in docs from bevy_window ?
- NamedKey integration on bevy_input:
rust-windowing/winit#3143 introduced a new
NamedKey variant. I implemented it only on the converters but we'd
benefit making the same changes to bevy_input.
- Add more info in KeyboardInput
bevyengine/bevy#10702 (review)
- bevyengine/bevy#9905 added a workaround on a
bug allegedly fixed by winit 0.29. We should check if it's still
necessary.
- update to raw_window_handle 0.6
  - blocked by wgpu
- Rename `KeyCode` to `PhysicalKeyCode`
bevyengine/bevy#10702 (comment)
- remove `instant` dependency, [replaced
by](rust-windowing/winit#2836) `web_time`), we'd
need to update to :
  - fastrand >= 2.0
- [`async-executor`](https://github.com/smol-rs/async-executor) >= 1.7
    - [`futures-lite`](https://github.com/smol-rs/futures-lite) >= 2.0
- Verify license, see
[discussion](bevyengine/bevy#8745 (comment))
  - we might be missing a short notice or description of changes made
- Consider using https://github.com/rust-windowing/cursor-icon directly
rather than vendoring it in bevy.
- investigate [this
unwrap](bevyengine/bevy#8745 (comment))
(`winit_window.canvas().unwrap();`)
- Use more good things about winit's update
- bevyengine/bevy#10689 (comment)
## Migration Guide

This PR should have one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-MacOS Specific to the MacOS (Apple) desktop operating system P-Crash A sudden unexpected crash P-High This is particularly urgent, and deserves immediate attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants