Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion extensions/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@score_bazel_cpp_toolchains//packages:version_matrix.bzl", "VERSION_MATRIX")
load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING")
load("@score_bazel_cpp_toolchains//rules:common.bzl", "QNX_SDP_TO_GCC_VERSION", "SDP_VERSION_MAPPING")
load("@score_bazel_cpp_toolchains//rules:gcc.bzl", "gcc_toolchain")

# Constants
_PACKAGE_SUFFIX = "_pkg"
_IDENTIFIER_GCC = "gcc"
_IDENTIFIER_SDK = "sdk"
_IDENTIFIER_SDP = "sdp"
_OS_QNX = "qnx"
_SUPPORTED_CPUS = ["x86_64", "aarch64"]
_SUPPORTED_OSS = ["linux", "qnx"]
_SDP_VERSION_MAPPING = SDP_VERSION_MAPPING
_QNX_SDP_TO_GCC_VERSION = QNX_SDP_TO_GCC_VERSION

# GCC interface API for archive tag class
_attrs_sdp = {
Expand Down Expand Up @@ -381,6 +383,39 @@ def _resolve_identifier(toolchain_info):

return "{}_{}".format(identifier, version)

def _resolve_qnx_gcc_version(toolchain_info):
"""Defaults or validates gcc_version against the GCC version bundled with sdp_version.

Args:
toolchain_info: dict holding toolchain configuration (modified in-place).

Fails:
If an explicit `version` doesn't match the GCC version bundled with the SDP's
major release, per QNX_SDP_TO_GCC_VERSION.
"""
if toolchain_info["tc_os"] != _OS_QNX or toolchain_info["sdp_version"] == "":
return

sdp_major = toolchain_info["sdp_version"].split(".")[0]
expected_gcc_version = _QNX_SDP_TO_GCC_VERSION.get(sdp_major)
if expected_gcc_version == None:
return

if toolchain_info["gcc_version"] == "":
toolchain_info["gcc_version"] = expected_gcc_version
elif toolchain_info["gcc_version"] != expected_gcc_version:
fail((
"Toolchain '{name}': version = '{actual}' does not match GCC {expected}, " +
"which is what QNX SDP {sdp_major}.x (sdp_version = '{sdp_version}') ships. " +
"Either drop the explicit version or set it to '{expected}'."
).format(
name = toolchain_info["name"],
actual = toolchain_info["gcc_version"],
expected = expected_gcc_version,
sdp_major = sdp_major,
sdp_version = toolchain_info["sdp_version"],
))

def _get_info(mctx):
"""Extracts and validates toolchain and package information from module configuration.

Expand Down Expand Up @@ -415,11 +450,14 @@ def _get_info(mctx):

# need to be sure not to link package in case of system toolchain.
if tc["use_system_toolchain"]:
_resolve_qnx_gcc_version(tc)
continue

if tc["use_default_package"]:
packages.append(_create_and_link_sdp(tc))

_resolve_qnx_gcc_version(tc)

return toolchains, packages

def _impl(mctx):
Expand Down
43 changes: 0 additions & 43 deletions features/custom/qnx/gcc_version_flags/BUILD
Original file line number Diff line number Diff line change
@@ -1,43 +0,0 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")

cc_args(
name = "qnx_gcc_version_compile_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = select({
"@score_bazel_platforms//settings:aarch64-qnx8": ["-V12.2.0,gcc_ntoaarch64le"],
"@score_bazel_platforms//settings:x86_64-qnx8": ["-V12.2.0,gcc_ntox86_64"],
}),
)

cc_args(
name = "qnx_gcc_version_link_args",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = select({
"@score_bazel_platforms//settings:aarch64-qnx8": ["-V12.2.0,gcc_ntoaarch64le_cxx"],
"@score_bazel_platforms//settings:x86_64-qnx8": ["-V12.2.0,gcc_ntox86_64_cxx"],
}),
)

cc_feature(
name = "gcc_version_flags",
args = [
":qnx_gcc_version_compile_args",
":qnx_gcc_version_link_args",
],
feature_name = "gcc_version_flags",
visibility = ["//visibility:public"],
)
47 changes: 47 additions & 0 deletions features/custom/qnx/gcc_version_flags/feature.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")

def make_gcc_version_flags_feature(cpu, version):
"""Creates a feature pinning qcc to the toolchain instance's resolved GCC version.

Args:
cpu: str, normalized target CPU as used in qcc's `gcc_nto*` identifiers
(e.g. "aarch64le", "x86_64").
version: str, GCC version resolved for this toolchain instance.

Returns:
A feature definition for the gcc_version_flags toolchain.
"""
cc_args(
name = "gcc_version_compile_args",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = ["-V{version},gcc_nto{cpu}".format(version = version, cpu = cpu)],
)

cc_args(
name = "gcc_version_link_args",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = ["-V{version},gcc_nto{cpu}_cxx".format(version = version, cpu = cpu)],
)

cc_feature(
name = "gcc_version_flags",
feature_name = "gcc_version_flags",
args = [
":gcc_version_compile_args",
":gcc_version_link_args",
],
)
2 changes: 1 addition & 1 deletion features/custom/qnx/make_cc_features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _QNX_FEATURES = [
("@score_bazel_cpp_toolchains//features/native/markers:dbg", False), # Bazel auto-toggles via -c dbg
("@score_bazel_cpp_toolchains//features/native/markers:no_legacy_features", True),
("@score_bazel_cpp_toolchains//features/native/unfiltered_compile_flags", True),
("@score_bazel_cpp_toolchains//features/custom/qnx/gcc_version_flags", True),
(":gcc_version_flags", True), # per-instance, see templates/BUILD.template
("@score_bazel_cpp_toolchains//features/native/default_compile_flags", True),
("@score_bazel_cpp_toolchains//features/native/random_seed", True),
("@score_bazel_cpp_toolchains//features/native/include_paths", True),
Expand Down
7 changes: 7 additions & 0 deletions rules/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ SDP_VERSION_MAPPING = {
"8.0.4": "8.0.0",
}

# GCC version bundled with each QNX SDP major release, keyed by SDP major version.
# Used to default/validate a toolchain's `version` attribute from its `sdp_version`.
QNX_SDP_TO_GCC_VERSION = {
"7": "8.3.0",
"8": "12.2.0",
}

def get_flag_strings(flags):
"""Converts a list of warning flags into a Bazel flag group representation.

Expand Down
10 changes: 9 additions & 1 deletion rules/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def get_custom_cc_features_qnx(rctx, canonical_pkg_name):

# TODO: Once Bazel enables label resolution in cc_args' env, we can use labels instead of resolved paths.

custom_load = """load("@score_bazel_cpp_toolchains//features/custom/qnx/sdp_env:feature.bzl", "make_sdp_env_feature")"""
custom_load = """load("@score_bazel_cpp_toolchains//features/custom/qnx/sdp_env:feature.bzl", "make_sdp_env_feature")
load("@score_bazel_cpp_toolchains//features/custom/qnx/gcc_version_flags:feature.bzl", "make_gcc_version_flags_feature")"""
custom_features = """
make_sdp_env_feature(
host_dir = "{host_dir}",
Expand All @@ -106,12 +107,19 @@ make_sdp_env_feature(
license_info_variable = "{license_info_variable}",
license_info_value = "{license_info_value}",
)

make_gcc_version_flags_feature(
cpu = "{gcc_version_cpu}",
version = "{gcc_version}",
)
""".format(
host_dir = "/proc/self/cwd/external/{canonical_pkg}/host/linux/x86_64".format(canonical_pkg = canonical_pkg_name),
target_dir = "/proc/self/cwd/external/{canonical_pkg}/target/qnx".format(canonical_pkg = canonical_pkg_name),
license_path = rctx.attr.license_path,
license_info_variable = rctx.attr.license_info_variable,
license_info_value = rctx.attr.license_info_value,
gcc_version_cpu = _normalize_cpu(rctx.attr.tc_cpu),
gcc_version = rctx.attr.gcc_version,
)
return custom_load, custom_features

Expand Down
2 changes: 1 addition & 1 deletion tests/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading