swift lib

main
Ziyang Hu 2 years ago
parent ec35697820
commit 2a22b28301

@ -0,0 +1,3 @@
generated
CozoSwiftBridge
.idea

@ -0,0 +1,19 @@
[package]
name = "cozo-swift"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
storage-rocksdb = ["cozo/storage-rocksdb"]
[build-dependencies]
swift-bridge-build = "0.1.41"
[dependencies]
swift-bridge = "0.1.41"
cozo = { version = "0.1.7", path = "../cozo-core", default-features = false, features = ["compact"] }

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e
THISDIR=$(dirname $0)
cd $THISDIR
export SWIFT_BRIDGE_OUT_DIR="$(pwd)/generated"
# Build the project for the desired platforms:
cargo build -p cozo-swift --target x86_64-apple-darwin --release
cargo build -p cozo-swift --target aarch64-apple-darwin --release
mkdir -p ../target/universal-macos/release
lipo \
../target/aarch64-apple-darwin/release/libcozo_swift.a \
../target/x86_64-apple-darwin/release/libcozo_swift.a -create -output \
../target/universal-macos/release/libcozo_swift.a
cargo build -p cozo-swift --target aarch64-apple-ios --release
cargo build -p cozo-swift --target x86_64-apple-ios --release
cargo build -p cozo-swift --target aarch64-apple-ios-sim --release
mkdir -p ../target/universal-ios/release
lipo \
../target/aarch64-apple-ios-sim/release/libcozo_swift.a \
../target/x86_64-apple-ios/release/libcozo_swift.a -create -output \
../target/universal-ios/release/libcozo_swift.a
swift-bridge-cli create-package \
--bridges-dir ./generated \
--out-dir CozoSwiftBridge \
--ios ../target/aarch64-apple-ios/release/libcozo_swift.a \
--simulator ../target/universal-ios/release/libcozo_swift.a \
--macos ../target/universal-macos/release/libcozo_swift.a \
--name CozoSwiftBridge

@ -0,0 +1,13 @@
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from("./generated");
let bridges = vec!["src/lib.rs"];
for path in &bridges {
println!("cargo:rerun-if-changed={}", path);
}
swift_bridge_build::parse_bridges(bridges)
.write_all_concatenated(out_dir, env!("CARGO_PKG_NAME"));
}

@ -0,0 +1,10 @@
#[swift_bridge::bridge]
mod ffi {
extern "Rust" {
fn hello_rust(name: &str) -> String;
}
}
fn hello_rust(name: &str) -> String {
String::from(format!("Hello {} from Rust!", name))
}
Loading…
Cancel
Save