No #[no_mangle]

It's indeed very rare for Rust programs and libraries that have only Rust API. However, I'm using Rust to write a library for use in C and other languages. In a library with C-compatible interface every public function has to have #[no_mangle].

I've scanned 8000 files I have in ~/.cargo/registry as well as Rust's own repo (excluding test cases):

  • Inherited #[mangle] exception_cleanup src/libpanic_unwind/lib.rs

  • Inherited #[mangle] locking_function openssl-sys-0.7.1/src/lib.rs

  • Inherited #[mangle] thread_id openssl-sys-0.7.1/src/lib.rs

  • Inherited #[mangle] shutdown log-0.3.4/src/lib.rs

  • Inherited #[mangle] raw_verify openssl/src/ssl/mod.rs

  • Inherited #[mangle] subtransport_free git2/src/transport.rs

  • Inherited #[no_mangle] rust_eh_personality src/libpanic_unwind/lib.rs

  • Inherited #[no_mangle] block_context_copy block/src/lib.rs

  • Inherited #[no_mangle] locking_function openssl-sys/src/lib.rs

  • Inherited #[no_mangle] ppapi_instance_created ppapi/src/lib/lib.rs

  • Inherited #[no_mangle] ppapi_instance_destroyed ppapi/src/lib/lib.rs

  • Public #[no_mangle] __rust_allocate src/liballoc_jemalloc/lib.rs

  • Public #[no_mangle] __rust_allocate src/liballoc_system/lib.rs

  • Public #[no_mangle] __rust_deallocate src/liballoc_jemalloc/lib.rs

  • Public #[no_mangle] __rust_deallocate src/liballoc_system/lib.rs

  • Public #[no_mangle] __rust_maybe_catch_panic src/libpanic_abort/lib.rs

  • Public #[no_mangle] __rust_maybe_catch_panic src/libpanic_unwind/lib.rs

  • Public #[no_mangle] __rust_reallocate src/liballoc_jemalloc/lib.rs

  • Public #[no_mangle] __rust_reallocate src/liballoc_system/lib.rs

  • Public #[no_mangle] __rust_reallocate_inplace src/liballoc_jemalloc/lib.rs

  • Public #[no_mangle] __rust_reallocate_inplace src/liballoc_system/lib.rs

  • Public #[no_mangle] __rust_start_panic src/libpanic_abort/lib.rs

  • Public #[no_mangle] __rust_start_panic src/libpanic_unwind/lib.rs

  • Public #[no_mangle] __rust_usable_size src/liballoc_jemalloc/lib.rs

  • Public #[no_mangle] __rust_usable_size src/liballoc_system/lib.rs

  • Public #[no_mangle] rust_eh_personality src/libpanic_abort/lib.rs

  • Public #[no_mangle] rust_eh_personality_catch src/libpanic_unwind/lib.rs

These would be affected:

  • Public #[mangle] callback glutin/src/api/win32/callback.rs -- used as pub(crate)

  • Public #[mangle] curl_progress_fn curl/src/ffi/easy.rs -- used as a callback

  • Public #[mangle] did_change_focus ppapi/src/lib/lib.rs -- used as pub(crate)

  • Public #[mangle] did_change_view ppapi/src/lib/lib.rs

  • Public #[mangle] did_create ppapi/src/lib/lib.rs

  • Public #[mangle] did_destroy ppapi/src/lib/lib.rs

  • Public #[mangle] graphics_context_lost ppapi/src/lib/lib.rs

  • Public #[mangle] handle_document_load ppapi/src/lib/lib.rs

  • Public #[mangle] handle_input_event ppapi/src/lib/lib.rs

  • Public #[mangle] handle_message ppapi/src/lib/lib.rs

  • Public #[mangle] mz_crc32 flate2/src/ffi.rs -- used as pub(crate)? Probably doesn't have to be extern "C"

  • Public #[mangle] mz_deflateInit2 flate2/src/ffi.rs

  • Public #[mangle] mz_inflateInit2 flate2/src/ffi.rs

  • Public #[mangle] open libc/rust/src/liblibc/lib.rs -- odd, looks like an error?

  • Public #[mangle] FD_SET libc-0.x/src/lib.rs - pub extern fn functions without #[no_mangle] · Issue #376 · rust-lang/libc · GitHub

  • Public #[mangle] FD_ZERO libc-0.x/src/lib.rs

  • Public #[mangle] WCOREDUMP libc-0.x/src/lib.rs

  • Public #[mangle] WEXITSTATUS libc-0.x/src/lib.rs

  • Public #[mangle] WIFCONTINUED libc-0.x/src/lib.rs

  • Public #[mangle] WIFEXITED libc-0.x/src/lib.rs

  • Public #[mangle] WTERMSIG libc-0.x/src/lib.rs

  • Public #[mangle] _WSTATUS libc-0.x/src/lib.rs