I have a Rust crate that I have compiled as a cdylib. I have created a xcframework
with two frameworks
inside. One for iOS device and one for the simulator. Then linked the xcframework
with Cocoapods.
When I run my app in the simulator it works fine. I can call my rust functions. However, when I try to run on the device I get the following crash upon app start:
dyld[673]: Library not loaded: /Users/osp/Developer/notary-core/target/aarch64-apple-ios/release/deps/libnotary.dylib
Referenced from: <9FE91A07-F954-36AA-8F9E-0BA14E473913> /private/var/containers/Bundle/Application/7DA323A5-0E86-409A-8516-B42240426377/Clip.app/Clip
Reason: tried: '/usr/lib/system/introspection/libnotary.dylib' (no such file, not in dyld cache), '/Users/osp/Developer/notary-core/target/aarch64-apple-ios/release/deps/libnotary.dylib' (no such file), '/private/preboot/Cryptexes/OS/Users/osp/Developer/notary-core/target/aarch64-apple-ios/release/deps/libnotary.dylib' (no such file), '/Users/osp/Developer/notary-core/target/aarch64-apple-ios/release/deps/libnotary.dylib' (no such file)
It seems somehow it is trying to point to my original crate output folder. Which is not correct, I thought the dylib should be able to be loaded without other dependencies.
In order to create the xcframework
I have the following makefile:
ARCH_IOS_SIM = aarch64-apple-ios-sim
ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
IOS_LIB = libnotary.dylib
XCFRAMEWORK = NotaryLib.xcframework
HEADER = notary.h
export IPHONEOS_DEPLOYMENT_TARGET = 14.0
.PHONY: clean ios android $(ARCH_IOS_SIM) $(ARCHS_IOS) $(ARCHS_ANDROID) sim nuke
nuke:
rm -rf ./target
clean:
# rm -rf generated
rm -rf generated/device_framework
rm -rf generated/sim_framework
rm -rf generated/NotaryLib.xcframework
mkdir -p generated/simulator_fat
mkdir -p generated/device_framework/NotaryLib.framework/Headers
mkdir -p generated/device_framework/NotaryLib.framework/Modules
mkdir -p generated/sim_framework/NotaryLib.framework/Headers
mkdir -p generated/sim_framework/NotaryLib.framework/Modules
################# iOS #################
ios: clean ios-build ios-package nocap-package ios-build-full ios-package
sim: clean
cargo build --target $(ARCH_IOS_SIM)
xcodebuild -create-xcframework -library target/$(ARCH_IOS_SIM)/debug/$(IOS_LIB) -headers include -output ios/$(XCFRAMEWORK)
nocap-package:
# Copy to nocap app
cp -R generated/$(XCFRAMEWORK) ../nocap/tm
# XCode is absolutely retarded and picks up the wrong headers if we don't do this
cp generated/include/notary.h ../nocap/tm
ios-package:
rm -rf generated/notary.xcframework
lipo -create target/x86_64-apple-ios/release/$(IOS_LIB) target/aarch64-apple-ios-sim/release/$(IOS_LIB) -output generated/simulator_fat/$(IOS_LIB)
# Create device framework
cp target/aarch64-apple-ios/release/$(IOS_LIB) generated/device_framework/NotaryLib.framework/NotaryLib
cp templates/Info.plist generated/device_framework/NotaryLib.framework/Info.plist
cp templates/module.modulemap generated/device_framework/NotaryLib.framework/Modules/module.modulemap
cp generated/include/$(HEADER) generated/device_framework/NotaryLib.framework/Headers/$(HEADER)
# Create sim framework
cp target/aarch64-apple-ios-sim/release/$(IOS_LIB) generated/sim_framework/NotaryLib.framework/NotaryLib
cp templates/Info.plist generated/sim_framework/NotaryLib.framework/Info.plist
cp templates/module.modulemap generated/sim_framework/NotaryLib.framework/Modules/module.modulemap
cp generated/include/$(HEADER) generated/sim_framework/NotaryLib.framework/Headers/$(HEADER)
# Combine into a single xcframework
xcodebuild -create-xcframework -framework generated/device_framework/NotaryLib.framework -framework generated/sim_framework/NotaryLib.framework -output generated/$(XCFRAMEWORK)
ios-build-full: $(ARCHS_IOS:%=ios-build-full-%)
ios-build: $(ARCHS_IOS:%=ios-build-base-%)
ios-build-full-%:
cargo build --release --target $* --all-features
ios-build-base-%:
cargo build --release --target $*
Any idea what might be wrong?