-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc++] Move the availability documentation to a design document #169371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philnik777
wants to merge
1
commit into
llvm:main
Choose a base branch
from
philnik777:move_availability_docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+46
−49
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
|
|
||
| ==================== | ||
| Availability markups | ||
| ==================== | ||
|
|
||
| Libc++ is shipped by various vendors. In particular, it is used as a system library on macOS, iOS and other Apple | ||
| platforms. In order for users to be able to compile a binary that is intended to be deployed to an older version of a | ||
| platform, Clang provides `availability attributes <https://clang.llvm.org/docs/AttributeReference.html#availability>`_. | ||
| These attributes can be placed on declarations and are used to describe the life cycle of a symbol in the library. | ||
|
|
||
| The main goal is to ensure a compile-time error if a symbol that hasn't been introduced in a previously released library | ||
| is used in a program that targets that previously released library. Normally, this would be a load-time error when one | ||
| tries to launch the program against the older library. | ||
|
|
||
| For example, the filesystem library was introduced in the dylib in LLVM 9. On Apple platforms, this corresponds to | ||
| macOS 10.15. If a user compiles on a macOS 10.15 host but targets macOS 10.13 with their program, the compiler would | ||
| normally not complain (because the required declarations are in the headers), but the dynamic loader would fail to find | ||
| the symbols when actually trying to launch the program on macOS 10.13. To turn this into a compile-time issue instead, | ||
| declarations are annotated with when they were introduced, and the compiler can produce a diagnostic if the program | ||
| references something that isn't available on the deployment target. | ||
|
|
||
|
|
||
| This mechanism is general in nature, and any vendor can add their markup to the library (see below). Whenever a new | ||
| feature is added that requires support in the shared library, two macros are added below to allow marking the feature as | ||
| unavailable: | ||
|
|
||
| 1. A macro named ``_LIBCPP_AVAILABILITY_HAS_<feature>`` which must be defined to ``_LIBCPP_INTRODUCED_IN_<version>`` for | ||
| the appropriate LLVM version. | ||
|
|
||
| 2. A macro named ``_LIBCPP_AVAILABILITY_<feature>``, which must be defined to ``_LIBCPP_INTRODUCED_IN_<version>_MARKUP`` | ||
| for the appropriate LLVM version. | ||
|
|
||
| When vendors decide to ship the feature as part of their shared library, they can update the | ||
| ``_LIBCPP_INTRODUCED_IN_<version>`` macro (and the markup counterpart) based on the platform version they shipped that | ||
| version of LLVM in. The library will then use this markup to provide an optimal user experience on these platforms. | ||
|
|
||
| Furthermore, many features in the standard library have corresponding feature-test macros. The | ||
| ``_LIBCPP_AVAILABILITY_HAS_<feature>`` macros are checked by the corresponding feature-test macros generated by | ||
| ``generate_feature_test_macro_components.py`` to ensure that the library doesn't announce a feature as being implemented | ||
| if it is unavailable on the deployment target. | ||
|
|
||
| Note that this mechanism is disabled by default in the "upstream" libc++. Availability annotations are only meaningful | ||
| when shipping libc++ inside a platform (i.e. as a system library), and so vendors that want them should turn those | ||
| annotations on at CMake configuration time. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,55 +17,7 @@ | |||||||||||||||
| # pragma GCC system_header | ||||||||||||||||
| #endif | ||||||||||||||||
|
|
||||||||||||||||
| // Libc++ is shipped by various vendors. In particular, it is used as a system | ||||||||||||||||
| // library on macOS, iOS and other Apple platforms. In order for users to be | ||||||||||||||||
| // able to compile a binary that is intended to be deployed to an older version | ||||||||||||||||
| // of a platform, Clang provides availability attributes [1]. These attributes | ||||||||||||||||
| // can be placed on declarations and are used to describe the life cycle of a | ||||||||||||||||
| // symbol in the library. | ||||||||||||||||
| // | ||||||||||||||||
| // The main goal is to ensure a compile-time error if a symbol that hasn't been | ||||||||||||||||
| // introduced in a previously released library is used in a program that targets | ||||||||||||||||
| // that previously released library. Normally, this would be a load-time error | ||||||||||||||||
| // when one tries to launch the program against the older library. | ||||||||||||||||
| // | ||||||||||||||||
| // For example, the filesystem library was introduced in the dylib in LLVM 9. | ||||||||||||||||
| // On Apple platforms, this corresponds to macOS 10.15. If a user compiles on | ||||||||||||||||
| // a macOS 10.15 host but targets macOS 10.13 with their program, the compiler | ||||||||||||||||
| // would normally not complain (because the required declarations are in the | ||||||||||||||||
| // headers), but the dynamic loader would fail to find the symbols when actually | ||||||||||||||||
| // trying to launch the program on macOS 10.13. To turn this into a compile-time | ||||||||||||||||
| // issue instead, declarations are annotated with when they were introduced, and | ||||||||||||||||
| // the compiler can produce a diagnostic if the program references something that | ||||||||||||||||
| // isn't available on the deployment target. | ||||||||||||||||
| // | ||||||||||||||||
| // This mechanism is general in nature, and any vendor can add their markup to | ||||||||||||||||
| // the library (see below). Whenever a new feature is added that requires support | ||||||||||||||||
| // in the shared library, two macros are added below to allow marking the feature | ||||||||||||||||
| // as unavailable: | ||||||||||||||||
| // 1. A macro named `_LIBCPP_AVAILABILITY_HAS_<feature>` which must be defined | ||||||||||||||||
| // to `_LIBCPP_INTRODUCED_IN_<version>` for the appropriate LLVM version. | ||||||||||||||||
| // 2. A macro named `_LIBCPP_AVAILABILITY_<feature>`, which must be defined to | ||||||||||||||||
| // `_LIBCPP_INTRODUCED_IN_<version>_MARKUP` for the appropriate LLVM version. | ||||||||||||||||
| // | ||||||||||||||||
| // When vendors decide to ship the feature as part of their shared library, they | ||||||||||||||||
| // can update the `_LIBCPP_INTRODUCED_IN_<version>` macro (and the markup counterpart) | ||||||||||||||||
| // based on the platform version they shipped that version of LLVM in. The library | ||||||||||||||||
| // will then use this markup to provide an optimal user experience on these platforms. | ||||||||||||||||
| // | ||||||||||||||||
| // Furthermore, many features in the standard library have corresponding | ||||||||||||||||
| // feature-test macros. The `_LIBCPP_AVAILABILITY_HAS_<feature>` macros | ||||||||||||||||
| // are checked by the corresponding feature-test macros generated by | ||||||||||||||||
| // generate_feature_test_macro_components.py to ensure that the library | ||||||||||||||||
| // doesn't announce a feature as being implemented if it is unavailable on | ||||||||||||||||
| // the deployment target. | ||||||||||||||||
| // | ||||||||||||||||
| // Note that this mechanism is disabled by default in the "upstream" libc++. | ||||||||||||||||
| // Availability annotations are only meaningful when shipping libc++ inside | ||||||||||||||||
| // a platform (i.e. as a system library), and so vendors that want them should | ||||||||||||||||
| // turn those annotations on at CMake configuration time. | ||||||||||||||||
| // | ||||||||||||||||
| // [1]: https://clang.llvm.org/docs/AttributeReference.html#availability | ||||||||||||||||
| // Documentation for this utility can be found at https://libcxx.llvm.org/DesignDocs/Availability.html | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also note the link will need to be updated if we move it into vendor docs. |
||||||||||||||||
|
|
||||||||||||||||
| // Availability markup is disabled when building the library, or when a non-Clang | ||||||||||||||||
| // compiler is used because only Clang supports the necessary attributes. | ||||||||||||||||
|
|
||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be a design document. This should probably be included in the vendor documentation.