AvailabilityMarkup.rst 4.2 KB

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