@shd101wyy/yo 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +80 -0
  3. package/out/cjs/index.cjs +51 -0
  4. package/out/cjs/yo-cli.cjs +2158 -0
  5. package/out/esm/index.mjs +51 -0
  6. package/out/types/src/codegen/async/runtime.d.ts +2 -0
  7. package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
  8. package/out/types/src/codegen/async/state-machine.d.ts +13 -0
  9. package/out/types/src/codegen/c/collection.d.ts +3 -0
  10. package/out/types/src/codegen/codegen-c.d.ts +12 -0
  11. package/out/types/src/codegen/constants.d.ts +3 -0
  12. package/out/types/src/codegen/expressions/array.d.ts +4 -0
  13. package/out/types/src/codegen/expressions/generation.d.ts +11 -0
  14. package/out/types/src/codegen/expressions/index.d.ts +2 -0
  15. package/out/types/src/codegen/functions/collection.d.ts +5 -0
  16. package/out/types/src/codegen/functions/context.d.ts +57 -0
  17. package/out/types/src/codegen/functions/generation.d.ts +25 -0
  18. package/out/types/src/codegen/functions/index.d.ts +2 -0
  19. package/out/types/src/codegen/index.d.ts +20 -0
  20. package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
  21. package/out/types/src/codegen/types/collection.d.ts +8 -0
  22. package/out/types/src/codegen/types/generation.d.ts +13 -0
  23. package/out/types/src/codegen/types/index.d.ts +2 -0
  24. package/out/types/src/codegen/utils/fixup.d.ts +2 -0
  25. package/out/types/src/codegen/utils/index.d.ts +77 -0
  26. package/out/types/src/codegen/values/index.d.ts +1 -0
  27. package/out/types/src/emitter.d.ts +11 -0
  28. package/out/types/src/env.d.ts +85 -0
  29. package/out/types/src/error.d.ts +45 -0
  30. package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
  31. package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
  32. package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
  33. package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
  34. package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
  35. package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
  36. package/out/types/src/evaluator/builtins/as.d.ts +8 -0
  37. package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
  38. package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
  39. package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
  40. package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
  41. package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
  42. package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
  43. package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
  44. package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
  45. package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
  46. package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
  47. package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
  48. package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
  49. package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
  50. package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
  51. package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
  52. package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
  53. package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
  54. package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
  55. package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
  56. package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
  57. package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
  58. package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
  59. package/out/types/src/evaluator/builtins/the.d.ts +8 -0
  60. package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
  61. package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
  62. package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
  63. package/out/types/src/evaluator/calls/array.d.ts +13 -0
  64. package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
  65. package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
  66. package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
  67. package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
  68. package/out/types/src/evaluator/calls/function.d.ts +16 -0
  69. package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
  70. package/out/types/src/evaluator/calls/helper.d.ts +42 -0
  71. package/out/types/src/evaluator/calls/iso.d.ts +15 -0
  72. package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
  73. package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
  74. package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
  75. package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
  76. package/out/types/src/evaluator/calls/type.d.ts +12 -0
  77. package/out/types/src/evaluator/context.d.ts +169 -0
  78. package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
  79. package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
  80. package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
  81. package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
  82. package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
  83. package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
  84. package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
  85. package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
  86. package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
  87. package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
  88. package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
  89. package/out/types/src/evaluator/exprs/import.d.ts +9 -0
  90. package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
  91. package/out/types/src/evaluator/exprs/match.d.ts +8 -0
  92. package/out/types/src/evaluator/exprs/open.d.ts +8 -0
  93. package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
  94. package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
  95. package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
  96. package/out/types/src/evaluator/exprs/test.d.ts +8 -0
  97. package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
  98. package/out/types/src/evaluator/exprs/while.d.ts +8 -0
  99. package/out/types/src/evaluator/index.d.ts +26 -0
  100. package/out/types/src/evaluator/types/array.d.ts +8 -0
  101. package/out/types/src/evaluator/types/closure.d.ts +8 -0
  102. package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
  103. package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
  104. package/out/types/src/evaluator/types/dyn.d.ts +8 -0
  105. package/out/types/src/evaluator/types/enum.d.ts +8 -0
  106. package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
  107. package/out/types/src/evaluator/types/field.d.ts +14 -0
  108. package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
  109. package/out/types/src/evaluator/types/function.d.ts +58 -0
  110. package/out/types/src/evaluator/types/future_module.d.ts +8 -0
  111. package/out/types/src/evaluator/types/module.d.ts +19 -0
  112. package/out/types/src/evaluator/types/newtype.d.ts +8 -0
  113. package/out/types/src/evaluator/types/object.d.ts +8 -0
  114. package/out/types/src/evaluator/types/proofs.d.ts +0 -0
  115. package/out/types/src/evaluator/types/slice.d.ts +8 -0
  116. package/out/types/src/evaluator/types/struct.d.ts +8 -0
  117. package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
  118. package/out/types/src/evaluator/types/tuple.d.ts +18 -0
  119. package/out/types/src/evaluator/types/union.d.ts +8 -0
  120. package/out/types/src/evaluator/types/utils.d.ts +71 -0
  121. package/out/types/src/evaluator/types/validation.d.ts +3 -0
  122. package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
  123. package/out/types/src/evaluator/utils/closure.d.ts +35 -0
  124. package/out/types/src/evaluator/utils.d.ts +4 -0
  125. package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
  126. package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
  127. package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
  128. package/out/types/src/evaluator/values/array.d.ts +8 -0
  129. package/out/types/src/evaluator/values/boolean.d.ts +3 -0
  130. package/out/types/src/evaluator/values/char.d.ts +3 -0
  131. package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
  132. package/out/types/src/evaluator/values/dyn.d.ts +8 -0
  133. package/out/types/src/evaluator/values/float.d.ts +4 -0
  134. package/out/types/src/evaluator/values/integer.d.ts +4 -0
  135. package/out/types/src/evaluator/values/module.d.ts +58 -0
  136. package/out/types/src/evaluator/values/string.d.ts +3 -0
  137. package/out/types/src/evaluator/values/tuple.d.ts +32 -0
  138. package/out/types/src/expr.d.ts +456 -0
  139. package/out/types/src/function-value.d.ts +42 -0
  140. package/out/types/src/index.d.ts +4 -0
  141. package/out/types/src/lexer.d.ts +2 -0
  142. package/out/types/src/logger.d.ts +1 -0
  143. package/out/types/src/module-manager.d.ts +30 -0
  144. package/out/types/src/naming-checker.d.ts +4 -0
  145. package/out/types/src/parser.d.ts +33 -0
  146. package/out/types/src/test-runner.d.ts +30 -0
  147. package/out/types/src/tests/codegen.test.d.ts +1 -0
  148. package/out/types/src/tests/fixme.test.d.ts +1 -0
  149. package/out/types/src/tests/module-manager.test.d.ts +1 -0
  150. package/out/types/src/tests/parser.test.d.ts +1 -0
  151. package/out/types/src/tests/sample.test.d.ts +0 -0
  152. package/out/types/src/tests/std.test.d.ts +1 -0
  153. package/out/types/src/token.d.ts +40 -0
  154. package/out/types/src/type-value.d.ts +7 -0
  155. package/out/types/src/types/compatibility.d.ts +16 -0
  156. package/out/types/src/types/creators.d.ts +73 -0
  157. package/out/types/src/types/definitions.d.ts +218 -0
  158. package/out/types/src/types/guards.d.ts +70 -0
  159. package/out/types/src/types/hierarchy.d.ts +4 -0
  160. package/out/types/src/types/index.d.ts +7 -0
  161. package/out/types/src/types/module_field.d.ts +2 -0
  162. package/out/types/src/types/tags.d.ts +45 -0
  163. package/out/types/src/types/utils.d.ts +50 -0
  164. package/out/types/src/unit-value.d.ts +7 -0
  165. package/out/types/src/utils.d.ts +6 -0
  166. package/out/types/src/value-tag.d.ts +29 -0
  167. package/out/types/src/value.d.ts +110 -0
  168. package/out/types/src/yo-cli.d.ts +1 -0
  169. package/out/types/tsconfig.tsbuildinfo +1 -0
  170. package/package.json +57 -0
  171. package/scripts/check-liburing.js +76 -0
  172. package/std/alg/hash.yo +50 -0
  173. package/std/allocator.yo +113 -0
  174. package/std/allocators/c_allocator.yo +118 -0
  175. package/std/async.yo +13 -0
  176. package/std/collections/array_list.yo +415 -0
  177. package/std/collections/hash_map.yo +482 -0
  178. package/std/collections/hash_set.yo +706 -0
  179. package/std/collections/index.yo +11 -0
  180. package/std/collections/linked_list.yo +439 -0
  181. package/std/error.yo +0 -0
  182. package/std/gc.yo +10 -0
  183. package/std/index.yo +12 -0
  184. package/std/io/file.yo +191 -0
  185. package/std/io/index.yo +5 -0
  186. package/std/libc/assert.yo +39 -0
  187. package/std/libc/ctype.yo +57 -0
  188. package/std/libc/errno.yo +182 -0
  189. package/std/libc/float.yo +87 -0
  190. package/std/libc/index.yo +29 -0
  191. package/std/libc/limits.yo +65 -0
  192. package/std/libc/math.yo +679 -0
  193. package/std/libc/signal.yo +101 -0
  194. package/std/libc/stdatomic.yo +213 -0
  195. package/std/libc/stdint.yo +214 -0
  196. package/std/libc/stdio.yo +225 -0
  197. package/std/libc/stdlib.yo +204 -0
  198. package/std/libc/string.yo +151 -0
  199. package/std/libc/time.yo +92 -0
  200. package/std/libc/unistd.yo +130 -0
  201. package/std/monad.yo +152 -0
  202. package/std/prelude.yo +3094 -0
  203. package/std/string/index.yo +8 -0
  204. package/std/string/rune.yo +82 -0
  205. package/std/string/string.yo +288 -0
  206. package/std/sync.yo +95 -0
  207. package/std/thread.yo +36 -0
  208. package/std/time.yo +13 -0
  209. package/std/worker.yo +36 -0
  210. package/vendor/mimalloc/.gitattributes +12 -0
  211. package/vendor/mimalloc/CMakeLists.txt +763 -0
  212. package/vendor/mimalloc/LICENSE +21 -0
  213. package/vendor/mimalloc/SECURITY.md +41 -0
  214. package/vendor/mimalloc/azure-pipelines.yml +251 -0
  215. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
  216. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
  217. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
  218. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
  219. package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
  220. package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
  221. package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
  222. package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
  223. package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
  224. package/vendor/mimalloc/bin/minject.exe +0 -0
  225. package/vendor/mimalloc/bin/minject32.exe +0 -0
  226. package/vendor/mimalloc/bin/readme.md +118 -0
  227. package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
  228. package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
  229. package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
  230. package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
  231. package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
  232. package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
  233. package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
  234. package/vendor/mimalloc/contrib/docker/readme.md +10 -0
  235. package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
  236. package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
  237. package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
  238. package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
  239. package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
  240. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
  241. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
  242. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
  243. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
  244. package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
  245. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
  246. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
  247. package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
  248. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
  249. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
  250. package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
  251. package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
  252. package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
  253. package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
  254. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
  255. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
  256. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
  257. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
  258. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
  259. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
  260. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
  261. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
  262. package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
  263. package/vendor/mimalloc/doc/doxyfile +2895 -0
  264. package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
  265. package/vendor/mimalloc/doc/ds-logo.png +0 -0
  266. package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
  267. package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
  268. package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
  269. package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
  270. package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
  271. package/vendor/mimalloc/doc/spades-logo.png +0 -0
  272. package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
  273. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
  274. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
  275. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
  276. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
  277. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
  278. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
  279. package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
  280. package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
  281. package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
  282. package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
  283. package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
  284. package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
  285. package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
  286. package/vendor/mimalloc/include/mimalloc/track.h +145 -0
  287. package/vendor/mimalloc/include/mimalloc/types.h +685 -0
  288. package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
  289. package/vendor/mimalloc/include/mimalloc-override.h +68 -0
  290. package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
  291. package/vendor/mimalloc/include/mimalloc.h +612 -0
  292. package/vendor/mimalloc/mimalloc.pc.in +11 -0
  293. package/vendor/mimalloc/readme.md +946 -0
  294. package/vendor/mimalloc/src/alloc-aligned.c +360 -0
  295. package/vendor/mimalloc/src/alloc-override.c +316 -0
  296. package/vendor/mimalloc/src/alloc-posix.c +185 -0
  297. package/vendor/mimalloc/src/alloc.c +692 -0
  298. package/vendor/mimalloc/src/arena-abandon.c +346 -0
  299. package/vendor/mimalloc/src/arena.c +1043 -0
  300. package/vendor/mimalloc/src/bitmap.c +441 -0
  301. package/vendor/mimalloc/src/bitmap.h +119 -0
  302. package/vendor/mimalloc/src/free.c +572 -0
  303. package/vendor/mimalloc/src/heap.c +733 -0
  304. package/vendor/mimalloc/src/init.c +714 -0
  305. package/vendor/mimalloc/src/libc.c +334 -0
  306. package/vendor/mimalloc/src/options.c +663 -0
  307. package/vendor/mimalloc/src/os.c +770 -0
  308. package/vendor/mimalloc/src/page-queue.c +390 -0
  309. package/vendor/mimalloc/src/page.c +1049 -0
  310. package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
  311. package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
  312. package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
  313. package/vendor/mimalloc/src/prim/prim.c +76 -0
  314. package/vendor/mimalloc/src/prim/readme.md +9 -0
  315. package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
  316. package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
  317. package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
  318. package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
  319. package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
  320. package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
  321. package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
  322. package/vendor/mimalloc/src/random.c +258 -0
  323. package/vendor/mimalloc/src/segment-map.c +142 -0
  324. package/vendor/mimalloc/src/segment.c +1702 -0
  325. package/vendor/mimalloc/src/static.c +41 -0
  326. package/vendor/mimalloc/src/stats.c +635 -0
  327. package/vendor/mimalloc/test/CMakeLists.txt +56 -0
  328. package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
  329. package/vendor/mimalloc/test/main-override-dep.h +11 -0
  330. package/vendor/mimalloc/test/main-override-static.c +539 -0
  331. package/vendor/mimalloc/test/main-override.c +36 -0
  332. package/vendor/mimalloc/test/main-override.cpp +497 -0
  333. package/vendor/mimalloc/test/main.c +46 -0
  334. package/vendor/mimalloc/test/readme.md +16 -0
  335. package/vendor/mimalloc/test/test-api-fill.c +343 -0
  336. package/vendor/mimalloc/test/test-api.c +466 -0
  337. package/vendor/mimalloc/test/test-stress.c +428 -0
  338. package/vendor/mimalloc/test/test-wrong.c +92 -0
  339. package/vendor/mimalloc/test/testhelper.h +49 -0
