Skip to content

Commit 2740ce6

Browse files
authored
Merge pull request #65255 from Azoy/availability-feature-59
[5.9] [Frontend] Add AvailabilityMacro feature
2 parents 2f1e771 + 5c37595 commit 2740ce6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,19 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
717717

718718
Opts.Features.insert(*feature);
719719
}
720+
721+
// Hack: In order to support using availability macros in SPM packages, we
722+
// need to be able to use:
723+
// .enableExperimentalFeature("AvailabilityMacro='...'")
724+
// within the package manifest and the feature recognizer can't recognize
725+
// this form of feature, so specially handle it here until features can
726+
// maybe have extra arguments in the future.
727+
auto strRef = StringRef(A->getValue());
728+
if (strRef.startswith("AvailabilityMacro=")) {
729+
auto availability = strRef.split("=").second;
730+
731+
Opts.AvailabilityMacros.push_back(availability.str());
732+
}
720733
}
721734

722735
// Map historical flags over to future features.

test/Sema/availability_define.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
// RUN: -define-availability "_macOS11_0:macOS 11.0" \
66
// RUN: -define-availability "_myProject 1.0:macOS 11.0" \
77
// RUN: -define-availability "_myProject 2.5:macOS 12.5"
8+
9+
// RUN: %target-typecheck-verify-swift \
10+
// RUN: -enable-experimental-feature AvailabilityMacro='_iOS13Aligned:macOS 10.15, iOS 13.0' \
11+
// RUN: -enable-experimental-feature AvailabilityMacro="_iOS14Aligned:macOS 11.0, iOS 14.0" \
12+
// RUN: -enable-experimental-feature AvailabilityMacro='_iOS14:iOS 14.0' \
13+
// RUN: -enable-experimental-feature AvailabilityMacro="_macOS11_0:macOS 11.0" \
14+
// RUN: -enable-experimental-feature AvailabilityMacro='_myProject 1.0:macOS 11.0' \
15+
// RUN: -enable-experimental-feature AvailabilityMacro="_myProject 2.5:macOS 12.5"
16+
817
// REQUIRES: OS=macosx
918

1019
@available(_iOS13Aligned, *)

0 commit comments

Comments
 (0)