Skip to content

Commit c29a783

Browse files
committed
Remove superfluous use of build.rs
This should make building of this crate significantly faster. At the same time we also correctly annotate the linkage on the `extern` block, the way it ought to be. Sadly there's a regression in tests – the helper scripts no longer specify the target for which tests are being built. This shall be addressed in a subsequent commit.
1 parent 1de6189 commit c29a783

File tree

4 files changed

+26
-80
lines changed

4 files changed

+26
-80
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ readme = "README.mkd"
1212
description = "A safer binding to platform’s dynamic library loading utilities"
1313
keywords = ["dlopen", "load", "shared", "dylib"]
1414
categories = ["api-bindings"]
15-
build = "build.rs"
1615

1716
[target.'cfg(windows)'.dependencies.winapi]
1817
version = "0.3"

build.rs

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/os/unix/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,25 @@ impl Library {
220220
/// care about, consider using the [`Library::get_singlethreaded`] call.
221221
#[inline(always)]
222222
pub unsafe fn get<T>(&self, symbol: &[u8]) -> Result<Symbol<T>, crate::Error> {
223-
#[cfg(mtsafe_dlerror)]
224-
{ self.get_singlethreaded(symbol) }
225-
#[cfg(not(mtsafe_dlerror))]
226-
{ self.get_impl(symbol, || Err(crate::Error::DlSymUnknown)) }
223+
extern crate cfg_if;
224+
cfg_if::cfg_if! {
225+
// These targets are known to have MT-safe `dlerror`.
226+
if #[cfg(any(
227+
target_os = "linux",
228+
target_os = "android",
229+
target_os = "openbsd",
230+
target_os = "macos",
231+
target_os = "ios",
232+
target_os = "solaris",
233+
target_os = "illumos",
234+
target_os = "redox",
235+
target_os = "fuchsia"
236+
))] {
237+
self.get_singlethreaded(symbol)
238+
} else {
239+
self.get_impl(symbol, || Err(crate::Error::DlSymUnknown))
240+
}
241+
}
227242
}
228243

229244
/// Get a pointer to function or static variable by symbol name.
@@ -387,6 +402,8 @@ impl<T> fmt::Debug for Symbol<T> {
387402
}
388403

389404
// Platform specific things
405+
#[cfg_attr(any(target_os = "linux", target_os = "android"), link(name="dl"))]
406+
#[cfg_attr(any(target_os = "freebsd", target_os = "dragonfly"), link(name="c"))]
390407
extern {
391408
fn dlopen(filename: *const raw::c_char, flags: raw::c_int) -> *mut raw::c_void;
392409
fn dlclose(handle: *mut raw::c_void) -> raw::c_int;

tests/functions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ extern crate winapi;
44
extern crate libloading;
55
use libloading::{Symbol, Library};
66

7-
const LIBPATH: &'static str = concat!(env!("OUT_DIR"), "/libtest_helpers.module");
7+
const LIBPATH: &'static str = "target/libtest_helpers.module";
88

99
fn make_helpers() {
1010
static ONCE: ::std::sync::Once = ::std::sync::Once::new();
1111
ONCE.call_once(|| {
12-
let rustc = option_env!("RUSTC").unwrap_or_else(|| { "rustc".into() });
12+
let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| { "rustc".into() });
1313
let mut cmd = ::std::process::Command::new(rustc);
1414
cmd
1515
.arg("src/test_helpers.rs")
1616
.arg("-o")
1717
.arg(LIBPATH)
18-
.arg("--target")
19-
.arg(env!("LIBLOADING_TEST_TARGET"))
18+
// .arg("--target")
19+
// .arg(env!("LIBLOADING_TEST_TARGET"))
2020
.arg("-O");
2121

2222
cmd
@@ -67,7 +67,7 @@ fn test_0_no_0() {
6767

6868
#[test]
6969
fn wrong_name_fails() {
70-
Library::new(concat!(env!("OUT_DIR"), "/libtest_help")).err().unwrap();
70+
Library::new("target/this_location_is_definitely_non existent:^~").err().unwrap();
7171
}
7272

7373
#[test]

0 commit comments

Comments
 (0)