diff --git a/CMakeLists.txt b/CMakeLists.txt index 8506e17..91cdbe9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ option(SNMALLOC_ENABLE_FUZZING "Enable fuzzing instrumentation tests" OFF) option(SNMALLOC_USE_SELF_VENDORED_STL "Avoid using system STL" OFF) # Options that apply only if we're not building the header-only library cmake_dependent_option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) +cmake_dependent_option(SNMALLOC_RUST_LIBC_API "Include libc API in the rust library" OFF "SNMALLOC_RUST_SUPPORT" OFF) cmake_dependent_option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) cmake_dependent_option(SNMALLOC_CHECK_LOADS "Perform bounds checks on the source argument to memcpy with heap objects" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) cmake_dependent_option(SNMALLOC_OPTIMISE_FOR_CURRENT_MACHINE "Compile for current machine architecture" Off "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF) @@ -585,6 +586,10 @@ endif() add_shim(snmallocshim-rust STATIC src/snmalloc/override/rust.cc) add_shim(snmallocshim-checks-rust STATIC src/snmalloc/override/rust.cc) target_compile_definitions(snmallocshim-checks-rust PRIVATE SNMALLOC_CHECK_CLIENT) + if (SNMALLOC_RUST_LIBC_API) + target_compile_definitions(snmallocshim-rust PRIVATE SNMALLOC_RUST_LIBC_API) + target_compile_definitions(snmallocshim-checks-rust PRIVATE SNMALLOC_RUST_LIBC_API) + endif() endif() if (SNMALLOC_BUILD_TESTING) diff --git a/src/snmalloc/override/rust.cc b/src/snmalloc/override/rust.cc index 571f1d3..6f9e6c4 100644 --- a/src/snmalloc/override/rust.cc +++ b/src/snmalloc/override/rust.cc @@ -1,5 +1,11 @@ #define SNMALLOC_NAME_MANGLE(a) sn_##a -#include "snmalloc/snmalloc.h" + +// The libc API provided by malloc.cc will always be mangled per above. +#ifdef SNMALLOC_RUST_LIBC_API +# include "malloc.cc" +#else +# include "snmalloc/snmalloc.h" +#endif #include