Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 1 | =================== |
| 2 | Availability Markup |
| 3 | =================== |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | Overview |
| 9 | ======== |
| 10 | |
| 11 | Libc++ is used as a system library on macOS and iOS (amongst others). In order |
| 12 | for users to be able to compile a binary that is intended to be deployed to an |
| 13 | older version of the platform, clang provides the |
| 14 | `availability attribute <https://clang.llvm.org/docs/AttributeReference.html#availability>`_ |
| 15 | that can be placed on declarations to describe the lifecycle of a symbol in the |
| 16 | library. |
| 17 | |
| 18 | Design |
| 19 | ====== |
| 20 | |
| 21 | When a new feature is introduced that requires dylib support, a macro should be |
| 22 | created in include/__config to mark this feature as unavailable for all the |
| 23 | systems. For example:: |
| 24 | |
| 25 | // Define availability macros. |
| 26 | #if defined(_LIBCPP_USE_AVAILABILITY_APPLE) |
Louis Dionne | d4fc5e5 | 2018-11-20 23:07:01 +0000 | [diff] [blame] | 27 | # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((unavailable)) |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 28 | #else if defined(_LIBCPP_USE_AVAILABILITY_SOME_OTHER_VENDOR) |
Louis Dionne | d4fc5e5 | 2018-11-20 23:07:01 +0000 | [diff] [blame] | 29 | # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS __attribute__((unavailable)) |
| 30 | #else |
| 31 | # define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
| 34 | When the library is updated by the platform vendor, the markup can be updated. |
| 35 | For example:: |
| 36 | |
| 37 | #define _LIBCPP_AVAILABILITY_SHARED_MUTEX \ |
| 38 | __attribute__((availability(macosx,strict,introduced=10.12))) \ |
| 39 | __attribute__((availability(ios,strict,introduced=10.0))) \ |
| 40 | __attribute__((availability(tvos,strict,introduced=10.0))) \ |
| 41 | __attribute__((availability(watchos,strict,introduced=3.0))) |
| 42 | |
| 43 | In the source code, the macro can be added on a class if the full class requires |
| 44 | type info from the library for example:: |
| 45 | |
Louis Dionne | d4fc5e5 | 2018-11-20 23:07:01 +0000 | [diff] [blame] | 46 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL |
| 47 | class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access |
| 48 | : public std::logic_error { |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 49 | |
| 50 | or on a particular symbol: |
| 51 | |
| 52 | _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; |
| 53 | |
Louis Dionne | b64592b | 2019-02-05 19:22:38 +0000 | [diff] [blame] | 54 | Furthermore, a lit feature should be added to match that availability macro, |
| 55 | so that tests depending on that feature can be marked to XFAIL if the feature |
| 56 | is not supported. This way, the test suite will work on platforms that have |
| 57 | not shipped the feature yet. This can be done by adding the appropriate lit |
| 58 | feature in test/config.py. |
| 59 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 60 | |
| 61 | Testing |
| 62 | ======= |
| 63 | |
Louis Dionne | 4a83803 | 2018-12-07 21:48:39 +0000 | [diff] [blame] | 64 | Some parameters can be passed to lit to run the test-suite and exercise the |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 65 | availability. |
| 66 | |
Bruce Mitchener | 2715e2c | 2018-02-13 08:12:00 +0000 | [diff] [blame] | 67 | * The `platform` parameter controls the deployment target. For example lit can |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 68 | be invoked with `--param=platform=macosx10.12`. Default is the current host. |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 69 | * The `use_system_cxx_lib` parameter indicates to use another library than the |
| 70 | just built one. Invoking lit with `--param=use_system_cxx_lib=true` will run |
| 71 | the test-suite against the host system library. Alternatively a path to the |
| 72 | directory containing a specific prebuilt libc++ can be used, for example: |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 73 | `--param=use_system_cxx_lib=/path/to/macOS/10.12/`. |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 74 | |
| 75 | Tests can be marked as XFAIL based on multiple features made available by lit: |
| 76 | |
| 77 | |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 78 | * if `--param=platform=macosx10.12` is passed, the following features will be available: |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 79 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 80 | - availability=macosx |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 81 | - availability=macosx10.12 |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 82 | |
Louis Dionne | d4fc5e5 | 2018-11-20 23:07:01 +0000 | [diff] [blame] | 83 | This feature is used to XFAIL a test that *is* using a class or a method marked |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 84 | as unavailable *and* that is expected to *fail* if deployed on an older system. |
| 85 | |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 86 | * if `use_system_cxx_lib` and `--param=platform=macosx10.12` are passed to lit, |
Louis Dionne | 4a83803 | 2018-12-07 21:48:39 +0000 | [diff] [blame] | 87 | the following features will also be available: |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 88 | |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 89 | - with_system_cxx_lib=macosx |
Louis Dionne | 985ef73 | 2020-04-10 16:14:10 -0400 | [diff] [blame] | 90 | - with_system_cxx_lib=macosx10.12 |
Louis Dionne | c44138f | 2020-04-13 17:12:30 -0400 | [diff] [blame] | 91 | - with_system_cxx_lib=x86_64-apple-macosx10.12 |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 92 | |
Louis Dionne | d4fc5e5 | 2018-11-20 23:07:01 +0000 | [diff] [blame] | 93 | This feature is used to XFAIL a test that is *not* using a class or a method |
Mehdi Amini | 228053d | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 94 | marked as unavailable *but* that is expected to fail if deployed on an older |
Louis Dionne | 4a83803 | 2018-12-07 21:48:39 +0000 | [diff] [blame] | 95 | system. For example, if the test exhibits a bug in the libc on a particular |
| 96 | system version, or if the test uses a symbol that is not available on an |
| 97 | older version of the dylib (but for which there is no availability markup, |
| 98 | otherwise the XFAIL should use `availability` above). |