Skip to content

Commit

Permalink
Adding support for compiling xcode package directly
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinHV committed Apr 5, 2024
1 parent 96018a0 commit fad4cec
Show file tree
Hide file tree
Showing 13 changed files with 671 additions and 278 deletions.
506 changes: 265 additions & 241 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[package]
name = "stremio-core-apple"
version = "1.0.0"
name = "stremio-core-swift"
version = "1.2.2"
authors = ["Smart Code OOD"]
edition = "2021"
resolver = "2"

rust-version = "1.67.1"

[lib]
crate-type = ["staticlib"]
path = "src/commonMain/rust/lib.rs"
Expand All @@ -22,7 +20,7 @@ stremio-core = { git = "https://github.com/Stremio/stremio-core", rev = "f451b2c
"env-future-send",
] }

stremio-watched-bitfield = { git = "https://github.com/Stremio/stremio-core", rev = "f451b2cb3645c21463c84dd6446b266659c45ded"}
stremio-watched-bitfield = { git = "https://github.com/Stremio/stremio-core", rev = "f451b2cb3645c21463c84dd6446b266659c45ded" }
serde = "1.0.*"
serde_json = "1.0.*"
futures = "0.3.*"
Expand Down
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
LIBRARY_NAME := libstremio_core_swift
FRAMEWORK_NAME := StremioCore
.PHONY: all

all: macos ios iossim package

macos:
@cargo +nightly build -Z build-std --release --lib --target aarch64-apple-ios-macabi
@cargo +nightly build -Z build-std --release --lib --target x86_64-apple-ios-macabi
@$(RM) -rf target/universal/$(LIBRARY_NAME)-macabi.a
@mkdir -p target/universal/
@lipo -create -output target/universal/$(LIBRARY_NAME)-macabi.a \
target/aarch64-apple-ios-macabi/release/$(LIBRARY_NAME).a \
target/x86_64-apple-ios-macabi/release/$(LIBRARY_NAME).a

ios:
@cargo build --release --lib --target aarch64-apple-ios
@$(RM) -rf target/universal/$(LIBRARY_NAME)-ios.a
@mkdir -p target/universal/
@cp target/aarch64-apple-ios/release/$(LIBRARY_NAME).a target/universal/$(LIBRARY_NAME)-ios.a

iossim:
@cargo build --release --lib --target aarch64-apple-ios-sim
@cargo build --release --lib --target x86_64-apple-ios
@$(RM) -rf target/universal/$(LIBRARY_NAME)-ios-sim.a
@mkdir -p target/universal/
@lipo -create -output target/universal/$(LIBRARY_NAME)-ios-sim.a \
target/aarch64-apple-ios-sim/release/$(LIBRARY_NAME).a \
target/x86_64-apple-ios/release/$(LIBRARY_NAME).a

framework:
@mkdir -p build/
@$(RM) -rf build/$(FRAMEWORK_NAME).xcframework
@xcodebuild -create-xcframework \
-library target/universal/$(LIBRARY_NAME)-ios.a \
-library target/universal/$(LIBRARY_NAME)-ios-sim.a \
-library target/universal/$(LIBRARY_NAME)-macabi.a \
-output build/$(FRAMEWORK_NAME).xcframework

package: framework
@$(RM) -rf build/StremioCore
@cp -rf bridge/StremioCore build/
@./buildBridge.command
@mv build/$(FRAMEWORK_NAME).xcframework build/StremioCore/Frameworks/$(FRAMEWORK_NAME).xcframework
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ Install rust on your macOS machine:
./installDependencies.command
```

Build Bridge. It will create interface between Swift -> C -> Rust. Use this command when you make changes to C exports or in proto files:
Make package for xcode.

```zsh
./buildBridge.command
make all
```

Compile rust code to library file.

```zsh
./build.command
```

Finally copy bridge folder to xcode and include it in your Objective-c bridging header, then add compiled library file to your xcode project.
Package folder will be generated in build folder. It will contain protobuf files for swift and compiled binary for supported apple platforms
10 changes: 10 additions & 0 deletions bridge/StremioCore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Sources/StremioCore/stremio
.netrc
28 changes: 28 additions & 0 deletions bridge/StremioCore/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "StremioCore",
platforms: [
.macCatalyst(.v13),
.iOS(.v12),
],
products: [
.library(
name: "StremioCore",
targets: ["StremioCore", "XCFramework"]),
], dependencies: [
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.0"),
],
targets: [
.target(name: "Wrapper", dependencies: []),
.target(name: "StremioCore",
dependencies: [
"Wrapper",
.product(name: "SwiftProtobuf", package: "swift-protobuf")
]),
.binaryTarget(name: "XCFramework", path: "Frameworks/StremioCore.xcframework")
]
)
Loading

0 comments on commit fad4cec

Please # to comment.