@@ -0,0 +1,763 @@
1
+ cmake_minimum_required(VERSION 3.18)
2
+ project(libmimalloc C CXX)
3
+
4
+ set(CMAKE_C_STANDARD 11)
5
+ set(CMAKE_CXX_STANDARD 17)
6
+
7
+ option(MI_SECURE "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF)
8
+ option(MI_DEBUG_FULL "Use full internal heap invariant checking in DEBUG mode (expensive)" OFF)
9
+ option(MI_PADDING "Enable padding to detect heap block overflow (always on in DEBUG or SECURE mode, or with Valgrind/ASAN)" OFF)
10
+ option(MI_OVERRIDE "Override the standard malloc interface (i.e. define entry points for 'malloc', 'free', etc)" ON)
11
+ option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF)
12
+ option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
13
+ option(MI_TRACK_VALGRIND "Compile with Valgrind support (adds a small overhead)" OFF)
14
+ option(MI_TRACK_ASAN "Compile with address sanitizer support (adds a small overhead)" OFF)
15
+ option(MI_TRACK_ETW "Compile with Windows event tracing (ETW) support (adds a small overhead)" OFF)
16
+ option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
17
+ option(MI_OPT_ARCH "Only for optimized builds: turn on architecture specific optimizations (for arm64: '-march=armv8.1-a' (2016))" OFF)
18
+ option(MI_SEE_ASM "Generate assembly files" OFF)
19
+ option(MI_OSX_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
20
+ option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" ON)
21
+ option(MI_WIN_REDIRECT "Use redirection module ('mimalloc-redirect') on Windows if compiling mimalloc as a DLL" ON)
22
+ option(MI_WIN_USE_FIXED_TLS "Use a fixed TLS slot on Windows to avoid extra tests in the malloc fast path" OFF)
23
+ option(MI_LOCAL_DYNAMIC_TLS "Use local-dynamic-tls, a slightly slower but dlopen-compatible thread local storage mechanism (Unix)" OFF)
24
+ option(MI_LIBC_MUSL "Set this when linking with musl libc" OFF)
25
+ option(MI_BUILD_SHARED "Build shared library" ON)
26
+ option(MI_BUILD_STATIC "Build static library" ON)
27
+ option(MI_BUILD_OBJECT "Build object library" ON)
28
+ option(MI_BUILD_TESTS "Build test executables" ON)
29
+ option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
30
+ option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF)
31
+ option(MI_GUARDED "Build with guard pages behind certain object allocations (implies MI_NO_PADDING=ON)" OFF)
32
+ option(MI_SKIP_COLLECT_ON_EXIT "Skip collecting memory on program exit" OFF)
33
+ option(MI_NO_PADDING "Force no use of padding even in DEBUG mode etc." OFF)
34
+ option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF)
35
+ option(MI_NO_THP "Disable transparent huge pages support on Linux/Android for the mimalloc process only" OFF)
36
+ option(MI_EXTRA_CPPDEFS "Extra pre-processor definitions (use as `-DMI_EXTRA_CPPDEFS=\"opt1=val1;opt2=val2\"`)" "")
37
+
38
+ # negated options for vcpkg features
39
+ option(MI_NO_USE_CXX "Use plain C compilation (has priority over MI_USE_CXX)" OFF)
40
+ option(MI_NO_OPT_ARCH "Do not use architecture specific optimizations (like '-march=armv8.1-a' for example) (has priority over MI_OPT_ARCH)" OFF)
41
+
42
+ # deprecated options
43
+ option(MI_WIN_USE_FLS "Use Fiber local storage on Windows to detect thread termination (deprecated)" OFF)
44
+ option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
45
+ option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems) (deprecated and detected automatically)" OFF)
46
+
47
+ include(CheckLinkerFlag) # requires cmake 3.18
48
+ include(CheckIncludeFiles)
49
+ include(GNUInstallDirs)
50
+ include("cmake/mimalloc-config-version.cmake")
51
+
52
+ set(mi_sources
53
+ src/alloc.c
54
+ src/alloc-aligned.c
55
+ src/alloc-posix.c
56
+ src/arena.c
57
+ src/bitmap.c
58
+ src/heap.c
59
+ src/init.c
60
+ src/libc.c
61
+ src/options.c
62
+ src/os.c
63
+ src/page.c
64
+ src/random.c
65
+ src/segment.c
66
+ src/segment-map.c
67
+ src/stats.c
68
+ src/prim/prim.c)
69
+
70
+ set(mi_cflags "")
71
+ set(mi_cflags_static "") # extra flags for a static library build
72
+ set(mi_cflags_dynamic "") # extra flags for a shared-object library build
73
+ set(mi_libraries "")
74
+
75
+ if(MI_EXTRA_CPPDEFS)
76
+ set(mi_defines ${MI_EXTRA_CPPDEFS})
77
+ else()
78
+ set(mi_defines "")
79
+ endif()
80
+
81
+ # pass git revision as a define
82
+ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/index")
83
+ find_package(Git)
84
+ if(GIT_FOUND)
85
+ execute_process(COMMAND ${GIT_EXECUTABLE} "describe" OUTPUT_VARIABLE mi_git_describe RESULT_VARIABLE mi_git_res ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
86
+ if(mi_git_res EQUAL "0")
87
+ list(APPEND mi_defines "MI_GIT_DESCRIBE=${mi_git_describe}")
88
+ # add to dependencies so we rebuild if the git head commit changes
89
+ set_property(GLOBAL APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/index")
90
+ endif()
91
+ endif()
92
+ endif()
93
+
94
+ # -----------------------------------------------------------------------------
95
+ # Convenience: set default build type and compiler depending on the build directory
96
+ # -----------------------------------------------------------------------------
97
+
98
+ message(STATUS "")
99
+ if (NOT CMAKE_BUILD_TYPE)
100
+ if ("${CMAKE_BINARY_DIR}" MATCHES ".*((D|d)ebug|asan|tsan|ubsan|valgrind)$" OR MI_DEBUG_FULL)
101
+ message(STATUS "No build type selected, default to 'Debug'")
102
+ set(CMAKE_BUILD_TYPE "Debug")
103
+ else()
104
+ message(STATUS "No build type selected, default to 'Release'")
105
+ set(CMAKE_BUILD_TYPE "Release")
106
+ endif()
107
+ endif()
108
+
109
+ if (CMAKE_GENERATOR MATCHES "^Visual Studio.*$")
110
+ message(STATUS "Note: when building with Visual Studio the build type is specified when building.")
111
+ message(STATUS "For example: 'cmake --build . --config=Release")
112
+ endif()
113
+
114
+ if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$")
115
+ message(STATUS "Default to secure build")
116
+ set(MI_SECURE "ON")
117
+ endif()
118
+
119
+
120
+ # Determine architecture
121
+ set(MI_OPT_ARCH_FLAGS "")
122
+ set(MI_ARCH "unknown")
123
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3456]86)$" OR CMAKE_GENERATOR_PLATFORM MATCHES "^(x86|Win32)$")
124
+ set(MI_ARCH "x86")
125
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) # must be before arm64
126
+ set(MI_ARCH "x64")
127
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv[89].?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
128
+ set(MI_ARCH "arm64")
129
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567].?|ARM)$")
130
+ set(MI_ARCH "arm32")
131
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$")
132
+ if(CMAKE_SIZEOF_VOID_P==4)
133
+ set(MI_ARCH "riscv32")
134
+ else()
135
+ set(MI_ARCH "riscv64")
136
+ endif()
137
+ else()
138
+ set(MI_ARCH ${CMAKE_SYSTEM_PROCESSOR})
139
+ endif()
140
+ message(STATUS "Architecture: ${MI_ARCH}") # (${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE_GENERATOR_PLATFORM}, ${CMAKE_GENERATOR})")
141
+
142
+ # negative overrides (mainly to support vcpkg features)
143
+ if(MI_NO_USE_CXX)
144
+ set(MI_USE_CXX "OFF")
145
+ endif()
146
+ if(MI_NO_OPT_ARCH)
147
+ set(MI_OPT_ARCH "OFF")
148
+ elseif(MI_ARCH STREQUAL "arm64")
149
+ set(MI_OPT_ARCH "ON") # enable armv8.1-a by default on arm64 unless MI_NO_OPT_ARCH is set
150
+ endif()
151
+
152
+
153
+ # -----------------------------------------------------------------------------
154
+ # Process options
155
+ # -----------------------------------------------------------------------------
156
+
157
+ if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
158
+ set(MI_CLANG_CL "ON")
159
+ endif()
160
+
161
+ # put -Wall early so other warnings can be disabled selectively
162
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
163
+ if (MI_CLANG_CL)
164
+ list(APPEND mi_cflags -W)
165
+ else()
166
+ list(APPEND mi_cflags -Wall -Wextra -Wpedantic)
167
+ endif()
168
+ endif()
169
+ if(CMAKE_C_COMPILER_ID MATCHES "GNU")
170
+ list(APPEND mi_cflags -Wall -Wextra)
171
+ endif()
172
+ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
173
+ list(APPEND mi_cflags -Wall)
174
+ endif()
175
+
176
+ # force C++ compilation with msvc or clang-cl to use modern C++ atomics
177
+ if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR MI_CLANG_CL)
178
+ set(MI_USE_CXX "ON")
179
+ endif()
180
+
181
+ if(MI_OVERRIDE)
182
+ message(STATUS "Override standard malloc (MI_OVERRIDE=ON)")
183
+ if(APPLE)
184
+ if(MI_OSX_ZONE)
185
+ # use zone's on macOS
186
+ message(STATUS " Use malloc zone to override malloc (MI_OSX_ZONE=ON)")
187
+ list(APPEND mi_sources src/prim/osx/alloc-override-zone.c)
188
+ list(APPEND mi_defines MI_OSX_ZONE=1)
189
+ if (NOT MI_OSX_INTERPOSE)
190
+ message(STATUS " WARNING: zone overriding usually also needs interpose (use -DMI_OSX_INTERPOSE=ON)")
191
+ endif()
192
+ endif()
193
+ if(MI_OSX_INTERPOSE)
194
+ # use interpose on macOS
195
+ message(STATUS " Use interpose to override malloc (MI_OSX_INTERPOSE=ON)")
196
+ list(APPEND mi_defines MI_OSX_INTERPOSE=1)
197
+ if (NOT MI_OSX_ZONE)
198
+ message(STATUS " WARNING: interpose usually also needs zone overriding (use -DMI_OSX_INTERPOSE=ON)")
199
+ endif()
200
+ endif()
201
+ if(MI_USE_CXX AND MI_OSX_INTERPOSE)
202
+ message(STATUS " WARNING: if dynamically overriding malloc/free, it is more reliable to build mimalloc as C code (use -DMI_USE_CXX=OFF)")
203
+ endif()
204
+ endif()
205
+ endif()
206
+
207
+ if(WIN32)
208
+ if (NOT MI_WIN_REDIRECT)
209
+ # use a negative define for backward compatibility
210
+ list(APPEND mi_defines MI_WIN_NOREDIRECT=1)
211
+ endif()
212
+ endif()
213
+
214
+ if(MI_SECURE)
215
+ message(STATUS "Set full secure build (MI_SECURE=ON)")
216
+ list(APPEND mi_defines MI_SECURE=4)
217
+ endif()
218
+
219
+ if(MI_TRACK_VALGRIND)
220
+ CHECK_INCLUDE_FILES("valgrind/valgrind.h;valgrind/memcheck.h" MI_HAS_VALGRINDH)
221
+ if (NOT MI_HAS_VALGRINDH)
222
+ set(MI_TRACK_VALGRIND OFF)
223
+ message(WARNING "Cannot find the 'valgrind/valgrind.h' and 'valgrind/memcheck.h' -- install valgrind first?")
224
+ message(STATUS "Disabling Valgrind support (MI_TRACK_VALGRIND=OFF)")
225
+ else()
226
+ message(STATUS "Compile with Valgrind support (MI_TRACK_VALGRIND=ON)")
227
+ list(APPEND mi_defines MI_TRACK_VALGRIND=1)
228
+ endif()
229
+ endif()
230
+
231
+ if(MI_TRACK_ASAN)
232
+ if (APPLE AND MI_OVERRIDE)
233
+ set(MI_TRACK_ASAN OFF)
234
+ message(WARNING "Cannot enable address sanitizer support on macOS if MI_OVERRIDE is ON (MI_TRACK_ASAN=OFF)")
235
+ endif()
236
+ if (MI_TRACK_VALGRIND)
237
+ set(MI_TRACK_ASAN OFF)
238
+ message(WARNING "Cannot enable address sanitizer support with also Valgrind support enabled (MI_TRACK_ASAN=OFF)")
239
+ endif()
240
+ if(MI_TRACK_ASAN)
241
+ CHECK_INCLUDE_FILES("sanitizer/asan_interface.h" MI_HAS_ASANH)
242
+ if (NOT MI_HAS_ASANH)
243
+ set(MI_TRACK_ASAN OFF)
244
+ message(WARNING "Cannot find the 'sanitizer/asan_interface.h' -- install address sanitizer support first")
245
+ message(STATUS "Compile **without** address sanitizer support (MI_TRACK_ASAN=OFF)")
246
+ else()
247
+ message(STATUS "Compile with address sanitizer support (MI_TRACK_ASAN=ON)")
248
+ list(APPEND mi_defines MI_TRACK_ASAN=1)
249
+ list(APPEND mi_cflags -fsanitize=address)
250
+ list(APPEND mi_libraries -fsanitize=address)
251
+ endif()
252
+ endif()
253
+ endif()
254
+
255
+ if(MI_TRACK_ETW)
256
+ if(NOT WIN32)
257
+ set(MI_TRACK_ETW OFF)
258
+ message(WARNING "Can only enable ETW support on Windows (MI_TRACK_ETW=OFF)")
259
+ endif()
260
+ if (MI_TRACK_VALGRIND OR MI_TRACK_ASAN)
261
+ set(MI_TRACK_ETW OFF)
262
+ message(WARNING "Cannot enable ETW support with also Valgrind or ASAN support enabled (MI_TRACK_ETW=OFF)")
263
+ endif()
264
+ if(MI_TRACK_ETW)
265
+ message(STATUS "Compile with Windows event tracing support (MI_TRACK_ETW=ON)")
266
+ list(APPEND mi_defines MI_TRACK_ETW=1)
267
+ endif()
268
+ endif()
269
+
270
+ if(MI_GUARDED)
271
+ message(STATUS "Compile guard pages behind certain object allocations (MI_GUARDED=ON)")
272
+ list(APPEND mi_defines MI_GUARDED=1)
273
+ if(NOT MI_NO_PADDING)
274
+ message(STATUS " Disabling padding due to guard pages (MI_NO_PADDING=ON)")
275
+ set(MI_NO_PADDING ON)
276
+ endif()
277
+ endif()
278
+
279
+ if(MI_SEE_ASM)
280
+ message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)")
281
+ list(APPEND mi_cflags -save-temps)
282
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
283
+ message(STATUS "No GNU Line marker")
284
+ list(APPEND mi_cflags -Wno-gnu-line-marker)
285
+ endif()
286
+ endif()
287
+
288
+ if(MI_CHECK_FULL)
289
+ message(STATUS "The MI_CHECK_FULL option is deprecated, use MI_DEBUG_FULL instead")
290
+ set(MI_DEBUG_FULL "ON")
291
+ endif()
292
+
293
+ if (MI_SKIP_COLLECT_ON_EXIT)
294
+ message(STATUS "Skip collecting memory on program exit (MI_SKIP_COLLECT_ON_EXIT=ON)")
295
+ list(APPEND mi_defines MI_SKIP_COLLECT_ON_EXIT=1)
296
+ endif()
297
+
298
+ if(MI_DEBUG_FULL)
299
+ message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)")
300
+ list(APPEND mi_defines MI_DEBUG=3) # full invariant checking
301
+ endif()
302
+
303
+ if(MI_NO_PADDING)
304
+ message(STATUS "Suppress any padding of heap blocks (MI_NO_PADDING=ON)")
305
+ list(APPEND mi_defines MI_PADDING=0)
306
+ else()
307
+ if(MI_PADDING)
308
+ message(STATUS "Enable explicit padding of heap blocks (MI_PADDING=ON)")
309
+ list(APPEND mi_defines MI_PADDING=1)
310
+ endif()
311
+ endif()
312
+
313
+ if(MI_XMALLOC)
314
+ message(STATUS "Enable abort() calls on memory allocation failure (MI_XMALLOC=ON)")
315
+ list(APPEND mi_defines MI_XMALLOC=1)
316
+ endif()
317
+
318
+ if(MI_SHOW_ERRORS)
319
+ message(STATUS "Enable printing of error and warning messages by default (MI_SHOW_ERRORS=ON)")
320
+ list(APPEND mi_defines MI_SHOW_ERRORS=1)
321
+ endif()
322
+
323
+ if(MI_DEBUG_TSAN)
324
+ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
325
+ message(STATUS "Build with thread sanitizer (MI_DEBUG_TSAN=ON)")
326
+ list(APPEND mi_defines MI_TSAN=1)
327
+ list(APPEND mi_cflags -fsanitize=thread -g -O1)
328
+ list(APPEND mi_libraries -fsanitize=thread)
329
+ else()
330
+ message(WARNING "Can only use thread sanitizer with clang (MI_DEBUG_TSAN=ON but ignored)")
331
+ endif()
332
+ endif()
333
+
334
+ if(MI_DEBUG_UBSAN)
335
+ if(CMAKE_BUILD_TYPE MATCHES "Debug")
336
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
337
+ message(STATUS "Build with undefined-behavior sanitizer (MI_DEBUG_UBSAN=ON)")
338
+ list(APPEND mi_defines MI_UBSAN=1)
339
+ list(APPEND mi_cflags -fsanitize=undefined -g -fno-sanitize-recover=undefined)
340
+ list(APPEND mi_libraries -fsanitize=undefined)
341
+ if (NOT MI_USE_CXX)
342
+ message(STATUS "(switch to use C++ due to MI_DEBUG_UBSAN)")
343
+ set(MI_USE_CXX "ON")
344
+ endif()
345
+ else()
346
+ message(WARNING "Can only use undefined-behavior sanitizer with clang++ (MI_DEBUG_UBSAN=ON but ignored)")
347
+ endif()
348
+ else()
349
+ message(WARNING "Can only use undefined-behavior sanitizer with a debug build (CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})")
350
+ endif()
351
+ endif()
352
+
353
+ if(MI_USE_CXX)
354
+ message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)")
355
+ set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
356
+ set_source_files_properties(src/static.c test/test-api.c test/test-api-fill test/test-stress PROPERTIES LANGUAGE CXX )
357
+ if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
358
+ list(APPEND mi_cflags -Wno-deprecated)
359
+ endif()
360
+ if(CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
361
+ list(APPEND mi_cflags -Kc++)
362
+ endif()
363
+ endif()
364
+
365
+ if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
366
+ if(MI_NO_THP)
367
+ message(STATUS "Disable transparent huge pages support (MI_NO_THP=ON)")
368
+ list(APPEND mi_defines MI_NO_THP=1)
369
+ endif()
370
+ endif()
371
+
372
+ if(MI_LIBC_MUSL)
373
+ message(STATUS "Assume using musl libc (MI_LIBC_MUSL=ON)")
374
+ list(APPEND mi_defines MI_LIBC_MUSL=1)
375
+ endif()
376
+
377
+ if(MI_WIN_USE_FLS)
378
+ message(STATUS "Use the Fiber API to detect thread termination (deprecated) (MI_WIN_USE_FLS=ON)")
379
+ list(APPEND mi_defines MI_WIN_USE_FLS=1)
380
+ endif()
381
+
382
+ if(MI_WIN_USE_FIXED_TLS)
383
+ message(STATUS "Use fixed TLS slot on Windows to avoid extra tests in the malloc fast path (MI_WIN_USE_FIXED_TLS=ON)")
384
+ list(APPEND mi_defines MI_WIN_USE_FIXED_TLS=1)
385
+ endif()
386
+
387
+ # Check /proc/cpuinfo for an SV39 MMU and limit the virtual address bits.
388
+ # (this will skip the aligned hinting in that case. Issue #939, #949)
389
+ if (EXISTS /proc/cpuinfo)
390
+ file(STRINGS /proc/cpuinfo mi_sv39_mmu REGEX "^mmu[ \t]+:[ \t]+sv39$")
391
+ if (mi_sv39_mmu)
392
+ MESSAGE( STATUS "Set virtual address bits to 39 (SV39 MMU detected)" )
393
+ list(APPEND mi_defines MI_DEFAULT_VIRTUAL_ADDRESS_BITS=39)
394
+ endif()
395
+ endif()
396
+
397
+ # On Haiku use `-DCMAKE_INSTALL_PREFIX` instead, issue #788
398
+ # if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
399
+ # SET(CMAKE_INSTALL_LIBDIR ~/config/non-packaged/lib)
400
+ # SET(CMAKE_INSTALL_INCLUDEDIR ~/config/non-packaged/headers)
401
+ # endif()
402
+
403
+ # Compiler flags
404
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU" AND NOT MI_CLANG_CL)
405
+ list(APPEND mi_cflags -Wno-unknown-pragmas -fvisibility=hidden)
406
+ if(NOT MI_USE_CXX)
407
+ list(APPEND mi_cflags -Wstrict-prototypes)
408
+ endif()
409
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
410
+ list(APPEND mi_cflags -Wno-static-in-inline)
411
+ endif()
412
+ endif()
413
+
414
+ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
415
+ list(APPEND mi_cflags -fvisibility=hidden)
416
+ endif()
417
+
418
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku" AND NOT MI_CLANG_CL)
419
+ if(MI_LOCAL_DYNAMIC_TLS)
420
+ list(APPEND mi_cflags -ftls-model=local-dynamic)
421
+ else()
422
+ if(MI_LIBC_MUSL)
423
+ # with musl we use local-dynamic for the static build, see issue #644
424
+ list(APPEND mi_cflags_static -ftls-model=local-dynamic)
425
+ list(APPEND mi_cflags_dynamic -ftls-model=initial-exec)
426
+ message(STATUS "Use local dynamic TLS for the static build (since MI_LIBC_MUSL=ON)")
427
+ else()
428
+ list(APPEND mi_cflags -ftls-model=initial-exec)
429
+ endif()
430
+ endif()
431
+ if(MI_OVERRIDE)
432
+ list(APPEND mi_cflags -fno-builtin-malloc)
433
+ endif()
434
+ endif()
435
+
436
+ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
437
+ if(MI_OPT_ARCH)
438
+ if(APPLE AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang" AND CMAKE_OSX_ARCHITECTURES) # to support multi-arch binaries (#999)
439
+ if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
440
+ list(APPEND MI_OPT_ARCH_FLAGS "-Xarch_arm64;-march=armv8.1-a")
441
+ endif()
442
+ elseif(MI_ARCH STREQUAL "arm64")
443
+ set(MI_OPT_ARCH_FLAGS "-march=armv8.1-a") # fast atomics
444
+ endif()
445
+ endif()
446
+ endif()
447
+
448
+ if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
449
+ list(APPEND mi_cflags /Zc:__cplusplus)
450
+ if(MI_OPT_ARCH AND NOT MI_CLANG_CL)
451
+ if(MI_ARCH STREQUAL "arm64")
452
+ set(MI_OPT_ARCH_FLAGS "/arch:armv8.1") # fast atomics
453
+ endif()
454
+ endif()
455
+ endif()
456
+
457
+ if(MINGW)
458
+ add_definitions(-D_WIN32_WINNT=0x600) # issue #976
459
+ endif()
460
+
461
+ if(MI_OPT_ARCH_FLAGS)
462
+ list(APPEND mi_cflags ${MI_OPT_ARCH_FLAGS})
463
+ message(STATUS "Architecture specific optimization is enabled (with ${MI_OPT_ARCH_FLAGS}) (MI_OPT_ARCH=ON)")
464
+ endif()
465
+
466
+ # extra needed libraries
467
+
468
+ # we prefer -l<lib> test over `find_library` as sometimes core libraries
469
+ # like `libatomic` are not on the system path (see issue #898)
470
+ function(find_link_library libname outlibname)
471
+ check_linker_flag(C "-l${libname}" mi_has_lib${libname})
472
+ if (mi_has_lib${libname})
473
+ message(VERBOSE "link library: -l${libname}")
474
+ set(${outlibname} ${libname} PARENT_SCOPE)
475
+ else()
476
+ find_library(MI_LIBPATH libname)
477
+ if (MI_LIBPATH)
478
+ message(VERBOSE "link library ${libname} at ${MI_LIBPATH}")
479
+ set(${outlibname} ${MI_LIBPATH} PARENT_SCOPE)
480
+ else()
481
+ message(VERBOSE "link library not found: ${libname}")
482
+ set(${outlibname} "" PARENT_SCOPE)
483
+ endif()
484
+ endif()
485
+ endfunction()
486
+
487
+ if(WIN32)
488
+ list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
489
+ else()
490
+ find_link_library("pthread" MI_LIB_PTHREAD)
491
+ if(MI_LIB_PTHREAD)
492
+ list(APPEND mi_libraries "${MI_LIB_PTHREAD}")
493
+ endif()
494
+ find_link_library("rt" MI_LIB_RT)
495
+ if(MI_LIB_RT)
496
+ list(APPEND mi_libraries "${MI_LIB_RT}")
497
+ endif()
498
+ find_link_library("atomic" MI_LIB_ATOMIC)
499
+ if(MI_LIB_ATOMIC)
500
+ list(APPEND mi_libraries "${MI_LIB_ATOMIC}")
501
+ endif()
502
+ endif()
503
+
504
+
505
+ # -----------------------------------------------------------------------------
506
+ # Install and output names
507
+ # -----------------------------------------------------------------------------
508
+
509
+ # dynamic/shared library and symlinks always go to /usr/local/lib equivalent
510
+ # we use ${CMAKE_INSTALL_BINDIR} and ${CMAKE_INSTALL_LIBDIR}.
511
+
512
+ # static libraries and object files, includes, and cmake config files
513
+ # are either installed at top level, or use versioned directories for side-by-side installation (default)
514
+ if (MI_INSTALL_TOPLEVEL)
515
+ set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}")
516
+ set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}")
517
+ set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc")
518
+ else()
519
+ set(mi_install_objdir "${CMAKE_INSTALL_LIBDIR}/mimalloc-${mi_version}") # for static library and object files
520
+ set(mi_install_incdir "${CMAKE_INSTALL_INCLUDEDIR}/mimalloc-${mi_version}") # for includes
521
+ set(mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/mimalloc-${mi_version}") # for cmake package info
522
+ endif()
523
+
524
+ set(mi_libname "mimalloc")
525
+ if(MI_SECURE)
526
+ set(mi_libname "${mi_libname}-secure")
527
+ endif()
528
+ if(MI_TRACK_VALGRIND)
529
+ set(mi_libname "${mi_libname}-valgrind")
530
+ endif()
531
+ if(MI_TRACK_ASAN)
532
+ set(mi_libname "${mi_libname}-asan")
533
+ endif()
534
+ string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
535
+ list(APPEND mi_defines "MI_CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE_LC}") #todo: multi-config project needs $<CONFIG> ?
536
+ if(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$")
537
+ list(APPEND mi_defines MI_BUILD_RELEASE)
538
+ else()
539
+ set(mi_libname "${mi_libname}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
540
+ endif()
541
+
542
+ if(MI_BUILD_SHARED)
543
+ list(APPEND mi_build_targets "shared")
544
+ endif()
545
+ if(MI_BUILD_STATIC)
546
+ list(APPEND mi_build_targets "static")
547
+ endif()
548
+ if(MI_BUILD_OBJECT)
549
+ list(APPEND mi_build_targets "object")
550
+ endif()
551
+ if(MI_BUILD_TESTS)
552
+ list(APPEND mi_build_targets "tests")
553
+ endif()
554
+
555
+ message(STATUS "")
556
+ message(STATUS "Library name : ${mi_libname}")
557
+ message(STATUS "Version : ${mi_version}.${mi_version_patch}")
558
+ message(STATUS "Build type : ${CMAKE_BUILD_TYPE_LC}")
559
+ if(MI_USE_CXX)
560
+ message(STATUS "C++ Compiler : ${CMAKE_CXX_COMPILER}")
561
+ else()
562
+ message(STATUS "C Compiler : ${CMAKE_C_COMPILER}")
563
+ endif()
564
+ message(STATUS "Compiler flags : ${mi_cflags}")
565
+ message(STATUS "Compiler defines : ${mi_defines}")
566
+ message(STATUS "Link libraries : ${mi_libraries}")
567
+ message(STATUS "Build targets : ${mi_build_targets}")
568
+ message(STATUS "")
569
+
570
+ # -----------------------------------------------------------------------------
571
+ # Main targets
572
+ # -----------------------------------------------------------------------------
573
+
574
+ # shared library
575
+ if(MI_BUILD_SHARED)
576
+ add_library(mimalloc SHARED ${mi_sources})
577
+ set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_libname} )
578
+ target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
579
+ target_compile_options(mimalloc PRIVATE ${mi_cflags} ${mi_cflags_dynamic})
580
+ target_link_libraries(mimalloc PRIVATE ${mi_libraries})
581
+ target_include_directories(mimalloc PUBLIC
582
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
583
+ $<INSTALL_INTERFACE:${mi_install_incdir}>
584
+ )
585
+ install(TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
586
+ install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
587
+
588
+ if(WIN32 AND NOT MINGW)
589
+ # On windows, the import library name for the dll would clash with the static mimalloc.lib library
590
+ # so we postfix the dll import library with `.dll.lib` (and also the .pdb debug file)
591
+ set_property(TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname}.dll" )
592
+ install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR})
593
+ set_property(TARGET mimalloc PROPERTY PDB_NAME "${mi_libname}.dll")
594
+ # don't try to install the pdb since it may not be generated depending on the configuration
595
+ # install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.pdb" DESTINATION ${CMAKE_INSTALL_LIBDIR})
596
+ endif()
597
+ if(WIN32 AND MI_WIN_REDIRECT)
598
+ if(MINGW)
599
+ set_property(TARGET mimalloc PROPERTY PREFIX "")
600
+ endif()
601
+ # On windows, link and copy the mimalloc redirection dll too.
602
+ if(CMAKE_GENERATOR_PLATFORM STREQUAL "arm64ec")
603
+ set(MIMALLOC_REDIRECT_SUFFIX "-arm64ec")
604
+ elseif(MI_ARCH STREQUAL "x64")
605
+ set(MIMALLOC_REDIRECT_SUFFIX "")
606
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
607
+ message(STATUS "Note: x64 code emulated on Windows for arm64 should use an arm64ec build of 'mimalloc.dll'")
608
+ message(STATUS " together with 'mimalloc-redirect-arm64ec.dll'. See the 'bin\\readme.md' for more information.")
609
+ endif()
610
+ elseif(MI_ARCH STREQUAL "x86")
611
+ set(MIMALLOC_REDIRECT_SUFFIX "32")
612
+ else()
613
+ set(MIMALLOC_REDIRECT_SUFFIX "-${MI_ARCH}") # -arm64 etc.
614
+ endif()
615
+
616
+ target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.lib) # the DLL import library
617
+ add_custom_command(TARGET mimalloc POST_BUILD
618
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" $<TARGET_FILE_DIR:mimalloc>
619
+ COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll to output directory")
620
+ install(FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${CMAKE_INSTALL_BINDIR})
621
+ endif()
622
+ endif()
623
+
624
+
625
+ # static library
626
+ if (MI_BUILD_STATIC)
627
+ add_library(mimalloc-static STATIC ${mi_sources})
628
+ set_property(TARGET mimalloc-static PROPERTY OUTPUT_NAME ${mi_libname})
629
+ set_property(TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
630
+ target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
631
+ target_compile_options(mimalloc-static PRIVATE ${mi_cflags} ${mi_cflags_static})
632
+ target_link_libraries(mimalloc-static PRIVATE ${mi_libraries})
633
+ target_include_directories(mimalloc-static PUBLIC
634
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
635
+ $<INSTALL_INTERFACE:${mi_install_incdir}>
636
+ )
637
+ install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY)
638
+ install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
639
+ endif()
640
+
641
+ # install include files
642
+ install(FILES include/mimalloc.h DESTINATION ${mi_install_incdir})
643
+ install(FILES include/mimalloc-override.h DESTINATION ${mi_install_incdir})
644
+ install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_incdir})
645
+ install(FILES include/mimalloc-stats.h DESTINATION ${mi_install_incdir})
646
+ install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_cmakedir})
647
+ install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_cmakedir})
648
+
649
+
650
+ # single object file for more predictable static overriding
651
+ if (MI_BUILD_OBJECT)
652
+ add_library(mimalloc-obj OBJECT src/static.c)
653
+ set_property(TARGET mimalloc-obj PROPERTY POSITION_INDEPENDENT_CODE ON)
654
+ target_compile_definitions(mimalloc-obj PRIVATE ${mi_defines})
655
+ target_compile_options(mimalloc-obj PRIVATE ${mi_cflags} ${mi_cflags_static})
656
+ target_include_directories(mimalloc-obj PUBLIC
657
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
658
+ $<INSTALL_INTERFACE:${mi_install_incdir}>
659
+ )
660
+
661
+ # Copy the generated object file (`static.o`) to the output directory (as `mimalloc.o`)
662
+ if(CMAKE_GENERATOR MATCHES "^Visual Studio.*$")
663
+ set(mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR}/mimalloc-obj.dir/$<CONFIG>/static${CMAKE_C_OUTPUT_EXTENSION}")
664
+ else()
665
+ set(mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}")
666
+ endif()
667
+ set(mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR}/${mi_libname}${CMAKE_C_OUTPUT_EXTENSION}")
668
+ add_custom_command(OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND}" -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}")
669
+ add_custom_target(mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out})
670
+
671
+
672
+ # the following seems to lead to cmake warnings/errors on some systems, disable for now :-(
673
+ # install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_objdir})
674
+
675
+ # the FILES expression can also be: $<TARGET_OBJECTS:mimalloc-obj>
676
+ # but that fails cmake versions less than 3.10 so we leave it as is for now
677
+ install(FILES ${mimalloc-obj-static}
678
+ DESTINATION ${mi_install_objdir}
679
+ RENAME ${mi_libname}${CMAKE_C_OUTPUT_EXTENSION} )
680
+ endif()
681
+
682
+
683
+ # pkg-config file support
684
+ set(mi_pc_libraries "")
685
+ foreach(item IN LISTS mi_libraries)
686
+ if(item MATCHES " *[-].*")
687
+ set(mi_pc_libraries "${mi_pc_libraries} ${item}")
688
+ else()
689
+ set(mi_pc_libraries "${mi_pc_libraries} -l${item}")
690
+ endif()
691
+ endforeach()
692
+
693
+ include("cmake/JoinPaths.cmake")
694
+ join_paths(mi_pc_includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
695
+ join_paths(mi_pc_libdir "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
696
+
697
+ configure_file(mimalloc.pc.in mimalloc.pc @ONLY)
698
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
699
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
700
+
701
+
702
+
703
+ # -----------------------------------------------------------------------------
704
+ # API surface testing
705
+ # -----------------------------------------------------------------------------
706
+
707
+ if (MI_BUILD_TESTS)
708
+ enable_testing()
709
+
710
+ # static link tests
711
+ foreach(TEST_NAME api api-fill stress)
712
+ add_executable(mimalloc-test-${TEST_NAME} test/test-${TEST_NAME}.c)
713
+ target_compile_definitions(mimalloc-test-${TEST_NAME} PRIVATE ${mi_defines})
714
+ target_compile_options(mimalloc-test-${TEST_NAME} PRIVATE ${mi_cflags})
715
+ target_include_directories(mimalloc-test-${TEST_NAME} PRIVATE include)
716
+ if(MI_BUILD_STATIC AND NOT MI_DEBUG_TSAN)
717
+ target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries})
718
+ elseif(MI_BUILD_SHARED)
719
+ target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc ${mi_libraries})
720
+ else()
721
+ message(STATUS "cannot build TSAN tests without MI_BUILD_SHARED being enabled")
722
+ endif()
723
+ add_test(NAME test-${TEST_NAME} COMMAND mimalloc-test-${TEST_NAME})
724
+ endforeach()
725
+
726
+ # dynamic override test
727
+ if(MI_BUILD_SHARED AND NOT (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
728
+ add_executable(mimalloc-test-stress-dynamic test/test-stress.c)
729
+ target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE ${mi_defines} "USE_STD_MALLOC=1")
730
+ target_compile_options(mimalloc-test-stress-dynamic PRIVATE ${mi_cflags})
731
+ target_include_directories(mimalloc-test-stress-dynamic PRIVATE include)
732
+ if(WIN32)
733
+ target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1") # link mi_version
734
+ target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # link mi_version
735
+ add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
736
+ else()
737
+ if(APPLE)
738
+ set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
739
+ else()
740
+ set(LD_PRELOAD "LD_PRELOAD")
741
+ endif()
742
+ add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 ${LD_PRELOAD}=$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test-stress-dynamic>)
743
+ endif()
744
+ endif()
745
+ endif()
746
+
747
+ # -----------------------------------------------------------------------------
748
+ # Set override properties
749
+ # -----------------------------------------------------------------------------
750
+ if (MI_OVERRIDE)
751
+ if (MI_BUILD_SHARED)
752
+ target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
753
+ endif()
754
+ if(NOT WIN32)
755
+ # It is only possible to override malloc on Windows when building as a DLL.
756
+ if (MI_BUILD_STATIC)
757
+ target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
758
+ endif()
759
+ if (MI_BUILD_OBJECT)
760
+ target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
761
+ endif()
762
+ endif()
763
+ endif()