lib.rs 795 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #![feature(drop_types_in_const)]
  2. extern crate libloading;
  3. use std::sync::{Once, ONCE_INIT};
  4. use libloading::Library;
  5. static mut GCC_S: Option<Library> = None;
  6. #[cfg(not(windows))]
  7. fn gcc_s() -> &'static Library {
  8. #[cfg(not(target_os = "macos"))]
  9. const LIBGCC_S: &'static str = "libgcc_s.so.1";
  10. #[cfg(target_os = "macos")]
  11. const LIBGCC_S: &'static str = "libgcc_s.1.dylib";
  12. unsafe {
  13. static INIT: Once = ONCE_INIT;
  14. INIT.call_once(|| {
  15. GCC_S = Some(Library::new(LIBGCC_S).unwrap());
  16. });
  17. GCC_S.as_ref().unwrap()
  18. }
  19. }
  20. #[cfg(windows)]
  21. pub fn get(_sym: &str) -> Option<usize> {
  22. None
  23. }
  24. #[cfg(not(windows))]
  25. pub fn get(sym: &str) -> Option<usize> {
  26. unsafe {
  27. gcc_s().get(sym.as_bytes()).ok().map(|s| *s)
  28. }
  29. }