-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcompat.mimalloc.lua
More file actions
151 lines (148 loc) · 6.94 KB
/
Copy pathcompat.mimalloc.lua
File metadata and controls
151 lines (148 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
-- compat.mimalloc — Microsoft's general-purpose allocator, built as a static lib.
--
-- Shape A (C-source compat): the user writes `#include <mimalloc.h>` and calls
-- mi_malloc / mi_free / mi_heap_* directly.
--
-- WHY THE SOURCE LIST IS ENUMERATED AND NOT A GLOB.
-- `src/*.c` would be wrong three times over, and each way is a link error
-- rather than a compile error:
--
-- src/static.c is an amalgamation -- it #includes the whole library
-- into one TU, so globbing it alongside the others
-- duplicates every symbol.
-- src/free.c is #included BY alloc.c (`#include "free.c"`, alloc.c:22),
-- src/alloc-override.c likewise (alloc.c:21). Neither is a standalone TU.
--
-- The list below is upstream's own `mi_sources` (CMakeLists.txt:75-93), which is
-- the only authoritative answer to "which files are TUs".
--
-- `src/prim/prim.c` is a dispatcher: it #includes the platform implementation
-- (prim/unix, prim/windows, prim/osx, …) for the host it is compiled on, so one
-- entry covers all three platforms with no per-platform source lists.
--
-- OVERRIDE IS OFF, which is the right default for a package. mimalloc can
-- replace the global malloc/free, but only when MI_MALLOC_OVERRIDE is defined
-- (alloc-override.c:13) -- and a dependency silently taking over the process
-- allocator is not something an index package should decide for its consumer.
-- The mi_* API is unaffected.
package = {
spec = "1",
namespace = "compat",
name = "mimalloc",
description = "mimalloc — compact general-purpose allocator with excellent performance",
licenses = {"MIT"},
repo = "https://github.com/microsoft/mimalloc",
type = "package",
xpm = {
linux = {
["3.4.5"] = {
url = {
GLOBAL = "https://github.com/microsoft/mimalloc/archive/refs/tags/v3.4.5.tar.gz",
CN = "https://gitcode.com/mcpp-res/mimalloc/releases/download/3.4.5/mimalloc-3.4.5.tar.gz",
},
sha256 = "19a43af0645c57d348e729d5b31e23e912582911bb1047f795790834d3416221",
},
},
macosx = {
["3.4.5"] = {
url = {
GLOBAL = "https://github.com/microsoft/mimalloc/archive/refs/tags/v3.4.5.tar.gz",
CN = "https://gitcode.com/mcpp-res/mimalloc/releases/download/3.4.5/mimalloc-3.4.5.tar.gz",
},
sha256 = "19a43af0645c57d348e729d5b31e23e912582911bb1047f795790834d3416221",
},
},
windows = {
["3.4.5"] = {
url = {
GLOBAL = "https://github.com/microsoft/mimalloc/archive/refs/tags/v3.4.5.tar.gz",
CN = "https://gitcode.com/mcpp-res/mimalloc/releases/download/3.4.5/mimalloc-3.4.5.tar.gz",
},
sha256 = "19a43af0645c57d348e729d5b31e23e912582911bb1047f795790834d3416221",
},
},
},
mcpp = {
language = "c++23",
import_std = false,
c_standard = "c11",
include_dirs = { "*/include" },
sources = {
"*/src/alloc.c",
"*/src/alloc-aligned.c",
"*/src/alloc-posix.c",
"*/src/arena.c",
"*/src/arena-meta.c",
"*/src/bitmap.c",
"*/src/heap.c",
"*/src/init.c",
"*/src/libc.c",
"*/src/options.c",
"*/src/os.c",
"*/src/page.c",
"*/src/page-map.c",
"*/src/random.c",
"*/src/stats.c",
"*/src/theap.c",
"*/src/threadlocal.c",
"*/src/prim/prim.c",
},
targets = { ["mimalloc"] = { kind = "lib" } },
deps = {},
linux = {
-- CMakeLists.txt:618-626 -- pthread for thread state, rt for
-- clock_gettime/shm, atomic for the 64-bit atomics on targets
-- where libatomic is not folded into libgcc.
ldflags = { "-lpthread", "-lrt", "-latomic" },
},
macosx = {
ldflags = { "-lpthread" },
},
windows = {
-- CMakeLists.txt:614 -- psapi/bcrypt for process memory info and
-- the RNG seed, the rest for the Win32 primitives.
--
-- `runtime.libraries` rather than `ldflags`: ldflags reach the
-- linker verbatim, and link.exe drops a GNU `-lpsapi` with
-- "LNK4044: unrecognized option; ignored" -- silently, until the
-- consumer's link ends in unresolved externals. This spelling is
-- rendered per dialect (psapi.lib / -lpsapi).
runtime = {
libraries = { "psapi", "shell32", "user32", "advapi32", "bcrypt" },
},
-- `__builtin_thread_pointer()` IS NOT AVAILABLE FOR EVERY OS THE
-- TRIPLE CAN NAME, AND THE FAILURE IS A BACKEND CRASH.
--
-- prim-tls.h:176 turns the builtin on for x86_64 with clang >= 14
-- unless `__APPLE__`, `__CYGWIN__` or `MI_LIBC_MUSL` says
-- otherwise. Two of those three would have excluded this target
-- and neither reaches it: mcpp suppresses `__CYGWIN__` on purpose,
-- because source must not read the realisation triple as a
-- statement about Cygwin, and `MI_LIBC_MUSL` is a build option
-- upstream expects the packager to set ("Enable this when linking
-- with musl libc", CMakeLists.txt:39) rather than something it
-- detects. So the guard passes, and LLVM has no lowering for the
-- builtin on this OS:
--
-- fatal error: error in backend: Target OS doesn't support
-- __builtin_thread_pointer() yet.
--
-- prim-tls.h:176 opens with `#if !defined(...) /* allow user
-- override */`, so the answer is to give it one. This is the
-- Windows branch, and on a Win32 target the setting is not read at
-- all --- `_WIN32` selects `NtCurrentTeb()` three arms earlier ---
-- so it changes only the target that has no `_WIN32`.
--
-- WHAT THIS FIXES AND WHAT IT DOES NOT. The cell goes from
-- `fails: error: build failed` to `builds`: the backend crash is
-- gone and the member compiles and links for this target. Its
-- `alloc` test then passes under one Wine and exits 1 under the
-- one this repository's CI installs, so the published reading is
-- `builds` rather than `runs`. That remainder is a separate
-- question about the TLS path the override falls back to, and it
-- is recorded here rather than folded into this one so the next
-- reader does not take a green build for a green test.
cflags = { "-DMI_USE_BUILTIN_THREAD_POINTER=0" },
},
},
}