Please pass a compilation condition to Playground Auxiliary Sources

Originator:zach
Number:rdar://38865726 Date Originated:March 26 2018, 10:54 AM
Status:Open Resolved:false
Product:Developer Tools Product Version:N/A
Classification:Suggestion Reproducible:N/A
 
Xcode playgrounds pass a short list of compiler flags to build a playground's auxiliary sources; `-O`, a bunch of `-F` statements the SDK and target triple, etc. Please pass a unique `-D` such as `-DXCODE_PLAYGROUND` to allow frameworks that ship multiple forms (playground demo, Xcode framework, SPM framework, CocoaPod, etc.) to reliably detect the playground environment.

For instance, I have a framework that uses some C headers on Apple's platforms. In a regular framework target, I may choose to discover and link those using a custom module map. In a playground, I may use runtime linkage to load those C symbols, or use alternate implementations entirely.

It is possible to accomplish this already by organizing the code such that the playground is the default/fallback code and defining, i.e., `-DXCODE`. This is suboptimal in environments where our Xcode's configs aren't respected, such as when the source files are copied and pasted.

Risks: There may be concerns about using this detection to do nefarious things. However, the playground environment can already be detected at runtime.

Alternatives Considered:
- Allow module maps/submodules in auxiliary sources. This wouldn't help my case much without providing my own headers. Those combined seem like an awful lot of work.
- Allow binary frameworks in playgrounds. Feasible with a stable ABI, but that's not really up to me. And it certainly increases the risk of nefarious playgrounds.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!