Skip to content

Commit 5f27b23

Browse files
committed
Add Sphinx docs
Add Sphinx docs.
1 parent 2074ea6 commit 5f27b23

9 files changed

Lines changed: 653 additions & 14 deletions

docs/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13+
import importlib.util
14+
1315
project = "S-CORE Bazel C/C++ Toolchain configurations"
1416
project_url = "https://eclipse-score.github.io/bazel_cpp_toolchains"
1517
version = "0.1"
16-
extensions = [
18+
19+
_optional_extensions = [
1720
"sphinxcontrib.plantuml",
1821
"score_sphinx_bundle",
1922
]
23+
24+
extensions = [
25+
ext for ext in _optional_extensions if importlib.util.find_spec(ext) is not None
26+
]

docs/examples_and_validation.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
Examples And Validation
16+
=======================
17+
18+
Example Workspace Purpose
19+
-------------------------
20+
21+
The ``examples/`` directory is a separate Bazel workspace used as a lightweight
22+
integration test bed for the repository.
23+
24+
It demonstrates how consumers declare toolchains while also serving as the main
25+
smoke-test surface for validating that the generated toolchains can build and,
26+
where appropriate, run example targets.
27+
28+
Important Files
29+
---------------
30+
31+
``examples/MODULE.bazel``
32+
Declares representative Linux and QNX toolchain repositories and wires the
33+
example workspace back to the local checkout with ``local_path_override``.
34+
35+
``examples/.bazelrc``
36+
Defines named Bazel configurations that activate the generated toolchains and
37+
platforms.
38+
39+
``examples/BUILD``
40+
Contains small C++ targets used to verify compilation, linking, pthread
41+
support, and sanitizer integration.
42+
43+
``examples/tests/toolchain_smoke_tests.sh``
44+
Matrix runner that maps each configuration name to a small build or test
45+
sequence.
46+
47+
Smoke-Test Matrix
48+
-----------------
49+
50+
The example workspace currently validates these configuration groups:
51+
52+
- Linux host toolchains
53+
- Linux cross-compilation toolchains
54+
- runtime-specific Linux toolchains such as AutoSD and EB corbos Linux for Safety Applications
55+
- packaged QNX toolchains
56+
- locally built QNX SDP toolchains
57+
58+
The smoke-test runner isolates Bazel state per configuration so it does not rely
59+
on ``bazel clean --expunge`` between cases.
60+
61+
Useful Commands
62+
---------------
63+
64+
.. code-block:: bash
65+
66+
cd examples
67+
./test.sh --list
68+
./test.sh host_config_1
69+
./test.sh --keep-going
70+
71+
What The Tests Prove
72+
--------------------
73+
74+
The example workspace is not intended to be an exhaustive compiler correctness
75+
suite. Instead, it answers a narrower question: did the configuration repository
76+
produce a usable toolchain definition for each supported scenario?
77+
78+
In practice this means checking:
79+
80+
- successful compilation with the selected compiler and sysroot,
81+
- correct toolchain registration and platform matching,
82+
- basic linking behavior,
83+
- feature coverage such as pthread-enabled builds,
84+
- optional sanitizer feature wiring for the local Linux toolchain path.

docs/extension_api.rst

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
Extension API
16+
=============
17+
18+
Consumer Entry Point
19+
--------------------
20+
21+
Consumers interact with this repository through the ``gcc`` module extension in
22+
``@score_bazel_cpp_toolchains//extensions:gcc.bzl``.
23+
24+
Typical usage looks like this:
25+
26+
.. code-block:: starlark
27+
28+
bazel_dep(name = "score_bazel_cpp_toolchains", version = "0.4.0")
29+
30+
gcc = use_extension("@score_bazel_cpp_toolchains//extensions:gcc.bzl", "gcc")
31+
32+
gcc.toolchain(
33+
name = "score_gcc_toolchain",
34+
target_cpu = "x86_64",
35+
target_os = "linux",
36+
version = "12.2.0",
37+
use_default_package = True,
38+
)
39+
40+
use_repo(gcc, "score_gcc_toolchain")
41+
42+
Public Tags
43+
-----------
44+
45+
``gcc.toolchain(...)``
46+
Declares a toolchain repository to generate.
47+
48+
``gcc.sdp(...)``
49+
Declares a package repository explicitly. This is used when the package is
50+
not taken from the default version matrix or when local QNX SDP generation is
51+
required.
52+
53+
``gcc.toolchain(...)`` Attributes
54+
---------------------------------
55+
56+
Required attributes:
57+
58+
- ``name``: name of the generated repository
59+
- ``target_cpu``: target CPU, currently ``x86_64`` or ``aarch64``
60+
- ``target_os``: target OS, currently ``linux`` or ``qnx``
61+
62+
Common package selection attributes:
63+
64+
- ``use_default_package``: resolve package metadata from ``packages/version_matrix.bzl``
65+
- ``version``: GCC version string for Linux toolchains
66+
- ``sdp_version``: QNX SDP version string
67+
- ``sdk_version``: alternative SDK identifier used in matrix resolution
68+
- ``sdp_to_link``: override the package repository name that the toolchain uses
69+
70+
Flag and runtime attributes:
71+
72+
- ``extra_compile_flags``
73+
- ``extra_c_compile_flags``
74+
- ``extra_cxx_compile_flags``
75+
- ``extra_link_flags``
76+
- ``ld_library_paths``
77+
- ``runtime_ecosystem``
78+
- ``use_base_constraints_only``
79+
80+
QNX-specific attributes:
81+
82+
- ``license_path``
83+
- ``license_info_variable``
84+
- ``license_info_url``
85+
86+
``gcc.sdp(...)`` Attributes
87+
---------------------------
88+
89+
The ``gcc.sdp`` tag defines the package side of the toolchain setup. Important
90+
attributes are:
91+
92+
- ``name``: repository name for the package
93+
- ``build_file``: BUILD file that exposes the package contents as Bazel targets
94+
- ``url`` and ``sha256``: archive or installer source
95+
- ``strip_prefix``: extraction prefix for packaged archives
96+
- ``mode``: ``archive`` or ``build``
97+
- ``patchset``: QNX SDP patchset definition used in build mode
98+
- ``target_cpu``: target CPU used when building an SDP locally
99+
100+
Activation In A Workspace
101+
-------------------------
102+
103+
Declaring a toolchain repository is not enough on its own. Consumers still need
104+
to activate the generated toolchain during Bazel analysis, typically with a
105+
configuration such as:
106+
107+
.. code-block:: text
108+
109+
--extra_toolchains=@score_gcc_toolchain//:x86_64-linux-gcc_12.2.0
110+
111+
The example workspace under ``examples/`` provides complete ``.bazelrc``
112+
configurations for this activation step.
113+
114+
Behavior Notes
115+
--------------
116+
117+
- The extension is intended for the root module.
118+
- When ``use_default_package`` is enabled, the version matrix can inject extra
119+
include and link flags required by non-standard sysroot layouts.
120+
- QNX toolchains use additional licensing and include-path parameters that do
121+
not apply to Linux toolchains.

docs/generation_flow.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
Generation Flow
16+
===============
17+
18+
End-To-End Flow
19+
---------------
20+
21+
The repository turns a small ``MODULE.bazel`` declaration into a generated
22+
toolchain repository through these steps:
23+
24+
1. ``extensions/gcc.bzl`` collects ``gcc.toolchain`` and ``gcc.sdp`` tags.
25+
2. Package metadata is resolved from ``packages/version_matrix.bzl`` or from an
26+
explicit ``gcc.sdp`` declaration.
27+
3. ``rules/gcc.bzl`` renders a BUILD file and configuration files into a new
28+
repository.
29+
4. Platform-specific templates from ``templates/linux/`` or ``templates/qnx/``
30+
are populated with CPU, version, licensing, and flag information.
31+
5. The consuming workspace enables the generated toolchain with
32+
``--extra_toolchains`` and compatible platform constraints.
33+
34+
Subsystem Roles
35+
---------------
36+
37+
``packages/version_matrix.bzl``
38+
Defines the supported package matrix. Each entry maps a logical toolchain key
39+
to download metadata and, when needed, extra compiler or linker flags.
40+
41+
``rules/common.bzl``
42+
Provides small helpers that convert lists of flags into the Bazel
43+
``flag_group`` representation needed by the templates and repository rules.
44+
45+
``rules/gcc.bzl``
46+
Generates the toolchain repository. It decides whether Linux or QNX template
47+
content is required, performs placeholder substitution, and emits the final
48+
``BUILD``, ``cc_toolchain_config.bzl``, ``flags.bzl``, and Linux ``gcov``
49+
wrapper files.
50+
51+
``rules/qnx_sdp_gen.bzl``
52+
Handles the special case where a QNX SDP must be built locally rather than
53+
downloaded as a ready-made archive.
54+
55+
Template Families
56+
-----------------
57+
58+
Linux templates:
59+
60+
- ``templates/linux/cc_toolchain_config.bzl.template``
61+
- ``templates/linux/cc_toolchain_flags.bzl.template``
62+
- ``templates/linux/cc_gcov_wrapper.template``
63+
64+
QNX templates:
65+
66+
- ``templates/qnx/cc_toolchain_config.bzl.template``
67+
- ``templates/qnx/cc_toolchain_flags.bzl.template``
68+
69+
Shared template:
70+
71+
- ``templates/BUILD.template``
72+
73+
Important Implementation Details
74+
--------------------------------
75+
76+
- Some package definitions rely on the ``%{toolchain_pkg}%`` placeholder, which
77+
is rewritten to the canonical Bzlmod repository name during repository-rule
78+
generation.
79+
- QNX ``aarch64`` is mapped internally to ``aarch64le`` where required by the
80+
underlying SDK layout.
81+
- SDP version ``8.0.3`` is normalized to ``8.0.0`` in the generated toolchain
82+
configuration because platform constraint support currently uses the older
83+
identifier.
84+
- Linux toolchains generate an extra ``gcov_wrapper`` script to work around the
85+
current ``rules_cc`` coverage integration behavior.
86+
87+
Version Matrix Responsibilities
88+
-------------------------------
89+
90+
The version matrix is more than a list of URLs. It is also the place where the
91+
repository centralizes:
92+
93+
- package build-file selection,
94+
- archive extraction prefixes,
95+
- sysroot-specific compiler flags,
96+
- extra link flags,
97+
- compiler library search paths,
98+
- runtime-ecosystem variants such as AutoSD or EB corbos Linux for Safety Applications.

docs/index.rst

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,49 @@
1111
#
1212
# SPDX-License-Identifier: Apache-2.0
1313
# *******************************************************************************
14-
Bazel C/C++ Toolchain Config Documentation
15-
============================
1614
17-
TBD
15+
S-CORE Bazel C/C++ Toolchain Configuration Repository
16+
=====================================================
1817

19-
.. contents:: Table of Contents
20-
:depth: 2
21-
:local:
18+
This repository contains the configuration layer for S-CORE C and C++
19+
toolchains used in Bazel builds. It does not ship compiler binaries. Instead,
20+
it defines the metadata, templates, repository rules, module extension logic,
21+
and validation workspace needed to fetch and register external toolchain
22+
packages reproducibly.
2223

23-
Purpose
24-
-------
25-
TBD
24+
The documentation below is organized around the main subsystems of the
25+
repository: how consumers declare toolchains, how Bazel repositories are
26+
generated, how platform packages are described, how the example workspace
27+
validates the setup, and how QNX-specific authentication and licensing fit in.
2628

27-
Summary
28-
-------
29+
.. toctree::
30+
:maxdepth: 2
31+
:caption: Contents
2932

30-
**Library:** `Score C/C++ Toolchain configurations`
33+
overview
34+
repository_layout
35+
extension_api
36+
generation_flow
37+
examples_and_validation
38+
qnx_integration
39+
maintenance
3140

32-
**Type:** Bazel toolchain configurations
41+
Quick Summary
42+
-------------
43+
44+
**Library:** S-CORE Bazel C/C++ toolchain configurations
45+
46+
**Type:** Bazel module with repository rules, templates, and example validation
47+
48+
**Primary consumer entry point:** ``@score_bazel_cpp_toolchains//extensions:gcc.bzl``
49+
50+
**Main validation surface:** ``examples/`` smoke-test workspace
51+
52+
Key Capabilities
53+
----------------
54+
55+
- Define Linux and QNX toolchains through a Bzlmod extension.
56+
- Resolve default package metadata through ``packages/version_matrix.bzl``.
57+
- Generate toolchain repositories from platform-specific templates.
58+
- Support both packaged and locally built QNX SDP flows.
59+
- Validate toolchain selections through the example workspace test matrix.

0 commit comments

Comments
 (0)