Skip to content

Commit

Permalink
feat: Using bazel toolchains instead of clang target
Browse files Browse the repository at this point in the history
Part of #2

clang target is not very stable on github, try using bazel toolchains
instead (i.e platforms)
  • Loading branch information
Gashmob committed Jul 17, 2024
1 parent 46e21a6 commit d9d5f2f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 39 deletions.
62 changes: 26 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ jobs:
- name: Set matrix data
id: set-matrix
run: |
echo -e "Using json:\n$(cat ./tools/ci/build-matrix.json)"
echo 'matrix<<EOF' >> "$GITHUB_OUTPUT"
echo "$(cat ./tools/ci/build-matrix.json)" >> "$GITHUB_OUTPUT"
echo EOF >> "$GITHUB_OUTPUT"
build:
name: "Build & Run [${{ matrix.os }} - ${{ matrix.triple }}]"
name: "Build & Run [${{ matrix.os }} - ${{ matrix.platform }}]"
needs: configure
strategy:
fail-fast: false
Expand All @@ -38,14 +36,10 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b
- name: Build then run
uses: workflow/nix-shell-action@10ebd4e80eae8a5bc5147c0a36ebb568d1b277bd
with:
script: |
bazel build //:filc --copt="--target=${{ matrix.triple }}"
bazel run //:filc
run: nix-shell --pure --run '${{ github.workspace }}/tools/ci/build_and_run.sh ${{ matrix.platform }}'

unit-tests:
name: "Unit tests [${{ matrix.os }} - ${{ matrix.triple }}]"
name: "Unit tests [${{ matrix.os }} - ${{ matrix.platform }}]"
needs: configure
strategy:
fail-fast: false
Expand All @@ -57,30 +51,26 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b
- name: Run tests
uses: workflow/nix-shell-action@10ebd4e80eae8a5bc5147c0a36ebb568d1b277bd
with:
script: |
bazel build //:unit-tests --copt="--target=${{ matrix.triple }}"
bazel test //:unit-tests
test-coverage:
name: "Unit test coverage"
needs: configure
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332

- name: Install Nix
uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b
- name: Run tests
id: tests
uses: workflow/nix-shell-action@10ebd4e80eae8a5bc5147c0a36ebb568d1b277bd
with:
script: |
bazel coverage --combined_report=lcov //:unit-tests
echo "coverage_path=$(bazel info output_path)/_coverage/_coverage_report.dat" >> "$GITHUB_OUTPUT"
- name: Upload coverage report to Codacy
uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ${{ steps.tests.outputs.coverage_path }}
run: nix-shell --pure --run '${{ github.workspace }}/tools/ci/run_unit_tests.sh ${{ matrix.plaform }}'
#
# test-coverage:
# name: "Unit test coverage"
# needs: configure
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
#
# - name: Install Nix
# uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b
# - name: Run tests
# id: tests
# uses: workflow/nix-shell-action@10ebd4e80eae8a5bc5147c0a36ebb568d1b277bd
# with:
# script: |
# bazel coverage --combined_report=lcov //:unit-tests
# echo "coverage_path=$(bazel info output_path)/_coverage/_coverage_report.dat" >> "$GITHUB_OUTPUT"
# - name: Upload coverage report to Codacy
# uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699
# with:
# project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
# coverage-reports: ${{ steps.tests.outputs.coverage_path }}
41 changes: 41 additions & 0 deletions tools/bazel/platform/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# --- Linux ---
platform(
name = "linux_x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
]
)

platform(
name = "linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
]
)

platform(
name = "linux_i386",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:i386",
]
)

platform(
name = "linux_riscv64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:riscv64",
]
)

# --- NixOS ---
platform(
name = "nixos_x86_64",
constraint_values = [
"@platforms//os:nixos",
"@platforms//cpu:x86_64",
]
)
18 changes: 15 additions & 3 deletions tools/ci/build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
"include": [
{
"os": "ubuntu-22.04",
"triple": "x86_64-unknown-linux"
"platform": "linux_x86_64"
},
{
"os": "macos-14",
"triple": "arm64-apple-darwin"
"os": "ubuntu-22.04",
"platform": "linux_arm64"
},
{
"os": "ubuntu-22.04",
"platform": "linux_i386"
},
{
"os": "ubuntu-22.04",
"platform": "linux_riscv64"
},
{
"os": "ubuntu-22.04",
"platform": "nixos_x86_64"
}
]
}
10 changes: 10 additions & 0 deletions tools/ci/build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

if [ -z "$1" ]; then
platform=""
else
platform="--platforms=//tools/bazel/platform:$1"
fi

bazel build -c opt $platform //:filc
bazel run //:filc
10 changes: 10 additions & 0 deletions tools/ci/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

if [ -z "$1" ]; then
platform=""
else
platform="--platforms=//tools/bazel/platform:$1"
fi

bazel build $platform //:unit-tests
bazel test //:unit-tests

0 comments on commit d9d5f2f

Please sign in to comment.