diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml index 698e6dd0554e2..a74e50d1da2a1 100644 --- a/.github/workflows/post-release.yml +++ b/.github/workflows/post-release.yml @@ -44,7 +44,7 @@ jobs: --no-push \ --exclude ci \ --exclude errors \ - --exclude bevy-ios-example \ + --exclude bevy_mobile_example \ --exclude build-wasm-example - name: Create PR diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ac6375b3c4ba..5bf527fcf2321 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,7 +41,7 @@ jobs: --dependent-version upgrade \ --exclude ci \ --exclude errors \ - --exclude bevy-ios-example \ + --exclude bevy_mobile_example \ --exclude build-wasm-example - name: Create PR diff --git a/.github/workflows/validation-jobs.yml b/.github/workflows/validation-jobs.yml index ea98a13261fab..4d306320dae00 100644 --- a/.github/workflows/validation-jobs.yml +++ b/.github/workflows/validation-jobs.yml @@ -29,7 +29,7 @@ jobs: run: rustup target add aarch64-apple-ios x86_64-apple-ios - name: Build and install iOS app in iOS Simulator. - run: cd examples/ios && make install + run: cd examples/mobile && make install build-android: runs-on: ubuntu-latest @@ -56,7 +56,7 @@ jobs: run: cargo install --force cargo-apk - name: Build APK - run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy-android-example + run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example run-examples-on-windows-dx12: runs-on: windows-latest diff --git a/Cargo.toml b/Cargo.toml index dec2d5c128464..e2292acec8925 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,7 @@ rust-version = "1.67.0" exclude = ["benches", "crates/bevy_ecs_compile_fail_tests", "crates/bevy_reflect_compile_fail_tests"] members = [ "crates/*", - "examples/android", - "examples/ios", + "examples/mobile", "tools/ci", "tools/build-example-pages", "tools/build-wasm-example", diff --git a/crates/bevy_audio/Cargo.toml b/crates/bevy_audio/Cargo.toml index eca14a2c34ba1..d943feee34880 100644 --- a/crates/bevy_audio/Cargo.toml +++ b/crates/bevy_audio/Cargo.toml @@ -21,6 +21,9 @@ anyhow = "1.0.4" rodio = { version = "0.16", default-features = false } parking_lot = "0.12.1" +[target.'cfg(target_os = "android")'.dependencies] +oboe = { version = "0.4", features = ["shared-stdcxx"] } + [target.'cfg(target_arch = "wasm32")'.dependencies] rodio = { version = "0.16", default-features = false, features = ["wasm-bindgen"] } diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 67d77d00b2dd6..ccccd64619c8b 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -230,7 +230,7 @@ struct WinitPersistentState { impl Default for WinitPersistentState { fn default() -> Self { Self { - active: true, + active: false, low_power_event: false, redraw_request_sent: false, timeout_reached: false, @@ -289,7 +289,7 @@ pub fn winit_runner(mut app: App) { } } - { + if winit_state.active { #[cfg(not(target_arch = "wasm32"))] let (commands, mut new_windows, created_window_writer, winit_windows) = create_window_system_state.get_mut(&mut app.world); @@ -474,14 +474,7 @@ pub fn winit_runner(mut app: App) { } }, WindowEvent::Touch(touch) => { - let mut location = - touch.location.to_logical(window.resolution.scale_factor()); - - // On a mobile window, the start is from the top while on PC/Linux/OSX from - // bottom - if cfg!(target_os = "android") || cfg!(target_os = "ios") { - location.y = window.height() as f64 - location.y; - } + let location = touch.location.to_logical(window.resolution.scale_factor()); // Event input_events @@ -615,6 +608,13 @@ pub fn winit_runner(mut app: App) { } event::Event::Suspended => { winit_state.active = false; + #[cfg(target_os = "android")] + { + // Bevy doesn't support suspend/resume so we just exit + // and Android will restart the application on resume + // TODO: Save save some state and load on resume + *control_flow = ControlFlow::Exit; + } } event::Event::Resumed => { winit_state.active = true; diff --git a/examples/README.md b/examples/README.md index 11a3c64351bed..8f92252b3cc07 100644 --- a/examples/README.md +++ b/examples/README.md @@ -368,7 +368,7 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus To run on a device setup for Android development, run: ```sh -cargo apk run --example android_example +cargo apk run -p bevy_mobile_example ``` When using Bevy as a library, the following fields must be added to `Cargo.toml`: @@ -415,7 +415,7 @@ min_sdk_version = >>API or less<< Example | File | Description --- | --- | --- -`android` | [`android/android.rs`](./android/android.rs) | The `3d/3d_scene.rs` example for Android +`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound ## iOS @@ -436,7 +436,7 @@ rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim Using bash: ```sh -cd examples/ios +cd examples/mobile make run ``` @@ -451,7 +451,7 @@ DEVICE_ID=${YOUR_DEVICE_ID} make run If you'd like to see xcode do stuff, you can run ```sh -open bevy_ios_example.xcodeproj/ +open bevy_mobile_example.xcodeproj/ ``` which will open xcode. You then must push the zoom zoom play button and wait @@ -459,7 +459,7 @@ for the magic. Example | File | Description --- | --- | --- -`ios` | [`ios/src/lib.rs`](./ios/src/lib.rs) | The `3d/3d_scene.rs` example for iOS +`ios` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound ## WASM diff --git a/examples/README.md.tpl b/examples/README.md.tpl index 21e894198a7d9..19e0007274884 100644 --- a/examples/README.md.tpl +++ b/examples/README.md.tpl @@ -98,7 +98,7 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus To run on a device setup for Android development, run: ```sh -cargo apk run --example android_example +cargo apk run -p bevy_mobile_example ``` When using Bevy as a library, the following fields must be added to `Cargo.toml`: @@ -145,7 +145,7 @@ min_sdk_version = >>API or less<< Example | File | Description --- | --- | --- -`android` | [`android/android.rs`](./android/android.rs) | The `3d/3d_scene.rs` example for Android +`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound ## iOS @@ -166,7 +166,7 @@ rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim Using bash: ```sh -cd examples/ios +cd examples/mobile make run ``` @@ -181,7 +181,7 @@ DEVICE_ID=${YOUR_DEVICE_ID} make run If you'd like to see xcode do stuff, you can run ```sh -open bevy_ios_example.xcodeproj/ +open bevy_mobile_example.xcodeproj/ ``` which will open xcode. You then must push the zoom zoom play button and wait @@ -189,7 +189,7 @@ for the magic. Example | File | Description --- | --- | --- -`ios` | [`ios/src/lib.rs`](./ios/src/lib.rs) | The `3d/3d_scene.rs` example for iOS +`ios` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound ## WASM diff --git a/examples/android/src/lib.rs b/examples/android/src/lib.rs deleted file mode 100644 index 244027265a2cf..0000000000000 --- a/examples/android/src/lib.rs +++ /dev/null @@ -1,54 +0,0 @@ -use bevy::{ - prelude::*, - render::{ - settings::{WgpuSettings, WgpuSettingsPriority}, - RenderPlugin, - }, -}; - -// the `bevy_main` proc_macro generates the required android boilerplate -#[bevy_main] -fn main() { - App::new() - .add_plugins(DefaultPlugins.set(RenderPlugin { - // This configures the app to use the most compatible rendering settings. - // They help with compatibility with as many devices as possible. - wgpu_settings: WgpuSettings { - priority: WgpuSettingsPriority::Compatibility, - ..default() - }, - })) - .add_startup_system(setup) - .run(); -} - -/// set up a simple 3D scene -fn setup( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - // plane - commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), - ..default() - }); - // cube - commands.spawn(PbrBundle { - mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), - material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), - transform: Transform::from_xyz(0.0, 0.5, 0.0), - ..default() - }); - // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..default() - }); - // camera - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); -} diff --git a/examples/ios/Cargo.toml b/examples/ios/Cargo.toml deleted file mode 100644 index 2e2d425dd287c..0000000000000 --- a/examples/ios/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "bevy-ios-example" -version = "0.1.0" -edition = "2021" -description = "Example for building an iOS app with Bevy" -publish = false -license = "MIT OR Apache-2.0" - -[lib] -name = "bevy_ios_example" -crate-type = ["staticlib"] - -[dependencies] -bevy = { path = "../../" } diff --git a/examples/ios/.gitignore b/examples/mobile/.gitignore similarity index 100% rename from examples/ios/.gitignore rename to examples/mobile/.gitignore diff --git a/examples/android/Cargo.toml b/examples/mobile/Cargo.toml similarity index 75% rename from examples/android/Cargo.toml rename to examples/mobile/Cargo.toml index 6f8cd0074a7bf..8101ca0da6b4f 100644 --- a/examples/android/Cargo.toml +++ b/examples/mobile/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "bevy-android-example" +name = "bevy_mobile_example" version = "0.1.0" edition = "2021" -description = "Example for building an Android app with Bevy" +description = "Example for building an iOS or Android app with Bevy" publish = false license = "MIT OR Apache-2.0" [lib] -name = "bevy_android_example" -crate-type = ["cdylib"] +name = "bevy_mobile_example" +crate-type = ["staticlib", "cdylib"] [dependencies] bevy = { path = "../../" } diff --git a/examples/ios/Makefile b/examples/mobile/Makefile similarity index 57% rename from examples/ios/Makefile rename to examples/mobile/Makefile index bb5444093245f..1b12ab1d815ac 100644 --- a/examples/ios/Makefile +++ b/examples/mobile/Makefile @@ -6,19 +6,19 @@ ifndef DEVICE_ID endif run: install - xcrun simctl launch --console $(DEVICE) com.rust.bevy-ios-example + xcrun simctl launch --console $(DEVICE) com.rust.bevy_mobile_example boot-sim: xcrun simctl boot $(DEVICE) || true install: xcodebuild-simulator boot-sim - xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/bevy_ios_example.app + xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/bevy_mobile_example.app xcodebuild-simulator: - IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)" + IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_mobile_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)" xcodebuild-iphone: - IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -arch arm64 + IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_mobile_example -configuration Debug -derivedDataPath build -arch arm64 clean: rm -r build diff --git a/examples/ios/bevy_ios_example.xcodeproj/.gitignore b/examples/mobile/bevy_mobile_example.xcodeproj/.gitignore similarity index 100% rename from examples/ios/bevy_ios_example.xcodeproj/.gitignore rename to examples/mobile/bevy_mobile_example.xcodeproj/.gitignore diff --git a/examples/ios/bevy_ios_example.xcodeproj/project.pbxproj b/examples/mobile/bevy_mobile_example.xcodeproj/project.pbxproj similarity index 94% rename from examples/ios/bevy_ios_example.xcodeproj/project.pbxproj rename to examples/mobile/bevy_mobile_example.xcodeproj/project.pbxproj index 790312c38e20a..4ac87d8415e26 100644 --- a/examples/ios/bevy_ios_example.xcodeproj/project.pbxproj +++ b/examples/mobile/bevy_mobile_example.xcodeproj/project.pbxproj @@ -28,7 +28,7 @@ /* Begin PBXFileReference section */ 160DB77300A3F1806F024D47 /* bindings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bindings.h; sourceTree = ""; }; - 55EAC02897847195D2F44C15 /* bevy_ios_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bevy_ios_example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 55EAC02897847195D2F44C15 /* bevy_mobile_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bevy_mobile_example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 57CD6305253C7A940098CD4A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 57CD630A253C7F5F0098CD4A /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = ../../../assets; sourceTree = ""; }; 8EE7F1E3B0303533925D7E33 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; @@ -58,7 +58,7 @@ 321F7D6A765B38E746C35105 /* Products */ = { isa = PBXGroup; children = ( - 55EAC02897847195D2F44C15 /* bevy_ios_example.app */, + 55EAC02897847195D2F44C15 /* bevy_mobile_example.app */, ); name = Products; sourceTree = ""; @@ -116,9 +116,9 @@ /* End PBXLegacyTarget section */ /* Begin PBXNativeTarget section */ - 3BDB8152E4962373181B4FE5 /* bevy_ios_example */ = { + 3BDB8152E4962373181B4FE5 /* bevy_mobile_example */ = { isa = PBXNativeTarget; - buildConfigurationList = E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_ios_example" */; + buildConfigurationList = E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_mobile_example" */; buildPhases = ( 9F13800790AD9DBC2BC0F116 /* Sources */, D5A822CB2D6847BA8800BE4C /* Frameworks */, @@ -129,9 +129,9 @@ dependencies = ( 19D4B9C22ADC6705B5132B4C /* PBXTargetDependency */, ); - name = bevy_ios_example; - productName = bevy_ios_example; - productReference = 55EAC02897847195D2F44C15 /* bevy_ios_example.app */; + name = bevy_mobile_example; + productName = bevy_mobile_example; + productReference = 55EAC02897847195D2F44C15 /* bevy_mobile_example.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -142,7 +142,7 @@ attributes = { LastUpgradeCheck = 1240; }; - buildConfigurationList = 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_ios_example" */; + buildConfigurationList = 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_mobile_example" */; compatibilityVersion = "Xcode 10.0"; developmentRegion = en; hasScannedForEncodings = 0; @@ -153,7 +153,7 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 3BDB8152E4962373181B4FE5 /* bevy_ios_example */, + 3BDB8152E4962373181B4FE5 /* bevy_mobile_example */, D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */, ); }; @@ -290,10 +290,10 @@ ); OTHER_LDFLAGS = ( "$(inherited)", - "-lbevy_ios_example", + "-lbevy_mobile_example", "-lc++abi", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy-ios-example"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy_mobile_example"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -397,10 +397,10 @@ ); OTHER_LDFLAGS = ( "$(inherited)", - "-lbevy_ios_example", + "-lbevy_mobile_example", "-lc++abi", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy-ios-example"; + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy_mobile_example"; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -422,7 +422,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_ios_example" */ = { + 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_mobile_example" */ = { isa = XCConfigurationList; buildConfigurations = ( 4AD7BC6FDD56FF18FA6DA7D7 /* Debug */, @@ -440,7 +440,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; }; - E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_ios_example" */ = { + E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_mobile_example" */ = { isa = XCConfigurationList; buildConfigurations = ( A2D5B73DD30D562B6F366526 /* Debug */, diff --git a/examples/ios/bevy_ios_example.xcodeproj/xcshareddata/xcschemes/bevy_ios_example.xcscheme b/examples/mobile/bevy_mobile_example.xcodeproj/xcshareddata/xcschemes/bevy_mobile_example.xcscheme similarity index 81% rename from examples/ios/bevy_ios_example.xcodeproj/xcshareddata/xcschemes/bevy_ios_example.xcscheme rename to examples/mobile/bevy_mobile_example.xcodeproj/xcshareddata/xcschemes/bevy_mobile_example.xcscheme index e9da20104f702..21da7f3077f8e 100644 --- a/examples/ios/bevy_ios_example.xcodeproj/xcshareddata/xcschemes/bevy_ios_example.xcscheme +++ b/examples/mobile/bevy_mobile_example.xcodeproj/xcshareddata/xcschemes/bevy_mobile_example.xcscheme @@ -15,9 +15,9 @@ + BuildableName = "bevy_mobile_example.app" + BlueprintName = "bevy_mobile_example" + ReferencedContainer = "container:bevy_mobile_example.xcodeproj"> @@ -45,9 +45,9 @@ + BuildableName = "bevy_mobile_example.app" + BlueprintName = "bevy_mobile_example" + ReferencedContainer = "container:bevy_mobile_example.xcodeproj"> @@ -62,9 +62,9 @@ + BuildableName = "bevy_mobile_example.app" + BlueprintName = "bevy_mobile_example" + ReferencedContainer = "container:bevy_mobile_example.xcodeproj"> diff --git a/examples/ios/build_rust_deps.sh b/examples/mobile/build_rust_deps.sh similarity index 85% rename from examples/ios/build_rust_deps.sh rename to examples/mobile/build_rust_deps.sh index 7714d6c6f851c..2914faad5c0d0 100755 --- a/examples/ios/build_rust_deps.sh +++ b/examples/mobile/build_rust_deps.sh @@ -40,16 +40,16 @@ for arch in $ARCHS; do # Intel iOS simulator export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" - cargo build --lib $RELFLAG --target x86_64-apple-ios + cargo rustc --crate-type staticlib --lib $RELFLAG --target x86_64-apple-ios ;; arm64) if [ $IS_SIMULATOR -eq 0 ]; then # Hardware iOS targets - cargo build --lib $RELFLAG --target aarch64-apple-ios + cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios else # M1 iOS simulator -- currently in Nightly only and requires to build `libstd` - cargo build --lib $RELFLAG --target aarch64-apple-ios-sim + cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios-sim fi esac done diff --git a/examples/ios/ios-src/Info.plist b/examples/mobile/ios-src/Info.plist similarity index 100% rename from examples/ios/ios-src/Info.plist rename to examples/mobile/ios-src/Info.plist diff --git a/examples/ios/ios-src/bindings.h b/examples/mobile/ios-src/bindings.h similarity index 100% rename from examples/ios/ios-src/bindings.h rename to examples/mobile/ios-src/bindings.h diff --git a/examples/ios/ios-src/main.m b/examples/mobile/ios-src/main.m similarity index 100% rename from examples/ios/ios-src/main.m rename to examples/mobile/ios-src/main.m diff --git a/examples/ios/src/lib.rs b/examples/mobile/src/lib.rs similarity index 98% rename from examples/ios/src/lib.rs rename to examples/mobile/src/lib.rs index f7474b37433a5..76651e24e1767 100644 --- a/examples/ios/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -1,6 +1,6 @@ use bevy::{input::touch::TouchPhase, prelude::*, window::WindowMode}; -// the `bevy_main` proc_macro generates the required ios boilerplate +// the `bevy_main` proc_macro generates the required boilerplate for iOS and Android #[bevy_main] fn main() { App::new()