From fb668816996021b050ce392d62ff986147641a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:34:46 +0100 Subject: [PATCH 1/4] Allow log stubs to be unused. --- src/log_stubs.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 4a72d9a5ea..4af496ce14 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + macro_rules! log { (target: $target:expr, $lvl:expr, $($arg:tt)+) => { let _ = $target; From 2ab4a00cae8bc1141eb610838ca320eb6c97f659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:47:41 +0100 Subject: [PATCH 2/4] integration: Forward some features to bindgen. --- bindgen-integration/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index e82fbd9905..2664b60ad7 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -11,6 +11,10 @@ bindgen = { path = ".." } cc = "1.0" [features] +static = ["bindgen/static"] +runtime = ["bindgen/runtime"] + +testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"] From c56b29f6f319744b03906ce20c2b7aac3b46b005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 04:47:58 +0100 Subject: [PATCH 3/4] tests: Remove unnecessary system header include that makes macos unhappy --- bindgen-integration/cpp/Test.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index a9c5258c44..7605d9f0f3 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -20,8 +20,6 @@ #define TESTMACRO_STRING_EXPR ("string") #define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ÿÿ") /* invalid UTF-8 on purpose */ -#include - enum { MY_ANNOYING_MACRO = #define MY_ANNOYING_MACRO 1 From c23031a15304e1628c0c3aa0bcb232685a5dcdac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:10:12 +0100 Subject: [PATCH 4/4] ci: Switch most CI to GitHub actions. --- .github/workflows/bindgen.yml | 150 +++++++++++++++++++++++++++++++++ .travis.yml | 83 +----------------- bindgen-integration/Cargo.toml | 1 + ci/assert-docs.sh | 6 -- ci/assert-no-diff.sh | 8 -- ci/assert-rustfmt.sh | 13 --- ci/assert-warnings.sh | 6 -- ci/before_install.sh | 77 ----------------- ci/script.sh | 65 -------------- ci/test.sh | 130 ++++++++++++++++++++++++++++ tests/quickchecking/.gitignore | 1 + 11 files changed, 283 insertions(+), 257 deletions(-) create mode 100644 .github/workflows/bindgen.yml delete mode 100755 ci/assert-docs.sh delete mode 100755 ci/assert-no-diff.sh delete mode 100755 ci/assert-rustfmt.sh delete mode 100755 ci/assert-warnings.sh delete mode 100644 ci/before_install.sh delete mode 100755 ci/script.sh create mode 100755 ci/test.sh create mode 100644 tests/quickchecking/.gitignore diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml new file mode 100644 index 0000000000..29309e8270 --- /dev/null +++ b/.github/workflows/bindgen.yml @@ -0,0 +1,150 @@ +name: bindgen + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + rustfmt: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + # TODO: Should ideally be stable, but we use some nightly-only + # features. + toolchain: nightly + override: true + components: rustfmt + + - name: Run rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + msrv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install msrv + uses: actions-rs/toolchain@v1 + with: + profile: minimal + # MSRV below is documented in README.md, please update that if you + # change this. + toolchain: 1.40.0 + override: true + + - name: Build with msrv + run: rm Cargo.lock && cargo +1.40.0 build --lib + + quickchecking: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # TODO: Actually run quickchecks once `bindgen` is reliable enough. + - name: Build quickcheck tests + run: cd tests/quickchecking && cargo test + + test-expectations: + runs-on: ${{matrix.os}} + strategy: + matrix: + # TODO(#1954): These should be run on mac too, but turns out they're + # broken. + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Test expectations + run: cd tests/expectations && cargo test + + test: + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest] + llvm_version: ["3.9", "4.0", "5.0", "9.0"] + release_build: [0, 1] + no_default_features: [0, 1] + # FIXME: There are no pre-built static libclang libraries, so the + # `static` feature is not testable atm. + feature_runtime: [0, 1] + feature_extra_asserts: [0] + feature_testing_only_docs: [0] + + exclude: + # 3.9 and 4.0 are too old to support regular dynamic linking, so this + # is not expected to work. + - os: ubuntu-latest + llvm_version: "3.9" + no_default_features: 1 + feature_runtime: 0 + + - os: ubuntu-latest + llvm_version: "4.0" + no_default_features: 1 + feature_runtime: 0 + + include: + # Test with extra asserts + docs just with latest llvm versions to + # prevent explosion + - os: ubuntu-latest + llvm_version: "9.0" + release_build: 0 + no_default_features: 0 + feature_extra_asserts: 1 + feature_testing_only_docs: 1 + + # Ensure stuff works on macos too + - os: macos-latest + llvm_version: "9.0" + release_build: 0 + no_default_features: 0 + feature_extra_asserts: 0 + feature_testing_only_docs: 0 + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run all the tests + env: + GITHUB_ACTIONS_OS: ${{matrix.os}} + LLVM_VERSION: ${{matrix.llvm_version}} + BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} + BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} + BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} + BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} + BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} + run: ./ci/test.sh diff --git a/.travis.yml b/.travis.yml index c44aaa05cd..1e6d4f0aec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,96 +1,15 @@ language: rust - dist: xenial - os: - linux - rust: - stable - env: global: - CARGO_TARGET_DIR=/tmp/bindgen - matrix: - # Miscellaneous tests. - # Start "misc" job first since it runs longer than any other job. - - LLVM_VERSION="9.0" BINDGEN_JOB="misc" - - LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking" - - LLVM_VERSION="9.0" BINDGEN_JOB="msrv" - - # General matrix. - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="5.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" - - # FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment. - # - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - # - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" - - # FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment. - # - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - # - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - - # Testing with extra asserts enabled - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions" - - - # Test the expectations build and pass tests. - - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release" - -matrix: - fast_finish: true - - # Include a few jobs for spot-checking different configurations without - # invoking combinatoric explosion of Travis jobs. - include: - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - -cache: - directories: - - $HOME/.cargo - - $HOME/.llvm-builds - -before_install: . ./ci/before_install.sh - script: - - BINDGEN_JOB="$BINDGEN_JOB" BINDGEN_PROFILE="$BINDGEN_PROFILE" BINDGEN_FEATURES="$BINDGEN_FEATURES" BINDGEN_NO_DEFAULT_FEATURES="$BINDGEN_NO_DEFAULT_FEATURES" ./ci/script.sh - + - ./ci/test-book.sh after_success: - test "$TRAVIS_PULL_REQUEST" == "false" && test "$TRAVIS_BRANCH" == "master" && - test "$BINDGEN_JOB" == "misc" && ./ci/deploy-book.sh diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 2664b60ad7..650dedafe2 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -14,6 +14,7 @@ cc = "1.0" static = ["bindgen/static"] runtime = ["bindgen/runtime"] +testing_only_docs = ["bindgen/testing_only_docs"] testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] diff --git a/ci/assert-docs.sh b/ci/assert-docs.sh deleted file mode 100755 index 2bbc35af38..0000000000 --- a/ci/assert-docs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -cargo check --features "$BINDGEN_FEATURES testing_only_docs" diff --git a/ci/assert-no-diff.sh b/ci/assert-no-diff.sh deleted file mode 100755 index 14f2aa2161..0000000000 --- a/ci/assert-no-diff.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -git add -u -git diff @ -git diff-index --quiet HEAD diff --git a/ci/assert-rustfmt.sh b/ci/assert-rustfmt.sh deleted file mode 100755 index 785530cb85..0000000000 --- a/ci/assert-rustfmt.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" -rustup update "$TOOLCHAIN" -rustup component add rustfmt --toolchain "$TOOLCHAIN" - -# Run `rustfmt` on the crate! If `rustfmt` can't make a long line shorter, it -# prints an error and exits non-zero, so tell it to kindly shut its yapper and -# make sure it doesn't cause us to exit this whole script non-zero. -rustup run "$TOOLCHAIN" cargo fmt -- --check diff --git a/ci/assert-warnings.sh b/ci/assert-warnings.sh deleted file mode 100755 index 62c12c42d0..0000000000 --- a/ci/assert-warnings.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -cargo rustc --lib --features "$BINDGEN_FEATURES" -- -Dwarnings diff --git a/ci/before_install.sh b/ci/before_install.sh deleted file mode 100644 index 2e66ae4e74..0000000000 --- a/ci/before_install.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash -# Bail on first error -set -e -# Bail if an unset variable is encountered -set -u -# Enable debugging output -set -x -# Give a pipeline a non-zero exit code if one of its constituents fails -set -o pipefail - -function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" -} - -function llvm_macos_target_triple() { - case "$1" in - [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; - # Starting with 9.0.1, triple swapped ordering - *) echo "x86_64-apple-darwin" ;; - esac -} - -function llvm_version_triple() { - case "$1" in - 5.0) echo "5.0.1" ;; - # By default, take the .0 patch release - *) echo "$1.0" ;; - esac -} - -function llvm_base_url() { - local llvm_version_triple=$1 - - case "$llvm_version_triple" in - [0-8].* | 9.0.0) - echo "http://releases.llvm.org/$llvm_version_triple" - ;; - # Starting with 9.0.1, releases are hosted on github - *) - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" - ;; - esac -} - -function llvm_download() { - local base_url=$1 - local arch=$2 - - export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch - export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" - - if [ -d "${LLVM_DIRECTORY}" ]; then - echo "Using cached LLVM download for ${LLVM}..." - else - wget $base_url/${LLVM}.tar.xz - mkdir -p "${LLVM_DIRECTORY}" - tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 - fi - - export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" - export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" -} - -export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` - -base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` - -if [ "${TRAVIS_OS_NAME}" == "linux" ]; then - llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` - export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} -else - llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` - export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} -fi - -# Subsequent scripts can see the state of `set -eu`, so unset it again. -set +eu diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100755 index 16eddbf81d..0000000000 --- a/ci/script.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -# Note that `$BINDGEN_PROFILE` is never in quotes so that it expands to nothing -# (not even an empty string argument) when the variable is empty. This is -# necessary so we don't pass an unexpected flag to cargo. - -export RUST_BACKTRACE=1 - -NO_DEFAULT_FEATURES="" -if [ ! -z $BINDGEN_NO_DEFAULT_FEATURES ]; then - NO_DEFAULT_FEATURES=--no-default-features -fi - -case "$BINDGEN_JOB" in - "test") - # Need rustfmt to compare the test expectations. - TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" - rustup update "$TOOLCHAIN" - rustup component add rustfmt --toolchain "$TOOLCHAIN" - RUSTFMT="$(rustup which --toolchain "$TOOLCHAIN" rustfmt)" - export RUSTFMT - cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ./ci/assert-no-diff.sh - ;; - - "msrv") - # Test that the bindgen library can be built with the minimum supported Rust version - # This test should not use Cargo.lock as it's ignored for library builds - rm Cargo.lock - # The MSRV below is also documented in README.md, please keep in sync - rustup install 1.40.0 - cargo +1.40.0 build --lib $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ;; - - "integration") - cd ./bindgen-integration - cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ;; - - "expectations") - cd ./tests/expectations - cargo test "$BINDGEN_PROFILE" - ;; - - "misc") - ./ci/assert-docs.sh - ./ci/assert-warnings.sh - ./ci/test-book.sh - ./ci/no-includes.sh - ./ci/assert-rustfmt.sh - ;; - - "quickchecking") - cd ./tests/quickchecking - # TODO: Actually run quickchecks once `bindgen` is reliable enough. - cargo test - ;; - - *) - echo "Error! Unknown \$BINDGEN_JOB: '$BINDGEN_JOB'" - exit 1 -esac diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 0000000000..d5bb0bf40d --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Bail on first error +set -e +# Bail if an unset variable is encountered +set -u +# Enable debugging output +set -x +# Give a pipeline a non-zero exit code if one of its constituents fails +set -o pipefail + +function llvm_linux_target_triple() { + echo "x86_64-linux-gnu-ubuntu-16.04" +} + +function llvm_macos_target_triple() { + case "$1" in + [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; + # Starting with 9.0.1, triple swapped ordering + *) echo "x86_64-apple-darwin" ;; + esac +} + +function llvm_version_triple() { + case "$1" in + 5.0) echo "5.0.1" ;; + # By default, take the .0 patch release + *) echo "$1.0" ;; + esac +} + +function llvm_base_url() { + local llvm_version_triple=$1 + + case "$llvm_version_triple" in + [0-8].* | 9.0.0) + echo "http://releases.llvm.org/$llvm_version_triple" + ;; + # Starting with 9.0.1, releases are hosted on github + *) + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" + ;; + esac +} + +function llvm_download() { + local base_url=$1 + local arch=$2 + + export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch + export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" + + if [ -d "${LLVM_DIRECTORY}" ]; then + echo "Using cached LLVM download for ${LLVM}..." + else + wget --no-verbose $base_url/${LLVM}.tar.xz + mkdir -p "${LLVM_DIRECTORY}" + tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 + fi + + export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" + export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" +} + +# Download and set up a sane LLVM version +set_llvm_env() { + export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` + local base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` + + if [ "$GITHUB_ACTIONS_OS" == "ubuntu-latest" ]; then + llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` + export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} + else + llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` + export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} + fi +} + +# Need rustfmt to compare the test expectations. +set_rustfmt_env() { + local toolchain="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" + rustup update "$toolchain" + rustup component add rustfmt --toolchain "$toolchain" + export RUSTFMT="$(rustup which --toolchain "$toolchain" rustfmt)" +} + +assert_no_diff() { + git add -u + git diff @ + git diff-index --quiet HEAD +} + +set_llvm_env +set_rustfmt_env + +get_cargo_args() { + local args="" + if [ "$BINDGEN_RELEASE_BUILD" == "1" ]; then + args+=" --release" + fi + if [ "$BINDGEN_NO_DEFAULT_FEATURES" == "1" ]; then + args+=" --no-default-features" + fi + local features="" + if [ "$BINDGEN_FEATURE_RUNTIME" == "1" ]; then + features+="runtime" + fi + if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1" ]; then + features+=" testing_only_extra_assertions" + fi + if [ "$BINDGEN_FEATURE_TESTING_ONLY_DOCS" == "1" ]; then + features+=" testing_only_docs" + fi + if [ ! -z "$features" ]; then + args+=" --features $(echo $features | tr ' ' ',')" + fi + echo $args +} + +CARGO_ARGS=`get_cargo_args` + +# Ensure we build without warnings +cargo rustc --lib $CARGO_ARGS -- -Dwarnings + +# Run the tests +cargo test $CARGO_ARGS + +assert_no_diff + +# Run the integration tests +(cd bindgen-integration && cargo test $CARGO_ARGS) diff --git a/tests/quickchecking/.gitignore b/tests/quickchecking/.gitignore new file mode 100644 index 0000000000..03314f77b5 --- /dev/null +++ b/tests/quickchecking/.gitignore @@ -0,0 +1 @@ +Cargo.lock