Skip to content

Commit 186f174

Browse files
committed
compat.mbedtls: Windows with musl is a POSIX environment for mbedtls's own units
mbedtls chooses its entropy, timing and socket code by asking whether the environment is Windows or Unix. With musl as the C library on Windows (an openkal graph) the answer the triple gives is Windows and the headers are POSIX, so timing.c included windows.h and failed (mcpp-index#435 through tinyhttps). mbedtls's own units are built without _WIN32 and with __unix__ there; no public header of mbedtls tests either macro. -lbcrypt applies to Windows with the platform C runtime only. Measured with mcpp carrying #662: tinyhttps's openkal example cross-builds for x86_64-windows-gnu and runs its framing tests under Wine.
1 parent b2bab2f commit 186f174

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎pkgs/c/compat.mbedtls.lua‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,24 @@ package = {
5656
c_standard = "c11",
5757
targets = { ["mbedtls"] = { kind = "lib" } },
5858
deps = { },
59-
windows = {
60-
ldflags = { "-lbcrypt" },
59+
-- Windows with the platform's C runtime: the entropy source is
60+
-- BCryptGenRandom. Not on Windows with musl (an openkal graph), where
61+
-- no platform import library is in the graph.
62+
target_cfg = {
63+
["cfg(all(windows, not(c-abi = \"musl\")))"] = {
64+
ldflags = { "-lbcrypt" },
65+
},
66+
-- Windows with musl as the C library. mbedtls selects its entropy,
67+
-- timing and socket code by asking whether the environment is
68+
-- Windows (_WIN32) or Unix (__unix__); the triple answers Windows,
69+
-- and the C library these units compile against is POSIX-shaped
70+
-- (openkal-musl: getrandom, clock_gettime, BSD sockets). Both
71+
-- flags are confined to mbedtls's own translation units, and no
72+
-- public header of mbedtls tests either macro, so its consumers
73+
-- read the same declarations.
74+
["cfg(all(windows, c-abi = \"musl\"))"] = {
75+
cflags = { "-U_WIN32", "-D__unix__" },
76+
},
6177
},
6278
},
6379
}

0 commit comments

Comments
 (0)