Post

03. DevOps about Build

03. DevOps about Build

DevOps about Build


Prerequisites


1. What is Build in DevOps?

The Build phase is where source code is transformed into a runnable artifact.

For C++ systems, this is not a trivial step. It includes:

  • compiling source code
  • resolving dependencies
  • linking libraries
  • generating executables

Build is the phase where source code is compiled, linked, and packaged into a runnable artifact.

2. Why Build is Critical in C++

Compared to languages like Python:

  • C++ requires compilation
  • dependency management is complex
  • platform differences matter
  • build configuration affects performance

❌ Poor build setup leads to:

  • inconsistent environments
  • broken CI pipelines
  • hard-to-reproduce bugs
  • long build times
  • incorrect optimizations

✔ Good build setup enables:

  • reproducible builds
  • fast iteration
  • reliable CI/CD
  • consistent deployment artifacts

3. Build Goals

The Build phase should guarantee:

  1. correct compilation
  2. consistent dependency resolution
  3. optimized binary output
  4. reproducibility across environments
  5. integration with CI/CD pipelines

4. Core Components of the Build Phase

4-1. Build System — CMake

C++ projects require a build system to manage:

  • source files
  • compiler flags
  • dependencies
  • targets

Example

1
2
cmake -S . -B build
cmake --build build --config Release
  • cross-platform
  • widely adopted
  • integrates with CI/CD
  • works with dependency managers

4-2. Dependency Management — vcpkg

C++ libraries are not trivial to manage.

Using vcpkg:

1
vcpkg install opencv

Then connect to CMake:

1
2
cmake -B build -S . \
 -DCMAKE_TOOLCHAIN_FILE=[vcpkg]/scripts/buildsystems/vcpkg.cmake
  • consistent dependency versions
  • automatic include/link setup
  • cross-platform compatibility

4-3. Build Configuration

Different build types affect performance:

TypePurpose
Debugdebugging, no optimization
Releaseoptimized performance
RelWithDebInfooptimized + debug symbols
1
cmake --build build --config Release

For real-time systems, Release build is mandatory

4-4. Compiler Optimization

Build is where performance begins.

Typical flags:

  • -O2 / -O3
  • architecture-specific optimizations
  • vectorization enabled

Bad flags = bad performance Good flags = free speed improvement

4-5. Artifact Generation

The final output:

  • executable
  • shared library
  • static library

Example:

1
2
3
build/
 ├── app.exe
 ├── libpreprocessor.so

This artifact is what gets deployed

Build Flow in DevOps

1
2
3
4
5
6
7
8
9
10
11
Code committed
   ↓
CI triggered
   ↓
CMake configure
   ↓
Compile + link
   ↓
Artifact generated
   ↓
Artifact passed to next stage (Test / Deploy)

Build in Docker (Best Practice)

Example Dockerfile:

1
2
3
4
5
6
7
8
9
10
11
12
13
FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
    build-essential cmake git

WORKDIR /app

COPY . .

RUN cmake -S . -B build \
 && cmake --build build --config Release

CMD ["./build/app"]
  • identical build environment
  • easy CI integration
  • eliminates environment mismatch

5. Common Mistakes

❌ Mixing Debug and Release artifacts

→ inconsistent behavior

❌ Hardcoding include paths

→ breaks portability

❌ Not using a build system

→ manual builds become unmanageable

❌ Ignoring dependency versions

→ unexpected breakages

❌ No CI integration

→ builds fail later in pipeline

This post is licensed under CC BY 4.0 by the author.