| 1 | SHELL := /bin/sh |
| 2 | |
| 3 | SWIFT_REPO := $(CURDIR) |
| 4 | ONDE_REPO ?= $(abspath ../onde) |
| 5 | CARGO_MANIFEST := $(ONDE_REPO)/Cargo.toml |
| 6 | BINDGEN_MANIFEST := $(ONDE_REPO)/uniffi-bindgen/Cargo.toml |
| 7 | BINDGEN := $(ONDE_REPO)/uniffi-bindgen/target/release/uniffi-bindgen |
| 8 | |
| 9 | RUST_STABLE ?= +1.92.0 |
| 10 | RUST_NIGHTLY ?= +nightly |
| 11 | |
| 12 | IOS_DEPLOYMENT_TARGET ?= 16.0 |
| 13 | MACOS_DEPLOYMENT_TARGET ?= 14.0 |
| 14 | TVOS_DEPLOYMENT_TARGET ?= 16.0 |
| 15 | VISIONOS_DEPLOYMENT_TARGET ?= 1.0 |
| 16 | WATCHOS_DEPLOYMENT_TARGET ?= 9.0 |
| 17 | |
| 18 | LOCAL_DIR := $(SWIFT_REPO)/.local |
| 19 | GENERATED_DIR := $(LOCAL_DIR)/generated/Onde |
| 20 | HEADERS_DIR := $(LOCAL_DIR)/Headers |
| 21 | FRAMEWORK_DIR := $(SWIFT_REPO)/OndeFramework.xcframework |
| 22 | SWIFT_GLUE := $(SWIFT_REPO)/Sources/Onde/onde.swift |
| 23 | |
| 24 | SUPPORTED_PLATFORMS := ios macos tvos visionos watchos |
| 25 | |
| 26 | .PHONY: help platform ios macos tvos visionos watchos validate build-bindgen prepare generate-swift clean |
| 27 | |
| 28 | help: |
| 29 | @printf '%s\n' \ |
| 30 | 'Onde Swift local Apple-platform builds' \ |
| 31 | '' \ |
| 32 | 'Usage:' \ |
| 33 | ' make ios Build OndeFramework.xcframework for iOS device + simulator' \ |
| 34 | ' make macos Build OndeFramework.xcframework for macOS (Apple silicon)' \ |
| 35 | ' make tvos Build OndeFramework.xcframework for tvOS device + simulator' \ |
| 36 | ' make visionos Build OndeFramework.xcframework for visionOS device + simulator' \ |
| 37 | ' make watchos Build OndeFramework.xcframework for watchOS device + simulator' \ |
| 38 | ' make platform PLATFORM=ios' \ |
| 39 | '' \ |
| 40 | 'Artifacts:' \ |
| 41 | ' OndeFramework.xcframework' \ |
| 42 | ' Sources/Onde/onde.swift (regenerated from the local Rust build)' \ |
| 43 | '' \ |
| 44 | 'Optional overrides:' \ |
| 45 | ' ONDE_REPO=/absolute/path/to/onde' |
| 46 | |
| 47 | platform: |
| 48 | @test -n "$(PLATFORM)" || { echo "Set PLATFORM=$(SUPPORTED_PLATFORMS)"; exit 1; } |
| 49 | @case "$(PLATFORM)" in \ |
| 50 | ios|macos|tvos|visionos|watchos) $(MAKE) "$(PLATFORM)" ;; \ |
| 51 | *) echo "Unsupported PLATFORM='$(PLATFORM)'. Expected one of: $(SUPPORTED_PLATFORMS)"; exit 1 ;; \ |
| 52 | esac |
| 53 | |
| 54 | validate: |
| 55 | @test -f "$(CARGO_MANIFEST)" || { echo "Could not find onde Cargo.toml at $(CARGO_MANIFEST)"; exit 1; } |
| 56 | @test -d "$(SWIFT_REPO)/Sources/Onde" || { echo "Run make from the onde-swift repository root."; exit 1; } |
| 57 | |
| 58 | build-bindgen: validate |
| 59 | cargo $(RUST_STABLE) build --manifest-path "$(BINDGEN_MANIFEST)" --release |
| 60 | |
| 61 | prepare: |
| 62 | @rm -rf "$(FRAMEWORK_DIR)" "$(GENERATED_DIR)" "$(HEADERS_DIR)" |
| 63 | @mkdir -p "$(GENERATED_DIR)" "$(HEADERS_DIR)" |
| 64 | |
| 65 | generate-swift: |
| 66 | @test -n "$(BINDGEN_INPUT)" || { echo "BINDGEN_INPUT is required"; exit 1; } |
| 67 | cd "$(ONDE_REPO)" && "$(BINDGEN)" generate "$(BINDGEN_INPUT)" --crate onde --language swift --out-dir "$(GENERATED_DIR)" |
| 68 | cp "$(GENERATED_DIR)/onde.swift" "$(SWIFT_GLUE)" |
| 69 | cp "$(GENERATED_DIR)/ondeFFI.h" "$(HEADERS_DIR)/ondeFFI.h" |
| 70 | cp "$(GENERATED_DIR)/ondeFFI.modulemap" "$(HEADERS_DIR)/module.modulemap" |
| 71 | @echo "Updated $(SWIFT_GLUE)" |
| 72 | |
| 73 | ios: build-bindgen prepare |
| 74 | IPHONEOS_DEPLOYMENT_TARGET=$(IOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-ios --release --lib --crate-type staticlib |
| 75 | IPHONEOS_DEPLOYMENT_TARGET=$(IOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-ios-sim --release --lib --crate-type staticlib |
| 76 | $(MAKE) generate-swift BINDGEN_INPUT="$(ONDE_REPO)/target/aarch64-apple-ios/release/libonde.a" |
| 77 | xcodebuild -create-xcframework \ |
| 78 | -library "$(ONDE_REPO)/target/aarch64-apple-ios/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 79 | -library "$(ONDE_REPO)/target/aarch64-apple-ios-sim/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 80 | -output "$(FRAMEWORK_DIR)" |
| 81 | @echo "Built $(FRAMEWORK_DIR) for iOS" |
| 82 | |
| 83 | macos: build-bindgen prepare |
| 84 | MACOSX_DEPLOYMENT_TARGET=$(MACOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-darwin --release --lib --crate-type staticlib |
| 85 | $(MAKE) generate-swift BINDGEN_INPUT="$(ONDE_REPO)/target/aarch64-apple-darwin/release/libonde.a" |
| 86 | xcodebuild -create-xcframework \ |
| 87 | -library "$(ONDE_REPO)/target/aarch64-apple-darwin/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 88 | -output "$(FRAMEWORK_DIR)" |
| 89 | @echo "Built $(FRAMEWORK_DIR) for macOS" |
| 90 | |
| 91 | tvos: build-bindgen prepare |
| 92 | TVOS_DEPLOYMENT_TARGET=$(TVOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-tvos --release --lib --crate-type staticlib |
| 93 | TVOS_DEPLOYMENT_TARGET=$(TVOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-tvos-sim --release --lib --crate-type staticlib |
| 94 | $(MAKE) generate-swift BINDGEN_INPUT="$(ONDE_REPO)/target/aarch64-apple-tvos/release/libonde.a" |
| 95 | xcodebuild -create-xcframework \ |
| 96 | -library "$(ONDE_REPO)/target/aarch64-apple-tvos/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 97 | -library "$(ONDE_REPO)/target/aarch64-apple-tvos-sim/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 98 | -output "$(FRAMEWORK_DIR)" |
| 99 | @echo "Built $(FRAMEWORK_DIR) for tvOS" |
| 100 | |
| 101 | visionos: build-bindgen prepare |
| 102 | XROS_DEPLOYMENT_TARGET=$(VISIONOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-visionos --release --lib --crate-type staticlib |
| 103 | XROS_DEPLOYMENT_TARGET=$(VISIONOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-visionos-sim --release --lib --crate-type staticlib |
| 104 | $(MAKE) generate-swift BINDGEN_INPUT="$(ONDE_REPO)/target/aarch64-apple-visionos/release/libonde.a" |
| 105 | xcodebuild -create-xcframework \ |
| 106 | -library "$(ONDE_REPO)/target/aarch64-apple-visionos/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 107 | -library "$(ONDE_REPO)/target/aarch64-apple-visionos-sim/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 108 | -output "$(FRAMEWORK_DIR)" |
| 109 | @echo "Built $(FRAMEWORK_DIR) for visionOS" |
| 110 | |
| 111 | watchos: build-bindgen prepare |
| 112 | WATCHOS_DEPLOYMENT_TARGET=$(WATCHOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-watchos --release --lib --crate-type staticlib |
| 113 | WATCHOS_DEPLOYMENT_TARGET=$(WATCHOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --target aarch64-apple-watchos-sim --release --lib --crate-type staticlib |
| 114 | $(MAKE) generate-swift BINDGEN_INPUT="$(ONDE_REPO)/target/aarch64-apple-watchos/release/libonde.a" |
| 115 | xcodebuild -create-xcframework \ |
| 116 | -library "$(ONDE_REPO)/target/aarch64-apple-watchos/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 117 | -library "$(ONDE_REPO)/target/aarch64-apple-watchos-sim/release/libonde.a" -headers "$(HEADERS_DIR)" \ |
| 118 | -output "$(FRAMEWORK_DIR)" |
| 119 | @echo "Built $(FRAMEWORK_DIR) for watchOS" |
| 120 | |
| 121 | clean: |
| 122 | rm -rf "$(FRAMEWORK_DIR)" "$(LOCAL_DIR)" |
| 123 | @echo "Removed local Onde Swift build artifacts" |