diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index c839846365a..24f759e6c7a 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -12,7 +12,7 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: - # Build and test p4c on Ubuntu 20.04. + # Build with gcc and test p4c on Ubuntu 20.04. build-linux: strategy: fail-fast: false @@ -33,10 +33,10 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1 with: - key: test-${{ matrix.unified }}-${{ runner.os }} + key: test-${{ matrix.unified }}-${{ runner.os }}-gcc max-size: 1000M - - name: Build (Ubuntu Linux) + - name: Build (Ubuntu Linux, GCC) run: | # To flush out issues with unified vs. non-unified builds, # do a non-unified build before continuing with the rest, @@ -51,6 +51,35 @@ jobs: sudo docker run --privileged -w /p4c/build -e $CTEST_PARALLEL_LEVEL p4c ctest --output-on-failure --schedule-random if: matrix.unified == 'ON' + # Build with clang and test p4c on Ubuntu 20.04. + build-linux-clang: + strategy: + fail-fast: false + runs-on: ubuntu-latest + env: + CTEST_PARALLEL_LEVEL: 4 + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: ccache + uses: hendrikmuhs/ccache-action@v1 + with: + key: test-${{ runner.os }}-clang + max-size: 1000M + + - name: Build (Ubuntu Linux, Clang) + run: | + docker build -t p4c --build-arg IMAGE_TYPE=test --build-arg ENABLE_UNIFIED_COMPILATION=ON --build-arg ENABLE_GMP=OFF --build-arg ENABLE_WERROR=OFF --build-arg COMPILE_WITH_CLANG=ON . + ./tools/export_ccache.sh + + # run with sudo (...) --privileged + # this is needed to create network namespaces for the ebpf tests. + - name: Run tests (Ubuntu Linux) + run: | + sudo docker run --privileged -w /p4c/build -e $CTEST_PARALLEL_LEVEL p4c ctest --output-on-failure --schedule-random + # Build and test p4c on Fedora. build-fedora-linux: strategy: diff --git a/Dockerfile b/Dockerfile index 962e51d01bf..35bb55584cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,8 @@ ARG KERNEL_VERSIONS ARG ENABLE_TEST_TOOLS=OFF # Whether to treat warnings as errors. ARG ENABLE_WERROR=ON +# Compile with Clang compiler +ARG COMPILE_WITH_CLANG=OFF # Delegate the build to tools/ci-build. COPY . /p4c/ diff --git a/tools/ci-build.sh b/tools/ci-build.sh index e81b6a3ac5f..2a2752cd569 100644 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -51,7 +51,8 @@ apt-get install -y --no-install-recommends \ ${P4C_DEPS} \ ${P4C_EBPF_DEPS} \ ${P4C_RUNTIME_DEPS} \ - git + git \ + lld # TODO: Remove this rm -rf line once the ccache memcache config is removed. rm -rf /usr/local/etc/ccache.conf @@ -157,6 +158,11 @@ function build() { make } +if [ "$COMPILE_WITH_CLANG" == "ON" ]; then + export CC=clang + export CXX=clang++ +fi + # Strong optimization. export CXXFLAGS="${CXXFLAGS} -O3" # Toggle unified compilation.