Skip to content

Commit

Permalink
Catch more failures on Windows in CI (#84)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexcrichton authored Jan 5, 2021
1 parent 6eaa2b2 commit a85d18b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 70 deletions.
101 changes: 34 additions & 67 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,140 +1,107 @@
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
with:
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
./ci/run-docker.sh ${{ matrix.target }}
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
Expand Down
27 changes: 24 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub struct Build {
pub struct Artifacts {
include_dir: PathBuf,
lib_dir: PathBuf,
bin_dir: PathBuf,
libs: Vec<String>,
target: String,
shared: bool,
}

impl Build {
Expand Down Expand Up @@ -143,19 +146,23 @@ 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");

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",
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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");
}
}
}
}

0 comments on commit a85d18b

Please sign in to comment.