Tuesday, July 9, 2024
HomeiOS Developmentxcode - Rust cdylib in a iOS app crashes on app begin

xcode – Rust cdylib in a iOS app crashes on app begin


I’ve a Rust crate that I’ve compiled as a cdylib. I’ve created a xcframework with two frameworks inside. One for iOS machine and one for the simulator. Then linked the xcframework with Cocoapods.

Once I run my app within the simulator it really works high-quality. I can name my rust capabilities. Nevertheless, when I attempt to run on the machine I get the next crash upon app begin:

Crash

dyld[673]: Library not loaded: /Customers/osp/Developer/notary-core/goal/aarch64-apple-ios/launch/deps/libnotary.dylib
  Referenced from: <9FE91A07-F954-36AA-8F9E-0BA14E473913> /non-public/var/containers/Bundle/Software/7DA323A5-0E86-409A-8516-B42240426377/Clip.app/Clip
  Cause: tried: '/usr/lib/system/introspection/libnotary.dylib' (no such file, not in dyld cache), '/Customers/osp/Developer/notary-core/goal/aarch64-apple-ios/launch/deps/libnotary.dylib' (no such file), '/non-public/preboot/Cryptexes/OS/Customers/osp/Developer/notary-core/goal/aarch64-apple-ios/launch/deps/libnotary.dylib' (no such file), '/Customers/osp/Developer/notary-core/goal/aarch64-apple-ios/launch/deps/libnotary.dylib' (no such file)

It appears someway it’s attempting to level to my authentic crate output folder. Which isn’t right, I assumed the dylib ought to have the ability to be loaded with out different dependencies.

To be able to create the xcframework I’ve the next 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: clear ios android $(ARCH_IOS_SIM) $(ARCHS_IOS) $(ARCHS_ANDROID) sim nuke 

nuke:
    rm -rf ./goal

clear:
    # 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: clear ios-build ios-package nocap-package ios-build-full ios-package

sim: clear
    cargo construct --target $(ARCH_IOS_SIM)
    xcodebuild -create-xcframework -library goal/$(ARCH_IOS_SIM)/debug/$(IOS_LIB) -headers embody -output ios/$(XCFRAMEWORK)

nocap-package:
# Copy to nocap app
    cp -R generated/$(XCFRAMEWORK) ../nocap/tm
# XCode is totally retarded and picks up the incorrect headers if we do not do that
    cp generated/embody/notary.h ../nocap/tm

ios-package:
    rm -rf generated/notary.xcframework
    lipo -create goal/x86_64-apple-ios/launch/$(IOS_LIB) goal/aarch64-apple-ios-sim/launch/$(IOS_LIB) -output generated/simulator_fat/$(IOS_LIB)

# Create machine framework
    cp goal/aarch64-apple-ios/launch/$(IOS_LIB) generated/device_framework/NotaryLib.framework/NotaryLib
    cp templates/Data.plist generated/device_framework/NotaryLib.framework/Data.plist
    cp templates/module.modulemap generated/device_framework/NotaryLib.framework/Modules/module.modulemap
    cp generated/embody/$(HEADER) generated/device_framework/NotaryLib.framework/Headers/$(HEADER)

# Create sim framework
    cp goal/aarch64-apple-ios-sim/launch/$(IOS_LIB) generated/sim_framework/NotaryLib.framework/NotaryLib
    cp templates/Data.plist generated/sim_framework/NotaryLib.framework/Data.plist
    cp templates/module.modulemap generated/sim_framework/NotaryLib.framework/Modules/module.modulemap
    cp generated/embody/$(HEADER) generated/sim_framework/NotaryLib.framework/Headers/$(HEADER)

# Mix right 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 construct --release --target $* --all-features

ios-build-base-%:
    cargo construct --release --target $*

Any thought what could be incorrect?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments