Hi Alex,
It seems that a tool called Dinghy already exists, and the authors there did the hard work of figuring out a lot of the steps required. By looking at that and also through various other articles, I was able to come up with the following steps which will compile the tests and run them on an iOS simulator:
Prerequisites:
- rustup target install x86_64-apple-ios
Steps:
- Create a shim to the cross-compiling linker for the simulator:
xcrun --sdk iphonesimulator --show-sdk-path
a) With the given path, create a shim called linker_shim.sh:
#!/bin/sh
cc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk "$@"
b) Make it executable:
chmod 777 linker_shim.sh
- Set an environment variable so that cargo doesn’t use the default linker:
export CARGO_TARGET_X86_64_APPLE_IOS_LINKER=~/<path>/linker_shim.sh
- Compile tests:
cargo test --no-run --target=x86_64-apple-ios
- Wrap as an app:
a) Copy executable to a separate empty directory.
mkdir app
cp target/x86_64-apple-ios/debug/hello-a254f99d8b1ee1bc app/hello
b) Create an Info.plist file with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>hello</string>
<key>CFBundleIdentifier</key>
<string>com.rust.tests</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>x86_64</string>
</array>
</dict>
</plist>
- Start the iOS simulator:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
- Install app:
xcrun simctl install booted app/
-
Use LLDB to prepare to receive process return value:
lldb
platform select ios-simulator
platform connect
process attach -n hello --waitfor
-
In another terminal window, run app:
xcrun simctl launch booted com.rust.tests
- in LLDB, complete execution:
continue
Output will look as follows:
Process 21635 resuming
Process 21635 exited with status = 0 (0x00000000)
In the case of a test failure, the output will instead look as follows:
Process 21742 resuming
Process 21742 exited with status = 101 (0x00000065)
Gist: https://gist.github.com/learnopengles/60c945b92fbe60a0fecaa0143c35c4af
I’m not really sure right now how to make this more automated let alone integrate it into the compiler’s test framework, but just wanted to document everything I found so far.