From 9cc6368b28a2df2dff652ae1a087f74fd0362a6a Mon Sep 17 00:00:00 2001 From: simlay Date: Sat, 31 Oct 2020 14:36:24 -0700 Subject: [PATCH] An initial xcode setup for using xcode (#539) An example of bevy using xcode --- .github/workflows/ios.yml | 36 ++ Cargo.toml | 2 +- README.md | 1 + crates/bevy_render/Cargo.toml | 2 +- examples/README.md | 33 ++ examples/ios/.gitignore | 1 + examples/ios/Cargo.toml | 14 + examples/ios/Makefile | 25 ++ .../ios/bevy_ios_example.xcodeproj/.gitignore | 2 + .../project.pbxproj | 420 ++++++++++++++++++ examples/ios/build_rust_deps.sh | 12 + examples/ios/ios-src/Info.plist | 33 ++ examples/ios/ios-src/bindings.h | 1 + examples/ios/ios-src/main.m | 6 + examples/ios/src/lib.rs | 66 +++ 15 files changed, 652 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ios.yml create mode 100644 examples/ios/.gitignore create mode 100644 examples/ios/Cargo.toml create mode 100644 examples/ios/Makefile create mode 100644 examples/ios/bevy_ios_example.xcodeproj/.gitignore create mode 100644 examples/ios/bevy_ios_example.xcodeproj/project.pbxproj create mode 100755 examples/ios/build_rust_deps.sh create mode 100644 examples/ios/ios-src/Info.plist create mode 100644 examples/ios/ios-src/bindings.h create mode 100644 examples/ios/ios-src/main.m create mode 100644 examples/ios/src/lib.rs diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml new file mode 100644 index 0000000000..1c0830db9e --- /dev/null +++ b/.github/workflows/ios.yml @@ -0,0 +1,36 @@ +name: iOS cron CI + +on: + schedule: + - cron: '0 0 * * *' + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: macOS-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - uses: actions/cache@v2 + with: + path: | + target + key: ${{ runner.os }}-cargo-check-test-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }} + + - uses: actions-rs/install@v0.1 + with: + crate: cargo-lipo + version: latest + + - name: Add iOS targets + 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 diff --git a/Cargo.toml b/Cargo.toml index 6b863e4cbb..7287f6a0fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ wayland = ["bevy_winit/wayland"] x11 = ["bevy_winit/x11"] [workspace] -members = ["crates/*", "crates/bevy_ecs/hecs"] +members = ["crates/*", "crates/bevy_ecs/hecs", "examples/ios"] exclude = ["benches"] [dependencies] diff --git a/README.md b/README.md index 0a14c4d5c9..c8db04afe3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/bevyengine/bevy/blob/master/LICENSE) [![Crates.io](https://img.shields.io/crates/d/bevy.svg)](https://crates.io/crates/bevy) [![Rust](https://github.com/bevyengine/bevy/workflows/CI/badge.svg)](https://github.com/bevyengine/bevy/actions) +![iOS cron CI](https://github.com/bevyengine/bevy/workflows/iOS%20cron%20CI/badge.svg) ## What is Bevy? diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 63734d83f2..6374c6c97c 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -51,7 +51,7 @@ spirv-reflect = "0.2.3" bevy-glsl-to-spirv = "0.1.7" [target.'cfg(target_os = "ios")'.dependencies] -shaderc = "0.6.2" +shaderc = "0.6.3" [features] png = ["image/png"] diff --git a/examples/README.md b/examples/README.md index 9e206f6852..6de19fbeb5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -136,3 +136,36 @@ to point to the correct `.js` file. Then serve `examples/wasm` dir to browser. i.e. $ basic-http-server examples/wasm + +## iOS + +#### pre-req + + $ rustup target add aarch64-apple-ios x86_64-apple-ios + $ cargo install cargo-lipo + +#### build & run + +Using bash: + $ cd examples/ios + $ make run + +In an ideal world, this will boot up, install and run the app for the first +iOS simulator in your `xcrun simctl devices list`. If this fails, you can +specify the simulator device UUID via: + $ DEVICE_ID=${YOUR_DEVICE_ID} make run + +If you'd like to see xcode do stuff, you can run + $ open bevy_ios_example.xcodeproj/ + +which will open xcode. You then must push the zoom zoom play button and wait +for the magic. + +The Xcode build GUI will by default build the rust library for both +`x86_64-apple-ios`, and `aarch64-apple-ios` which may take a while. If you'd +like speed this up, you update the `IOS_TARGETS` User-Defined environment +variable in the "`cargo_ios` target" to be either `x86_64-apple-ios` or +`aarch64-applo-ios` depending on your goal. + +Note: if you update this variable in Xcode, it will also change the default +used for the `Makefile`. diff --git a/examples/ios/.gitignore b/examples/ios/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/examples/ios/.gitignore @@ -0,0 +1 @@ +/build diff --git a/examples/ios/Cargo.toml b/examples/ios/Cargo.toml new file mode 100644 index 0000000000..26a1f0948b --- /dev/null +++ b/examples/ios/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "bevy-ios-example" +version = "0.1.0" +authors = ["Sebastian Imlay "] +edition = "2018" + +[lib] +name = "bevy_ios_example" +crate-type = ["staticlib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bevy = { path = "../../", features = [ "bevy_gilrs", "bevy_gltf", "bevy_wgpu", "bevy_winit", "render", "png", "hdr"], default-features = false} diff --git a/examples/ios/Makefile b/examples/ios/Makefile new file mode 100644 index 0000000000..f16ec7a27d --- /dev/null +++ b/examples/ios/Makefile @@ -0,0 +1,25 @@ +.PHONY: xcodebuild run install boot-sim generate clean + +DEVICE = ${DEVICE_ID} +ifndef DEVICE_ID + DEVICE=$(shell xcrun simctl list devices 'iOS' | grep -v 'unavailable' | grep -v '^--' | grep -v '==' | head -n 1 | cut -d ' ' -f 7 | sed 's/[()]//g') +endif + +run: install + xcrun simctl launch --console $(DEVICE) com.rust.bevy-ios-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 + +xcodebuild-simulator: + IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_ios_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 + +clean: + rm -r build + cargo clean diff --git a/examples/ios/bevy_ios_example.xcodeproj/.gitignore b/examples/ios/bevy_ios_example.xcodeproj/.gitignore new file mode 100644 index 0000000000..8b53cbff82 --- /dev/null +++ b/examples/ios/bevy_ios_example.xcodeproj/.gitignore @@ -0,0 +1,2 @@ +xcuserdata +project.xcworkspace diff --git a/examples/ios/bevy_ios_example.xcodeproj/project.pbxproj b/examples/ios/bevy_ios_example.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..d224a3e88c --- /dev/null +++ b/examples/ios/bevy_ios_example.xcodeproj/project.pbxproj @@ -0,0 +1,420 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXBuildFile section */ + 134866208A035F8615C99114 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A1E5B62F48B379829E8A0D /* Metal.framework */; }; + 2604C99FAB5A8322EDCABB9F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FE71FBCAA714DB4F42459106 /* UIKit.framework */; }; + 442540D056ADB9AE61A0A590 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F1B41978FA53999AA836D0F /* Security.framework */; }; + 55892F1396056740E1AF9685 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AF7DE91055EBD05ED77E57F9 /* main.m */; }; + 55B7188F81C3C4183F81D3AE /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A39528EB2CCB182F5328223A /* libc++.tbd */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 26BF2C4863C966DABAB40DC8 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8DBF1E2B5C613DA41701F6D9 /* Project object */; + proxyType = 1; + remoteGlobalIDString = D08AEBE0B1A9C9A7B8C7B33F; + remoteInfo = cargo_ios; + }; +/* End PBXContainerItemProxy section */ + +/* 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; }; + 8EE7F1E3B0303533925D7E33 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 96A1E5B62F48B379829E8A0D /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; + 9F1B41978FA53999AA836D0F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + A39528EB2CCB182F5328223A /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; + AF7DE91055EBD05ED77E57F9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + FE71FBCAA714DB4F42459106 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + D5A822CB2D6847BA8800BE4C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 442540D056ADB9AE61A0A590 /* Security.framework in Frameworks */, + 134866208A035F8615C99114 /* Metal.framework in Frameworks */, + 2604C99FAB5A8322EDCABB9F /* UIKit.framework in Frameworks */, + 55B7188F81C3C4183F81D3AE /* libc++.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 321F7D6A765B38E746C35105 /* Products */ = { + isa = PBXGroup; + children = ( + 55EAC02897847195D2F44C15 /* bevy_ios_example.app */, + ); + name = Products; + sourceTree = ""; + }; + 4F1D6F28B8A5D1927AB0ADED /* ios-src */ = { + isa = PBXGroup; + children = ( + 160DB77300A3F1806F024D47 /* bindings.h */, + 8EE7F1E3B0303533925D7E33 /* Info.plist */, + AF7DE91055EBD05ED77E57F9 /* main.m */, + ); + path = "ios-src"; + sourceTree = ""; + }; + 8F2E3E6040EAD2EC9F3FA530 = { + isa = PBXGroup; + children = ( + 4F1D6F28B8A5D1927AB0ADED /* ios-src */, + EB028409C2D0655412DA6E44 /* Frameworks */, + 321F7D6A765B38E746C35105 /* Products */, + ); + sourceTree = ""; + }; + EB028409C2D0655412DA6E44 /* Frameworks */ = { + isa = PBXGroup; + children = ( + A39528EB2CCB182F5328223A /* libc++.tbd */, + 96A1E5B62F48B379829E8A0D /* Metal.framework */, + 9F1B41978FA53999AA836D0F /* Security.framework */, + FE71FBCAA714DB4F42459106 /* UIKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXLegacyTarget section */ + D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */ = { + isa = PBXLegacyTarget; + buildArgumentsString = build_rust_deps.sh; + buildConfigurationList = AA00A0CFDB11F37F2BA3FC2E /* Build configuration list for PBXLegacyTarget "cargo_ios" */; + buildPhases = ( + FE045B3D04D57B713A565FF8 /* Sources */, + ); + buildToolPath = /bin/sh; + buildWorkingDirectory = .; + dependencies = ( + ); + name = cargo_ios; + passBuildSettingsInEnvironment = 1; + productName = cargo_ios; + }; +/* End PBXLegacyTarget section */ + +/* Begin PBXNativeTarget section */ + 3BDB8152E4962373181B4FE5 /* bevy_ios_example */ = { + isa = PBXNativeTarget; + buildConfigurationList = E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_ios_example" */; + buildPhases = ( + 9F13800790AD9DBC2BC0F116 /* Sources */, + D5A822CB2D6847BA8800BE4C /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 19D4B9C22ADC6705B5132B4C /* PBXTargetDependency */, + ); + name = bevy_ios_example; + productName = bevy_ios_example; + productReference = 55EAC02897847195D2F44C15 /* bevy_ios_example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 8DBF1E2B5C613DA41701F6D9 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1020; + }; + buildConfigurationList = 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_ios_example" */; + compatibilityVersion = "Xcode 10.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 8F2E3E6040EAD2EC9F3FA530; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 3BDB8152E4962373181B4FE5 /* bevy_ios_example */, + D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 9F13800790AD9DBC2BC0F116 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55892F1396056740E1AF9685 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + FE045B3D04D57B713A565FF8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 19D4B9C22ADC6705B5132B4C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */; + targetProxy = 26BF2C4863C966DABAB40DC8 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 4AD7BC6FDD56FF18FA6DA7D7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "DEBUG=1", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 5B14EC4ADC81FBF1F8CF20E9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++11"; + CLANG_CXX_LIBRARY = "libc++"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; + ENABLE_BITCODE = NO; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "ios-src/", + ); + INFOPLIST_FILE = "ios-src/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + ../../target/universal/release, + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-lbevy_ios_example", + "-lc++abi", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy-ios-example"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 79E3C28F06346EA58420A93D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_VERSION = 5.0; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 8265913A25816D964A847F1B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + IOS_TARGETS = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.cargo-ios"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A2D5B73DD30D562B6F366526 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++11"; + CLANG_CXX_LIBRARY = "libc++"; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEVELOPMENT_TEAM = ""; + ENABLE_BITCODE = NO; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "ios-src/", + ); + INFOPLIST_FILE = "ios-src/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + ../../target/universal/debug, + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-lbevy_ios_example", + "-lc++abi", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.bevy-ios-example"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + FEA9B18D9236F9F6DC6DF799 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + IOS_TARGETS = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.cargo-ios"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "bevy_ios_example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4AD7BC6FDD56FF18FA6DA7D7 /* Debug */, + 79E3C28F06346EA58420A93D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + AA00A0CFDB11F37F2BA3FC2E /* Build configuration list for PBXLegacyTarget "cargo_ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8265913A25816D964A847F1B /* Debug */, + FEA9B18D9236F9F6DC6DF799 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "bevy_ios_example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A2D5B73DD30D562B6F366526 /* Debug */, + 5B14EC4ADC81FBF1F8CF20E9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; +/* End XCConfigurationList section */ + }; + rootObject = 8DBF1E2B5C613DA41701F6D9 /* Project object */; +} diff --git a/examples/ios/build_rust_deps.sh b/examples/ios/build_rust_deps.sh new file mode 100755 index 0000000000..aa5ee3134e --- /dev/null +++ b/examples/ios/build_rust_deps.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +PATH=$PATH:$HOME/.cargo/bin + +# If you want your build to run faster, add a "--targets x86_64-apple-ios" for just using the ios simulator. +if [ -n ${IOS_TARGETS} ]; then + cargo lipo --targets ${IOS_TARGETS} +else + cargo lipo +fi diff --git a/examples/ios/ios-src/Info.plist b/examples/ios/ios-src/Info.plist new file mode 100644 index 0000000000..2c0e78e8a6 --- /dev/null +++ b/examples/ios/ios-src/Info.plist @@ -0,0 +1,33 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + UILaunchStoryboardName + LaunchScreen + UIRequiresFullScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown + + + diff --git a/examples/ios/ios-src/bindings.h b/examples/ios/ios-src/bindings.h new file mode 100644 index 0000000000..a705f03b13 --- /dev/null +++ b/examples/ios/ios-src/bindings.h @@ -0,0 +1 @@ +void main_rs(void); diff --git a/examples/ios/ios-src/main.m b/examples/ios/ios-src/main.m new file mode 100644 index 0000000000..7d152fb790 --- /dev/null +++ b/examples/ios/ios-src/main.m @@ -0,0 +1,6 @@ +#import "bindings.h" + +int main() { + main_rs(); + return 0; +} diff --git a/examples/ios/src/lib.rs b/examples/ios/src/lib.rs new file mode 100644 index 0000000000..06e267f196 --- /dev/null +++ b/examples/ios/src/lib.rs @@ -0,0 +1,66 @@ +use bevy::{ + prelude::{ + shape, AddDefaultPlugins, App, Assets, Camera3dComponents, Color, Commands, + IntoQuerySystem, LightComponents, Mesh, Msaa, PbrComponents, ResMut, StandardMaterial, + Transform, Vec3, WindowDescriptor, + }, + window::WindowMode, +}; + +#[no_mangle] +extern "C" fn main_rs() { + App::build() + .add_resource(WindowDescriptor { + vsync: true, + resizable: false, + mode: WindowMode::BorderlessFullscreen, + ..Default::default() + }) + .add_resource(Msaa { samples: 4 }) + .add_default_plugins() + .add_startup_system(setup.system()) + .run(); +} +/// set up a simple 3D scene +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // add entities to the world + commands + // plane + .spawn(PbrComponents { + mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), + material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), + ..Default::default() + }) + // cube + .spawn(PbrComponents { + mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), + transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), + ..Default::default() + }) + // sphere + .spawn(PbrComponents { + mesh: meshes.add(Mesh::from(shape::Icosphere { + subdivisions: 4, + radius: 0.5, + })), + material: materials.add(Color::rgb(0.1, 0.4, 0.8).into()), + transform: Transform::from_translation(Vec3::new(1.5, 1.5, 1.5)), + ..Default::default() + }) + // light + .spawn(LightComponents { + transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), + ..Default::default() + }) + // camera + .spawn(Camera3dComponents { + transform: Transform::from_translation(Vec3::new(-3.0, 5.0, 8.0)) + .looking_at(Vec3::default(), Vec3::unit_y()), + ..Default::default() + }); +}