[swift-evolution] Idea: Support #if os(Darwin) as shorthand for os(iOS) || os(OSX) || os(watchOS) || os(tvOS)

Evan Maloney emaloney at gilt.com
Mon Feb 22 09:22:06 CST 2016


>> SwiftPM passes DEBUG and NDEBUG. Ugly, but the standard.
> 
> I don't think it's the package manager's place to do that, since the compiler's already aware of the current build mode. IMO all the standard #if flags should ideally be centralized in the language so there isn't a forever-creeping set of conventional -D flags like there are in C land. (Tradition or not, negative flags like NDEBUG should be put out to pasture—we've let go of other, less terrible C traditions.)

Agreed!

> We specifically avoided making debug/release an #if condition because we considered #if to be the wrong point at which to start conditionalizing code generation for assertions.

There are many reasons besides assertions where one might want to know if code is running in release mode or debug mode.

For example, we use CleanroomLogger <https://github.com/emaloney/CleanroomLogger> as our in-app logging API, and we configure the logger differently in debug mode:

- We perform more verbose logging in debug mode; we don't want to ship with this since verbose logging can affect the performance of the app.

- We configure the logger to run synchronously, so that when we hit a breakpoint, the console output is up-to-date. In production code, we set up CleanroomLogger to log asynchronously, which is another way to optimize performance.

Currently, the concept of debug mode only lives at the application level, and we pass the -DDEBUG flag to indicate a debug build. Since the compiler knows whether we're building for debug or not, it would be great to not have to pass this in.

I can understand this would be tricky for binary-only frameworks, but in our case, everything we touch is open-source; we integrate as git submodules with embedded Xcode projects & compile everything ourselves. I suspect this is pretty common with pure-Swift projects. Since there isn't ABI compatibility yet, people probably aren't releasing binary-only packages with Swift.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160222/75146694/attachment.html>


More information about the swift-evolution mailing list