Skip to content

Commit d59a3dd

Browse files
committed
iOS: replace cargo-lipo, and update for new macOS (#3109)
# Objective - Remove `cargo-lipo` as [it's deprecated](https://github.com/TimNN/cargo-lipo#maintenance-status) and doesn't work on new Apple processors - Fix CI that will fail as soon as GitHub update the worker used by Bevy to macOS 11 ## Solution - Replace `cargo-lipo` with building with the correct target - Setup the correct path to libraries by using `xcrun --show-sdk-path` - Also try and fix path to cmake in case it's not found but available through homebrew
1 parent 1b8453d commit d59a3dd

File tree

6 files changed

+146
-28
lines changed

6 files changed

+146
-28
lines changed

examples/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,14 @@ Example | File | Description
322322

323323
### Setup
324324

325+
You need to install the correct rust targets:
326+
327+
- `aarch64-apple-ios`: iOS devices
328+
- `x86_64-apple-ios`: iOS simulator on x86 processors
329+
- `aarch64-apple-ios-sim`: iOS simulator on Apple processors
330+
325331
```sh
326-
rustup target add aarch64-apple-ios x86_64-apple-ios
327-
cargo install cargo-lipo
332+
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
328333
```
329334

330335
### Build & Run
@@ -353,15 +358,6 @@ open bevy_ios_example.xcodeproj/
353358
which will open xcode. You then must push the zoom zoom play button and wait
354359
for the magic.
355360

356-
The Xcode build GUI will by default build the rust library for both
357-
`x86_64-apple-ios`, and `aarch64-apple-ios` which may take a while. If you'd
358-
like speed this up, you update the `IOS_TARGETS` User-Defined environment
359-
variable in the "`cargo_ios` target" to be either `x86_64-apple-ios` or
360-
`aarch64-apple-ios` depending on your goal.
361-
362-
Note: if you update this variable in Xcode, it will also change the default
363-
used for the `Makefile`.
364-
365361
Example | File | Description
366362
--- | --- | ---
367363
`ios` | [`ios/src/lib.rs`](./ios/src/lib.rs) | The `3d/3d_scene.rs` example for iOS

examples/ios/Cargo.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ name = "bevy_ios_example"
1111
crate-type = ["staticlib"]
1212

1313
[dependencies]
14-
bevy = { path = "../../", features = [ "bevy_gilrs", "bevy_gltf", "bevy_wgpu", "bevy_winit", "render", "png", "hdr", "bevy_audio", "mp3"], default-features = false}
14+
bevy = { path = "../../", features = [
15+
"bevy_audio",
16+
"bevy_core_pipeline",
17+
"bevy_gltf2",
18+
"bevy_wgpu",
19+
"bevy_sprite2",
20+
"bevy_render2",
21+
"bevy_pbr2",
22+
"bevy_winit",
23+
"render",
24+
"png",
25+
"hdr",
26+
"mp3",
27+
"x11",
28+
"filesystem_watcher"
29+
], default-features = false}

examples/ios/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ install: xcodebuild-simulator boot-sim
1515
xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/bevy_ios_example.app
1616

1717
xcodebuild-simulator:
18-
IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)"
18+
IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)"
1919

2020
xcodebuild-iphone:
21-
IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -arch arm64
21+
IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -arch arm64
2222

2323
clean:
2424
rm -r build

