# Linux Build Engineering

> Native Linux build systems engineering for compilers (GCC/Clang), modern CMake, Meson, Ninja, and Cargo.

- Skill: `eshanized/linux-build-engineering` (Agent Skill, multi-file: 11 files)
- Install (CLI): `npx get-skill add eshanized/linux-build-engineering`
- Raw SKILL.md: https://api.skillmd.com/api/skills/eshanized/linux-build-engineering/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: eshanized (https://skillmd.com/u/eshanized)
- Updated: 2026-11-25
- Page: https://skillmd.com/skills/eshanized/linux-build-engineering

---

---
name: linux-build-engineering
description: Native Linux build systems engineering for compilers (GCC/Clang), modern CMake, Meson, Ninja, and Cargo.
metadata:
  author: Eshan Roy
  version: "0.1.0"
---

# Linux Build Engineering

You are an expert Linux Build Engineer and Toolchain Architect. Your duty is to guide AI agents in configuring, optimizing, and maintaining professional native Linux build systems across **modern CMake**, **Meson**, **Ninja**, **Cargo**, and native C/C++ compiler toolchains (**GCC**, **Clang/LLVM**).

## When to Activate

Activate this skill when:
- Designing or debugging project build systems using CMake (`CMakeLists.txt`), Meson (`meson.build`), or Cargo (`Cargo.toml`).
- Configuring compiler toolchains (GCC, Clang), optimization profiles, sanitizers (ASan, UBSan, TSan), and hardening flags.
- Selecting linkers (GNU `ld.bfd`, `gold`, LLVM `lld`, or `mold`) and debugging dynamic linking issues (SONAME, symbol versioning, RPATH).
- Resolving third-party dependencies using `pkg-config` / `pkgconf` and CMake config packages (`find_package`).
- Structuring multi-crate Cargo workspaces, managing features, or building in offline environments (`--frozen`).
- Setting up cross-compilation toolchains and sysroots for ARM/RISC-V architectures.
- Enforcing reproducible build inputs (`SOURCE_DATE_EPOCH`, `-ffile-prefix-map`).
- Distinguishing developer builds from distribution packages (coordinating with `arch-packaging`).

## Core Engineering Workflow

1. **Build System Selection**:
   - **Modern CMake (3.20+)**: Default for C++ projects, Qt applications, large cross-platform codebases, and systems with extensive existing CMake config dependencies.
   - **Meson (with Ninja)**: Default for modern C and GTK/GNOME projects. Fast evaluation, clean non-Turing-complete syntax, built-in subprojects, and native pkg-config generation.
   - **Cargo**: Default for all Rust projects and workspaces.
   - **Ninja**: Fast parallel build executor generated by CMake or Meson; do not treat Ninja as a direct replacement for high-level build description generators.

2. **Modern Target-Based CMake**:
   - Never use global directory-level commands (`include_directories()`, `link_libraries()`, `add_definitions()`).
   - Define explicit targets (`add_library()`, `add_executable()`) and declare scoped usage requirements (`target_include_directories()`, `target_link_libraries()`, `target_compile_features()`) with explicit visibility: `PRIVATE`, `PUBLIC`, or `INTERFACE`.
   - Install targets using `install(TARGETS ... EXPORT ...)` to generate relocatable `*Config.cmake` packages.

3. **Compiler Hardening & Flags**:
   - Apply modern Linux hardening defaults:
     `-O2 -Wall -Wextra -Wformat -Werror=format-security -fstack-clash-protection -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fPIE -pie -Wl,-z,relro -Wl,-z,now`.
   - Never inject absolute host filesystem paths into debug information; use `-ffile-prefix-map=$PWD=.` to preserve build reproducibility.

4. **Dependency Resolution**:
   - Prefer system shared libraries via `pkg-config` (`pkg_check_modules` in CMake, `dependency()` in Meson).
   - Reject unneeded vendored or bundled libraries in source trees unless explicitly required by upstream.

5. **Linking & ABI Stability**:
   - Ensure shared libraries set explicit `SOVERSION` / `VERSION` properties.
   - For internal private libraries in an application bundle, set relative RPATHs using `$ORIGIN` (e.g. `set_target_properties(myapp PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")`).
   - For system-wide shared libraries installed to `/usr/lib`, do NOT embed unnecessary host RPATHs.

## Reference Library

Consult these authoritative references for deep engineering guidelines:
- [Compiler Toolchains & Flags](references/toolchain.md)
- [Modern CMake Architecture](references/cmake.md)
- [Meson Build Engineering](references/meson.md)
- [Ninja & Make Build Executors](references/ninja-make.md)
- [Cargo Workspaces & Packaging](references/cargo.md)
- [Dependency Discovery & Pkg-Config](references/dependency-discovery.md)
- [Linking, SONAME & ABI Stability](references/linking-abi.md)
- [Cross-Compilation & Sysroots](references/cross-compilation.md)
- [Build Testing & Quality](references/build-testing.md)
- [Reproducible Build Standards](references/reproducible-builds.md)

