Skip to content

Commit 05aff14

Browse files
committed
De-duplicate and improve definition of core::ffi::c_char
Instead of having a list of unsigned char targets for each OS, follow the logic Clang uses and instead set the value based on architecture with a special case for Darwin and Windows operating systems. This makes it easier to support new operating systems targeting Arm/AArch64 without having to modify this config statement for each new OS. The new list does not quite match Clang since I noticed a few bugs in the Clang implementation (llvm/llvm-project#115957).
1 parent f7273e0 commit 05aff14

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

library/core/src/ffi/mod.rs

+37-47
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,46 @@ pub type c_ssize_t = isize;
9292
mod c_char_definition {
9393
cfg_if! {
9494
// These are the targets on which c_char is unsigned.
95-
if #[cfg(any(
96-
all(
97-
target_os = "linux",
98-
any(
99-
target_arch = "aarch64",
100-
target_arch = "arm",
101-
target_arch = "hexagon",
102-
target_arch = "powerpc",
103-
target_arch = "powerpc64",
104-
target_arch = "s390x",
105-
target_arch = "riscv64",
106-
target_arch = "riscv32",
107-
target_arch = "csky"
108-
)
95+
// See isSignedCharDefault() in clang/lib/Driver/ToolChains/Clang.cpp
96+
// PowerPC uses unsigned char for all targets except Darwin.
97+
// Arm/AArch64 uses unsigned char except for Darwin and Windows targets
98+
if #[cfg(all(
99+
any(
100+
target_os = "ios",
101+
target_os = "macos",
102+
target_os = "tvos",
103+
target_os = "visionos",
104+
target_os = "watchos",
109105
),
110-
all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")),
111-
all(target_os = "l4re", target_arch = "x86_64"),
112-
all(
113-
any(target_os = "freebsd", target_os = "openbsd", target_os = "rtems"),
114-
any(
115-
target_arch = "aarch64",
116-
target_arch = "arm",
117-
target_arch = "powerpc",
118-
target_arch = "powerpc64",
119-
target_arch = "riscv64"
120-
)
106+
any(
107+
target_arch = "aarch64",
108+
target_arch = "arm",
109+
target_arch = "powerpc",
110+
target_arch = "powerpc64",
121111
),
122-
all(
123-
target_os = "netbsd",
124-
any(
125-
target_arch = "aarch64",
126-
target_arch = "arm",
127-
target_arch = "powerpc",
128-
target_arch = "riscv64"
129-
)
130-
),
131-
all(
132-
target_os = "vxworks",
133-
any(
134-
target_arch = "aarch64",
135-
target_arch = "arm",
136-
target_arch = "powerpc64",
137-
target_arch = "powerpc"
138-
)
139-
),
140-
all(
141-
target_os = "fuchsia",
142-
any(target_arch = "aarch64", target_arch = "riscv64")
112+
))] {
113+
pub type c_char = i8;
114+
} else if #[cfg(all(
115+
target_os = "windows",
116+
any(
117+
target_arch = "aarch64",
118+
target_arch = "arm",
119+
target_arch = "arm64ec"
143120
),
144-
all(target_os = "nto", target_arch = "aarch64"),
121+
))] {
122+
pub type c_char = i8;
123+
} else if #[cfg(any(
124+
target_arch = "aarch64",
125+
target_arch = "arm",
126+
target_arch = "csky",
127+
target_arch = "hexagon",
128+
target_arch = "msp430",
129+
target_arch = "powerpc",
130+
target_arch = "powerpc64",
131+
target_arch = "riscv64",
132+
target_arch = "riscv32",
133+
target_arch = "s390x",
134+
target_arch = "xtensa",
145135
target_os = "horizon",
146136
target_os = "aix",
147137
))] {

0 commit comments

Comments
 (0)