Skip to content

Commit

Permalink
Experiment with version ranges, -Zminimal-versions
Browse files Browse the repository at this point in the history
This commit uses version ranges to accurately specify the minimum
version of the dependencies required for this library to work. These
version bounds are verified in the CI with `-Zminimal-versions`
functionality of cargo which forces cargo to select the earliest
versions of libraries possible.
  • Loading branch information
nagisa committed Oct 25, 2020
1 parent 4ad1af8 commit 7a8fa69
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 28 deletions.
91 changes: 81 additions & 10 deletions .github/workflows/libloading.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Test libloading
name: libloading

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

Expand All @@ -19,6 +21,8 @@ jobs:
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Set cfg(ci)
run: echo "RUSTFLAGS=--cfg ci" >> $GITHUB_ENV
- name: Install Rust ${{ matrix.rust_toolchain }}
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -58,6 +62,18 @@ jobs:
env:
RUSTDOCFLAGS: --cfg docsrs
if: ${{ matrix.rust_toolchain == 'nightly' }}
- name: Update Minimal Versions
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options
if: ${{ matrix.rust_toolchain == 'nightly' }}
- name: Test Minimal Versions
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options -- --nocapture
if: ${{ matrix.rust_toolchain == 'nightly' }}

windows-gnu-test:
runs-on: windows-latest
Expand All @@ -70,6 +86,8 @@ jobs:
- i686-pc-windows-gnu
steps:
- uses: actions/checkout@v2
- name: Set cfg(ci)
run: echo "RUSTFLAGS=--cfg ci" >> $GITHUB_ENV
- name: Add MSYS2 to the PATH
run: echo "c:/msys64/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Add 32-bit mingw-w64 to the PATH
Expand All @@ -78,7 +96,7 @@ jobs:
- name: Add 64-bit mingw-w64 to the PATH
run: echo "c:/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
if: startsWith(matrix.rust_target, 'x86_64')
- name: Set TARGET variable
- name: Set $TARGET
run: echo "TARGET=${{ matrix.rust_target}}" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
Expand All @@ -87,32 +105,59 @@ jobs:
target: ${{ matrix.rust_target }}
profile: minimal
default: true
- uses: actions-rs/cargo@v1
- name: Update
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml
command: update
args: --manifest-path=Cargo.toml
- uses: actions-rs/cargo@v1
with:
command: test
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml
- name: Update Minimal Versions
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options
if: ${{ matrix.rust_toolchain == 'nightly' }}
- name: Test Minimal Versions
uses: actions-rs/cargo@v1
with:
command: test
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options -- --nocapture
if: ${{ matrix.rust_toolchain == 'nightly' }}

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
- aarch64-unknown-linux-gnu
- arm-unknown-linux-gnueabihf
- mips64-unknown-linux-gnuabi64
- mips-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
- powerpc-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu
- sparc64-unknown-linux-gnu
- sparcv9-sun-solaris
- x86_64-fuchsia
- x86_64-unknown-dragonfly
- x86_64-unknown-freebsd
- x86_64-unknown-haiku
# - x86_64-unknown-netbsd
- x86_64-unknown-netbsd
- x86_64-unknown-openbsd
- x86_64-unknown-redox
- x86_64-fuchsia
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Set cfg(ci)
run: echo "RUSTFLAGS=--cfg ci" >> $GITHUB_ENV
- name: Set $TARGET
run: echo "TARGET=${{ matrix.rust_target}}" >> $GITHUB_ENV
- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
Expand All @@ -132,6 +177,16 @@ jobs:
with:
command: build
args: --target ${{ matrix.rust_target }} --manifest-path=Cargo.toml -Zbuild-std
- name: Update Minimal Versions
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options
- name: Build Minimal Versions
uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options

cross-ios-build:
runs-on: macos-latest
Expand All @@ -145,6 +200,10 @@ jobs:
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Set cfg(ci)
run: echo "RUSTFLAGS=--cfg ci" >> $GITHUB_ENV
- name: Set $TARGET
run: echo "TARGET=${{ matrix.rust_target}}" >> $GITHUB_ENV
- name: Install Rust ${{ matrix.rust_toolchain }}
uses: actions-rs/toolchain@v1
with:
Expand All @@ -162,3 +221,15 @@ jobs:
with:
command: build
args: --target=${{ matrix.rust_target }} --manifest-path=Cargo.toml
- name: Update Minimal Versions
uses: actions-rs/cargo@v1
with:
command: update
args: --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options
if: ${{ matrix.rust_toolchain == 'nightly' }}
- name: Build Minimal Versions
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.rust_target }} --manifest-path=Cargo.toml -Zminimal-versions -Zunstable-options
if: ${{ matrix.rust_toolchain == 'nightly' }}
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ keywords = ["dlopen", "load", "shared", "dylib"]
categories = ["api-bindings"]

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
version = ">=0.3.0, <0.4"
features = [
"winerror",
"errhandlingapi",
"libloaderapi",
]

[target.'cfg(unix)'.dependencies.cfg-if]
version = "1"
version = ">=0.1.10, <2"

[dev-dependencies]
libc = "0.2"
static_assertions = "1.1"
# We make some more rigorous checks in CI
[target.'cfg(ci)'.dependencies]
libc = ">=0.2.7, <0.3"
static_assertions = ">=1.0.0, <2"

[package.metadata.docs.rs]
all-features = true
Expand Down
13 changes: 13 additions & 0 deletions src/os/unix/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ mod posix {
}
}

#[cfg(ci)]
mod verify_consts {
extern crate static_assertions;
extern crate libc;
use self::static_assertions::*;

const_assert_eq!(false, true);
const_assert_eq!(super::RTLD_LOCAL, libc::RTLD_LOCAL);
const_assert_eq!(super::RTLD_GLOBAL, libc::RTLD_GLOBAL);
const_assert_eq!(super::RTLD_NOW, libc::RTLD_NOW);
const_assert_eq!(super::RTLD_LAZY, libc::RTLD_LAZY);
}

// Other constants that exist but are not bound because they are platform-specific (non-posix)
// extensions. Some of these constants are only relevant to `dlsym` or `dlmopen` calls.
//
Expand Down
13 changes: 0 additions & 13 deletions tests/constants.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn make_helpers() {
} else {
eprintln!("WARNING: $TARGET NOT SPECIFIED! BUILDING HELPER MODULE FOR NATIVE TARGET.");
}
eprintln!("Building helper: {:?}", cmd);
assert!(cmd
.status()
.expect("could not compile the test helpers!")
Expand Down

0 comments on commit 7a8fa69

Please sign in to comment.