examples/ios/bevy_ios_example.xcodeproj/project.pbxproj

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,17 @@
276276
"$(inherited)",
277277
"@executable_path/Frameworks",
278278
);
279-
LIBRARY_SEARCH_PATHS = (
279+
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = (
280280
"$(inherited)",
281-
../../target/universal/release,
281+
"../../target/aarch64-apple-ios/release",
282+
);
283+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = (
284+
"$(inherited)",
285+
"../../target/aarch64-apple-ios-sim/release",
286+
);
287+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = (
288+
"$(inherited)",
289+
"../../target/x86_64-apple-ios/release",
282290
);
283291
OTHER_LDFLAGS = (
284292
"$(inherited)",
@@ -346,7 +354,6 @@
346354
8265913A25816D964A847F1B /* Debug */ = {
347355
isa = XCBuildConfiguration;
348356
buildSettings = {
349-
IOS_TARGETS = "";
350357
LD_RUNPATH_SEARCH_PATHS = (
351358
"$(inherited)",
352359
"@executable_path/Frameworks",
@@ -376,9 +383,17 @@
376383
"$(inherited)",
377384
"@executable_path/Frameworks",
378385
);
379-
LIBRARY_SEARCH_PATHS = (
386+
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = (
387+
"$(inherited)",
388+
"../../target/aarch64-apple-ios/debug",
389+
);
390+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = (
391+
"$(inherited)",
392+
"../../target/aarch64-apple-ios-sim/debug",
393+
);
394+
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = (
380395
"$(inherited)",
381-
../../target/universal/debug,
396+
"../../target/x86_64-apple-ios/debug",
382397
);
383398
OTHER_LDFLAGS = (
384399
"$(inherited)",
@@ -394,7 +409,6 @@
394409
FEA9B18D9236F9F6DC6DF799 /* Release */ = {
395410
isa = XCBuildConfiguration;
396411
buildSettings = {
397-
IOS_TARGETS = "";
398412
LD_RUNPATH_SEARCH_PATHS = (
399413
"$(inherited)",
400414
"@executable_path/Frameworks",

examples/ios/build_rust_deps.sh

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
set -e
3+
# based on https://github.com/mozilla/glean/blob/main/build-scripts/xc-universal-binary.sh
4+
5+
set -eux
46

57
PATH=$PATH:$HOME/.cargo/bin
68

7-
# If you want your build to run faster, add a "--targets x86_64-apple-ios" for just using the ios simulator.
8-
if [ -n ${IOS_TARGETS} ]; then
9-
cargo lipo --targets ${IOS_TARGETS}
9+
RELFLAG=
10+
if [[ "$CONFIGURATION" != "Debug" ]]; then
11+
RELFLAG=--release
12+
fi
13+
14+
set -euvx
15+
16+
# add path to the system SDK, needed since macOS 11
17+
if [ -z ${LIBRARY_PATH+x} ]; then
18+
export LIBRARY_PATH="$(xcrun --show-sdk-path)/usr/lib"
1019
else
11-
cargo lipo
20+
export LIBRARY_PATH="$LIBRARY_PATH:$(xcrun --show-sdk-path)/usr/lib"
21+
fi
22+
23+
# add homebrew bin path, as it's the most commonly used package manager on macOS
24+
# this is needed for cmake on apple arm processors as it's not available by default
25+
export PATH="$PATH:/opt/homebrew/bin"
26+
27+
IS_SIMULATOR=0
28+
if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then
29+
IS_SIMULATOR=1
1230
fi
31+
32+
for arch in $ARCHS; do
33+
case "$arch" in
34+
x86_64)
35+
if [ $IS_SIMULATOR -eq 0 ]; then
36+
echo "Building for x86_64, but not a simulator build. What's going on?" >&2
37+
exit 2
38+
fi
39+
40+
# Intel iOS simulator
41+
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
42+
cargo build --lib $RELFLAG --target x86_64-apple-ios
43+
;;
44+
45+
arm64)
46+
if [ $IS_SIMULATOR -eq 0 ]; then
47+
# Hardware iOS targets
48+
cargo build --lib $RELFLAG --target aarch64-apple-ios
49+
else
50+
# M1 iOS simulator -- currently in Nightly only and requires to build `libstd`
51+
cargo build --lib $RELFLAG --target aarch64-apple-ios-sim
52+
fi
53+
esac
54+
done

examples/ios/src/lib.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
use bevy::{prelude::*, window::WindowMode};
1+
use bevy::{
2+
audio::{Audio, AudioPlugin},
3+
input::touch::TouchPhase,
4+
math::{Vec2, Vec3},
5+
pbr2::{PbrBundle, PointLight, PointLightBundle, StandardMaterial},
6+
prelude::{
7+
bevy_main, App, AssetServer, Assets, Commands, EventReader, Local, Query, Res, ResMut,
8+
TouchInput, Transform, With,
9+
},
10+
render2::{
11+
camera::{Camera, PerspectiveCameraBundle},
12+
color::Color,
13+
mesh::{shape, Mesh},
14+
view::Msaa,
15+
},
16+
window::{WindowDescriptor, WindowMode, Windows},
17+
PipelinedDefaultPlugins,
18+
};
219

320
// the `bevy_main` proc_macro generates the required ios boilerplate
421
#[bevy_main]
@@ -11,11 +28,40 @@ fn main() {
1128
..Default::default()
1229
})
1330
.insert_resource(Msaa { samples: 4 })
14-
.add_plugins(DefaultPlugins)
31+
.add_plugins(PipelinedDefaultPlugins)
32+
.add_plugin(AudioPlugin)
1533
.add_startup_system(setup_scene)
1634
.add_startup_system(setup_music)
35+
.add_system(touch_camera)
1736
.run();
1837
}
38+
39+
fn touch_camera(
40+
windows: ResMut<Windows>,
41+
mut touches: EventReader<TouchInput>,
42+
mut camera: Query<&mut Transform, With<Camera>>,
43+
mut last_position: Local<Option<Vec2>>,
44+
) {
45+
for touch in touches.iter() {
46+
if touch.phase == TouchPhase::Started {
47+
*last_position = None;
48+
}
49+
if let Some(last_position) = *last_position {
50+
let window = windows.get_primary().unwrap();
51+
let mut transform = camera.single_mut();
52+
*transform = Transform::from_xyz(
53+
transform.translation.x
54+
+ (touch.position.x - last_position.x) / window.width() * 5.0,
55+
transform.translation.y,
56+
transform.translation.z
57+
+ (touch.position.y - last_position.y) / window.height() * 5.0,
58+
)
59+
.looking_at(Vec3::ZERO, Vec3::Y);
60+
}
61+
*last_position = Some(touch.position);
62+
}
63+
}
64+
1965
/// set up a simple 3D scene
2066
fn setup_scene(
2167
mut commands: Commands,
@@ -48,6 +94,11 @@ fn setup_scene(
4894
// light
4995
commands.spawn_bundle(PointLightBundle {
5096
transform: Transform::from_xyz(4.0, 8.0, 4.0),
97+
point_light: PointLight {
98+
intensity: 5000.0,
99+
shadows_enabled: true,
100+
..Default::default()
101+
},
51102
..Default::default()
52103
});
53104
// camera

0 commit comments

Comments
 (0)