Skip to content

Commit f81d430

Browse files
committed
Make it clearer why we provide extern symbol
1 parent d59cac3 commit f81d430

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

library/std/src/sys/platform_version/darwin/public_extern.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1-
//! Runtime version checking ABI for other compilers.
1+
//! # Runtime version checking ABI for other compilers.
22
//!
33
//! The symbols in this file are useful for us to expose to allow linking code written in the
44
//! following languages when using their version checking functionality:
5-
//! - Objective-C's `@available`.
65
//! - Clang's `__builtin_available` macro.
6+
//! - Objective-C's `@available`.
77
//! - Swift's `#available`,
88
//!
9+
//! Without Rust exposing these symbols, the user would encounter a linker error when linking to
10+
//! C/Objective-C/Swift libraries using these features.
11+
//!
12+
//! The presence of these are mostly considered a quality-of-implementation detail, and should not
13+
//! be relied upon to be available.
14+
//!
15+
//! ## Background
16+
//!
917
//! The original discussion of this feature can be found at:
1018
//! - <https://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html>
1119
//! - <https://reviews.llvm.org/D27827>
1220
//! - <https://reviews.llvm.org/D30136>
1321
//!
14-
//! The implementation of these is a bit weird, since they're actually implemented in `compiler-rt`:
22+
//! And the upstream implementation of these can be found in `compiler-rt`:
1523
//! <https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0/compiler-rt/lib/builtins/os_version_check.c>
1624
//!
17-
//! While they probably should've been part of `libSystem.dylib`, both because they link to symbols
18-
//! from that, and because their implementation is quite complex, using allocation, environment
19-
//! variables, file access and dynamic library loading (and emitting all of this into every binary).
25+
//! Ideally, these symbols should probably have been a part of Apple's `libSystem.dylib`, both
26+
//! because their implementation is quite complex, using allocation, environment variables, file
27+
//! access and dynamic library loading (and emitting all of this into every binary).
2028
//!
2129
//! The reason why Apple chose to not do that originally is lost to the sands of time, but a good
2230
//! reason would be that implementing it as part of `compiler-rt` allowed them to back-deploy this
@@ -27,15 +35,15 @@
2735
//! in `std` makes sense, since then we can implement it using `std` utilities, and we can avoid
2836
//! having `compiler-builtins` depend on `libSystem.dylib`.
2937
//!
30-
//! This does mean that users that attempt to link Objective-C code _and_ use `#![no_std]` in all
31-
//! their crates may get a linker error because these symbols are missing. Using `no_std` is quite
32-
//! uncommon on Apple systems though, so it's probably fine to not support this use-case.
38+
//! This does mean that users that attempt to link C/Objective-C/Swift code _and_ use `#![no_std]`
39+
//! in all their crates may get a linker error because these symbols are missing. Using `no_std` is
40+
//! quite uncommon on Apple systems though, so it's probably fine to not support this use-case.
3341
//!
3442
//! The workaround would be to link `libclang_rt.osx.a` or otherwise use Clang's `compiler-rt`.
3543
//!
3644
//! See also discussion in <https://github.com/rust-lang/compiler-builtins/pull/794>.
3745
//!
38-
//! ---
46+
//! ## Implementation details
3947
//!
4048
//! NOTE: Since macOS 10.15, `libSystem.dylib` _has_ actually provided the undocumented
4149
//! `_availability_version_check` via `libxpc` for doing the version lookup (zippered, which is why

0 commit comments

Comments
 (0)