You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
rule("mimalloc_dynamic")
|
|
on_load(function (target)
|
|
target:add("defines", "MI_SHARED_LIB")
|
|
|
|
local mimalloc_dir = path.join(os.projectdir(), "extern/mimalloc")
|
|
target:add("includedirs", path.join(mimalloc_dir, "include"))
|
|
target:add("linkdirs", path.join(mimalloc_dir, "lib")) -- 注意这里查询的是 lib 目录
|
|
|
|
-- 只链接 DLL 导入库
|
|
if os.exists(path.join(mimalloc_dir, "lib/mimalloc.dll.lib")) then
|
|
target:add("links", "mimalloc.dll")
|
|
else
|
|
-- 警告:如果找不到 DLL 导入库,不要 fallback 到静态库!
|
|
raise("mimalloc.dll.lib not found! Please build mimalloc DLL first.")
|
|
end
|
|
|
|
if is_plat("windows") then
|
|
target:add("ldflags", "/INCLUDE:mi_version", {force = true})
|
|
end
|
|
end)
|
|
|
|
after_build(function (target)
|
|
local bin_dir = path.join(os.projectdir(), "extern/mimalloc/bin")
|
|
local dlls = {"mimalloc.dll", "mimalloc-redirect.dll"}
|
|
|
|
for _, dll in ipairs(dlls) do
|
|
local src = path.join(bin_dir, dll)
|
|
if os.exists(src) then
|
|
os.cp(src, target:targetdir())
|
|
end
|
|
end
|
|
end)
|
|
rule_end()
|