apple / swift-system

Low-level system calls and types for Swift
Apache License 2.0
1.18k stars 102 forks source link

Conditional compilation for `@available` attributes #195

Closed benrimmington closed 2 months ago

benrimmington commented 2 months ago

From the pinned FAQ issue:

Why are @available directives commented out?

This is due to language/tooling issues. We'd like the ability to add availability based on conditional compilation for ABI-stable builds of Swift System while not adding availability for package builds (i.e. a source dependency). For now, we include, but comment out, the availability declarations matching what has already been shipped in binary releases.

Should this be implemented now, using swift-tools-version:5.8 and SE-0367?

#if !SYSTEM_PACKAGE
  @available(/*System 0.0.1*/macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
#endif

I'm not sure if it's an improvement over the current format:

  @available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)

Using -define-availability macros only for ABI-stable builds might be possible:

#if false
  @available(System 0.0.1, *)  // warning: unrecognized platform name 'System'
#endif

#if compiler(>=5.8) && false
  @available(System 0.0.1, *)  // OK
#endif
benrimmington commented 2 months ago

AvailabilityMacro= in swift-tools-version: 5.9 would be better than conditional compilation.

Package:

.enableExperimentalFeature("AvailabilityMacro=System 0.0.1:iOS 8")

Framework:

-enable-experimental-feature "AvailabilityMacro=System 0.0.1:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0"