Skip to content

Commit e6bf857

Browse files
authored
[Rust] add support for optionally compiling libc functions (#763)
* add SNMALLOC_RUST_LIBC_API option
1 parent 59987ca commit e6bf857

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ option(SNMALLOC_ENABLE_FUZZING "Enable fuzzing instrumentation tests" OFF)
3232
option(SNMALLOC_USE_SELF_VENDORED_STL "Avoid using system STL" OFF)
3333
# Options that apply only if we're not building the header-only library
3434
cmake_dependent_option(SNMALLOC_RUST_SUPPORT "Build static library for rust" OFF "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF)
35+
cmake_dependent_option(SNMALLOC_RUST_LIBC_API "Include libc API in the rust library" OFF "SNMALLOC_RUST_SUPPORT" OFF)
3536
cmake_dependent_option(SNMALLOC_STATIC_LIBRARY "Build static libraries" ON "NOT SNMALLOC_HEADER_ONLY_LIBRARY" OFF)
3637
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)
3738
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()
585586
add_shim(snmallocshim-rust STATIC src/snmalloc/override/rust.cc)
586587
add_shim(snmallocshim-checks-rust STATIC src/snmalloc/override/rust.cc)
587588
target_compile_definitions(snmallocshim-checks-rust PRIVATE SNMALLOC_CHECK_CLIENT)
589+
if (SNMALLOC_RUST_LIBC_API)
590+
target_compile_definitions(snmallocshim-rust PRIVATE SNMALLOC_RUST_LIBC_API)
591+
target_compile_definitions(snmallocshim-checks-rust PRIVATE SNMALLOC_RUST_LIBC_API)
592+
endif()
588593
endif()
589594

590595
if (SNMALLOC_BUILD_TESTING)

src/snmalloc/override/rust.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#define SNMALLOC_NAME_MANGLE(a) sn_##a
2-
#include "snmalloc/snmalloc.h"
2+
3+
// The libc API provided by malloc.cc will always be mangled per above.
4+
#ifdef SNMALLOC_RUST_LIBC_API
5+
# include "malloc.cc"
6+
#else
7+
# include "snmalloc/snmalloc.h"
8+
#endif
39

410
#include <string.h>
511

0 commit comments

Comments
 (0)