From 359528c77b1e91f3fd9e6e1ce00bb96edd51f93c Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 25 Oct 2020 03:03:31 +0300 Subject: [PATCH] Experiment with version ranges, -Zminimal-versions 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. --- .github/workflows/libloading.yml | 91 ++++++++++++++++++++++++++++---- Cargo.toml | 11 ++-- src/changelog.rs | 1 + src/os/unix/consts.rs | 12 +++++ tests/constants.rs | 13 ----- tests/functions.rs | 1 + 6 files changed, 101 insertions(+), 28 deletions(-) delete mode 100644 tests/constants.rs diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index aa9b3f6b5..75728a9b6 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -1,10 +1,12 @@ -name: Test libloading +name: libloading on: push: paths-ignore: - '*.mkd' - 'LICENSE' + branches: + - master pull_request: types: [opened, repoened, synchronize] @@ -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: @@ -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 @@ -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 @@ -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 @@ -87,14 +105,27 @@ 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 @@ -102,17 +133,31 @@ jobs: 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: @@ -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 @@ -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: @@ -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' }} diff --git a/Cargo.toml b/Cargo.toml index 23324db94..90b6704c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ 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", @@ -22,11 +22,12 @@ features = [ ] [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 diff --git a/src/changelog.rs b/src/changelog.rs index 7d058b831..2e7db89fd 100644 --- a/src/changelog.rs +++ b/src/changelog.rs @@ -2,6 +2,7 @@ // TODO: for the next breaking release rename `Error::LoadLibraryW` to `Error::LoadLibraryExW`. // TODO: for the next breaking release use `RTLD_LAZY | RTLD_LOCAL` by default on unix. +// TODO: for the next breaking release build the changelog module for cfg(docsrs) only /// Release 0.6.5 (2020-10-23) /// diff --git a/src/os/unix/consts.rs b/src/os/unix/consts.rs index 2c18f950f..04e38908a 100644 --- a/src/os/unix/consts.rs +++ b/src/os/unix/consts.rs @@ -203,6 +203,18 @@ mod posix { } } +#[cfg(ci)] +mod verify_consts { + extern crate static_assertions; + extern crate libc; + use self::static_assertions::*; + + 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. // diff --git a/tests/constants.rs b/tests/constants.rs deleted file mode 100644 index ad910c405..000000000 --- a/tests/constants.rs +++ /dev/null @@ -1,13 +0,0 @@ -extern crate libloading; -extern crate libc; -extern crate static_assertions; - -#[cfg(all(test, unix))] -mod unix { - use super::static_assertions::const_assert_eq; - - const_assert_eq!(libloading::os::unix::RTLD_LOCAL, libc::RTLD_LOCAL); - const_assert_eq!(libloading::os::unix::RTLD_GLOBAL, libc::RTLD_GLOBAL); - const_assert_eq!(libloading::os::unix::RTLD_NOW, libc::RTLD_NOW); - const_assert_eq!(libloading::os::unix::RTLD_LAZY, libc::RTLD_LAZY); -} diff --git a/tests/functions.rs b/tests/functions.rs index 20ac3c1d9..09c0bf6aa 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -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!")