From 1c58557c67154ec800d0d1949c59c2fed877e407 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 13 Apr 2021 17:01:01 +0200 Subject: [PATCH] Rust: Force symbol re-export from libglean_ffi. Workaround to force a re-export of the `no_mangle` symbols from `glean_ffi` Due to how linking works and hides symbols the symbols from `glean_ffi` might not be re-exported and thus not usable. By forcing use of _at least one_ symbol in an exported function the functions will also be rexported. This is only required for debug builds (and `debug_assertions` is the closest thing we have to check that). In release builds we rely on LTO builds to take care of it. As the tests will use libglean_ffi functionality running the tests should ensure this actually happens. See https://github.com/rust-lang/rust/issues/50007 --- glean-core/bundle/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/glean-core/bundle/src/lib.rs b/glean-core/bundle/src/lib.rs index 4186312f15..3bfdc43719 100644 --- a/glean-core/bundle/src/lib.rs +++ b/glean-core/bundle/src/lib.rs @@ -3,3 +3,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ pub use glean_ffi; + +/// Workaround to force a re-export of the `no_mangle` symbols from `glean_ffi` +/// +/// Due to how linking works and hides symbols the symbols from `glean_ffi` might not be +/// re-exported and thus not usable. +/// By forcing use of _at least one_ symbol in an exported function the functions will also be +/// rexported. +/// This is only required for debug builds (and `debug_assertions` is the closest thing we have to +/// check that). +/// In release builds we rely on LTO builds to take care of it. +/// Our tests should ensure this actually happens. +/// +/// See https://github.com/rust-lang/rust/issues/50007 +#[cfg(debug_assertions)] +#[no_mangle] +pub unsafe extern "C" fn _glean_force_reexport_donotcall() { + glean_ffi::glean_enable_logging(); +}