|
1
|
#!/usr/bin/env bash |
|
2
|
set -euo pipefail |
|
3
|
|
|
4
|
ROOT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd) |
|
5
|
cd "$ROOT_DIR" |
|
6
|
|
|
7
|
DIST_DIR="$ROOT_DIR/dist/swift" |
|
8
|
PACKAGE_DIR="$DIST_DIR/Package" |
|
9
|
HEADERS_DIR="$DIST_DIR/Headers" |
|
10
|
FRAMEWORK_DIR="$DIST_DIR/OndeFramework.xcframework" |
|
11
|
ZIP_PATH="$DIST_DIR/OndeFramework.xcframework.zip" |
|
12
|
CHECKSUM_PATH="$DIST_DIR/OndeFramework.checksum.txt" |
|
13
|
VERSION_PATH="$DIST_DIR/version.txt" |
|
14
|
BINDGEN="$ROOT_DIR/uniffi-bindgen/target/release/uniffi-bindgen" |
|
15
|
|
|
16
|
mkdir -p "$DIST_DIR" "$PACKAGE_DIR/Sources/Onde" "$HEADERS_DIR" |
|
17
|
|
|
18
|
cargo +1.92.0 build --manifest-path uniffi-bindgen/Cargo.toml --release |
|
19
|
|
|
20
|
# Build staticlibs only. Avoid the cdylib link step; the XCFramework consumes .a slices. |
|
21
|
cargo +1.92.0 rustc --target aarch64-apple-ios --release --lib --crate-type staticlib |
|
22
|
cargo +1.92.0 rustc --target aarch64-apple-ios-sim --release --lib --crate-type staticlib |
|
23
|
cargo +1.92.0 rustc --target aarch64-apple-darwin --release --lib --crate-type staticlib |
|
24
|
cargo +nightly rustc -Z build-std --target aarch64-apple-tvos --release --lib --crate-type staticlib |
|
25
|
cargo +nightly rustc -Z build-std --target aarch64-apple-tvos-sim --release --lib --crate-type staticlib |
|
26
|
cargo +nightly rustc -Z build-std --target aarch64-apple-visionos --release --lib --crate-type staticlib |
|
27
|
cargo +nightly rustc -Z build-std --target aarch64-apple-visionos-sim --release --lib --crate-type staticlib |
|
28
|
cargo +nightly rustc -Z build-std --target aarch64-apple-watchos --release --lib --crate-type staticlib |
|
29
|
cargo +nightly rustc -Z build-std --target aarch64-apple-watchos-sim --release --lib --crate-type staticlib |
|
30
|
|
|
31
|
"$BINDGEN" generate "$ROOT_DIR/target/aarch64-apple-ios/release/libonde.a" --language swift --out-dir "$PACKAGE_DIR/Sources/Onde" |
|
32
|
|
|
33
|
cp "$PACKAGE_DIR/Sources/Onde/ondeFFI.h" "$HEADERS_DIR/ondeFFI.h" |
|
34
|
cp "$PACKAGE_DIR/Sources/Onde/ondeFFI.modulemap" "$HEADERS_DIR/module.modulemap" |
|
35
|
|
|
36
|
cp "$ROOT_DIR/target/aarch64-apple-ios-sim/release/libonde.a" "$DIST_DIR/libonde-ios-sim.a" |
|
37
|
|
|
38
|
cp "$ROOT_DIR/target/aarch64-apple-tvos-sim/release/libonde.a" "$DIST_DIR/libonde-tvos-sim.a" |
|
39
|
|
|
40
|
cp "$ROOT_DIR/target/aarch64-apple-visionos-sim/release/libonde.a" "$DIST_DIR/libonde-visionos-sim.a" |
|
41
|
|
|
42
|
cp "$ROOT_DIR/target/aarch64-apple-watchos-sim/release/libonde.a" "$DIST_DIR/libonde-watchos-sim.a" |
|
43
|
|
|
44
|
cp "$ROOT_DIR/target/aarch64-apple-darwin/release/libonde.a" "$DIST_DIR/libonde-macos.a" |
|
45
|
|
|
46
|
xcodebuild -create-xcframework \ |
|
47
|
-library "$ROOT_DIR/target/aarch64-apple-ios/release/libonde.a" -headers "$HEADERS_DIR" \ |
|
48
|
-library "$DIST_DIR/libonde-ios-sim.a" -headers "$HEADERS_DIR" \ |
|
49
|
-library "$ROOT_DIR/target/aarch64-apple-tvos/release/libonde.a" -headers "$HEADERS_DIR" \ |
|
50
|
-library "$DIST_DIR/libonde-tvos-sim.a" -headers "$HEADERS_DIR" \ |
|
51
|
-library "$ROOT_DIR/target/aarch64-apple-visionos/release/libonde.a" -headers "$HEADERS_DIR" \ |
|
52
|
-library "$DIST_DIR/libonde-visionos-sim.a" -headers "$HEADERS_DIR" \ |
|
53
|
-library "$ROOT_DIR/target/aarch64-apple-watchos/release/libonde.a" -headers "$HEADERS_DIR" \ |
|
54
|
-library "$DIST_DIR/libonde-watchos-sim.a" -headers "$HEADERS_DIR" \ |
|
55
|
-library "$DIST_DIR/libonde-macos.a" -headers "$HEADERS_DIR" \ |
|
56
|
-output "$FRAMEWORK_DIR" |
|
57
|
|
|
58
|
export FRAMEWORK_DIR ZIP_PATH |
|
59
|
python3 - <<'ZIP' |
|
60
|
import os |
|
61
|
import zipfile |
|
62
|
from pathlib import Path |
|
63
|
root = Path(os.environ['FRAMEWORK_DIR']) |
|
64
|
out = Path(os.environ['ZIP_PATH']) |
|
65
|
with zipfile.ZipFile(out, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf: |
|
66
|
for folder, _, files in os.walk(root): |
|
67
|
for name in files: |
|
68
|
path = Path(folder) / name |
|
69
|
zf.write(path, path.relative_to(root.parent)) |
|
70
|
ZIP |
|
71
|
|
|
72
|
CHECKSUM=$(swift package compute-checksum "$ZIP_PATH") |
|
73
|
printf '%s |
|
74
|
' "$CHECKSUM" > "$CHECKSUM_PATH" |
|
75
|
|
|
76
|
VERSION=$(python3 - <<'VER' |
|
77
|
from pathlib import Path |
|
78
|
import tomllib |
|
79
|
cargo = Path('Cargo.toml').read_text().encode() |
|
80
|
print(tomllib.loads(cargo.decode())['package']['version']) |
|
81
|
VER |
|
82
|
) |
|
83
|
printf '%s |
|
84
|
' "$VERSION" > "$VERSION_PATH" |
|
85
|
|
|
86
|
echo "XCFramework: $FRAMEWORK_DIR" |
|
87
|
echo "Zip: $ZIP_PATH" |
|
88
|
echo "Checksum: $CHECKSUM" |
|
89
|
echo "Version: $VERSION" |