From cb4029a1c5a75462127c8c101a7f2d29293fa3f1 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 18 Jul 2024 22:49:45 +0900 Subject: [PATCH] dev --- .github/workflows/ci.yml | 235 ++++++++++++++---------- tests/fixtures/crates/ffi/Cargo.toml | 2 +- tests/fixtures/crates/ffi/hello_c.c | 6 +- tests/fixtures/crates/ffi/hello_cpp.cpp | 6 +- 4 files changed, 154 insertions(+), 95 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0fdc7b1..c0550d56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,114 +25,165 @@ env: defaults: run: - shell: bash + shell: bash --noprofile --norc -CeEuxo pipefail {0} concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} cancel-in-progress: true jobs: - deny: - uses: taiki-e/github-actions/.github/workflows/deny.yml@main - miri: - uses: taiki-e/github-actions/.github/workflows/miri.yml@main - msrv: - uses: taiki-e/github-actions/.github/workflows/msrv.yml@main - with: - event_name: ${{ github.event_name }} - release-dry-run: - uses: taiki-e/github-actions/.github/workflows/release-dry-run.yml@main - tidy: - uses: taiki-e/github-actions/.github/workflows/tidy.yml@main + # deny: + # uses: taiki-e/github-actions/.github/workflows/deny.yml@main + # miri: + # uses: taiki-e/github-actions/.github/workflows/miri.yml@main + # msrv: + # uses: taiki-e/github-actions/.github/workflows/msrv.yml@main + # with: + # event_name: ${{ github.event_name }} + # release-dry-run: + # uses: taiki-e/github-actions/.github/workflows/release-dry-run.yml@main + # tidy: + # uses: taiki-e/github-actions/.github/workflows/tidy.yml@main - test: + # test: + # strategy: + # fail-fast: false + # matrix: + # include: + # # TODO: nightly-2023-04-27 (https://github.com/rust-lang/rust/pull/97368) + # # and nightly-2023-05-03 (https://github.com/rust-lang/rust/pull/111042) + # # fixed bugs in report generation, so the latest report is not the + # # same as the old report. + # # - rust: '1.60' + # - rust: stable + # - rust: beta + # - rust: nightly + # - rust: nightly + # os: macos-latest + # - rust: nightly + # os: windows-latest + # runs-on: ${{ matrix.os || 'ubuntu-latest' }} + # timeout-minutes: 60 + # steps: + # - uses: taiki-e/checkout-action@v1 + # - name: Install Rust + # run: rustup toolchain add "${{ matrix.rust }}" --no-self-update && rustup default "${{ matrix.rust }}" + # - run: rustup toolchain add nightly --no-self-update + # - uses: taiki-e/install-action@cargo-hack + # - uses: taiki-e/install-action@cargo-minimal-versions + # - uses: taiki-e/install-action@nextest + # - run: cargo test --workspace --all-features + # # TODO: move this test to tests/test.rs + # - run: cargo install --path . --debug + # - name: Test cargo llvm-cov nextest + # run: | + # cargo llvm-cov nextest --text --fail-under-lines 50 + # cargo llvm-cov nextest --text --fail-under-lines 50 --profile default --cargo-profile dev + # cargo llvm-cov nextest --text --fail-under-lines 50 --profile ci + # cargo llvm-cov nextest --text --fail-under-lines 50 --profile ci --cargo-profile dev + # cd -- ../real1 + # cargo llvm-cov nextest-archive --archive-file a.tar.zst + # cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 + # cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 + # rm -- a.tar.zst + # cargo clean + # cargo llvm-cov nextest-archive --archive-file a.tar.zst --release + # cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 + # cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 + # rm -- a.tar.zst + # cargo clean + # cargo llvm-cov nextest-archive --archive-file a.tar.zst --cargo-profile custom + # cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 + # cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 + # rm -- a.tar.zst + # cargo clean + # host=$(rustc -vV | grep -E '^host:' | cut -d' ' -f2) + # cargo llvm-cov nextest-archive --archive-file a.tar.zst --target "${host}" + # cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 + # cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 + # working-directory: tests/fixtures/crates/bin_crate + # - name: Test nightly-specific options, old Cargo compatibility, trybuild compatibility + # run: | + # unset RUSTFLAGS + + # # Test nightly-specific options + # git clone https://github.com/taiki-e/easytime.git + # pushd -- easytime >/dev/null + # git checkout 7ecb6e6 + # cargo llvm-cov test --doctests --text --fail-under-lines 30 + # popd >/dev/null + # pushd -- tests/fixtures/crates/cargo_config >/dev/null + # # TODO: --fail-under-branches? + # cargo llvm-cov test --branch --text --fail-under-lines 80 + # popd >/dev/null + # pushd -- easytime >/dev/null + # cargo llvm-cov test --branch --doctests --text --fail-under-lines 30 + # popd >/dev/null + + # # Test minimum runnable Cargo version. + # rustup toolchain add 1.60 --no-self-update + # pushd -- easytime >/dev/null + # cargo +1.60 llvm-cov test --text --fail-under-lines 30 + # popd >/dev/null + + # # Test trybuild compatibility. + # git clone --depth 1 https://github.com/taiki-e/easy-ext.git + # pushd -- easy-ext >/dev/null + # cargo llvm-cov --text --test compiletest --fail-under-lines 70 + # popd >/dev/null + # if: startsWith(matrix.rust, 'nightly') + # - run: cargo hack build --workspace --no-private --feature-powerset --no-dev-deps + # - run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features + + test-ffi: strategy: fail-fast: false matrix: include: - # TODO: nightly-2023-04-27 (https://github.com/rust-lang/rust/pull/97368) - # and nightly-2023-05-03 (https://github.com/rust-lang/rust/pull/111042) - # fixed bugs in report generation, so the latest report is not the - # same as the old report. - # - rust: '1.60' - - rust: stable - - rust: beta - - rust: nightly - - rust: nightly - os: macos-latest - - rust: nightly - os: windows-latest - runs-on: ${{ matrix.os || 'ubuntu-latest' }} + # https://github.com/rust-lang/rust/blob/1.60.0/src/bootstrap/native.rs#L403 + - llvm: '12' + - llvm: '13' + - llvm: '14' + - llvm: '15' + - llvm: '16' + - llvm: '17' + - llvm: '18' + runs-on: ubuntu-latest timeout-minutes: 60 steps: - uses: taiki-e/checkout-action@v1 - name: Install Rust - run: rustup toolchain add ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - - run: rustup toolchain add nightly --no-self-update - - uses: taiki-e/install-action@cargo-hack - - uses: taiki-e/install-action@cargo-minimal-versions - - uses: taiki-e/install-action@nextest - - run: cargo test --workspace --all-features - # TODO: move this test to tests/test.rs + run: rustup update stable --no-self-update + - name: Install LLVM + run: | + if type -P clang-"${{ matrix.llvm }}" &>/dev/null; then + exit 0 + fi + codename=$(grep -E '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2) + sudo mkdir -pm755 -- /etc/apt/keyrings + curl --proto '=https' --tlsv1.2 -fsSL --retry 10 --retry-connrefused https://apt.llvm.org/llvm-snapshot.gpg.key \ + | gpg --dearmor \ + | sudo tee -- /etc/apt/keyrings/llvm-snapshot.gpg >/dev/null + echo "deb [signed-by=/etc/apt/keyrings/llvm-snapshot.gpg] http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${{ matrix.llvm }} main" \ + | sudo tee -- "/etc/apt/sources.list.d/llvm-toolchain-${codename}-${{ matrix.llvm }}.list" >/dev/null + sudo apt-get -o Acquire::Retries=10 -qq update && sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \ + clang-"${{ matrix.llvm }}" \ + libc++-"${{ matrix.llvm }}"-dev \ + libc++abi-"${{ matrix.llvm }}"-dev \ + libclang-"${{ matrix.llvm }}"-dev \ + lld-"${{ matrix.llvm }}" \ + llvm-"${{ matrix.llvm }}" \ + llvm-"${{ matrix.llvm }}"-dev - run: cargo install --path . --debug - - name: Test cargo llvm-cov nextest + - name: Test run: | - set -eEuxo pipefail - cargo llvm-cov nextest --text --fail-under-lines 50 - cargo llvm-cov nextest --text --fail-under-lines 50 --profile default --cargo-profile dev - cargo llvm-cov nextest --text --fail-under-lines 50 --profile ci - cargo llvm-cov nextest --text --fail-under-lines 50 --profile ci --cargo-profile dev - cd ../real1 - cargo llvm-cov nextest-archive --archive-file a.tar.zst - cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 - cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 - rm a.tar.zst - cargo clean - cargo llvm-cov nextest-archive --archive-file a.tar.zst --release - cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 - cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 - rm a.tar.zst + export CC="clang-${{ matrix.llvm }}" + export CXX="clang++-${{ matrix.llvm }}" + export LLVM_COV="llvm-cov-${{ matrix.llvm }}" + export LLVM_PROFDATA="llvm-profdata-${{ matrix.llvm }}" + rustup toolchain add 1.60 --no-self-update cargo clean - cargo llvm-cov nextest-archive --archive-file a.tar.zst --cargo-profile custom - cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 - cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 - rm a.tar.zst + cargo +1.60 llvm-cov test --text --include-ffi --fail-under-lines 70 -vv cargo clean - host=$(rustc -vV | grep '^host:' | cut -d' ' -f2) - cargo llvm-cov nextest-archive --archive-file a.tar.zst --target "${host}" - cargo llvm-cov nextest --archive-file a.tar.zst --text --fail-under-lines 70 - cargo llvm-cov report --nextest-archive-file a.tar.zst --fail-under-lines 70 - working-directory: tests/fixtures/crates/bin_crate - - name: Test nightly-specific options, old Cargo compatibility, trybuild compatibility - run: | - set -eEuxo pipefail - unset RUSTFLAGS - - # Test nightly-specific options - git clone https://github.com/taiki-e/easytime.git - pushd easytime >/dev/null - git checkout 7ecb6e6 - cargo llvm-cov test --doctests --text --fail-under-lines 30 - popd >/dev/null - pushd tests/fixtures/crates/cargo_config >/dev/null - # TODO: --fail-under-branches? - cargo llvm-cov test --branch --text --fail-under-lines 80 - popd >/dev/null - pushd easytime >/dev/null - cargo llvm-cov test --branch --doctests --text --fail-under-lines 30 - popd >/dev/null - - # Test minimum runnable Cargo version. - rustup toolchain add 1.60 --no-self-update - pushd easytime >/dev/null - cargo +1.60 llvm-cov test --text --fail-under-lines 30 - popd >/dev/null - - # Test trybuild compatibility. - git clone --depth 1 https://github.com/taiki-e/easy-ext.git - pushd easy-ext >/dev/null - cargo llvm-cov --text --test compiletest --fail-under-lines 70 - popd >/dev/null - if: startsWith(matrix.rust, 'nightly') - - run: cargo hack build --workspace --no-private --feature-powerset --no-dev-deps - - run: cargo minimal-versions build --workspace --no-private --detach-path-deps=skip-exact --all-features + cargo +stable llvm-cov test --text --include-ffi --fail-under-lines 70 -vv + working-directory: tests/fixtures/crates/ffi diff --git a/tests/fixtures/crates/ffi/Cargo.toml b/tests/fixtures/crates/ffi/Cargo.toml index 4e51f5ac..09fb5570 100644 --- a/tests/fixtures/crates/ffi/Cargo.toml +++ b/tests/fixtures/crates/ffi/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" publish = false [build-dependencies] -cc = "1" +cc = "=1.0.83" [workspace] diff --git a/tests/fixtures/crates/ffi/hello_c.c b/tests/fixtures/crates/ffi/hello_c.c index 65647a59..aabebf95 100644 --- a/tests/fixtures/crates/ffi/hello_c.c +++ b/tests/fixtures/crates/ffi/hello_c.c @@ -1,5 +1,9 @@ #include void hello_c() { - printf("Hello C from Rust!\n"); + if (1) { + printf("Hello C from Rust!\n"); + } else { + printf("this line in C is not covered\n"); + } } diff --git a/tests/fixtures/crates/ffi/hello_cpp.cpp b/tests/fixtures/crates/ffi/hello_cpp.cpp index 7990d375..9d9c9137 100644 --- a/tests/fixtures/crates/ffi/hello_cpp.cpp +++ b/tests/fixtures/crates/ffi/hello_cpp.cpp @@ -1,5 +1,9 @@ #include extern "C" void hello_cpp() { - std::cout << "Hello C++ from Rust!" << std::endl; + if (1) { + std::cout << "Hello C++ from Rust!" << std::endl; + } else { + std::cout << "this line in C++ is not covered" << std::endl; + } }