A much simpler solution:
Build mimalloc
into a single object file, either via cmake
or src/static.c
in its repository. Then place it in the root directory of your swift package (next to Package.swift
) and add linkerSettings: [.unsafeFlags(["mimalloc.o"])]
to your executable target.
This works for me, but it would be great for the Swift core team to comment on this method. LLVM linker documentation states that object files are linked before library files, in this case, mimalloc.o
before libc.a
. The microsoft/mimalloc
repository also prescribes this method for static overriding.