Skip to content

Commit 791f2dc

Browse files
authored
Merge pull request #65218 from Azoy/availability-feature
[Frontend] Add AvailabilityMacro feature
2 parents 7b78d39 + bd5d24d commit 791f2dc

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
@@ -748,6 +748,19 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
748748

749749
Opts.Features.insert(*feature);
750750
}
751+
752+
// Hack: In order to support using availability macros in SPM packages, we
753+
// need to be able to use:
754+
// .enableExperimentalFeature("AvailabilityMacro='...'")
755+
// within the package manifest and the feature recognizer can't recognize
756+
// this form of feature, so specially handle it here until features can
757+
// maybe have extra arguments in the future.
758+
auto strRef = StringRef(A->getValue());
759+
if (strRef.startswith("AvailabilityMacro=")) {
760+
auto availability = strRef.split("=").second;
761+
762+
Opts.AvailabilityMacros.push_back(availability.str());
763+
}
751764
}
752765

753766
// 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)