Skip to content

Commit 7ea5e68

Browse files
iOS: Namespace includes to avoid polluting global name space (#924)
* Namespace includes without renaming FerrostarCoreRS target. This might be a more transparent change since the internal frameworks don't change names, but it does rely on an unreleased feature of uniffi to set the ffi_module_name * Revert "Namespace includes without renaming FerrostarCoreRS target." This reverts commit 0ec7f04. * Namespace includes (requires renaming FFI target to match UniFFI conventions) Otherwise module.modulemap will be dumped in the top level build includes, which will conflict with any other package doing the same thing. To avoid collision, we should put it in a subdir of Headers. To be sure the xcode build process finds our includes, the subdir should have the same name as the target. With the latest stable uniffi (0.31), it's not possible to rename `ffi_module_name`, so we instead have to line up all our names with uniffi's defaults. * Cleanup --------- Co-authored-by: Ian Wagner <ian.wagner@stadiamaps.com>
1 parent d669701 commit 7ea5e68

2 files changed

Lines changed: 23 additions & 31 deletions

File tree

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let useLocalMapLibreSwiftUIDSL = false
1010

1111
if useLocalFramework {
1212
binaryTarget = .binaryTarget(
13-
name: "FerrostarCoreRS",
13+
name: "ferrostarFFI",
1414
// IMPORTANT: Swift packages importing this locally will not be able to
1515
// import Ferrostar core unless you specify this as a relative path!
1616
path: "./common/target/ios/libferrostar-rs.xcframework"
@@ -19,7 +19,7 @@ if useLocalFramework {
1919
let releaseTag = "0.51.0"
2020
let releaseChecksum = "23a35bcd60eb926465458f40f8f764e068878d96fe4ed76b73ed4dfd3e56ed1f"
2121
binaryTarget = .binaryTarget(
22-
name: "FerrostarCoreRS",
22+
name: "ferrostarFFI",
2323
url:
2424
"https://github.com/stadiamaps/ferrostar/releases/download/\(releaseTag)/libferrostar-rs.xcframework.zip",
2525
checksum: releaseChecksum
@@ -111,7 +111,7 @@ let package = Package(
111111
),
112112
.target(
113113
name: "FerrostarCoreFFI",
114-
dependencies: [.target(name: "FerrostarCoreRS")],
114+
dependencies: [.target(name: "ferrostarFFI")],
115115
path: "apple/Sources/UniFFI"
116116
),
117117

common/build-ios.sh

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@ set -u
1111
release=false
1212
ffi_only=false
1313

14-
for arg in "$@"
15-
do
16-
case $arg in
17-
--release)
18-
release=true
19-
shift # Remove --release from processing
20-
;;
21-
--ffi-only)
22-
ffi_only=true
23-
shift # Remove --ffi-only from processing
24-
;;
25-
*)
26-
shift # Ignore other argument from processing
27-
;;
28-
esac
14+
for arg in "$@"; do
15+
case $arg in
16+
--release)
17+
release=true
18+
shift # Remove --release from processing
19+
;;
20+
--ffi-only)
21+
ffi_only=true
22+
shift # Remove --ffi-only from processing
23+
;;
24+
*)
25+
shift # Ignore other argument from processing
26+
;;
27+
esac
2928
done
3029

31-
3230
# Potential optimizations for the future:
3331
#
3432
# * Only build one simulator arch for local development (we build both since many still use Intel Macs)
@@ -37,7 +35,7 @@ fat_simulator_lib_dir="target/ios-simulator-fat/release"
3735

3836
generate_ffi() {
3937
echo "Generating framework module mapping and FFI bindings"
40-
38+
4139
# Use different library path based on build mode
4240
if $ffi_only; then
4341
echo "Using native library for FFI generation"
@@ -46,20 +44,15 @@ generate_ffi() {
4644
if [[ "$(uname)" == "Darwin" ]]; then
4745
lib_ext="dylib"
4846
fi
49-
cargo run -p uniffi-bindgen-swift -- target/release/lib$1.$lib_ext target/uniffi-xcframework-staging --swift-sources --headers --modulemap --module-name $1FFI --modulemap-filename module.modulemap
47+
cargo run -p uniffi-bindgen-swift -- target/release/lib$1.$lib_ext target/uniffi-xcframework-staging/$1FFI --swift-sources --headers --modulemap --module-name $1FFI --modulemap-filename module.modulemap
5048
else
5149
echo "Using iOS library for FFI generation"
5250
# NOTE: Convention requires the modulemap be named module.modulemap
53-
cargo run -p uniffi-bindgen-swift -- target/aarch64-apple-ios/release/lib$1.a target/uniffi-xcframework-staging --swift-sources --headers --modulemap --module-name $1FFI --modulemap-filename module.modulemap
51+
cargo run -p uniffi-bindgen-swift -- target/aarch64-apple-ios/release/lib$1.a target/uniffi-xcframework-staging/$1FFI --swift-sources --headers --modulemap --module-name $1FFI --modulemap-filename module.modulemap
5452
fi
55-
53+
5654
mkdir -p ../apple/Sources/UniFFI/
57-
mv target/uniffi-xcframework-staging/*.swift ../apple/Sources/UniFFI/
58-
59-
# Only move modulemap if not in ffi-only mode
60-
if ! $ffi_only; then
61-
mv target/uniffi-xcframework-staging/module.modulemap target/uniffi-xcframework-staging/module.modulemap
62-
fi
55+
mv target/uniffi-xcframework-staging/$1FFI/*.swift ../apple/Sources/UniFFI/
6356
}
6457

6558
create_fat_simulator_lib() {
@@ -111,6 +104,5 @@ git config core.hooksPath .githooks
111104
cargo build -p $basename --lib --release --target aarch64-apple-ios-sim
112105
cargo build -p $basename --lib --release --target x86_64-apple-ios
113106

114-
115107
create_fat_simulator_lib $basename
116-
build_xcframework $basename
108+
build_xcframework $basename

0 commit comments

Comments
 (0)