Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/qnx_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ QNX directory structure after extraction. A typical installation looks like:
└── ...
```

Where `{TRIPLE}` is the target triple, e.g. `aarch64-unknown-nto-qnx7.1.0`.
Where `{TRIPLE}` is the target triple, e.g. `aarch64-unknown-nto-qnx8.0.0`.

The toolchain locates these directories via the `QNX_HOST` and `QNX_TARGET` environment
variables, which are set automatically by the toolchain's `sdp_env` feature.
Expand Down
Empty file.
79 changes: 0 additions & 79 deletions packages/qnx/aarch64/sdp/7.1.0/sdp.BUILD

This file was deleted.

5 changes: 5 additions & 0 deletions packages/qnx/aarch64/sdp/8.0.0/sdp.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ filegroup(
srcs = glob(["target/qnx/**/*"]),
)

filegroup(
name = "sysroot_dir",
srcs = ["."],
)

filegroup(
name = "target_dir",
srcs = ["target/qnx"],
Expand Down
Empty file.
79 changes: 0 additions & 79 deletions packages/qnx/x86_64/sdp/7.1.0/sdp.BUILD

This file was deleted.

5 changes: 5 additions & 0 deletions packages/qnx/x86_64/sdp/8.0.0/sdp.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ filegroup(
srcs = glob(["target/qnx/**/*"]),
)

filegroup(
name = "sysroot_dir",
srcs = ["."],
)

filegroup(
name = "target_dir",
srcs = ["target/qnx"],
Expand Down
131 changes: 49 additions & 82 deletions rules/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,56 +43,14 @@ def dict_union(x, y):
z.update(y)
return z

def _get_cc_config_linux(rctx):
"""Generates cc_toolchain_config filegroup and rule content for Linux targets.
def _get_cc_config(rctx):
"""Generates cc_toolchain_config filegroup and rule content for a toolchain.

Args:
rctx: RepositoryContext object with toolchain attributes.

Returns:
str: BUILD file content defining filegroup and cc_toolchain_config for Linux.
"""
return """filegroup(
name = "all_files",
srcs = [
"@{tc_pkg_repo}//:all_files",
"gcov_wrapper",
]
)

cc_toolchain_config(
name = "cc_toolchain_config",
ar_binary = "@{tc_pkg_repo}//:ar",
cc_binary = "@{tc_pkg_repo}//:cc",
cxx_binary = "@{tc_pkg_repo}//:cxx",
gcov_binary = "@{tc_pkg_repo}//:gcov",
strip_binary = "@{tc_pkg_repo}//:strip",
sysroot = "@{tc_pkg_repo}//:sysroot_dir",
target_cpu = "{tc_cpu}",
target_os = "{tc_os}",
known_features = _KNOWN_FEATURES,
enabled_features = _ENABLED_FEATURES,
cxx_builtin_include_directories = ["@{tc_pkg_repo}//:cxx_builtin_include_directories"],
extra_known_features = {tc_extra_known_features},
extra_enabled_features = {tc_extra_enabled_features},
visibility = ["//visibility:public"],
)
""".format(
tc_pkg_repo = rctx.attr.tc_pkg_repo,
tc_cpu = rctx.attr.tc_cpu,
tc_os = rctx.attr.tc_os,
tc_extra_known_features = label_list_to_string(rctx.attr.extra_known_features),
tc_extra_enabled_features = label_list_to_string(rctx.attr.extra_enabled_features),
)

def _get_cc_config_qnx(rctx):
"""Generates cc_toolchain_config filegroup and rule content for QNX targets.

Args:
rctx: RepositoryContext object with toolchain attributes.

Returns:
str: BUILD file content defining filegroup and cc_toolchain_config for QNX.
str: BUILD file content defining filegroup and cc_toolchain_config.
"""
return """
filegroup(
Expand All @@ -110,6 +68,7 @@ cc_toolchain_config(
cxx_binary = "@{tc_pkg_repo}//:cxx",
gcov_binary = "@{tc_pkg_repo}//:gcov",
strip_binary = "@{tc_pkg_repo}//:strip",
sysroot = "@{tc_pkg_repo}//:sysroot_dir",
cxx_builtin_include_directories = ["@{tc_pkg_repo}//:cxx_builtin_include_directories"],
target_cpu = "{tc_cpu}",
target_os = "{tc_os}",
Expand All @@ -133,7 +92,8 @@ def get_custom_cc_features_linux(rctx):
def get_custom_cc_features_qnx(rctx, canonical_pkg_name):
# host_dir/target_dir must be plain resolved paths, not labels: cc_args'
# `env` rejects format() variables that aren't builtin cc_toolchain
# variables ("The variable host_dir does not exist").
# variables ("The variable host_dir does not exist"). _get_gcov_path has
# the same limitation for the gcov binary path.

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

Expand Down Expand Up @@ -181,6 +141,38 @@ def _apply_sdp_version_mapping(sdp_version):
"""
return _SDP_VERSION_MAPPING.get(sdp_version, sdp_version)

def _get_gcov_path(rctx, canonical_pkg_name):
"""Computes the gcov binary path used by the gcov_wrapper template.

NOTE: The path is hand-built using Bazel's default exec-path convention
("external/<repo>/...") because a repository rule cannot resolve a
label's execpath (that only exists at analysis/execution time). This will
break under --experimental_sibling_repository_layout ("../<repo>/...").
See the related TODO in get_custom_cc_features_qnx.

Args:
rctx: RepositoryContext object with toolchain attributes.
canonical_pkg_name: str, canonical repository name of the toolchain package.

Returns:
str: Path to the gcov binary, relative to the execroot.
"""
if rctx.attr.tc_os == _OS_LINUX:
return "external/{canonical_pkg}/bin/{cpu}-unknown-linux-gnu-gcov".format(
canonical_pkg = canonical_pkg_name,
cpu = rctx.attr.tc_cpu,
)

mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version)
if rctx.attr.tc_cpu == _CPU_AARCH64:
gcov_triple = _TRIPLE_AARCH64_QNX_FMT.format(sdp = mapped_sdp_version)
else:
gcov_triple = _TRIPLE_GENERIC_QNX_FMT.format(cpu = rctx.attr.tc_cpu, sdp = mapped_sdp_version)
return "external/{canonical_pkg}/host/linux/x86_64/usr/bin/{triple}-gcov".format(
canonical_pkg = canonical_pkg_name,
triple = gcov_triple,
)

def _get_canonical_pkg_name(rctx):
"""Resolves the canonical repository name for the toolchain package.

Expand Down Expand Up @@ -216,16 +208,13 @@ def _impl(rctx):
"""
tc_identifier = rctx.attr.tc_identifier

if rctx.attr.tc_os == _OS_QNX:
cc_toolchain_config = _get_cc_config_qnx(rctx)
elif rctx.attr.tc_os == _OS_LINUX:
cc_toolchain_config = _get_cc_config_linux(rctx)
else:
if rctx.attr.tc_os not in (_OS_QNX, _OS_LINUX):
fail("Unsupported OS '{}' detected! Supported values: {}, {}".format(
rctx.attr.tc_os,
_OS_LINUX,
_OS_QNX,
))
cc_toolchain_config = _get_cc_config(rctx)

# Build constraint identifiers for toolchain registration
tc_identifier_short_1 = ""
Expand Down Expand Up @@ -321,37 +310,15 @@ def _impl(rctx):
template_dict,
)

if rctx.attr.tc_os == _OS_LINUX:
# There is an issue with gcov and cc_toolchain config.
# See: https://github.com/bazelbuild/rules_cc/issues/351
rctx.template(
"gcov_wrapper",
rctx.attr._cc_gcov_wrapper_script,
{
"%{tc_gcov_path}": "external/{canonical_pkg}/bin/{cpu}-unknown-linux-gnu-gcov".format(
canonical_pkg = canonical_pkg_name,
cpu = rctx.attr.tc_cpu,
),
},
)
elif rctx.attr.tc_os == _OS_QNX:
# Generate gcov wrapper for QNX toolchains to enable `bazel coverage`.
# See: https://github.com/bazelbuild/rules_cc/issues/351
mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version)
if rctx.attr.tc_cpu == _CPU_AARCH64:
gcov_triple = _TRIPLE_AARCH64_QNX_FMT.format(sdp = mapped_sdp_version)
else:
gcov_triple = _TRIPLE_GENERIC_QNX_FMT.format(cpu = rctx.attr.tc_cpu, sdp = mapped_sdp_version)
rctx.template(
"gcov_wrapper",
rctx.attr._cc_gcov_wrapper_script,
{
"%{tc_gcov_path}": "external/{canonical_pkg}/host/linux/x86_64/usr/bin/{triple}-gcov".format(
canonical_pkg = canonical_pkg_name,
triple = gcov_triple,
),
},
)
# There is an issue with gcov and cc_toolchain config.
# See: https://github.com/bazelbuild/rules_cc/issues/351
rctx.template(
"gcov_wrapper",
rctx.attr._cc_gcov_wrapper_script,
{
"%{tc_gcov_path}": _get_gcov_path(rctx, canonical_pkg_name),
},
)

gcc_toolchain = repository_rule(
implementation = _impl,
Expand Down
Empty file removed templates/linux/BUILD
Empty file.
Empty file removed templates/qnx/BUILD
Empty file.
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