Skip to content

Commit

Permalink
Update for visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jun 24, 2023
1 parent 04df8a5 commit 54f6019
Show file tree
Hide file tree
Showing 26 changed files with 59 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -15,4 +15,6 @@ target/
**/*.so
JetpackCompose/
iOS/libs/debug/*
iOS/libs/release/*
iOS/libs/release/*
Apple/libs/debug/*
Apple/libs/release/*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -132,7 +132,7 @@
};
};
};
buildConfigurationList = AD4B1FE426EB1B90008A6AEE /* Build configuration list for PBXProject "wgpu_in_iOS_App" */;
buildConfigurationList = AD4B1FE426EB1B90008A6AEE /* Build configuration list for PBXProject "wgpu_in_App" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
Expand Down Expand Up @@ -387,7 +387,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
AD4B1FE426EB1B90008A6AEE /* Build configuration list for PBXProject "wgpu_in_iOS_App" */ = {
AD4B1FE426EB1B90008A6AEE /* Build configuration list for PBXProject "wgpu_in_App" */ = {
isa = XCConfigurationList;
buildConfigurations = (
AD4B1FFB26EB1B91008A6AEE /* Debug */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Expand Up @@ -17,7 +17,7 @@
BlueprintIdentifier = "AD4B1FE826EB1B90008A6AEE"
BuildableName = "wgpu_phone.app"
BlueprintName = "wgpu_phone"
ReferencedContainer = "container:wgpu_in_iOS_App.xcodeproj">
ReferencedContainer = "container:wgpu_in_App.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand Down Expand Up @@ -47,7 +47,7 @@
BlueprintIdentifier = "AD4B1FE826EB1B90008A6AEE"
BuildableName = "wgpu_phone.app"
BlueprintName = "wgpu_phone"
ReferencedContainer = "container:wgpu_in_iOS_App.xcodeproj">
ReferencedContainer = "container:wgpu_in_App.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
Expand All @@ -74,7 +74,7 @@
<EnvironmentVariable
key = "gfx_backend_metal"
value = "debug"
isEnabled = "YES">
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -12,9 +12,9 @@ noise = { version = "0.7", default-features = false }
pollster = "0.2"
rand = { version = "0.7.2" }
# wgpu = "0.16"
# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "45efae31" }
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "757245cd" }
# wgpu = { path = "../../forks/wgpu/wgpu" }
wgpu = { git = "https://github.com/jinleili/wgpu", branch="visionOS" }
# wgpu = { git = "https://github.com/jinleili/wgpu", branch="visionOS" }

async-executor = "1.0"
winit = "0.27.1"
Expand Down
54 changes: 40 additions & 14 deletions README.MD
@@ -1,34 +1,57 @@
# wgpu in App

![Minimum Rust Version](https://img.shields.io/badge/min%20rust-1.64-green.svg)
[![Build Status](https://github.com/jinleili/wgpu-in-app/workflows/CI/badge.svg?branch=master)](https://github.com/jinleili/wgpu-in-app/actions)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jinleili/wgpu-in-app/blob/master/LICENSE.MIT)

Integrate wgpu into your existing iOS | Android apps.
Integrate wgpu into your existing iOS | Android apps.

wgpu does not depend on any window program, so it does not provide window creation and management functions. Only when creating a window-based `Surface`, an argument that implements the [raw-window-handle](https://github.com/rust-windowing/raw-window-handle) abstract interface may be needed (*may be needed* because on iOS/macOS, instance of `Surface` can be created directly by `CAMetalLayer`). The `winit` used by the wgpu examples is a cross-platform window creation and management crate that implements the raw-window-handle abstract interface. It will take over the window management and events loop of the entire app, there is no doubt that for game apps, the combination of wgpu + winit is very suitable.
wgpu does not depend on any window program, so it does not provide window creation and management functions. Only when creating a window-based `Surface`, an argument that implements the [raw-window-handle](https://github.com/rust-windowing/raw-window-handle) abstract interface may be needed (_may be needed_ because on iOS/macOS, instance of `Surface` can be created directly by `CAMetalLayer`). The `winit` used by the wgpu examples is a cross-platform window creation and management crate that implements the raw-window-handle abstract interface. It will take over the window management and events loop of the entire app, there is no doubt that for game apps, the combination of wgpu + winit is very suitable.

However, a large number of non-game apps also need to use graphics APIs (such as charts, image filters, etc.). These apps may require a large number of system components, as well as the ability to freely control various input devices (e.g., stylus, motion sensors). So, it would be very useful to integrate wgpu into these apps without using third-party window management libraries.

#### [中文版文档](https://jinleili.github.io/learn-wgpu-zh/integration-and-debugging/)

## Screenshot
|![wgpu in iOS](screenshot/on_ios.png)|![wgpu in Android](screenshot/on_android.png)|
|---|---|

## **iOS**
| ![wgpu in iOS](screenshot/on_ios.png) | ![wgpu in Android](screenshot/on_android.png) |
| ------------------------------------- | --------------------------------------------- |

<video src="screenshot/on_visionOS.mp4" autoplay loop></video>

## **iOS | iPadOS | visionOS**

### Add target

```sh
# Add Apple device (iOS | iPadOS | visionOS) target
# Since iPhone 5 and later are all 64-bit devices, `armv7s-apple-ios` and `armv7-apple-ios` are not required.
rustup target add aarch64-apple-ios

# Add Apple Simulator target
# M1+ Mac
rustup target add aarch64-apple-ios-sim
```

### Build for Apple real device

```sh
# Add iOS device target
# Since iPhone 5 and later are 64-bit devices, `armv7s-apple-ios` and `armv7-apple-ios` are not required.
rustup target add aarch64-apple-ios
# Build for iOS | iPadOS
sh ./apple_lib_build.sh --release
```

Then, Open `Apple/wgpu_in_App.xcodeproj` with Xcode and run on iPhone、iPad.

### Build for visionOS Simulator

# Build for iOS device
sh ./ios_lib_build.sh --release
```sh
sh ./apple_lib_build.sh aarch64-apple-ios-sim --release
```

Then, Open `iOS/wgpu_in_iOS_App.xcodeproj` with Xcode an run on iOS device and/or M1+ Mac (Designed for iPad).
Then, Open `Apple/wgpu_in_App.xcodeproj` with Xcode 15 Beta 2+ and run on visionOS Simulator.

### About Rust and Swift Interaction

[Passing Primitive Data Between Rust and iOS](https://bignerdranch.com/blog/building-an-ios-app-in-rust-part-2-passing-primitive-data-between-rust-and-ios/)

[Passing Owned Objects between Rust and iOS](https://bignerdranch.com/blog/building-an-ios-app-in-rust-part-3-passing-owned-objects-between-rust-and-ios/)
Expand All @@ -39,7 +62,7 @@ Then, Open `iOS/wgpu_in_iOS_App.xcodeproj` with Xcode an run on iOS device and/o

### Set up Android environment

Assuming your computer already has Android Studio installed, go to `Android Studio` > `Tools` > `SDK Manager` > `Android SDK` > `SDK Tools`. Check the following options for installation and click OK.
Assuming your computer already has Android Studio installed, go to `Android Studio` > `Tools` > `SDK Manager` > `Android SDK` > `SDK Tools`. Check the following options for installation and click OK.

- [x] Android SDK Build-Tools
- [x] Android SDK Command-line Tools
Expand All @@ -49,11 +72,12 @@ Then, set two following environment variables:

```sh
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
# Replace the NDK version number with the version you installed
# Replace the NDK version number with the version you installed
export NDK_HOME=$ANDROID_SDK_ROOT/ndk/23.1.7779620
```

### Install cargo so subcommand

```sh
# from crates.io
cargo install cargo-so
Expand All @@ -62,6 +86,7 @@ cargo install --path cargo-so
```

### Build

```sh
# Add build targets
# Since simulator and virtual devices only support GLES, `x86_64-linux-android` and `i686-linux-android` targets are not necessary
Expand All @@ -72,6 +97,7 @@ sh ./android_lib_build.sh --release
```

## **Desktop**

```sh
# Use primary backend (metal vulkan or dx12, depend on your computer OS).
cargo run
Expand All @@ -82,4 +108,4 @@ WGPU_BACKEND=gl cargo run --features=angle
# https://github.com/gfx-rs/wgpu/pull/2488
WGPU_BACKEND=vk cargo run --features=vulkan-portability
# Then, press 0, 1, 2, 3, 4 keys change running example.
```
```
8 changes: 4 additions & 4 deletions ios_lib_build.sh → apple_lib_build.sh
Expand Up @@ -14,7 +14,7 @@ fi

cargo build --target ${TARGET} ${RELEASE_MODE}

# Copy .a file to iOS project
# Copy .a file to iOS/ipadOS/visionOS project
#
# Why copy?
# On Xcode 14.1, when xxx..dylib file exists in the library search path, Xcode will try to reference it and report an error:
Expand All @@ -25,8 +25,8 @@ case ${RELEASE_MODE} in
*) : ${LIB_FOLDER:=debug} ;;
esac

if [ ! -d "iOS/libs/${LIB_FOLDER}/" ]; then
mkdir -p "iOS/libs/${LIB_FOLDER}"
if [ ! -d "Apple/libs/${LIB_FOLDER}/" ]; then
mkdir -p "Apple/libs/${LIB_FOLDER}"
fi

cp target/${TARGET}/${LIB_FOLDER}/libwgpu_in_app.a iOS/libs/${LIB_FOLDER}/libwgpu_in_app.a
cp target/${TARGET}/${LIB_FOLDER}/libwgpu_in_app.a Apple/libs/${LIB_FOLDER}/libwgpu_in_app.a
Binary file not shown.
Binary file added screenshot/on_visionOS.mp4
Binary file not shown.

0 comments on commit 54f6019

Please sign in to comment.