Skip to content

[build]: Reduce duplicate compilation in CI - #4812

Draft
theasianpianist wants to merge 1 commit into
sonic-net:masterfrom
theasianpianist:ci/reduce-swss-build-time
Draft

[build]: Reduce duplicate compilation in CI#4812
theasianpianist wants to merge 1 commit into
sonic-net:masterfrom
theasianpianist:ci/reduce-swss-build-time

Conversation

@theasianpianist

Copy link
Copy Markdown
Contributor

Why

Recent SWSS jobs are approaching or exceeding the 60-minute CI timeout. Azure logs showed ASAN compilation at 48-53 minutes and Trixie compilation varying from 33 minutes to over 53 minutes. A timed-out Trixie job spent 32.6 minutes in orchagent compilation and another 9.7 minutes compiling mock tests before cancellation.

What changed

  • Build common cfgmgr framework sources once in libcfgmgrcommon.a instead of once per daemon.
  • Build production sources shared by orchagent and P4 tests once in libp4orchshared.a.
  • Keep P4 test-only sources at -O0 while production objects retain the package optimization level.
  • Convert unit-test binaries from noinst_PROGRAMS to check_PROGRAMS.
  • Use DEB_BUILD_OPTIONS=nocheck for Trixie package jobs, while primary Bookworm and ASAN jobs retain unit-test execution.
  • Skip test-result publishing for jobs that intentionally do not run unit tests.

Measured impact

In a container constrained to the CI agents' 4 CPUs and 32 GiB:

Build Before After
Default package build with tests 28:58 / 644 C++ compilations 26:12 / 552 compilations
Trixie-style nocheck package build 28:58 / 644 compilations 11:45 / 199 compilations
ASAN P4 test build/run 10:24 5:43

Validation

  • Rebased onto current master (4f3dda15).
  • Exact package command completed successfully in 24:04:
    • ./autogen.sh
    • RUSTFLAGS=-Dwarnings dpkg-buildpackage -us -uc -b -j$(nproc)
  • All C++ test suites passed with zero failures.
  • GCOV tests, coverage collection, and package generation completed successfully.
  • Trixie-style DEB_BUILD_OPTIONS=nocheck package generation completed successfully.
  • ASAN P4 tests completed successfully.
  • Verified no-op orchagent builds do not relink, while changes to shared sources rebuild the archive and relink in one invocation.

Reuse common cfgmgr and P4 orchagent objects through static archives. Build unit-test binaries only for check targets so Trixie package jobs can use DEB_BUILD_OPTIONS=nocheck without compiling redundant tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f289b446-dbae-48ba-8d0a-dc02083cdf07
Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
Copilot AI review requested due to automatic review settings August 1, 2026 07:19
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the SWSS autotools build and Azure CI pipeline to reduce duplicate compilations (notably in orchagent/P4 and cfgmgr paths) and keep CI runtimes under timeout by reusing newly introduced static convenience archives and selectively skipping unit-test execution in Trixie package builds.

Changes:

  • Introduce reusable static archives (libcfgmgrcommon.a, libp4orchshared.a) to compile shared sources once and link them into multiple binaries.
  • Move unit-test binaries from noinst_PROGRAMS to check_PROGRAMS so they compile only during make check (and can be skipped via DEB_BUILD_OPTIONS=nocheck).
  • Add an Azure pipeline parameter to disable unit tests for Trixie package builds and skip publishing test results when tests are intentionally not run.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/mock_tests/Makefile.am Switch unit-test targets to check_PROGRAMS to avoid building them during the normal make all path.
tests/Makefile.am Convert the tests binary to check_PROGRAMS so it builds/runs only under make check.
orchagent/p4orch/tests/Makefile.am Add libp4orchshared.a and link it into p4orch_tests; keep test-only objects at -O0.
orchagent/p4orch/shared_sources.mk Define a shared source list for orchagent/P4 code to be compiled once into an archive.
orchagent/Makefile.am Link orchagent against the shared archive and add build dependency wiring.
configure.ac Add AM_PROG_AR to support building new static archives reliably.
cfgmgr/Makefile.am Build common cfgmgr framework sources once as libcfgmgrcommon.a and link it into cfgmgr daemons.
azure-pipelines.yml Disable unit tests in the Trixie build stages via a new template parameter.
.azure-pipelines/build-template.yml Implement run_unit_tests parameter: set DEB_BUILD_OPTIONS=nocheck when false and gate test publishing accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants