Skip to content

Commit

Permalink
ffi: add script to build xcframework
Browse files Browse the repository at this point in the history
We need to use a custom target spec for the iOS simulator. More details:

  rust-lang/rust#79408

Since that issue, all the targets except the x86_64 simulator have been
updated (one landed last night). There is a PR that updates the
simulator:

  rust-lang/rust#87699

Once that PR is merged we can remove the `x86_64-apple-ios7.0.json`
custom target spec and use the builtin.
  • Loading branch information
David Cowden authored and dcow committed Sep 2, 2021
1 parent 90293e7 commit b178f93
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ffi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
libs/
out/
4 changes: 4 additions & 0 deletions ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ authors = ["David Cowden <david@withuno.com>"]
license = "AGPL-3.0-only"
edition = "2018"

[lib]
name = "uno"
crate-type = ["staticlib"]

[dependencies]
uno = "0.1"

Expand Down
11 changes: 11 additions & 0 deletions ffi/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -x

# libuno-*.a
rm libs/*

# Uno.xcframework
rm out/*

rmdir libs out
130 changes: 130 additions & 0 deletions ffi/sumo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/sh
set -ex

: "${LIBNAME:=libuno}"
: "${OUTNAME:=Uno}"
: "${TOOLCHAIN:=nightly}"
: "${PROFILE:=release}"
: "${PROFDIR:=$PROFILE}"

#
# Build an archs table because the triple arch is not the same as lipo arch.
#
ARCHS="
aarch64
x86_64
"
subarchs=$(mktemp -d)
echo "arm64v8" > $subarchs/aarch64
echo "x86_64" > $subarchs/x86_64

mkdir -p libs

#
# Build macOS.
#
lipo_args=""

for ARCH in $ARCHS
do
TRIPLE="$ARCH-apple-darwin"
cargo +$TOOLCHAIN build \
-Z unstable-options --profile $PROFILE \
-Z build-std \
--target $TRIPLE

larch=$(< $subarchs/$ARCH)
lipo_args="$lipo_args
-arch $larch ../target/$TRIPLE/$PROFDIR/$LIBNAME.a"
done

lipo -create $lipo_args -output libs/$LIBNAME-macos.a

xc_args="$xc_args
-library libs/$LIBNAME-macos.a"
xc_args="$xc_args
-headers include"


#
# Build iOS.
#
cargo +$TOOLCHAIN build \
-Z unstable-options --profile $PROFILE \
-Z build-std \
--target aarch64-apple-ios

cp ../target/aarch64-apple-ios/$PROFDIR/$LIBNAME.a libs/$LIBNAME-ios.a

xc_args="$xc_args
-library libs/$LIBNAME-ios.a"
xc_args="$xc_args
-headers include"


#
# Build ios simulator.
#
cargo +$TOOLCHAIN build \
-Z unstable-options --profile $PROFILE \
-Z build-std \
--target aarch64-apple-ios-sim

lipo_args="
-arch arm64v8 ../target/aarch64-apple-ios-sim/$PROFDIR/$LIBNAME.a"

#
# The simulator rustc target on x86_64 does not have the correct load_command.
# Use a custom target with the correct one specified. Can be removed when:
#
# https://github.com/rust-lang/rust/pull/87699
#
# is merged.
#
cargo +$TOOLCHAIN build \
-Z unstable-options --profile $PROFILE \
-Z build-std \
--target x86_64-apple-ios7.0.json

lipo_args="$lipo_args
-arch x86_64 ../target/x86_64-apple-ios7.0/$PROFDIR/$LIBNAME.a"

lipo -create $lipo_args -output libs/$LIBNAME-ios-sim.a

xc_args="$xc_args
-library libs/$LIBNAME-ios-sim.a"
xc_args="$xc_args
-headers include"


#
# Build mac catalyst.
#
lipo_args=""
for ARCH in $ARCHS
do
TRIPLE="$ARCH-apple-ios-macabi"
cargo +$TOOLCHAIN build \
-Z unstable-options --profile $PROFILE \
-Z build-std \
--target $TRIPLE

larch=$(< $subarchs/$ARCH)
lipo_args="$lipo_args
-arch $larch ../target/$TRIPLE/$PROFDIR/$LIBNAME.a"
done

lipo -create $lipo_args -output libs/$LIBNAME-ios-macabi.a

xc_args="$xc_args
-library libs/$LIBNAME-ios-macabi.a"
xc_args="$xc_args
-headers include"


#
# Build the sumo xcframework.
#
mkdir -p out
xcodebuild -create-xcframework $xc_args -output out/$OUTNAME.xcframework

36 changes: 36 additions & 0 deletions ffi/x86_64-apple-ios7.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"abi-return-struct-as-int": true,
"arch": "x86_64",
"archive-format": "darwin",
"cpu": "core2",
"data-layout": "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"dll-suffix": ".dylib",
"dwarf-version": 2,
"eh-frame-header": false,
"emit-debug-gdb-scripts": false,
"executables": true,
"frame-pointer": "always",
"function-sections": false,
"has-rpath": true,
"is-builtin": false,
"is-like-osx": true,
"link-env": [
"ZERO_AR_DATE=1"
],
"link-env-remove": [
"MACOSX_DEPLOYMENT_TARGET"
],
"linker-is-gnu": false,
"llvm-target": "x86_64-apple-ios7.0",
"max-atomic-width": 64,
"os": "ios",
"split-debuginfo": "packed",
"stack-probes": {
"kind": "call"
},
"target-family": [
"unix"
],
"target-pointer-width": "64",
"vendor": "apple"
}

0 comments on commit b178f93

Please sign in to comment.