From a85d18b64c24cba140cd13516d1f4a83db6c9630 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Jan 2021 15:03:15 -0600 Subject: [PATCH] Catch more failures on Windows in CI (#84) * Catch more failures on Windows in CI * Link missing library for OpenSSL on MSVC Looks like some functions may pull in user32 functions, so that library needs to be linked. * Try to fix msvc +crt-static builds * Try to see all failures * More output * Fix setting crt-static * More CI tweaks * Add the bin dir to cargo's search path on MSVC That's where it contains the actual dlls needed at runtime --- .github/workflows/main.yml | 101 +++++++++++++------------------------ src/lib.rs | 27 ++++++++-- 2 files changed, 58 insertions(+), 70 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a36b5ee6..4a801f3e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,110 +1,81 @@ name: CI -on: [push, pull_request] +on: + push: + branches: [master] + pull_request: + branches: [master] + +defaults: + run: + shell: bash jobs: test: name: Test runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: - thing: - - stable - - beta - - nightly - - macos-x86_64 - - arm-android - - arm64-android - - i686-android - - x86_64-android - - i686-linux - - arm-linux - - aarch64-linux - - x86_64-musl - - x86_64-mingw - # - asmjs - - i686-msvc - - i686-msvc-static - - x86_64-msvc - - x86_64-msvc-static include: - - thing: stable - target: x86_64-unknown-linux-gnu + - target: x86_64-unknown-linux-gnu rust: stable os: ubuntu-latest - - thing: beta - target: x86_64-unknown-linux-gnu + - target: x86_64-unknown-linux-gnu rust: beta os: ubuntu-latest - - thing: nightly - target: x86_64-unknown-linux-gnu + - target: x86_64-unknown-linux-gnu rust: nightly os: ubuntu-latest - - thing: macos-x86_64 - target: x86_64-apple-darwin + - target: x86_64-apple-darwin rust: stable os: macos-latest - - thing: macos-aarch64 - target: aarch64-apple-darwin + - target: aarch64-apple-darwin rust: nightly os: macos-latest - - thing: arm-android - target: arm-linux-androideabi + - target: arm-linux-androideabi rust: stable os: ubuntu-latest - - thing: arm64-android - target: aarch64-linux-android + - target: aarch64-linux-android rust: stable os: ubuntu-latest - - thing: i686-android - target: i686-linux-android + - target: i686-linux-android rust: stable os: ubuntu-latest - - thing: x86_64-android - target: x86_64-linux-android + - target: x86_64-linux-android rust: stable os: ubuntu-latest - - thing: i686-linux - target: i686-unknown-linux-gnu + - target: i686-unknown-linux-gnu rust: stable os: ubuntu-latest - - thing: arm-linux - target: arm-unknown-linux-gnueabi + - target: arm-unknown-linux-gnueabi rust: stable os: ubuntu-latest - - thing: aarch64-linux - target: aarch64-unknown-linux-gnu + - target: aarch64-unknown-linux-gnu rust: stable os: ubuntu-latest - - thing: x86_64-musl - target: x86_64-unknown-linux-musl + - target: x86_64-unknown-linux-musl rust: stable os: ubuntu-latest - - thing: x86_64-mingw - target: x86_64-pc-windows-gnu + - target: x86_64-pc-windows-gnu rust: stable os: ubuntu-latest - # - thing: asmjs - # target: asmjs-unknown-emscripten + # - target: asmjs-unknown-emscripten # rust: stable # os: ubuntu-latest - - thing: i686-msvc - target: i686-pc-windows-msvc + - target: i686-pc-windows-msvc rust: stable-i686-msvc os: windows-2016 - - thing: i686-msvc-static - target: i686-pc-windows-msvc + - target: i686-pc-windows-msvc rust: stable-i686-msvc os: windows-2016 - crt_static: true - - thing: x86_64-msvc - target: x86_64-pc-windows-msvc + crt_static: yes + - target: x86_64-pc-windows-msvc rust: stable-x86_64-msvc os: windows-latest - - thing: x86_64-msvc-static - target: x86_64-pc-windows-msvc + - target: x86_64-pc-windows-msvc rust: stable-x86_64-msvc os: windows-latest - crt_static: true + crt_static: yes steps: - uses: actions/checkout@v1 @@ -112,16 +83,13 @@ jobs: submodules: true - name: Install Rust (rustup) run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - shell: bash - run: rustup target add ${{ matrix.target }} - name: Set crt-static if: matrix.crt_static == 'yes' run: echo RUSTFLAGS=-Ctarget-feature=+crt-static >> $GITHUB_ENV - shell: bash - name: Use strawberry perl if: startsWith(matrix.os, 'windows') run: echo OPENSSL_SRC_PERL=C:/Strawberry/perl/bin/perl >> $GITHUB_ENV - shell: bash - run: | set -e cargo generate-lockfile @@ -129,12 +97,11 @@ jobs: if: "!startsWith(matrix.os, 'windows')" name: Run tests (not Windows) - run: | - cargo test --manifest-path testcrate/Cargo.toml --target ${{ matrix.target }} - cargo test --manifest-path testcrate/Cargo.toml --target ${{ matrix.target }} --release - cargo run --release --target ${{ matrix.target }} --manifest-path testcrate/Cargo.toml --features package + cargo test --manifest-path testcrate/Cargo.toml --target ${{ matrix.target }} -vv + cargo test --manifest-path testcrate/Cargo.toml --target ${{ matrix.target }} --release -vv + cargo run --release --target ${{ matrix.target }} --manifest-path testcrate/Cargo.toml --features package -vv if: startsWith(matrix.os, 'windows') name: Run tests (Windows) - shell: cmd rustfmt: name: Rustfmt diff --git a/src/lib.rs b/src/lib.rs index 10b0c17b..98c84039 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,10 @@ pub struct Build { pub struct Artifacts { include_dir: PathBuf, lib_dir: PathBuf, + bin_dir: PathBuf, libs: Vec, + target: String, + shared: bool, } impl Build { @@ -143,7 +146,7 @@ impl Build { configure.arg("no-stdio"); } - if target.contains("msvc") { + let shared = if target.contains("msvc") { // On MSVC we need nasm.exe to compile the assembly files, but let's // just pessimistically assume for now that's not available. configure.arg("no-asm"); @@ -151,11 +154,15 @@ impl Build { let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or(String::new()); if features.contains("crt-static") { configure.arg("no-shared"); + false + } else { + true } } else { // Never shared on non-MSVC configure.arg("no-shared"); - } + false + }; let os = match target { "aarch64-apple-darwin" => "darwin64-arm64-cc", @@ -406,8 +413,11 @@ impl Build { Artifacts { lib_dir: install_dir.join("lib"), + bin_dir: install_dir.join("bin"), include_dir: install_dir.join("include"), libs: libs, + target: target.to_string(), + shared, } } @@ -511,9 +521,20 @@ impl Artifacts { pub fn print_cargo_metadata(&self) { println!("cargo:rustc-link-search=native={}", self.lib_dir.display()); for lib in self.libs.iter() { - println!("cargo:rustc-link-lib=static={}", lib); + if self.shared { + println!("cargo:rustc-link-lib={}", lib); + } else { + println!("cargo:rustc-link-lib=static={}", lib); + } } println!("cargo:include={}", self.include_dir.display()); println!("cargo:lib={}", self.lib_dir.display()); + if self.target.contains("msvc") { + if self.shared { + println!("cargo:rustc-link-search=native={}", self.bin_dir.display()); + } else { + println!("cargo:rustc-link-lib=user32"); + } + } } }