Skip to content

Commit cdaaeb6

Browse files
authored
compat.fribidi on macOS and Windows; compat.xdmcp without arc4random_buf (#571)
* compat.fribidi on macOS and Windows; compat.xdmcp without arc4random_buf compat.fribidi declared a Linux build only, so every macOS and Windows build that reaches it (openmui's text engine, pango) stopped at install. fribidi is portable C99 whose tables ship in the tarball and whose two config headers are written out here, so the same tarball serves all three platforms. The generated config.h no longer claims <strings.h> and <memory.h>: lib/common.h would include <strings.h>, which MSVC's headers do not have, and nothing in lib/ uses a function from either. compat.xdmcp declared HAVE_ARC4RANDOM_BUF, which assumes glibc 2.36+; on an older sysroot (the aarch64 one) Key.c's call is an implicit declaration, an error under C11. It now declares getentropy (glibc 2.25+) and lets Key.c's own arc4random_buf emulation use it. * compat.xdmcp: decide arc4random_buf from the libc, in config.h The x86_64 sysroot's glibc (2.36+) declares arc4random_buf, so Key.c's own static definition conflicts with it; the aarch64 sysroot's older glibc does not, so a fixed HAVE_ARC4RANDOM_BUF is an implicit declaration there. A generated config.h reads the libc's version macros and chooses: the libc's arc4random_buf, or Key.c's emulation over getentropy (glibc 2.25+, musl).
1 parent 2dd30cb commit cdaaeb6

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎pkgs/c/compat.fribidi.lua‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ package = {
4646
repo = "https://github.com/fribidi/fribidi",
4747
type = "package",
4848

49+
-- One source tarball for every platform: fribidi is portable C99 with no
50+
-- platform probes left (the two config headers below are written out),
51+
-- so macOS and Windows build the same files Linux does.
4952
xpm = {
5053
linux = {
5154
["1.0.16"] = {
@@ -56,6 +59,24 @@ package = {
5659
sha256 = "1b1cde5b235d40479e91be2f0e88a309e3214c8ab470ec8a2744d82a5a9ea05c",
5760
},
5861
},
62+
macosx = {
63+
["1.0.16"] = {
64+
url = {
65+
GLOBAL = "https://github.com/fribidi/fribidi/releases/download/v1.0.16/fribidi-1.0.16.tar.xz",
66+
CN = "https://gitcode.com/mcpp-res/fribidi/releases/download/1.0.16/fribidi-1.0.16.tar.xz",
67+
},
68+
sha256 = "1b1cde5b235d40479e91be2f0e88a309e3214c8ab470ec8a2744d82a5a9ea05c",
69+
},
70+
},
71+
windows = {
72+
["1.0.16"] = {
73+
url = {
74+
GLOBAL = "https://github.com/fribidi/fribidi/releases/download/v1.0.16/fribidi-1.0.16.tar.xz",
75+
CN = "https://gitcode.com/mcpp-res/fribidi/releases/download/1.0.16/fribidi-1.0.16.tar.xz",
76+
},
77+
sha256 = "1b1cde5b235d40479e91be2f0e88a309e3214c8ab470ec8a2744d82a5a9ea05c",
78+
},
79+
},
5980
},
6081

6182
mcpp = {
@@ -120,10 +141,12 @@ package = {
120141
121142
#define HAVE_STDLIB_H 1
122143
#define HAVE_STRING_H 1
123-
#define HAVE_STRINGS_H 1
124-
#define HAVE_MEMORY_H 1
125144
#define SIZEOF_INT 4
126145
146+
/* HAVE_STRINGS_H and HAVE_MEMORY_H are left out: lib/common.h would include
147+
<strings.h> (which MSVC's headers do not have) and <memory.h>, and nothing
148+
in lib/ uses a function from either; <string.h> covers memcpy and friends. */
149+
127150
/* HAVE_FRIBIDI_CUSTOM_H and HAVE_FRIBIDI_UNICODE_VERSION_H are
128151
DELIBERATELY ABSENT rather than 0.
129152
- fribidi_custom.h does not exist here (it is a downstream hook), and

‎pkgs/c/compat.xdmcp.lua‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,36 @@ package = {
2323
language = "c++23",
2424
import_std = false,
2525
c_standard = "c11",
26-
cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE", "-DHAVE_ARC4RANDOM_BUF=1"},
27-
include_dirs = {"*/include", "*"},
26+
-- Whether the libc has arc4random_buf is a property of the sysroot,
27+
-- not of the platform: glibc declares it from 2.36 (the x86_64
28+
-- sysroot), an older glibc or musl does not (the aarch64 sysroot).
29+
-- Key.c either calls the libc's or defines its own over getentropy,
30+
-- so the choice is made where it can be seen — in config.h below,
31+
-- from the libc's own version macros. A fixed -DHAVE_ARC4RANDOM_BUF
32+
-- breaks the older sysroot (an implicit declaration); leaving it out
33+
-- breaks the newer one (Key.c's static definition conflicts).
34+
cflags = {"-D_GNU_SOURCE", "-D_DEFAULT_SOURCE", "-DHAVE_CONFIG_H"},
35+
generated_files = {
36+
["mcpp_generated/config.h"] = [[
37+
/* compat.xdmcp: the one configure answer the sources depend on. */
38+
#ifndef MCPP_XDMCP_CONFIG_H
39+
#define MCPP_XDMCP_CONFIG_H
40+
#if defined(__has_include)
41+
# if __has_include(<features.h>)
42+
# include <features.h>
43+
# endif
44+
#endif
45+
#if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 36))
46+
# define HAVE_ARC4RANDOM_BUF 1
47+
#else
48+
/* getentropy: glibc 2.25+, musl 1.1.20+. */
49+
# define HAVE_GETENTROPY 1
50+
# define HAVE_SYS_RANDOM_H 1
51+
#endif
52+
#endif
53+
]],
54+
},
55+
include_dirs = {"mcpp_generated", "*/include", "*"},
2856
sources = {
2957
"*/Array.c",
3058
"*/Fill.c",

0 commit comments

Comments
 (0)