burtonageo / cargo-bundle

Wrap rust executables in OS-specific app bundles
Other
1.08k stars 74 forks source link

Race in macOS between creating bundle and launching it #187

Open madsmtm opened 3 weeks ago

madsmtm commented 3 weeks ago

So, this is a bit of a weird one.

I'm using cargo-bundle to launch the Winit examples on Mac Catalyst.

The command I use is:

cargo +nightly bundle --format=ios --target=aarch64-apple-ios-macabi --example=window

And then I run the binary with:

./target/aarch64-apple-ios-macabi/debug/examples/bundle/ios/winit.app/window

All good and fine, except it seems like there is some race-condition inherent between the creation of the binary, and running it, and sometimes the binary would fail to launch properly, and UIKit would throw an error.

I could reproduce it consistently with:

touch ./target/aarch64-apple-ios-macabi/debug/examples/bundle/ios/winit.app && ./target/aarch64-apple-ios-macabi/debug/examples/bundle/ios/winit.app/window

And could no longer reproduce it if I inserted a sleep 2s, either in my code or on the command line.

A bunch of rabbit holes later, I ended up finding all the winit.apps that existed on my system by running open -a winit (I had copied a few of them around), and deleting them; and suddenly everything worked fine again.

So it seems like there's something something launchctl something that keeps track of all application bundles, and that's having trouble with the bundle produced by cargo-bundle?

Idk., posting it here in case I hit the same issue again in a year.