Skip to content

Commit cc3679d

Browse files
authored
Add CPP toolchain configurations (#2)
* Add config files for different platforms. This commit enables CPP toolchains to be used with bazel for platforms: linux/qnx on x86_64/arm64 arch. Remove local paths Remove local paths for credential helper * Add README.md Add README.md for main repository page
1 parent 5e00895 commit cc3679d

49 files changed

Lines changed: 2969 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
15+
common --registry=https://bcr.bazel.build

BUILD

Whitespace-only changes.

MODULE.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
module(
15+
name = "score_bazel_cpp_toolchains",
16+
version = "0.1.0",
17+
compatibility_level = 0,
18+
)
19+
20+
# *******************************************************************************
21+
# Common useful functions and rules for Bazel
22+
# *******************************************************************************
23+
bazel_dep(name = "bazel_skylib", version = "1.8.1")
24+
25+
# *******************************************************************************
26+
# Constraint values for specifying platforms and toolchains
27+
# *******************************************************************************
28+
bazel_dep(name = "platforms", version = "1.0.0")
29+
bazel_dep(name = "score_bazel_platforms", version = "0.0.2")
30+
31+
# *******************************************************************************
32+
# C++ Rules for Bazel
33+
# *******************************************************************************
34+
bazel_dep(name = "rules_cc", version = "0.2.14")

README.md

Lines changed: 191 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,191 @@
1-
# bazel_cpp_toolchains
2-
Bazel C/C++ toolchain configuration repository
1+
# S-CORE Bazel C/C++ Toolchain Configuration Repository
2+
3+
This repository provides the configuration layer for all S-CORE C++ toolchains used in Bazel builds.</br>
4+
It contains **no compiler binaries**. Instead, it defines:
5+
* Toolchain configurations
6+
* Toolchain rules and extensions for Bzlmod
7+
* Common compiler flags
8+
* Templates for generating toolchain configs
9+
* Package descriptors for external toolchain binaries
10+
* Tests ensuring correct toolchain behavior
11+
12+
All toolchain binaries (GCC, QCC, etc.) are downloaded through Bazel repositories defined in consuming workspaces. </br>
13+
This repository is structured and versioned as a Bazel module and is intended to be consumed through MODULE.bazel.
14+
15+
## Key Goals
16+
17+
* Provide a centralized, unified configuration source for all C++ toolchains used across S-CORE.
18+
* Enforce consistency through shared flags, templates, and mandatory feature tests.
19+
* Support multiple compilers (GCC, QCC) and multiple platforms (Linux, QNX).
20+
* Ensure reproducible builds across architectures by separating:
21+
* configuration logic (this repo).
22+
* binary/toolchain distributions (external packages).
23+
* Support plug-and-play toolchain activation via Bzlmod extensions.
24+
25+
## Repository Structure
26+
27+
```bash
28+
.
29+
├── bazel
30+
│ ├── extentions/ # Module extensions for GCC/QCC toolchains
31+
│ └── rules/ # Bazel rule implementations for toolchains
32+
33+
├── configurations # Shared and compiler-specific configuration flags
34+
│ ├── common/
35+
│ ├── gcc/
36+
│ └── qcc/
37+
38+
├── packages # Toolchain package descriptors (no binaries)
39+
│ ├── linux/ # Linux toolchain versions (GCC only)
40+
│ ├── qnx/ # QNX SDP/QCC toolchain metadata
41+
│ └── version_matrix.bzl # Supported toolchain version definitions
42+
43+
├── templates # Templates for BUILD and cc_toolchain_config.bzl
44+
│ ├── common/
45+
│ ├── gcc/
46+
│ └── qcc/
47+
48+
├── tests # Functional tests for toolchain validation
49+
50+
├── docs # Sphinx documentation sources
51+
52+
├── tools # Utility scripts (e.g., QNX credential helper)
53+
54+
├── MODULE.bazel # Module declaration for Bzlmod
55+
├── BUILD
56+
├── LICENSE
57+
├── NOTICE
58+
└── README.md
59+
60+
```
61+
62+
## Toolchain Model
63+
64+
This repository does not contain compiler binaries. </br>
65+
Instead:
66+
- Toolchain **packages** describe how to fetch compiler binaries via `http_archive` or internal artifact storage.
67+
- Toolchain **configurations** describe how Bazel should use the binaries.
68+
- Toolchain **rules** and **extensions** generate and register toolchains.
69+
- Toolchain **tests** validate the toolchains.
70+
- This separation provides:
71+
- Hermetic configurations
72+
- Full reproducibility
73+
- Clear ownership boundaries
74+
- Easy addition of new compilers or versions
75+
76+
77+
## Using Toolchains in a Bazel Module
78+
79+
### GCC Example (Linux x86_64)
80+
81+
```starlark
82+
bazel_dep(name = "score_cpp_toolchains", version = "0.1.0")
83+
use_extension("@score_cpp_toolchains//bazel/extentions:gcc.bzl", "gcc")
84+
gcc.use(
85+
target_os = "linux",
86+
target_cpu = "x86_64",
87+
version = "12.2.0",
88+
use_default_package = True,
89+
)
90+
use_repo("score_gcc_toolchain", "score_gcc_toolchain_pkg")
91+
registry_toolchains("x86_64-linux-gcc-12.2.0")
92+
```
93+
94+
### QCC Example (QNX ARM64)
95+
96+
```starlark
97+
bazel_dep(name = "score_cpp_toolchains", version = "0.1.0")
98+
use_extension("@score_cpp_toolchains//bazel/extentions:gcc.bzl", "qcc")
99+
gcc.use(
100+
target_cpu = "arm64",
101+
sdp_version = "8.0.0",
102+
use_default_package = True,
103+
)
104+
use_repo("score_qcc_toolchain", "score_qcc_toolchain_pkg")
105+
registry_toolchains("x86_64-linux-qcc-12.2.0")
106+
```
107+
108+
## Configuration Flags
109+
110+
Shared flag sets live under:
111+
112+
- `configurations/common/flags.bzl`
113+
- `configurations/gcc/flags.bzl`
114+
- `configurations/qcc/flags.bzl`
115+
116+
These define:
117+
118+
- Base C/C++ flags
119+
- Optimization flags
120+
- PIC/PIE handling
121+
- Debug and sanitizer modes
122+
- Linker behavior
123+
- Warning levels
124+
125+
## Templates
126+
127+
Templates define how toolchain files are generated:
128+
129+
- `BUILD.template`
130+
- `cc_toolchain_config.bzl.template`
131+
132+
These templates simplify adding:
133+
134+
- New compiler versions
135+
- New compiler families
136+
- New OS/arch combinations
137+
138+
## Testing and Validation
139+
140+
Every toolchain must pass mandatory tests under `tests/`.
141+
142+
### Test Types
143+
144+
| Test Type | Purpose |
145+
|-----------|---------|
146+
| Smoke tests | Validate tool presence |
147+
| Feature tests | Verify compiler/linker capabilities |
148+
| Integration tests | Validate Bazel builds using the toolchain |
149+
150+
Tests cover:
151+
152+
- Simple compilation (`main.cpp`)
153+
- pthread linking (`main_pthread.cpp`)
154+
- Toolchain registration behavior
155+
156+
Testing is part of the **integration gate pipeline**.
157+
158+
159+
# Documentation
160+
161+
Documentation uses **Sphinx** and lives in `docs/`.
162+
163+
# Adding New Toolchain Versions
164+
165+
1. Update `packages/version_matrix.bzl`
166+
2. Add a package descriptor (e.g., `packages/linux/x86_64/gcc/13.1.0`)
167+
3. Generate configuration from templates
168+
4. Update flags if needed
169+
5. Run tests: `bazel test //tests/...`
170+
6. Submit through integration gate
171+
172+
---
173+
174+
# Tools
175+
176+
Utility scripts such as:
177+
178+
```
179+
tools/qnx_credential_helper.py
180+
```
181+
182+
are used for repository authentication flows.
183+
184+
---
185+
186+
# License
187+
188+
Distributed under:
189+
190+
- `LICENSE`
191+
- `NOTICE`

bazel/extentions/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************

0 commit comments

Comments
 (0)