Skip to content

Instantly share code, notes, and snippets.

@lovesegfault
Created May 28, 2020 02:14
Show Gist options
  • Save lovesegfault/63915ec3d3f26b235867a8282cd927e1 to your computer and use it in GitHub Desktop.
Save lovesegfault/63915ec3d3f26b235867a8282cd927e1 to your computer and use it in GitHub Desktop.
//! This module only exists to force rustc to actually link these libraries and avoid them getting
//! stripped later on. This way we can avoid the `dlopen` that some of our dependencies seem to
//! love so much.
//! This is also in part needed because `--as-needed` is hardcoded in rustc, c.f. https://github.com/rust-lang/rust/blob/7f3b3df9e2f2efe3434b4f6fc76462d2c8ad332f/src/librustc_target/spec/linux_base.rs#L7-L18
use paste;
macro_rules! link_hack {
($lib:expr, $symbol:ident) => {
#[link(name = $lib)]
extern "C" {
// The function signature doesnt actually matter because we never call it.
fn $symbol();
}
paste::item! {
#[used]
static [<$lib:upper _HACK>]: unsafe extern "C" fn() = $symbol;
}
};
}
link_hack!("X11", XOpenDisplay);
link_hack!("Xcursor", XcursorLibraryPath);
link_hack!("Xi", XSelectExtensionEvent);
link_hack!("Xrandr", XRRFindDisplay);
link_hack!("vulkan", loader_init_dispatch);
link_hack!("wayland-client", wl_display_connect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment