Running (test) binaries on iPhone Simulator
Created by: danzimm
Hey folks,
I'm working with buck on iOS. I had an idea that might be useful to you guys, before I dive in let me give some context...
Testing xplat code on iPhone Simulator: Today
Right now its common for users to set cxx.default_platform=iphonesimulator-x86_64
in their buckconfig so that when building/testing they default to using an iOS simulator. Let's focus on testing for a moment: this forces users to use apple_test
declarations in their buck files to declare tests. This becomes an issue when dealing with cross platform code, as often times their tests are declared as cxx_test
(and use e.g. gtest
). Now users can define two test targets, one apple_test
, one cxx_test
and invent a shim to create an XCTest
out of their native test, but this isn't super ideal.
xcrun simctl spawn
Enter: I stumbled upon this subcommand today which allows me to run binaries built for the simulator on the simulator without an app bundle. I've verified that I'm able to run the following commands successfully and observe the test's output and exit code reflect passing and failing tests:
> buck build //:gtest_target#iphonesimulator-x86_64
> xcrun simctl boot 'iPhone 11'
> xcrun simctl spawn 'iPhone 11' buck-out/gen/gtest_target
Idea
Now, this isn't necessarily a feature request as I'm not sure I need it, but I figure it might be a good idea for you folks moving forward: what if the iphonesimulator
flavor changes how binaries are ran internally so that doing buck run
or buck test
automatically invokes binaries with xcrun simctl spawn
instead of executing them directly? This could help cleanup the situation I mentioned above and more generally ease some xplat devx issues.
cc @mzlee