Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer depend on cc to build the library 4 unix #63

Merged
merged 5 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions .github/workflows/libloading.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Test libloading

on:
push:
paths-ignore:
- '*.mkd'
- 'LICENSE'
pull_request:
types: [opened, repoened, synchronize]

jobs:
native-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable, 1.14.0]
os: [ubuntu-latest, windows-latest, macOS-latest]
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Install Rust ${{ matrix.rust_toolchain }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_toolchain }}
profile: minimal
default: true
- name: Update
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path=Cargo.toml
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=Cargo.toml -- --nocapture
- name: Test Release
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=Cargo.toml --release -- --nocapture

windows-gnu-test:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable]
rust_target:
- x86_64-pc-windows-gnu
# Only 64 bit GCC is preinstalled
#- i686-pc-windows-gnu
steps:
- uses: actions/checkout@v2
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_toolchain }}
target: ${{ matrix.rust_target }}
profile: minimal
default: true
# https://github.com/rust-lang/rust/issues/49078
- name: Fix windows-gnu rust-mingw
run : |
for i in crt2.o dllcrt2.o libmingwex.a libmsvcrt.a ; do
cp -f "/C/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/lib/$i" "`rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib"
done
shell: bash
- uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml
- uses: actions-rs/cargo@v1
with:
command: test
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml

bare-cross-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust_target:
# BSDs: could be tested with full system emulation
# - x86_64-unknown-dragonfly
# - x86_64-unknown-freebsd
- x86_64-unknown-haiku
# - x86_64-unknown-netbsd
- x86_64-unknown-openbsd
- x86_64-unknown-redox
- x86_64-fuchsia
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
default: true
- name: Fix-up toolchain
run: |
rustup component add rust-src --toolchain nightly --target ${{ matrix.rust_target }}
- name: Update
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml
- name: Build ${{ matrix.rust_target }}
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml -Zbuild-std

cross-ios-build:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
rust_toolchain: [nightly, stable]
rust_target:
- aarch64-apple-ios
- x86_64-apple-ios
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Install Rust ${{ matrix.rust_toolchain }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust_toolchain }}
target: ${{ matrix.rust_target }}
profile: minimal
default: true
- name: Update
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml
- name: Build ${{ matrix.rust_target }}
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.rust_target }} --manifest-path=Cargo.toml
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ license = "ISC"
repository = "https://github.com/nagisa/rust_libloading/"
documentation = "https://docs.rs/libloading/"

[build-dependencies.cc]
version = "1.0"

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
features = [
Expand Down
7 changes: 1 addition & 6 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# libloading [![Travis CI][tcii]][tci] [![Appveyor CI][acii]][aci]

[tcii]: https://travis-ci.org/nagisa/rust_libloading.svg?branch=master
[tci]: https://travis-ci.org/nagisa/rust_libloading
[acii]: https://ci.appveyor.com/api/projects/status/cnncnu58qcxb1ikf/branch/master?svg=true
[aci]: https://ci.appveyor.com/project/nagisa/rust-libloading
# libloading

A memory-safer wrapper around system dynamic library loading primitives. The most important safety
guarantee by this library is prevention of dangling-`Symbol`s that may occur after a `Library` is
Expand Down
19 changes: 0 additions & 19 deletions appveyor.yml

This file was deleted.

63 changes: 47 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,63 @@
extern crate cc;

use std::io::Write;
use std::env;

fn main(){
let target_os = env::var("CARGO_CFG_TARGET_OS");
let is_unix = env::var_os("CARGO_CFG_UNIX").is_some();
match target_os.as_ref().map(|x| &**x) {
Ok("linux") | Ok("android") => println!("cargo:rustc-link-lib=dl"),
Ok("freebsd") | Ok("dragonfly") => println!("cargo:rustc-link-lib=c"),
fn dlerror_is_mtsafe(target_os: &str) {
match target_os {
// Confirmed MT-safe:
"linux"
| "android"
| "openbsd"
| "macos"
| "ios"
| "solaris"
| "redox"
| "fuchsia" => {
println!("cargo:rustc-cfg=mtsafe_dlerror");
}
// Confirmed not MT-safe:
"freebsd"
| "dragonfly"
| "netbsd"
| "bitrig"
| "haiku" => {}
// Unknown:
_ => {}
}
}

fn link_libraries(target_os: &str) {
match target_os {
"linux" | "android" => println!("cargo:rustc-link-lib=dl"),
"freebsd" | "dragonfly" => println!("cargo:rustc-link-lib=c"),
// netbsd claims dl* will be available to any dynamically linked binary, but I haven’t
// found any libraries that have to be linked to on other platforms.
// What happens if the executable is not linked up dynamically?
Ok("openbsd") | Ok("bitrig") | Ok("netbsd") | Ok("macos") | Ok("ios") => {}
Ok("solaris") => {}
Ok("haiku") => {}
"openbsd" | "bitrig" | "netbsd" | "macos" | "ios" => {}
"solaris" => {}
"haiku" => {}
"redox" => {}
"fuchsia" => {}
// dependencies come with winapi
Ok("windows") => {}
"windows" => {}
tos => {
writeln!(::std::io::stderr(),
"Building for an unknown target_os=`{:?}`!\nPlease report an issue ",
tos).expect("could not report the error");
::std::process::exit(0xfc);
}
}
if is_unix {
cc::Build::new()
.file("src/os/unix/global_static.c")
.compile("global_static");
}

fn main() {
match env::var("CARGO_CFG_TARGET_OS") {
Ok(target_os) => {
dlerror_is_mtsafe(&target_os);
link_libraries(&target_os);
}
Err(e) => {
writeln!(::std::io::stderr(),
"Unable to get target_os=`{}`!", e).expect("could not report the error");
::std::process::exit(0xfd);
}
}
}
9 changes: 9 additions & 0 deletions src/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
//! Project changelog

/// Release NEXT (2020-04-??)
///
/// * Removed dependency on the C compiler to build this library on unix-like platforms. We used to
/// utilize it to work-around the very unlikely possibility of the target having thread-unsafe
/// `dlerror` function, but the effect of the work-around was very opportunistic. We deemed the
/// cost of the work-around to be higher than the benefit of it.
pub mod rNEXT {}


/// Release 0.5.2 (2019-07-07)
///
/// * Added API to convert OS-specific `Library` and `Symbol` conversion to underlying resources.
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ impl Library {
///
/// ## Platform-specific behaviour
///
/// On Linux and Windows, a TLS variable acts just like any regular static variable. OS X uses
/// On Linux and Windows, a TLS variable acts just like any regular global variable. OS X uses
/// some sort of lazy initialization scheme, which makes loading TLS variables this way
/// impossible. Using a TLS variable loaded this way on OS X is undefined behaviour.
///
/// On POSIX implementations where the `dlerror` function is not confirmed to be MT-safe, this
/// function will return an error if this function was to return `Ok` with a null `Symbol`
/// otherwise. As a work-around consider using the platform-specific
/// [`os::unix::Library::get_singlethreaded`] call.
///
/// ## Examples
///
/// Given a loaded library:
Expand Down
20 changes: 0 additions & 20 deletions src/os/unix/global_static.c

This file was deleted.

Loading