From 3e9e0f0bca1743f96f9460a071bf4863110a2607 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Thu, 27 Aug 2026 16:56:09 +0200 Subject: [PATCH 1/7] Temp commit --- docs/maintenance.md | 60 ++++++++ features/BUILD | 99 ++++++++++++ features/archiver_flags/BUILD | 77 ++++++++++ features/compiler_input_flags/BUILD | 34 +++++ features/compiler_library_search_paths/BUILD | 37 +++++ features/compiler_output_flags/BUILD | 54 +++++++ features/default_compile_flags/BUILD | 141 ++++++++++++++++++ features/default_link_flags/BUILD | 90 +++++++++++ features/dependency_file/BUILD | 88 +++++++++++ features/fission_support/BUILD | 30 ++++ features/force_pic_flags/BUILD | 30 ++++ features/fully_static_link/BUILD | 33 ++++ features/gcc_coverage_map_format/BUILD | 62 ++++++++ features/include_paths/BUILD | 59 ++++++++ features/includes/BUILD | 35 +++++ features/libraries_to_link/BUILD | 105 +++++++++++++ features/library_search_directories/BUILD | 32 ++++ features/linker_param_file/BUILD | 34 +++++ features/linkstamps/BUILD | 32 ++++ features/linux_platform/BUILD | 20 +++ features/markers/BUILD | 90 +++++++++++ features/output_execpath_flags/BUILD | 34 +++++ features/per_object_debug_info/BUILD | 39 +++++ features/pic/BUILD | 37 +++++ features/preprocessor_defines/BUILD | 31 ++++ features/qnx_platform/BUILD | 20 +++ features/random_seed/BUILD | 36 +++++ .../runtime_library_search_directories/BUILD | 74 +++++++++ features/shared_flag/BUILD | 29 ++++ features/static_libgcc/BUILD | 39 +++++ features/strip_debug_symbols/BUILD | 30 ++++ features/sysroot_link_flags/BUILD | 31 ++++ features/unfiltered_compile_flags/BUILD | 37 +++++ features/use_pthread/BUILD | 29 ++++ features/user_compile_flags/BUILD | 32 ++++ features/user_link_flags/BUILD | 32 ++++ 36 files changed, 1772 insertions(+) create mode 100644 features/BUILD create mode 100644 features/archiver_flags/BUILD create mode 100644 features/compiler_input_flags/BUILD create mode 100644 features/compiler_library_search_paths/BUILD create mode 100644 features/compiler_output_flags/BUILD create mode 100644 features/default_compile_flags/BUILD create mode 100644 features/default_link_flags/BUILD create mode 100644 features/dependency_file/BUILD create mode 100644 features/fission_support/BUILD create mode 100644 features/force_pic_flags/BUILD create mode 100644 features/fully_static_link/BUILD create mode 100644 features/gcc_coverage_map_format/BUILD create mode 100644 features/include_paths/BUILD create mode 100644 features/includes/BUILD create mode 100644 features/libraries_to_link/BUILD create mode 100644 features/library_search_directories/BUILD create mode 100644 features/linker_param_file/BUILD create mode 100644 features/linkstamps/BUILD create mode 100644 features/linux_platform/BUILD create mode 100644 features/markers/BUILD create mode 100644 features/output_execpath_flags/BUILD create mode 100644 features/per_object_debug_info/BUILD create mode 100644 features/pic/BUILD create mode 100644 features/preprocessor_defines/BUILD create mode 100644 features/qnx_platform/BUILD create mode 100644 features/random_seed/BUILD create mode 100644 features/runtime_library_search_directories/BUILD create mode 100644 features/shared_flag/BUILD create mode 100644 features/static_libgcc/BUILD create mode 100644 features/strip_debug_symbols/BUILD create mode 100644 features/sysroot_link_flags/BUILD create mode 100644 features/unfiltered_compile_flags/BUILD create mode 100644 features/use_pthread/BUILD create mode 100644 features/user_compile_flags/BUILD create mode 100644 features/user_link_flags/BUILD diff --git a/docs/maintenance.md b/docs/maintenance.md index 2a91f65..f41e79e 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -73,6 +73,66 @@ means a broken build rather than a silent fallback. > libraries (e.g. AutoSD) cannot link fully static binaries, so that feature is > opt-in and its test is marked incompatible with such platforms. +## In-Progress: Declarative `features/` Catalog + +`features/` defines the same toolchain features declaratively with +`@rules_cc//cc/toolchains` (`cc_feature` / `cc_args` / `cc_feature_set`), as a +parallel catalog alongside the legacy `feature()` Starlark in +`templates/*/cc_toolchain_config.bzl.template`. The **real** toolchain +generation still goes exclusively through the legacy templates, rendered by +`rules/gcc.bzl`; nothing in the repository currently consumes +`//features:linux_features` or `//features:qnx_features`. + +`features/BUILD` defines two ordered `cc_feature_set` targets, `linux_features` +and `qnx_features`, whose `all_of` order intentionally mirrors the exact +feature order in the corresponding template's `features = [...]` list (order is +significant there — see the "order of the features is relevant" comment in both +templates). Platform membership (Linux-only vs. QNX-only vs. both) is expressed +purely by which set a feature is listed in; individual `cc_feature` targets no +longer carry `requires_any_of = ["//features/linux_platform"]` / +`["//features/qnx_platform"]` gates. `all_wall_warnings`, `minimal_warnings`, +`strict_warnings`, and `warnings_as_errors` were removed from `features/` +entirely — they are superseded by `score_cpp_policies` and injected via +`extra_known_features` / `extra_enabled_features` instead. + +### Open problem: the `extra_*_flags` hooks + +`extra_compile_flags`, `extra_c_compile_flags`, `extra_cxx_compile_flags`, and +`extra_link_flags` are intentionally **not** part of `linux_features` / +`qnx_features` yet. They don't fit the static-label model the rest of +`features/` uses: + +- **Content is dynamic per toolchain instance.** The flag lists come from + `gcc.toolchain(extra_compile_flags = [...])` (see `extensions/gcc.bzl`) and + are substituted via `%{...}` placeholders directly into the generated + `cc_toolchain_config.bzl` by `rules/gcc.bzl` (`_impl`, `get_flag_groups()`) — + not a fixed BUILD label a `cc_feature_set` could reference. +- **Position is order-sensitive.** `extra_compile_flags` / + `extra_c_compile_flags` / `extra_cxx_compile_flags` must land after + `preprocessor_defines` / `default_compile_flags` and before + `user_compile_flags`; `extra_link_flags` must land near the end, after + `user_link_flags`. The existing `extra_known_features` / + `extra_enabled_features` injection mechanism (used for `score_cpp_policies` + sanitizers/warnings) always appends via `features.extend(...)` at the very + end of the list — safe for position-independent features, unsafe for these. + +Options considered, decision still pending: + +1. **Leave as-is.** Keep the raw `%{...}` template-substitution mechanism + exactly as today; a static label structurally can't hold per-invocation + dynamic content, so these 4 simply stay outside the `features/` catalog. + Zero risk, matches current shipped behavior. +2. **Label-typed "slots".** Add label attributes (e.g. + `extra_compile_flags_target = attr.label(providers = [CcArgsInfo])`) to the + toolchain config rule. The caller defines their own small `cc_args`/ + `cc_feature` target with whatever flags they want and passes its label in; + the rule splices that label into the fixed position within the ordered + feature list — same trick as `extra_known_features`, but inserted at an + index instead of appended at the end. Preserves both order (repo controls + position) and dynamism (caller controls content). This is a real API change + touching `extensions/gcc.bzl` attrs, `rules/gcc.bzl` codegen, and + `docs/extension_api.md`. + ## Common Gotchas - runtime-specific toolchains may need extra include and link flags that do not diff --git a/features/BUILD b/features/BUILD new file mode 100644 index 0000000..a353617 --- /dev/null +++ b/features/BUILD @@ -0,0 +1,99 @@ +# ******************************************************************************* +# Copyright (c) 2025 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:feature_set.bzl", "cc_feature_set") + +# Order mirrors templates/linux/cc_toolchain_config.bzl.template's `features = [...]` list, +# since feature order determines command-line flag order. +cc_feature_set( + name = "linux", + all_of = [ + "//features/markers:no_legacy_features", + "//features/compiler_library_search_paths", + "//features/markers:dbg", + "//features/unfiltered_compile_flags", + "//features/markers:gnu11", + "//features/default_compile_flags", + "//features/random_seed", + "//features/include_paths", + "//features/preprocessor_defines", + "//features/user_compile_flags", + "//features/compiler_input_flags", + "//features/compiler_output_flags", + "//features/dependency_file", + "//features/per_object_debug_info", + "//features/includes", + "//features/default_link_flags", + "//features/archiver_flags", + "//features/linker_param_file", + "//features/library_search_directories", + "//features/shared_flag", + "//features/output_execpath_flags", + "//features/runtime_library_search_directories", + "//features/libraries_to_link", + "//features/user_link_flags", + "//features/linkstamps", + "//features/fission_support", + "//features/force_pic_flags", + "//features/strip_debug_symbols", + "//features/static_libgcc", + "//features/fully_static_link", + "//features/sysroot_link_flags", + "//features/use_pthread", + "//features/markers:opt", + "//features/markers:supports_dynamic_linker", + "//features/markers:supports_pic", + "//features/pic", + "//features/markers:supports_header_path_normalization", + "//features/markers:supports_fission", + "//features/markers:coverage", + "//features/gcc_coverage_map_format", + ], + visibility = ["//visibility:public"], +) + +# Order mirrors templates/qnx/cc_toolchain_config.bzl.template's `features = [...]` list, +# since feature order determines command-line flag order. +cc_feature_set( + name = "qnx", + all_of = [ + "//features/markers:dbg", + "//features/markers:no_legacy_features", + "//features/unfiltered_compile_flags", + "//features/default_compile_flags", + "//features/random_seed", + "//features/include_paths", + "//features/preprocessor_defines", + "//features/user_compile_flags", + "//features/compiler_input_flags", + "//features/compiler_output_flags", + "//features/markers:dependency_file_named_implicitly", + "//features/dependency_file", + "//features/default_link_flags", + "//features/archiver_flags", + "//features/linker_param_file", + "//features/library_search_directories", + "//features/shared_flag", + "//features/output_execpath_flags", + "//features/libraries_to_link", + "//features/user_link_flags", + "//features/markers:coverage", + "//features/markers:opt", + "//features/markers:supports_dynamic_linker", + "//features/markers:supports_pic", + "//features/pic", + "//features/runtime_library_search_directories", + "//features/gcc_coverage_map_format", + ], + visibility = ["//visibility:public"], +) diff --git a/features/archiver_flags/BUILD b/features/archiver_flags/BUILD new file mode 100644 index 0000000..030860d --- /dev/null +++ b/features/archiver_flags/BUILD @@ -0,0 +1,77 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +cc_args( + name = "archiver_static_flag_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + args = ["rcsD"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "archiver_output_execpath_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + args = ["{output_execpath}"], + format = {"output_execpath": "@rules_cc//cc/toolchains/variables:output_execpath"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_execpath", + visibility = ["//visibility:public"], +) + +cc_nested_args( + name = "archiver_object_file_entry", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file", +) + +cc_nested_args( + name = "archiver_object_file_group_entry", + args = ["{object_file}"], + format = {"object_file": "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files"}, + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files", + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file_group", +) + +cc_nested_args( + name = "archiver_iterate_libraries", + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link", + nested = [ + ":archiver_object_file_entry", + ":archiver_object_file_group_entry", + ], +) + +cc_args( + name = "archiver_libraries_args", + actions = ["@rules_cc//cc/toolchains/actions:ar_actions"], + nested = [":archiver_iterate_libraries"], + requires_not_none = "@rules_cc//cc/toolchains/variables:libraries_to_link", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "archiver_flags", + args = [ + ":archiver_static_flag_args", + ":archiver_output_execpath_args", + ":archiver_libraries_args", + ], + feature_name = "archiver_flags", + visibility = ["//visibility:public"], +) diff --git a/features/compiler_input_flags/BUILD b/features/compiler_input_flags/BUILD new file mode 100644 index 0000000..01612f2 --- /dev/null +++ b/features/compiler_input_flags/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "compiler_input_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-c", + "{source_file}", + ], + format = {"source_file": "@rules_cc//cc/toolchains/variables:source_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:source_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "compiler_input_flags", + args = [":compiler_input_flags_args"], + feature_name = "compiler_input_flags", + visibility = ["//visibility:public"], +) diff --git a/features/compiler_library_search_paths/BUILD b/features/compiler_library_search_paths/BUILD new file mode 100644 index 0000000..30323b3 --- /dev/null +++ b/features/compiler_library_search_paths/BUILD @@ -0,0 +1,37 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "compiler_library_search_paths_args", + actions = [ + "@rules_cc//cc/toolchains/actions:source_compile_actions", + "@rules_cc//cc/toolchains/actions:cpp_link_executable", + "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", + "@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library", + ], + args = ["-Wl,-rpath,{compiler_library_search_paths}"], + format = {"compiler_library_search_paths": "@rules_cc//cc/toolchains/variables:compiler_library_search_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:compiler_library_search_paths", + requires_not_none = "@rules_cc//cc/toolchains/variables:compiler_library_search_paths", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "compiler_library_search_paths", + args = [":compiler_library_search_paths_args"], + feature_name = "compiler_library_search_paths", + visibility = ["//visibility:public"], +) diff --git a/features/compiler_output_flags/BUILD b/features/compiler_output_flags/BUILD new file mode 100644 index 0000000..3adc126 --- /dev/null +++ b/features/compiler_output_flags/BUILD @@ -0,0 +1,54 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "output_assembly_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["-S"], + requires_not_none = "@rules_cc//cc/toolchains/variables:output_assembly_file", + visibility = ["//visibility:public"], +) + +cc_args( + name = "output_preprocess_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["-E"], + requires_not_none = "@rules_cc//cc/toolchains/variables:output_preprocess_file", + visibility = ["//visibility:public"], +) + +cc_args( + name = "output_file_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-o", + "{output_file}", + ], + format = {"output_file": "@rules_cc//cc/toolchains/variables:output_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "compiler_output_flags", + args = [ + ":output_assembly_file_args", + ":output_preprocess_file_args", + ":output_file_args", + ], + feature_name = "compiler_output_flags", + visibility = ["//visibility:public"], +) diff --git a/features/default_compile_flags/BUILD b/features/default_compile_flags/BUILD new file mode 100644 index 0000000..0b25a6e --- /dev/null +++ b/features/default_compile_flags/BUILD @@ -0,0 +1,141 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_args( + name = "default_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select( + { + "@platforms//os:linux": [ + "-U_FORTIFY_SOURCE", + "-D_XOPEN_SOURCE=700", + "-fstack-protector", + "-fdiagnostics-color=always", + "-fno-omit-frame-pointer", + "-ffunction-sections", + "-fdata-sections", + "-fno-canonical-system-headers", + "-no-canonical-prefixes", + "-z noexecstack", + ], + "@platforms//os:qnx": [ + "-fno-canonical-system-headers", + ], + "//conditions:default": [], + }, + ), +) + +# x86_64 requires -m64; other architectures need no CPU flags here +cc_args( + name = "target_cpu_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select({ + "@platforms//cpu:x86_64": ["-m64"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], +) + +cc_feature_constraint( + name = "not_gnu11", + none_of = ["//features/markers:gnu11"], +) + +cc_feature_constraint( + name = "is_gnu11", + all_of = ["//features/markers:gnu11"], +) + +cc_args( + name = "c_std_c11_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = ["-std=c11"], + requires_any_of = [":not_gnu11"], +) + +cc_args( + name = "c_std_gnu11_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = ["-std=gnu11"], + requires_any_of = [":is_gnu11"], +) + +cc_args( + name = "default_cxx_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], + args = ["-std=c++17"] + + select({ + "@platforms//os:qnx": [ + "-D_QNX_SOURCE", + ], + "//conditions:default": [], + }), +) + +cc_feature_constraint( + name = "is_dbg", + all_of = ["//features/markers:dbg"], +) + +cc_args( + name = "dbg_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-Og", + "-g3", + ], + requires_any_of = [":is_dbg"], +) + +cc_feature_constraint( + name = "is_opt", + all_of = ["//features/markers:opt"], +) + +cc_feature_constraint( + name = "is_fastbuild", + all_of = ["//features/markers:fastbuild"], +) + +cc_args( + name = "opt_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-O2", + "-DNDEBUG", + ], + requires_any_of = [ + ":is_opt", + ":is_fastbuild", + ], +) + +cc_feature( + name = "default_compile_flags", + args = [ + ":default_compile_flags_args", + ":target_cpu_flags_args", + ":c_std_c11_args", + ":c_std_gnu11_args", + ":default_cxx_compile_flags_args", + ":dbg_compile_flags_args", + ":opt_compile_flags_args", + ], + feature_name = "default_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/default_link_flags/BUILD b/features/default_link_flags/BUILD new file mode 100644 index 0000000..ce841cb --- /dev/null +++ b/features/default_link_flags/BUILD @@ -0,0 +1,90 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_feature_constraint( + name = "is_opt", + all_of = ["//features/markers:opt"], +) + +# compress-debug only when neither opt nor fastbuild +cc_feature_constraint( + name = "not_opt_not_fastbuild", + none_of = [ + "//features/markers:opt", + "//features/markers:fastbuild", + ], +) + +# Linux base link flags +cc_args( + name = "linux_base_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-lm", + "-ldl", + "-lrt", + "-static-libstdc++", + "-static-libgcc", + ], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_opt_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--gc-sections"], + requires_any_of = [":is_opt"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_debug_compress_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--compress-debug-sections=zlib"], + requires_any_of = [":not_opt_not_fastbuild"], + visibility = ["//visibility:public"], +) + +# QNX static link flags (the -V routing flag stays in toolchain config template) +cc_args( + name = "qnx_base_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-Wl,-z,relro", + "-Wl,-z,now", + "-Wl,--push-state", + "-Wl,--as-needed", + "-lc++", + "-lm", + "-Wl,--pop-state", + ], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "default_link_flags", + args = select({ + "@platforms//os:linux": [ + ":linux_base_link_args", + ":linux_opt_link_args", + ":linux_debug_compress_link_args", + ], + "@platforms//os:qnx": [":qnx_base_link_args"], + }), + feature_name = "default_link_flags", + visibility = ["//visibility:public"], +) diff --git a/features/dependency_file/BUILD b/features/dependency_file/BUILD new file mode 100644 index 0000000..dedcb16 --- /dev/null +++ b/features/dependency_file/BUILD @@ -0,0 +1,88 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +_COMPILE_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:cpp_header_parsing", +] + +# Linux: standard -MD -MF flags +cc_args( + name = "dependency_file_linux_args", + actions = _COMPILE_ACTIONS, + args = [ + "-MD", + "-MF", + "{dependency_file}", + ], + format = {"dependency_file": "@rules_cc//cc/toolchains/variables:dependency_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:dependency_file", + visibility = ["//visibility:public"], +) + +# QNX: QCC-wrapped flags — explicit filename (dependency_file_named_implicitly is NOT active) +cc_feature_constraint( + name = "not_dep_named_implicitly", + none_of = ["//features/markers:dependency_file_named_implicitly"], +) + +cc_args( + name = "dependency_file_qnx_explicit_args", + actions = _COMPILE_ACTIONS, + args = [ + "-Wc,-MD,{dependency_file}", + "-Wp,-MD,{dependency_file}", + ], + format = {"dependency_file": "@rules_cc//cc/toolchains/variables:dependency_file"}, + requires_any_of = [":not_dep_named_implicitly"], + requires_not_none = "@rules_cc//cc/toolchains/variables:dependency_file", + visibility = ["//visibility:public"], +) + +# QNX: QCC-wrapped flags — implicit filename (dependency_file_named_implicitly IS active) +cc_feature_constraint( + name = "is_dep_named_implicitly", + all_of = ["//features/markers:dependency_file_named_implicitly"], +) + +cc_args( + name = "dependency_file_qnx_implicit_args", + actions = _COMPILE_ACTIONS, + args = [ + "-Wc,-MD", + "-Wp,-MD", + ], + requires_any_of = [":is_dep_named_implicitly"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "dependency_file", + args = select({ + "@platforms//os:linux": [":dependency_file_linux_args"], + "@platforms//os:qnx": [ + ":dependency_file_qnx_explicit_args", + ":dependency_file_qnx_implicit_args", + ], + }), + feature_name = "dependency_file", + visibility = ["//visibility:public"], +) diff --git a/features/fission_support/BUILD b/features/fission_support/BUILD new file mode 100644 index 0000000..7e749dc --- /dev/null +++ b/features/fission_support/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "fission_support_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--gdb-index"], + requires_not_none = "@rules_cc//cc/toolchains/variables:is_using_fission", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fission_support", + args = [":fission_support_args"], + feature_name = "fission_support", + visibility = ["//visibility:public"], +) diff --git a/features/force_pic_flags/BUILD b/features/force_pic_flags/BUILD new file mode 100644 index 0000000..22c9f0d --- /dev/null +++ b/features/force_pic_flags/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "force_pic_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_link_executable"], + args = ["-pie"], + requires_not_none = "@rules_cc//cc/toolchains/variables:force_pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "force_pic_flags", + args = [":force_pic_flags_args"], + feature_name = "force_pic_flags", + visibility = ["//visibility:public"], +) diff --git a/features/fully_static_link/BUILD b/features/fully_static_link/BUILD new file mode 100644 index 0000000..f128a0e --- /dev/null +++ b/features/fully_static_link/BUILD @@ -0,0 +1,33 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "fully_static_link_args", + actions = [ + "@rules_cc//cc/toolchains/actions:cpp_link_executable", + "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", + "@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library", + ], + args = ["-static"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fully_static_link", + args = [":fully_static_link_args"], + feature_name = "fully_static_link", + visibility = ["//visibility:public"], +) diff --git a/features/gcc_coverage_map_format/BUILD b/features/gcc_coverage_map_format/BUILD new file mode 100644 index 0000000..c5dae21 --- /dev/null +++ b/features/gcc_coverage_map_format/BUILD @@ -0,0 +1,62 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set") + +cc_feature_set( + name = "requires_coverage", + all_of = ["//features/markers:coverage"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "coverage_compile_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + ], + args = [ + "-fprofile-arcs", + "-ftest-coverage", + ], + visibility = ["//visibility:public"], +) + +cc_args( + name = "linux_coverage_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["--coverage"], + visibility = ["//visibility:public"], +) + +cc_args( + name = "qnx_coverage_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-lgcov"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "gcc_coverage_map_format", + args = [":coverage_compile_args"] + select({ + "@platforms//os:linux": [":linux_coverage_link_args"], + "@platforms//os:qnx": [":qnx_coverage_link_args"], + }), + feature_name = "gcc_coverage_map_format", + requires_any_of = [":requires_coverage"], + visibility = ["//visibility:public"], +) diff --git a/features/include_paths/BUILD b/features/include_paths/BUILD new file mode 100644 index 0000000..676bab8 --- /dev/null +++ b/features/include_paths/BUILD @@ -0,0 +1,59 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "quote_include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-iquote", + "{quote_include_paths}", + ], + format = {"quote_include_paths": "@rules_cc//cc/toolchains/variables:quote_include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:quote_include_paths", + visibility = ["//visibility:public"], +) + +cc_args( + name = "include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = ["-I{include_paths}"], + format = {"include_paths": "@rules_cc//cc/toolchains/variables:include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:include_paths", + visibility = ["//visibility:public"], +) + +cc_args( + name = "system_include_paths_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-isystem", + "{system_include_paths}", + ], + format = {"system_include_paths": "@rules_cc//cc/toolchains/variables:system_include_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:system_include_paths", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "include_paths", + args = [ + ":quote_include_paths_args", + ":include_paths_args", + ":system_include_paths_args", + ], + feature_name = "include_paths", + visibility = ["//visibility:public"], +) diff --git a/features/includes/BUILD b/features/includes/BUILD new file mode 100644 index 0000000..f0dc8dd --- /dev/null +++ b/features/includes/BUILD @@ -0,0 +1,35 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "includes_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = [ + "-include", + "{includes}", + ], + format = {"includes": "@rules_cc//cc/toolchains/variables:includes"}, + iterate_over = "@rules_cc//cc/toolchains/variables:includes", + requires_not_none = "@rules_cc//cc/toolchains/variables:includes", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "includes", + args = [":includes_args"], + feature_name = "includes", + visibility = ["//visibility:public"], +) diff --git a/features/libraries_to_link/BUILD b/features/libraries_to_link/BUILD new file mode 100644 index 0000000..09e96a5 --- /dev/null +++ b/features/libraries_to_link/BUILD @@ -0,0 +1,105 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +# static_library: dispatch on is_whole_archive +cc_nested_args( + name = "whole_archive_static_library", + args = [ + "-Wl,--whole-archive", + "{lib_name}", + "-Wl,--no-whole-archive", + ], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_true = "@rules_cc//cc/toolchains/variables:libraries_to_link.is_whole_archive", +) + +cc_nested_args( + name = "non_whole_archive_static_library", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_false = "@rules_cc//cc/toolchains/variables:libraries_to_link.is_whole_archive", +) + +cc_nested_args( + name = "static_library_dispatch", + nested = [ + ":whole_archive_static_library", + ":non_whole_archive_static_library", + ], + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "static_library", +) + +cc_nested_args( + name = "object_file_entry", + args = ["{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file", +) + +cc_nested_args( + name = "object_file_group_entry", + args = ["{object_file}"], + format = {"object_file": "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files"}, + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link.object_files", + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "object_file_group", +) + +cc_nested_args( + name = "dynamic_library_entry", + args = ["-l{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "dynamic_library", +) + +cc_nested_args( + name = "versioned_dynamic_library_entry", + args = ["-l:{lib_name}"], + format = {"lib_name": "@rules_cc//cc/toolchains/variables:libraries_to_link.name"}, + requires_equal = "@rules_cc//cc/toolchains/variables:libraries_to_link.type", + requires_equal_value = "versioned_dynamic_library", +) + +cc_nested_args( + name = "iterate_libraries", + iterate_over = "@rules_cc//cc/toolchains/variables:libraries_to_link", + nested = [ + ":static_library_dispatch", + ":object_file_entry", + ":object_file_group_entry", + ":dynamic_library_entry", + ":versioned_dynamic_library_entry", + ], +) + +cc_args( + name = "libraries_to_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":iterate_libraries"], + requires_not_none = "@rules_cc//cc/toolchains/variables:libraries_to_link", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "libraries_to_link", + args = [":libraries_to_link_args"], + feature_name = "libraries_to_link", + visibility = ["//visibility:public"], +) diff --git a/features/library_search_directories/BUILD b/features/library_search_directories/BUILD new file mode 100644 index 0000000..1f65428 --- /dev/null +++ b/features/library_search_directories/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "library_search_directories_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-L{library_search_directories}"], + format = {"library_search_directories": "@rules_cc//cc/toolchains/variables:library_search_directories"}, + iterate_over = "@rules_cc//cc/toolchains/variables:library_search_directories", + requires_not_none = "@rules_cc//cc/toolchains/variables:library_search_directories", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "library_search_directories", + args = [":library_search_directories_args"], + feature_name = "library_search_directories", + visibility = ["//visibility:public"], +) diff --git a/features/linker_param_file/BUILD b/features/linker_param_file/BUILD new file mode 100644 index 0000000..cc097bb --- /dev/null +++ b/features/linker_param_file/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "linker_param_file_args", + actions = [ + "@rules_cc//cc/toolchains/actions:link_actions", + "@rules_cc//cc/toolchains/actions:ar_actions", + ], + args = ["@{linker_param_file}"], + format = {"linker_param_file": "@rules_cc//cc/toolchains/variables:linker_param_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:linker_param_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "linker_param_file", + args = [":linker_param_file_args"], + feature_name = "linker_param_file", + visibility = ["//visibility:public"], +) diff --git a/features/linkstamps/BUILD b/features/linkstamps/BUILD new file mode 100644 index 0000000..4dd5b32 --- /dev/null +++ b/features/linkstamps/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "linkstamps_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["{linkstamp_paths}"], + format = {"linkstamp_paths": "@rules_cc//cc/toolchains/variables:linkstamp_paths"}, + iterate_over = "@rules_cc//cc/toolchains/variables:linkstamp_paths", + requires_not_none = "@rules_cc//cc/toolchains/variables:linkstamp_paths", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "linkstamps", + args = [":linkstamps_args"], + feature_name = "linkstamps", + visibility = ["//visibility:public"], +) diff --git a/features/linux_platform/BUILD b/features/linux_platform/BUILD new file mode 100644 index 0000000..78fd395 --- /dev/null +++ b/features/linux_platform/BUILD @@ -0,0 +1,20 @@ +# ******************************************************************************* +# Copyright (c) 2025 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:feature.bzl", "cc_feature") + +cc_feature( + name = "linux_platform", + feature_name = "linux_platform", + visibility = ["//visibility:public"], +) diff --git a/features/markers/BUILD b/features/markers/BUILD new file mode 100644 index 0000000..3f3f131 --- /dev/null +++ b/features/markers/BUILD @@ -0,0 +1,90 @@ +# ******************************************************************************* +# Copyright (c) 2025 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:feature.bzl", "cc_feature") + +# Capability markers — enabled state is set at toolchain assembly, not here. +cc_feature( + name = "no_legacy_features", + feature_name = "no_legacy_features", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_pic", + feature_name = "supports_pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_dynamic_linker", + feature_name = "supports_dynamic_linker", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "dbg", + feature_name = "dbg", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "opt", + feature_name = "opt", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "fastbuild", + feature_name = "fastbuild", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "coverage", + feature_name = "coverage", + visibility = ["//visibility:public"], +) + +## Linux specficic +cc_feature( + name = "supports_fission", + feature_name = "supports_fission", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "supports_header_path_normalization", + feature_name = "supports_header_path_normalization", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "gnu11", + feature_name = "gnu11", + visibility = ["//visibility:public"], +) + +## QNX only +cc_feature( + name = "dependency_file_named_implicitly", + feature_name = "dependency_file_named_implicitly", + visibility = ["//visibility:public"], +) + +# Linked runtime control +cc_feature( + name = "static_link_cpp_runtimes", + feature_name = "static_link_cpp_runtimes", + visibility = ["//visibility:public"], +) diff --git a/features/output_execpath_flags/BUILD b/features/output_execpath_flags/BUILD new file mode 100644 index 0000000..e9cbcdb --- /dev/null +++ b/features/output_execpath_flags/BUILD @@ -0,0 +1,34 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "output_execpath_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = [ + "-o", + "{output_execpath}", + ], + format = {"output_execpath": "@rules_cc//cc/toolchains/variables:output_execpath"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_execpath", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "output_execpath_flags", + args = [":output_execpath_flags_args"], + feature_name = "output_execpath_flags", + visibility = ["//visibility:public"], +) diff --git a/features/per_object_debug_info/BUILD b/features/per_object_debug_info/BUILD new file mode 100644 index 0000000..6e284d8 --- /dev/null +++ b/features/per_object_debug_info/BUILD @@ -0,0 +1,39 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "per_object_debug_info_args", + actions = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + ], + args = [ + "-gsplit-dwarf", + "-g", + ], + requires_not_none = "@rules_cc//cc/toolchains/variables:per_object_debug_info_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "per_object_debug_info", + args = [":per_object_debug_info_args"], + feature_name = "per_object_debug_info", + visibility = ["//visibility:public"], +) diff --git a/features/pic/BUILD b/features/pic/BUILD new file mode 100644 index 0000000..5d0c864 --- /dev/null +++ b/features/pic/BUILD @@ -0,0 +1,37 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "pic_args", + actions = [ + "@rules_cc//cc/toolchains/actions:assemble", + "@rules_cc//cc/toolchains/actions:preprocess_assemble", + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + ], + args = ["-fPIC"], + requires_not_none = "@rules_cc//cc/toolchains/variables:pic", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "pic", + args = [":pic_args"], + feature_name = "pic", + visibility = ["//visibility:public"], +) diff --git a/features/preprocessor_defines/BUILD b/features/preprocessor_defines/BUILD new file mode 100644 index 0000000..b7bf963 --- /dev/null +++ b/features/preprocessor_defines/BUILD @@ -0,0 +1,31 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "preprocessor_defines_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = ["-D{preprocessor_defines}"], + format = {"preprocessor_defines": "@rules_cc//cc/toolchains/variables:preprocessor_defines"}, + iterate_over = "@rules_cc//cc/toolchains/variables:preprocessor_defines", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "preprocessor_defines", + args = [":preprocessor_defines_args"], + feature_name = "preprocessor_defines", + visibility = ["//visibility:public"], +) diff --git a/features/qnx_platform/BUILD b/features/qnx_platform/BUILD new file mode 100644 index 0000000..7eb012c --- /dev/null +++ b/features/qnx_platform/BUILD @@ -0,0 +1,20 @@ +# ******************************************************************************* +# Copyright (c) 2025 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:feature.bzl", "cc_feature") + +cc_feature( + name = "qnx_platform", + feature_name = "qnx_platform", + visibility = ["//visibility:public"], +) diff --git a/features/random_seed/BUILD b/features/random_seed/BUILD new file mode 100644 index 0000000..d0c33d1 --- /dev/null +++ b/features/random_seed/BUILD @@ -0,0 +1,36 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "random_seed_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_compile", + "@rules_cc//cc/toolchains/actions:cpp_module_codegen", + ], + args = ["-frandom-seed={output_file}"], + format = {"output_file": "@rules_cc//cc/toolchains/variables:output_file"}, + requires_not_none = "@rules_cc//cc/toolchains/variables:output_file", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "random_seed", + args = [":random_seed_args"], + feature_name = "random_seed", + visibility = ["//visibility:public"], +) diff --git a/features/runtime_library_search_directories/BUILD b/features/runtime_library_search_directories/BUILD new file mode 100644 index 0000000..5c248fd --- /dev/null +++ b/features/runtime_library_search_directories/BUILD @@ -0,0 +1,74 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:nested_args.bzl", "cc_nested_args") + +# Linux: fork rpath on is_cc_test +cc_nested_args( + name = "linux_rpath_test", + args = ["-Wl,-rpath,$ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + requires_true = "@rules_cc//cc/toolchains/variables:is_cc_test", +) + +cc_nested_args( + name = "linux_rpath_exec", + args = ["-Wl,-rpath,$EXEC_ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + requires_false = "@rules_cc//cc/toolchains/variables:is_cc_test", +) + +cc_nested_args( + name = "linux_rpath_iterate", + iterate_over = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + nested = [ + ":linux_rpath_test", + ":linux_rpath_exec", + ], +) + +cc_args( + name = "runtime_dirs_linux_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":linux_rpath_iterate"], + requires_not_none = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + visibility = ["//visibility:public"], +) + +# QNX: always $EXEC_ORIGIN, QCC uses -Wl,-rpath +cc_nested_args( + name = "qnx_rpath_iterate", + args = ["-Wl,-rpath,$EXEC_ORIGIN/{dir}"], + format = {"dir": "@rules_cc//cc/toolchains/variables:runtime_library_search_directories"}, + iterate_over = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", +) + +cc_args( + name = "runtime_dirs_qnx_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + nested = [":qnx_rpath_iterate"], + requires_not_none = "@rules_cc//cc/toolchains/variables:runtime_library_search_directories", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "runtime_library_search_directories", + args = select({ + "@platforms//os:linux": [":runtime_dirs_linux_args"], + "@platforms//os:qnx": [":runtime_dirs_qnx_args"], + }), + feature_name = "runtime_library_search_directories", + visibility = ["//visibility:public"], +) diff --git a/features/shared_flag/BUILD b/features/shared_flag/BUILD new file mode 100644 index 0000000..8b5d30d --- /dev/null +++ b/features/shared_flag/BUILD @@ -0,0 +1,29 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "shared_flag_args", + actions = ["@rules_cc//cc/toolchains/actions:dynamic_library_link_actions"], + args = ["-shared"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "shared_flag", + args = [":shared_flag_args"], + feature_name = "shared_flag", + visibility = ["//visibility:public"], +) diff --git a/features/static_libgcc/BUILD b/features/static_libgcc/BUILD new file mode 100644 index 0000000..d1e9d55 --- /dev/null +++ b/features/static_libgcc/BUILD @@ -0,0 +1,39 @@ +# ******************************************************************************* +# Copyright (c) 2025 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") +load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") + +cc_feature_constraint( + name = "is_static_link_cpp_runtimes", + all_of = ["//features/markers:static_link_cpp_runtimes"], +) + +cc_args( + name = "static_libgcc_args", + actions = [ + "@rules_cc//cc/toolchains/actions:cpp_link_executable", + "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", + ], + args = ["-static-libgcc"], + requires_any_of = [":is_static_link_cpp_runtimes"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "static_libgcc", + args = [":static_libgcc_args"], + feature_name = "static_libgcc", + visibility = ["//visibility:public"], +) diff --git a/features/strip_debug_symbols/BUILD b/features/strip_debug_symbols/BUILD new file mode 100644 index 0000000..6d5626f --- /dev/null +++ b/features/strip_debug_symbols/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "strip_debug_symbols_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,-S"], + requires_not_none = "@rules_cc//cc/toolchains/variables:strip_debug_symbols", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "strip_debug_symbols", + args = [":strip_debug_symbols_args"], + feature_name = "strip_debug_symbols", + visibility = ["//visibility:public"], +) diff --git a/features/sysroot_link_flags/BUILD b/features/sysroot_link_flags/BUILD new file mode 100644 index 0000000..502f2bc --- /dev/null +++ b/features/sysroot_link_flags/BUILD @@ -0,0 +1,31 @@ +# ******************************************************************************* +# Copyright (c) 2025 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:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot") + +cc_sysroot( + name = "sysroot_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--sysroot={sysroot}"], + requires_not_none = "@rules_cc//cc/toolchains/variables:sysroot", + sysroot = "@rules_cc//cc/toolchains/variables:sysroot", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "sysroot_link_flags", + args = [":sysroot_link_flags_args"], + feature_name = "sysroot_link_flags", + visibility = ["//visibility:public"], +) diff --git a/features/unfiltered_compile_flags/BUILD b/features/unfiltered_compile_flags/BUILD new file mode 100644 index 0000000..8ea2d00 --- /dev/null +++ b/features/unfiltered_compile_flags/BUILD @@ -0,0 +1,37 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "unfiltered_compile_flags_args", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile_actions", + "@rules_cc//cc/toolchains/actions:cpp_compile_actions", + ], + args = [ + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + "-Wno-builtin-macro-redefined", + ], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "unfiltered_compile_flags", + args = [":unfiltered_compile_flags_args"], + feature_name = "unfiltered_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/use_pthread/BUILD b/features/use_pthread/BUILD new file mode 100644 index 0000000..85922fc --- /dev/null +++ b/features/use_pthread/BUILD @@ -0,0 +1,29 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "use_pthread_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-pthread"], + visibility = ["//visibility:public"], +) + +cc_feature( + name = "use_pthread", + args = [":use_pthread_args"], + feature_name = "use_pthread", + visibility = ["//visibility:public"], +) diff --git a/features/user_compile_flags/BUILD b/features/user_compile_flags/BUILD new file mode 100644 index 0000000..f5a6702 --- /dev/null +++ b/features/user_compile_flags/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "user_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["{user_compile_flags}"], + format = {"user_compile_flags": "@rules_cc//cc/toolchains/variables:user_compile_flags"}, + iterate_over = "@rules_cc//cc/toolchains/variables:user_compile_flags", + requires_not_none = "@rules_cc//cc/toolchains/variables:user_compile_flags", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "user_compile_flags", + args = [":user_compile_flags_args"], + feature_name = "user_compile_flags", + visibility = ["//visibility:public"], +) diff --git a/features/user_link_flags/BUILD b/features/user_link_flags/BUILD new file mode 100644 index 0000000..d4e30f2 --- /dev/null +++ b/features/user_link_flags/BUILD @@ -0,0 +1,32 @@ +# ******************************************************************************* +# Copyright (c) 2025 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 = "user_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["{user_link_flags}"], + format = {"user_link_flags": "@rules_cc//cc/toolchains/variables:user_link_flags"}, + iterate_over = "@rules_cc//cc/toolchains/variables:user_link_flags", + requires_not_none = "@rules_cc//cc/toolchains/variables:user_link_flags", + visibility = ["//visibility:public"], +) + +cc_feature( + name = "user_link_flags", + args = [":user_link_flags_args"], + feature_name = "user_link_flags", + visibility = ["//visibility:public"], +) From 177ba309a34894229324ab85f60f87b6caf9507a Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 28 Aug 2026 15:56:28 +0200 Subject: [PATCH 2/7] Temp commit 2 --- docs/generation_flow.md | 8 +- extensions/gcc.bzl | 2 - features/compiler_library_search_paths/BUILD | 38 +- .../features.bzl | 45 + features/extra_compile_flags/BUILD | 0 features/extra_compile_flags/features.bzl | 60 ++ features/extra_link_flags/BUILD | 0 .../BUILD => extra_link_flags/features.bzl} | 22 +- features/make_cc_features.bzl | 141 +++ .../BUILD | 11 +- features/qnx_gcc_version_flags/features.bzl | 46 + features/sysroot_link_flags/BUILD | 20 +- features/sysroot_link_flags/features.bzl | 38 + rules/common.bzl | 13 + rules/gcc.bzl | 47 +- templates/BUILD.template | 38 + .../{linux => }/cc_gcov_wrapper.template | 0 .../linux/cc_toolchain_config.bzl.template | 891 +----------------- .../linux/cc_toolchain_flags.bzl.template | 95 -- .../qnx/cc_toolchain_config.bzl.template | 599 +----------- templates/qnx/cc_toolchain_flags.bzl.template | 81 -- tests/MODULE.bazel.lock | 12 +- 22 files changed, 469 insertions(+), 1738 deletions(-) create mode 100644 features/compiler_library_search_paths/features.bzl create mode 100644 features/extra_compile_flags/BUILD create mode 100644 features/extra_compile_flags/features.bzl create mode 100644 features/extra_link_flags/BUILD rename features/{linux_platform/BUILD => extra_link_flags/features.bzl} (54%) create mode 100644 features/make_cc_features.bzl rename features/{qnx_platform => qnx_gcc_version_flags}/BUILD (68%) create mode 100644 features/qnx_gcc_version_flags/features.bzl create mode 100644 features/sysroot_link_flags/features.bzl rename templates/{linux => }/cc_gcov_wrapper.template (100%) delete mode 100644 templates/linux/cc_toolchain_flags.bzl.template delete mode 100644 templates/qnx/cc_toolchain_flags.bzl.template diff --git a/docs/generation_flow.md b/docs/generation_flow.md index 2c6820e..8765bc3 100644 --- a/docs/generation_flow.md +++ b/docs/generation_flow.md @@ -46,7 +46,7 @@ representation needed by the templates and repository rules. Generates the toolchain repository. It decides whether Linux or QNX template content is required, performs placeholder substitution, and emits the final -`BUILD`, `cc_toolchain_config.bzl`, `flags.bzl`, and Linux `gcov` wrapper +`BUILD`, `cc_toolchain_config.bzl`, and Linux `gcov` wrapper files. ## Template Families @@ -54,17 +54,15 @@ files. Linux templates: - `templates/linux/cc_toolchain_config.bzl.template` -- `templates/linux/cc_toolchain_flags.bzl.template` -- `templates/linux/cc_gcov_wrapper.template` QNX templates: - `templates/qnx/cc_toolchain_config.bzl.template` -- `templates/qnx/cc_toolchain_flags.bzl.template` -Shared template: +Shared templates: - `templates/BUILD.template` +- `templates/cc_gcov_wrapper.template` ## Important Implementation Details diff --git a/extensions/gcc.bzl b/extensions/gcc.bzl index ae8b330..f745d9e 100644 --- a/extensions/gcc.bzl +++ b/extensions/gcc.bzl @@ -204,7 +204,6 @@ def _get_toolchains(tags): for tag in tags: toolchain = { "cc_toolchain_config": "@score_bazel_cpp_toolchains//templates/{}:cc_toolchain_config.bzl.template".format(tag.target_os), - "cc_toolchain_flags": "@score_bazel_cpp_toolchains//templates/{}:cc_toolchain_flags.bzl.template".format(tag.target_os), "gcc_version": tag.version, "name": tag.name, "use_base_constraints_only": tag.use_base_constraints_only, @@ -416,7 +415,6 @@ def _impl(mctx): tc_runtime_ecosystem = toolchain_info["tc_runtime_ecosystem"], gcc_version = toolchain_info["gcc_version"], cc_toolchain_config = toolchain_info["cc_toolchain_config"], - cc_toolchain_flags = toolchain_info["cc_toolchain_flags"], use_base_constraints_only = toolchain_info["use_base_constraints_only"], ) diff --git a/features/compiler_library_search_paths/BUILD b/features/compiler_library_search_paths/BUILD index 30323b3..269fe76 100644 --- a/features/compiler_library_search_paths/BUILD +++ b/features/compiler_library_search_paths/BUILD @@ -11,27 +11,19 @@ # 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 = "compiler_library_search_paths_args", - actions = [ - "@rules_cc//cc/toolchains/actions:source_compile_actions", - "@rules_cc//cc/toolchains/actions:cpp_link_executable", - "@rules_cc//cc/toolchains/actions:cpp_link_dynamic_library", - "@rules_cc//cc/toolchains/actions:cpp_link_nodeps_dynamic_library", - ], - args = ["-Wl,-rpath,{compiler_library_search_paths}"], - format = {"compiler_library_search_paths": "@rules_cc//cc/toolchains/variables:compiler_library_search_paths"}, - iterate_over = "@rules_cc//cc/toolchains/variables:compiler_library_search_paths", - requires_not_none = "@rules_cc//cc/toolchains/variables:compiler_library_search_paths", - visibility = ["//visibility:public"], -) +# ******************************************************************************* +# Copyright (c) 2025 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 +# ******************************************************************************* -cc_feature( - name = "compiler_library_search_paths", - args = [":compiler_library_search_paths_args"], - feature_name = "compiler_library_search_paths", - visibility = ["//visibility:public"], -) +# Instantiated per-toolchain via make_compiler_library_search_paths() in +# features.bzl, since each toolchain has different search paths — see +# templates/BUILD.template. diff --git a/features/compiler_library_search_paths/features.bzl b/features/compiler_library_search_paths/features.bzl new file mode 100644 index 0000000..3cfb0aa --- /dev/null +++ b/features/compiler_library_search_paths/features.bzl @@ -0,0 +1,45 @@ +# ******************************************************************************* +# 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") + +_ALL_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", + "@rules_cc//cc/toolchains/actions:strip", + "@rules_cc//cc/toolchains/actions:ar_actions", +] + +def make_compiler_library_search_paths(compiler_library_search_paths): + """Creates the compiler_library_search_paths feature. + + Sets LD_LIBRARY_PATH for every toolchain action (compile, link, archive, + strip) so the compiler/linker/ar/strip binaries themselves can find their + own runtime shared libraries. This is unrelated to the artifacts being + built, so it's an env var applied to all actions, not a linker flag. + + Args: + compiler_library_search_paths: colon-joined path string, "" if none. + """ + cc_args( + name = "compiler_library_search_paths_args", + actions = _ALL_ACTIONS, + env = {"LD_LIBRARY_PATH": compiler_library_search_paths} if compiler_library_search_paths else {}, + ) + + cc_feature( + name = "compiler_library_search_paths", + args = [":compiler_library_search_paths_args"], + feature_name = "compiler_library_search_paths", + ) diff --git a/features/extra_compile_flags/BUILD b/features/extra_compile_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/extra_compile_flags/features.bzl b/features/extra_compile_flags/features.bzl new file mode 100644 index 0000000..fafd227 --- /dev/null +++ b/features/extra_compile_flags/features.bzl @@ -0,0 +1,60 @@ +# ******************************************************************************* +# 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_extra_compile_features( + extra_compile_flags = None, + extra_c_compile_flags = None, + extra_cxx_compile_flags = None, +): + + cc_args( + name = "extra_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:source_compile_actions"], + args = extra_compile_flags, + ) + + cc_feature( + name = "extra_compile_flags", + args = [":extra_compile_flags_args"], + feature_name = "extra_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + ) + + cc_args( + name = "extra_c_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:c_compile_actions"], + args = extra_c_compile_flags, + ) + + cc_feature( + name = "extra_c_compile_flags", + args = [":extra_c_compile_flags_args"], + feature_name = "extra_c_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + ) + + cc_args( + name = "extra_cxx_compile_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], + args = extra_cxx_compile_flags, + ) + + cc_feature( + name = "extra_cxx_compile_flags", + args = [":extra_cxx_compile_flags_args"], + feature_name = "extra_cxx_compile_flags", + implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + ) \ No newline at end of file diff --git a/features/extra_link_flags/BUILD b/features/extra_link_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/linux_platform/BUILD b/features/extra_link_flags/features.bzl similarity index 54% rename from features/linux_platform/BUILD rename to features/extra_link_flags/features.bzl index 78fd395..5e3e231 100644 --- a/features/linux_platform/BUILD +++ b/features/extra_link_flags/features.bzl @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2025 Contributors to the Eclipse Foundation +# Copyright (c) 2026 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -11,10 +11,20 @@ # 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_feature( - name = "linux_platform", - feature_name = "linux_platform", - visibility = ["//visibility:public"], -) +def make_extra_link_features( + extra_link_flags = None, +): + cc_args( + name = "extra_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = extra_link_flags, + ) + + cc_feature( + name = "extra_link_flags", + args = [":extra_link_flags_args"], + feature_name = "extra_link_flags", + ) \ No newline at end of file diff --git a/features/make_cc_features.bzl b/features/make_cc_features.bzl new file mode 100644 index 0000000..fafda76 --- /dev/null +++ b/features/make_cc_features.bzl @@ -0,0 +1,141 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +_LINUX_FEATURES = [ + ("@score_bazel_cpp_toolchains//features/markers:no_legacy_features", True), + (":compiler_library_search_paths", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/markers:dbg", False), # Bazel auto-toggles via -c dbg + ("@score_bazel_cpp_toolchains//features/unfiltered_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/markers:gnu11", False), # opt-in + ("@score_bazel_cpp_toolchains//features/default_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/random_seed", True), + ("@score_bazel_cpp_toolchains//features/include_paths", True), + ("@score_bazel_cpp_toolchains//features/preprocessor_defines", True), + (":extra_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/user_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/compiler_input_flags", True), + ("@score_bazel_cpp_toolchains//features/compiler_output_flags", True), + ("@score_bazel_cpp_toolchains//features/dependency_file", True), + ("@score_bazel_cpp_toolchains//features/per_object_debug_info", True), + ("@score_bazel_cpp_toolchains//features/includes", True), + ("@score_bazel_cpp_toolchains//features/default_link_flags", True), + ("@score_bazel_cpp_toolchains//features/archiver_flags", True), + ("@score_bazel_cpp_toolchains//features/linker_param_file", True), + ("@score_bazel_cpp_toolchains//features/library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/shared_flag", True), + ("@score_bazel_cpp_toolchains//features/output_execpath_flags", True), + ("@score_bazel_cpp_toolchains//features/runtime_library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/libraries_to_link", True), + ("@score_bazel_cpp_toolchains//features/user_link_flags", True), + (":extra_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/linkstamps", True), + ("@score_bazel_cpp_toolchains//features/fission_support", True), + ("@score_bazel_cpp_toolchains//features/force_pic_flags", True), + ("@score_bazel_cpp_toolchains//features/strip_debug_symbols", True), + ("@score_bazel_cpp_toolchains//features/static_libgcc", True), + ("@score_bazel_cpp_toolchains//features/fully_static_link", False), # opt-in + (":sysroot_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/use_pthread", True), + ("@score_bazel_cpp_toolchains//features/markers:opt", False), # Bazel auto-toggles via -c opt + ("@score_bazel_cpp_toolchains//features/markers:supports_dynamic_linker", True), + ("@score_bazel_cpp_toolchains//features/markers:supports_pic", True), + ("@score_bazel_cpp_toolchains//features/pic", True), + ("@score_bazel_cpp_toolchains//features/markers:supports_header_path_normalization", True), + ("@score_bazel_cpp_toolchains//features/markers:supports_fission", True), + ("@score_bazel_cpp_toolchains//features/markers:coverage", False), # opt-in + ("@score_bazel_cpp_toolchains//features/gcc_coverage_map_format", False), # opt-in (+ requires "coverage") +] + +def linux_known_features(): + """Full ordered list of Linux feature labels — order drives flag order.""" + return [label for label, _enabled in _LINUX_FEATURES] + +def linux_enabled_features(): + """Subset of Linux feature labels that start enabled — order is irrelevant here.""" + return [label for label, enabled in _LINUX_FEATURES if enabled] + +# Single source of truth: ordered (label, enabled_by_default) pairs. +# Order here IS the command-line flag order — mirrors +# templates/qnx/cc_toolchain_config.bzl.template's `features = [...]` list. +_QNX_FEATURES = [ + ("@score_bazel_cpp_toolchains//features/markers:dbg", False), # Bazel auto-toggles via -c dbg + ("@score_bazel_cpp_toolchains//features/markers:no_legacy_features", True), + ("@score_bazel_cpp_toolchains//features/unfiltered_compile_flags", True), + (":qnx_gcc_version_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/default_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/random_seed", True), + ("@score_bazel_cpp_toolchains//features/include_paths", True), + ("@score_bazel_cpp_toolchains//features/preprocessor_defines", True), + (":extra_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/user_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/compiler_input_flags", True), + ("@score_bazel_cpp_toolchains//features/compiler_output_flags", True), + ("@score_bazel_cpp_toolchains//features/markers:dependency_file_named_implicitly", False), + ("@score_bazel_cpp_toolchains//features/dependency_file", True), + ("@score_bazel_cpp_toolchains//features/default_link_flags", True), + ("@score_bazel_cpp_toolchains//features/archiver_flags", True), + ("@score_bazel_cpp_toolchains//features/linker_param_file", True), + ("@score_bazel_cpp_toolchains//features/library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/shared_flag", True), + ("@score_bazel_cpp_toolchains//features/output_execpath_flags", True), + ("@score_bazel_cpp_toolchains//features/libraries_to_link", True), + ("@score_bazel_cpp_toolchains//features/user_link_flags", True), + (":extra_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/markers:coverage", False), # opt-in + ("@score_bazel_cpp_toolchains//features/markers:opt", False), # Bazel auto-toggles via -c opt + ("@score_bazel_cpp_toolchains//features/markers:supports_dynamic_linker", True), + ("@score_bazel_cpp_toolchains//features/markers:supports_pic", True), + ("@score_bazel_cpp_toolchains//features/pic", True), + ("@score_bazel_cpp_toolchains//features/runtime_library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/gcc_coverage_map_format", False), # opt-in +] + +def qnx_known_features(): + """Full ordered list of QNX feature labels — order drives flag order.""" + return [label for label, _enabled in _QNX_FEATURES] + +def qnx_enabled_features(): + """Subset of QNX feature labels that start enabled — order is irrelevant here.""" + return [label for label, enabled in _QNX_FEATURES if enabled] + +def compute_feature_lists(target_os): + """Returns the flat known/enabled feature label lists for target_os. + + Unlike cc_feature_set (which groups features for requires_any_of/requires_all_of + constraints and does not itself provide FeatureInfo), cc_toolchain_config's + known_features/enabled_features attrs require every entry to individually + provide FeatureInfo — so this returns plain lists of cc_feature labels rather + than a single grouping target. + + Per-instance features (extra_compile_flags, extra_c_compile_flags, + extra_cxx_compile_flags, extra_link_flags, sysroot_link_flags, + compiler_library_search_paths) are baked into _LINUX_FEATURES/_QNX_FEATURES + directly since their target names never change across toolchain instances — + see templates/BUILD.template for where those targets get created. + + Args: + target_os: "linux" or "qnx". + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + if target_os == "linux": + return linux_known_features(), linux_enabled_features() + elif target_os == "qnx": + return qnx_known_features(), qnx_enabled_features() + else: + fail("Unsupported target_os '{}', expected 'linux' or 'qnx'".format(target_os)) \ No newline at end of file diff --git a/features/qnx_platform/BUILD b/features/qnx_gcc_version_flags/BUILD similarity index 68% rename from features/qnx_platform/BUILD rename to features/qnx_gcc_version_flags/BUILD index 7eb012c..3d851ce 100644 --- a/features/qnx_platform/BUILD +++ b/features/qnx_gcc_version_flags/BUILD @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2025 Contributors to the Eclipse Foundation +# Copyright (c) 2026 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -11,10 +11,5 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") - -cc_feature( - name = "qnx_platform", - feature_name = "qnx_platform", - visibility = ["//visibility:public"], -) +# Instantiated per-toolchain via make_qnx_gcc_version_flags() in features.bzl, +# since the version/cpu differ per toolchain instance — see templates/BUILD.template. diff --git a/features/qnx_gcc_version_flags/features.bzl b/features/qnx_gcc_version_flags/features.bzl new file mode 100644 index 0000000..e0a68ec --- /dev/null +++ b/features/qnx_gcc_version_flags/features.bzl @@ -0,0 +1,46 @@ +# ******************************************************************************* +# 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_qnx_gcc_version_flags(tc_version, target_cpu, target_os): + """Creates the QCC "-V,gcc_nto[_cxx]" toolchain-routing flags. + + QCC needs an explicit -V flag to select which underlying GCC version/target + it should compile/link with; the value is per-toolchain-instance data. + + Args: + tc_version: GCC version string for this toolchain instance. + target_cpu: target CPU string for this toolchain instance. + target_os: target OS string for this toolchain instance. + """ + if target_os == "qnx": + cc_args( + name = "qnx_gcc_version_compile_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = ["-V{},gcc_nto{}".format(tc_version, target_cpu)], + ) + + cc_args( + name = "qnx_gcc_version_link_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-V{},gcc_nto{}_cxx".format(tc_version, target_cpu)], + ) + + cc_feature( + name = "qnx_gcc_version_flags", + args = [":qnx_gcc_version_compile_args", ":qnx_gcc_version_link_args"], + feature_name = "qnx_gcc_version_flags", + ) + diff --git a/features/sysroot_link_flags/BUILD b/features/sysroot_link_flags/BUILD index 502f2bc..73b762d 100644 --- a/features/sysroot_link_flags/BUILD +++ b/features/sysroot_link_flags/BUILD @@ -11,21 +11,5 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") -load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot") - -cc_sysroot( - name = "sysroot_link_flags_args", - actions = ["@rules_cc//cc/toolchains/actions:link_actions"], - args = ["-Wl,--sysroot={sysroot}"], - requires_not_none = "@rules_cc//cc/toolchains/variables:sysroot", - sysroot = "@rules_cc//cc/toolchains/variables:sysroot", - visibility = ["//visibility:public"], -) - -cc_feature( - name = "sysroot_link_flags", - args = [":sysroot_link_flags_args"], - feature_name = "sysroot_link_flags", - visibility = ["//visibility:public"], -) +# Instantiated per-toolchain via make_sysroot_link_flags() in features.bzl, since +# each toolchain has a different sysroot directory — see templates/BUILD.template. diff --git a/features/sysroot_link_flags/features.bzl b/features/sysroot_link_flags/features.bzl new file mode 100644 index 0000000..90fa0cf --- /dev/null +++ b/features/sysroot_link_flags/features.bzl @@ -0,0 +1,38 @@ +# ******************************************************************************* +# 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:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains/args:sysroot.bzl", "cc_sysroot") + +def make_sysroot_link_flags(target_os, sysroot): + """Creates the sysroot_link_flags feature for this toolchain's sysroot directory. + + cc_sysroot already emits "--sysroot={sysroot}" on its own; only the extra + "-Wl,--sysroot={sysroot}" needs to be listed here. + + Args: + sysroot: label of the directory rule for this toolchain's sysroot. + """ + if target_os == "linux": + cc_sysroot( + name = "sysroot_link_flags_args", + actions = ["@rules_cc//cc/toolchains/actions:link_actions"], + args = ["-Wl,--sysroot={sysroot}"], + sysroot = sysroot, + ) + + cc_feature( + name = "sysroot_link_flags", + args = [":sysroot_link_flags_args"], + feature_name = "sysroot_link_flags", + ) diff --git a/rules/common.bzl b/rules/common.bzl index ad756d6..b61011c 100644 --- a/rules/common.bzl +++ b/rules/common.bzl @@ -22,6 +22,19 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group") # uses the older identifier. SDP_VERSION_MAPPING = {"8.0.4": "8.0.0"} +def get_flag_strings(flags): + """Converts a list of warning flags into a Bazel flag group representation. + + Args: + flags (list[str]): A list of compiler warning flags. + + Returns: + str: A formatted string representing the flag group in Bazel syntax. + """ + if len(flags): + return "[" + ", ".join(['"%s"' % f for f in flags]) + "]" + return "None" + def get_flag_groups(flags): """Converts a list of warning flags into a Bazel flag group representation. diff --git a/rules/gcc.bzl b/rules/gcc.bzl index 1a9504b..4f15807 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -14,7 +14,7 @@ """ Module rule for defining GCC toolchains in Bazel. """ -load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "label_list_to_string") +load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "label_list_to_string", "get_flag_strings") # Constants _OS_QNX = "qnx" @@ -52,8 +52,7 @@ def _get_cc_config_linux(rctx): Returns: str: BUILD file content defining filegroup and cc_toolchain_config for Linux. """ - return """ -filegroup( + return """filegroup( name = "all_files", srcs = [ "@{tc_pkg_repo}//:all_files", @@ -71,6 +70,8 @@ cc_toolchain_config( sysroot = "@{tc_pkg_repo}//:sysroot_dir", target_cpu = "{tc_cpu}", target_os = "{tc_os}", + known_features = _KNOWN_FEATURES, + enabled_features = _ENABLED_FEATURES, extra_known_features = {tc_extra_known_features}, extra_enabled_features = {tc_extra_enabled_features}, visibility = ["//visibility:public"], @@ -113,6 +114,8 @@ cc_toolchain_config( cxx_builtin_include_directories = "@{tc_pkg_repo}//:cxx_builtin_include_directories", target_cpu = "{tc_cpu}", target_os = "{tc_os}", + known_features = _KNOWN_FEATURES, + enabled_features = _ENABLED_FEATURES, extra_known_features = {tc_extra_known_features}, extra_enabled_features = {tc_extra_enabled_features}, visibility = ["//visibility:public"], @@ -210,6 +213,17 @@ def _impl(rctx): tc_identifier_short_2 = "-{}".format(rctx.attr.tc_runtime_ecosystem) tc_identifier_long_2 = "[\"@score_bazel_platforms//runtime_es:{}\"]".format(rctx.attr.tc_runtime_ecosystem) + + # Get canonical repository name for the toolchain package + canonical_pkg_name = _get_canonical_pkg_name(rctx) + + # Replace %{toolchain_pkg}% placeholder in extra flags with canonical name + def replace_placeholder(flags): + return [flag.replace(_PLACEHOLDER_TOOLCHAIN_PKG, canonical_pkg_name) for flag in flags] + + compiler_library_search_paths = replace_placeholder(rctx.attr.tc_compiler_library_search_paths) + compiler_library_search_paths_str = ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]) + rctx.template( "BUILD", rctx.attr._cc_toolchain_build, @@ -221,6 +235,12 @@ def _impl(rctx): "%{tc_pkg_repo}": rctx.attr.tc_pkg_repo, "%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem, "%{tc_version}": rctx.attr.gcc_version, + "%{tc_sysroot}": "@{tc_pkg_repo}//:sysroot_dir".format(tc_pkg_repo = rctx.attr.tc_pkg_repo), + "%{tc_extra_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_compile_flags)), + "%{tc_extra_c_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_c_compile_flags)), + "%{tc_extra_cxx_compile_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_cxx_compile_flags)), + "%{tc_extra_link_flags}": get_flag_strings(replace_placeholder(rctx.attr.extra_link_flags)), + "%{tc_compiler_library_search_paths}": compiler_library_search_paths_str, "%{tc_identifier_short_1}": tc_identifier_short_1, "%{tc_identifier_short_2}": tc_identifier_short_2, "%{tc_identifier_long_1}": tc_identifier_long_1, @@ -228,22 +248,14 @@ def _impl(rctx): }, ) - # Get canonical repository name for the toolchain package - canonical_pkg_name = _get_canonical_pkg_name(rctx) - - # Replace %{toolchain_pkg}% placeholder in extra flags with canonical name - def replace_placeholder(flags): - return [flag.replace(_PLACEHOLDER_TOOLCHAIN_PKG, canonical_pkg_name) for flag in flags] - extra_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_compile_flags)) extra_c_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_c_compile_flags)) extra_cxx_compile_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_cxx_compile_flags)) extra_link_flags = get_flag_groups(replace_placeholder(rctx.attr.extra_link_flags)) - compiler_library_search_paths = replace_placeholder(rctx.attr.tc_compiler_library_search_paths) template_dict = { "%{compiler_library_search_paths_switch}": "True" if len(rctx.attr.tc_compiler_library_search_paths) else "False", - "%{compiler_library_search_paths}": ":".join(["/proc/self/cwd/" + entry for entry in compiler_library_search_paths]), + "%{compiler_library_search_paths}": compiler_library_search_paths_str, "%{extra_c_compile_flags_switch}": "True" if len(rctx.attr.extra_c_compile_flags) else "False", "%{extra_c_compile_flags}": extra_c_compile_flags, "%{extra_compile_flags_switch}": "True" if len(rctx.attr.extra_compile_flags) else "False", @@ -276,12 +288,6 @@ def _impl(rctx): template_dict, ) - rctx.template( - "flags.bzl", - rctx.attr.cc_toolchain_flags, - {}, - ) - 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 @@ -320,9 +326,6 @@ gcc_toolchain = repository_rule( "cc_toolchain_config": attr.label( doc = "Path to the cc_config.bzl template file.", ), - "cc_toolchain_flags": attr.label( - doc = "Path to the Bazel BUILD file template for the toolchain.", - ), "extra_c_compile_flags": attr.string_list(doc = "Extra/Additional C-specific compile flags."), "extra_compile_flags": attr.string_list(doc = "Extra/Additional compile flags."), "extra_cxx_compile_flags": attr.string_list(doc = "Extra/Additional C++-specific compile flags."), @@ -344,7 +347,7 @@ gcc_toolchain = repository_rule( "tc_runtime_ecosystem": attr.string(doc = "Runtime ecosystem."), "tc_system_toolchain": attr.bool(doc = "Boolean flag to state if this is a system toolchain"), "_cc_gcov_wrapper_script": attr.label( - default = "@score_bazel_cpp_toolchains//templates/linux:cc_gcov_wrapper.template", + default = "@score_bazel_cpp_toolchains//templates:cc_gcov_wrapper.template", ), "_cc_toolchain_build": attr.label( default = "@score_bazel_cpp_toolchains//templates:BUILD.template", diff --git a/templates/BUILD.template b/templates/BUILD.template index b7548da..f6c13a1 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -15,8 +15,46 @@ """ load("@rules_cc//cc:defs.bzl", "cc_toolchain") +load("@score_bazel_cpp_toolchains//features/extra_compile_flags:features.bzl", "make_extra_compile_features") +load("@score_bazel_cpp_toolchains//features/extra_link_flags:features.bzl", "make_extra_link_features") +load("@score_bazel_cpp_toolchains//features/compiler_library_search_paths:features.bzl", "make_compiler_library_search_paths") +load("@score_bazel_cpp_toolchains//features/sysroot_link_flags:features.bzl", "make_sysroot_link_flags") +load("@score_bazel_cpp_toolchains//features/qnx_gcc_version_flags:features.bzl", "make_qnx_gcc_version_flags") +load("@score_bazel_cpp_toolchains//features:make_cc_features.bzl", "compute_feature_lists") load(":cc_toolchain_config.bzl", "cc_toolchain_config") +make_extra_compile_features( + extra_compile_flags = %{tc_extra_compile_flags}, + extra_c_compile_flags = %{tc_extra_c_compile_flags}, + extra_cxx_compile_flags = %{tc_extra_cxx_compile_flags}, +) + +make_extra_link_features( + extra_link_flags = %{tc_extra_link_flags} +) + +make_compiler_library_search_paths( + compiler_library_search_paths = "%{tc_compiler_library_search_paths}", +) + +make_sysroot_link_flags( + target_os = "%{tc_os}", + sysroot = "%{tc_sysroot}", +) + +# TODO: Change the name of this macro +make_qnx_gcc_version_flags( + tc_version = "%{tc_version}", + target_cpu = "%{tc_cpu}", + target_os = "%{tc_os}", +) + +# known_features must list every feature (enabled or opt-in); enabled_features is +# the order-irrelevant subset that should start on. See compute_feature_lists(). +_KNOWN_FEATURES, _ENABLED_FEATURES = compute_feature_lists( + target_os = "%{tc_os}", +) + filegroup( name = "empty", ) diff --git a/templates/linux/cc_gcov_wrapper.template b/templates/cc_gcov_wrapper.template similarity index 100% rename from templates/linux/cc_gcov_wrapper.template rename to templates/cc_gcov_wrapper.template diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template index c5480ff..70e9b0b 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/linux/cc_toolchain_config.bzl.template @@ -16,75 +16,15 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "action_config", - "env_entry", - "env_set", - "feature", - "feature_set", "flag_group", "flag_set", "tool", "tool_path", - "variable_with_value", - "with_feature_set", ) load("@rules_cc//cc:defs.bzl", "cc_common", "CcToolchainConfigInfo") load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") -load(":flags.bzl", - "UNFILTERED_COMPILE_FLAGS", - "DEFAULT_COMPILE_FLAGS", - "DEFAULT_x86_64_COMPILE_FLAGS", - "DEFAULT_ARM64_COMPILE_FLAGS", - "DEFAULT_C_COMPILE_FLAGS", - "DEFAULT_CXX_COMPILE_FLAGS", - "DEFAULT_LINK_FLAGS", - "DBG_COMPILE_FLAGS", - "OPT_COMPILE_FLAGS", -) - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_c_compile_actions = [ - ACTION_NAMES.c_compile, -] - -all_assemble_actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, -] - -all_compile_actions = all_c_compile_actions + all_cpp_compile_actions + all_assemble_actions - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -all_actions = all_compile_actions + all_link_actions + [ - ACTION_NAMES.strip, - ACTION_NAMES.cpp_link_static_library, -] def _impl(ctx): - dbg_feature = feature(name = "dbg") - opt_feature = feature(name = "opt") - - no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) - - # Temp solution until we do not add feature injection - gnu11_feature = feature(name = "gnu11") - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - supports_fission_feature = feature(name = "supports_fission", enabled = True) - assemble_action = action_config( action_name = ACTION_NAMES.assemble, tools = [tool(tool = ctx.executable.cc_binary)], @@ -157,828 +97,9 @@ def _impl(ctx): strip_action, ] - # Set LD_LIBRARY_PATH environment variable for all actions - # This is needed by some toolchains since these libraries are not in `rpath` of compiler binary - # which are needed to run it. - compiler_library_search_paths = "%{compiler_library_search_paths}" - compiler_library_search_paths_feature = feature( - name = "compiler_library_search_paths", - enabled = %{compiler_library_search_paths_switch}, - env_sets = [ - env_set( - actions = all_actions, - env_entries = [env_entry(key = "LD_LIBRARY_PATH", value = compiler_library_search_paths)] if compiler_library_search_paths != "" else [], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_c_compile_actions + all_cpp_compile_actions, - flag_groups = UNFILTERED_COMPILE_FLAGS - ), - ], - ) - - target_cpu_flags = [] - if ctx.attr.target_cpu == "x86_64": - target_cpu_flags = DEFAULT_x86_64_COMPILE_FLAGS - else: - target_cpu_flags = DEFAULT_ARM64_COMPILE_FLAGS - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = DEFAULT_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = target_cpu_flags, - ), - flag_set( - actions = all_c_compile_actions, - flag_groups = [flag_group(flags = ["-std=c11"])], - with_features = [with_feature_set(not_features = ["gnu11"])], - ), - flag_set( - actions = all_c_compile_actions, - flag_groups = [flag_group(flags = ["-std=gnu11"])], - with_features = [with_feature_set(features = ["gnu11"])], - ), - flag_set( - actions = all_cpp_compile_actions, - flag_groups = DEFAULT_CXX_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, - with_features = [ - with_feature_set(features = ["opt"]), - with_feature_set(features = ["fastbuild"]), - ], - ), - ], - ) - - # Add sysroot linker flags as a separate feature (always enabled) - sysroot_link_flags_feature_flag_sets = [] - if ctx.attr.sysroot != None: - sysroot_files = ctx.attr.sysroot[DefaultInfo].files.to_list() - if sysroot_files: - sysroot_path = sysroot_files[0].path - sysroot_link_flags_feature_flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = [ - "--sysroot=" + sysroot_path, - "-Wl,--sysroot=" + sysroot_path, - ])], - ), - ] - - sysroot_link_flags_feature = feature( - name = "sysroot_link_flags", - enabled = True, - flag_sets = sysroot_link_flags_feature_flag_sets, - ) - - # Only enable default link flags if extra link flags are not provided - default_link_flags_enabled = not %{extra_link_flags_switch} - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = default_link_flags_enabled, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = DEFAULT_LINK_FLAGS, - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = [ - "-Wl,--compress-debug-sections=zlib", - ], - ), - ], - with_features = [with_feature_set(not_features = ["opt"])], - ), - ], - ) - - extra_compile_flags = %{extra_compile_flags} - extra_compile_flags_feature = feature( - name = "extra_compile_flags", - enabled = %{extra_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = extra_compile_flags, - ), - ], - ) - - extra_c_compile_flags = %{extra_c_compile_flags} - extra_c_compile_flags_feature = feature( - name = "extra_c_compile_flags", - enabled = %{extra_c_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_c_compile_actions, - flag_groups = extra_c_compile_flags, - ), - ], - ) - - extra_cxx_compile_flags = %{extra_cxx_compile_flags} - extra_cxx_compile_flags_feature = feature( - name = "extra_cxx_compile_flags", - enabled = %{extra_cxx_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_cpp_compile_actions, - flag_groups = extra_cxx_compile_flags, - ), - ], - ) - - extra_link_flags = %{extra_link_flags} - extra_link_flags_feature = feature( - name = "extra_link_flags", - enabled = %{extra_link_flags_switch}, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = extra_link_flags, - ), - ], - ) - - pthread_feature = feature( - name = "use_pthread", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group(flags = ["-pthread"]), - ], - ), - ], - ) - - supports_pic_feature = feature(name = "supports_pic", enabled = True) - - pic_feature = feature( - name = "pic", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group(flags = ["-fPIC"], expand_if_available = "pic"), - ], - ), - ], - ) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "user_compile_flags", - flags = ["%{user_compile_flags}"], - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - random_seed_feature = feature( - name = "random_seed", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ], - flag_groups = [ - flag_group( - expand_if_available = "output_file", - flags = ["-frandom-seed=%{output_file}"], - ), - ], - ), - ], - ) - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "quote_include_paths", - flags = ["-iquote", "%{quote_include_paths}"], - expand_if_available = "quote_include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "include_paths", - flags = ["-I%{include_paths}"], - expand_if_available = "include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "system_include_paths", - flags = ["-isystem", "%{system_include_paths}"], - expand_if_available = "system_include_paths", - ), - ], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "preprocessor_defines", - flags = ["-D%{preprocessor_defines}"], - expand_if_available = "preprocessor_defines", - ), - ], - ), - ], - ) - - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ) - - dependency_file_feature = feature( - name = "dependency_file", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-MD", "-MF", "%{dependency_file}"], - expand_if_available = "dependency_file", - ), - ], - ), - ], - ) - - compiler_output_flags_feature = feature( - name = "compiler_output_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-S"], - expand_if_available = "output_assembly_file", - ), - flag_group( - flags = ["-E"], - expand_if_available = "output_preprocess_file", - ), - flag_group( - flags = ["-o", "%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["rcsD", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - flag_group( - iterate_over = "user_archiver_flags", - flags = ["%{user_archiver_flags}"], - expand_if_available = "user_archiver_flags", - ), - ], - ), - ], - ) - - linker_param_file_feature = feature( - name = "linker_param_file", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - ], - ), - ], - ) - - library_search_directories_feature = feature( - name = "library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "library_search_directories", - flag_groups = [ - flag_group( - flags = ["-L%{library_search_directories}"], - ), - ], - expand_if_available = "library_search_directories", - ), - ], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-shared"])], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = ["-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}"], - expand_if_true = "is_cc_test", - ), - flag_group( - flags = ["-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}"], - expand_if_false = "is_cc_test", - ), - ], - expand_if_available = "runtime_library_search_directories", - ), - ], - ), - ], - ) - - libraries_to_link_feature = feature( - name = "libraries_to_link", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--whole-archive", "%{libraries_to_link.name}", "-Wl,--no-whole-archive"], - expand_if_true = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - flag_group( - flags = ["-l:%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "versioned_dynamic_library", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ) - - user_link_flags_feature = feature( - name = "user_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "user_link_flags", - flags = ["%{user_link_flags}"], - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) - - # ------------------------------------------------------------------------ - # Additional legacy features. - # - # These mirror features that Bazel's legacy toolchain machinery would add - # automatically. All except fully_static_link are guarded (via - # expand_if_available or with_features) so they are no-ops for normal builds - # and only emit flags when the relevant build mode is active (e.g. --fission, - # --force_pic, --stamp). They are therefore enabled by default. - # - # fully_static_link is left DISABLED by default because it emits -static - # unconditionally, which would force fully static linking for every target. - # Users who want it must opt in explicitly, e.g. via `--features=`. - # ------------------------------------------------------------------------ - - # Fission: emit split DWARF debug info into separate .dwo files at compile. - per_object_debug_info_feature = feature( - name = "per_object_debug_info", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["-gsplit-dwarf", "-g"], - expand_if_available = "per_object_debug_info_file", - ), - ], - ), - ], - ) - - # Fission: emit a .gdb_index section at link when fission is in use. - fission_support_feature = feature( - name = "fission_support", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,--gdb-index"], - expand_if_available = "is_using_fission", - ), - ], - ), - ], - ) - - # Pass linkstamp object files to the linker (used with --stamp). - linkstamps_feature = feature( - name = "linkstamps", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "linkstamp_paths", - flags = ["%{linkstamp_paths}"], - expand_if_available = "linkstamp_paths", - ), - ], - ), - ], - ) - - # Force-include headers via -include (the `includes` build variable). - includes_feature = feature( - name = "includes", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "includes", - flags = ["-include", "%{includes}"], - expand_if_available = "includes", - ), - ], - ), - ], - ) - - # Build position-independent executables under --force_pic. - force_pic_flags_feature = feature( - name = "force_pic_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_executable], - flag_groups = [ - flag_group( - flags = ["-pie"], - expand_if_available = "force_pic", - ), - ], - ), - ], - ) - - # Strip debug symbols at link time. - strip_debug_symbols_feature = feature( - name = "strip_debug_symbols", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,-S"], - expand_if_available = "strip_debug_symbols", - ), - ], - ), - ], - ) - - # Statically link libgcc (paired with static_link_cpp_runtimes). - static_libgcc_feature = feature( - name = "static_libgcc", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static-libgcc"])], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - ], - ) - - # Fully static link (-static) under --dynamic_mode=fully. - fully_static_link_feature = feature( - name = "fully_static_link", - enabled = False, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static"])], - ), - ], - ) - - # Feature to disable absolute path warnings for system headers - supports_header_path_normalization = feature( - name = "supports_header_path_normalization", - enabled = True, - ) - - coverage_feature = feature(name = "coverage") - gcc_coverage_map_format_feature = feature( - name = "gcc_coverage_map_format", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.preprocess_assemble, - ], - flag_groups = [flag_group( - expand_if_available = "gcov_gcno_file", - flags = ["-fprofile-arcs", "-ftest-coverage"], - )], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["--coverage"])], - ), - ], - requires = [feature_set(features = ["coverage"])], - ) - - # The order of the features is relevant, they are applied in this specific order. - # A command line parameter from a feature at the end of the list will appear - # after a command line parameter from a feature at the beginning of the list. - features = [ - no_legacy_features_feature, - compiler_library_search_paths_feature, - dbg_feature, - unfiltered_compile_flags_feature, - gnu11_feature, - default_compile_flags_feature, - random_seed_feature, - include_paths_feature, - preprocessor_defines_feature, - extra_compile_flags_feature, - extra_c_compile_flags_feature, - extra_cxx_compile_flags_feature, - user_compile_flags_feature, - compiler_input_flags_feature, - compiler_output_flags_feature, - dependency_file_feature, - per_object_debug_info_feature, - includes_feature, - default_link_flags_feature, - archiver_flags_feature, - linker_param_file_feature, - library_search_directories_feature, - shared_flag_feature, - output_execpath_flags_feature, - runtime_library_search_directories_feature, - libraries_to_link_feature, - user_link_flags_feature, - linkstamps_feature, - fission_support_feature, - force_pic_flags_feature, - strip_debug_symbols_feature, - static_libgcc_feature, - fully_static_link_feature, - sysroot_link_flags_feature, - pthread_feature, - extra_link_flags_feature, - opt_feature, - supports_dynamic_linker_feature, - supports_pic_feature, - pic_feature, - supports_header_path_normalization, - supports_fission_feature, - coverage_feature, - gcc_coverage_map_format_feature, + convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) + for known_feature in ctx.attr.known_features ] extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) @@ -1028,6 +149,14 @@ cc_toolchain_config = rule( "host_dir": attr.label(default = None), "target_dir": attr.label(default = None), "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), + "known_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True + ), + "enabled_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True + ), "extra_enabled_features": attr.label_list( providers = [FeatureInfo], default = [], diff --git a/templates/linux/cc_toolchain_flags.bzl.template b/templates/linux/cc_toolchain_flags.bzl.template deleted file mode 100644 index 416275e..0000000 --- a/templates/linux/cc_toolchain_flags.bzl.template +++ /dev/null @@ -1,95 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2025 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 -# ******************************************************************************* - -""" Common compile and link flags for GCC toolchains. -""" - -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group") - -def get_flag_group(flags): - """Helper function to create a flag_group. - - Args: - flags (list[str]): A list of compiler or linker flags. - - Returns: - flag_group: A Bazel flag_group object containing the provided flags. - """ - if len(flags): - return [ - flag_group( - flags = flags, - ) - ] - return [] - -# Flags that should always be applied, without filtering. -UNFILTERED_COMPILE_FLAGS = get_flag_group([ - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - "-Wno-builtin-macro-redefined", -]) - -# Default compile flags when no specific build type is selected. -DEFAULT_COMPILE_FLAGS = get_flag_group([ - "-U_FORTIFY_SOURCE", - "-D_XOPEN_SOURCE=700", - "-fstack-protector", - "-fdiagnostics-color=always", - "-fno-omit-frame-pointer", - "-ffunction-sections", - "-fdata-sections", - "-fno-canonical-system-headers", - "-no-canonical-prefixes", - "-z noexecstack", -]) - -# TODO: Check if we need this. -DEFAULT_x86_64_COMPILE_FLAGS = get_flag_group([ - "-m64", -]) - -DEFAULT_ARM64_COMPILE_FLAGS = get_flag_group([ -]) - -# Default compile flags for C language when no specific build type is selected. -DEFAULT_C_COMPILE_FLAGS = get_flag_group([ -]) - -# Default compile flags for C++ language when no specific build type is selected. -DEFAULT_CXX_COMPILE_FLAGS = get_flag_group([ - "-std=c++17", -]) - -# Debug compile flags. -DBG_COMPILE_FLAGS = get_flag_group([ - "-Og", - "-g3", -]) - -# Optimization compile flags. -OPT_COMPILE_FLAGS = get_flag_group([ - "-O2", - "-DNDEBUG", -]) - -# Default link flags when no specific build type is selected. -DEFAULT_LINK_FLAGS = get_flag_group([ - "-lm", - "-ldl", - "-lrt", - "-static-libstdc++", - "-static-libgcc", -]) - diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index 4c8f06a..139c4bf 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -19,25 +19,14 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "env_entry", "env_set", "feature", - "feature_set", "flag_group", "flag_set", "tool", "tool_path", - "variable_with_value", "with_feature_set", ) load("@rules_cc//cc:defs.bzl", "cc_common", "CcToolchainConfigInfo") load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") -load(":flags.bzl", - "UNFILTERED_COMPILE_FLAGS", - "DEFAULT_COMPILE_FLAGS", - "DEFAULT_C_COMPILE_FLAGS", - "DEFAULT_CXX_COMPILE_FLAGS", - "DEFAULT_LINK_FLAGS", - "DBG_COMPILE_FLAGS", - "OPT_COMPILE_FLAGS", -) all_cpp_compile_actions = [ ACTION_NAMES.cpp_compile, @@ -75,13 +64,6 @@ def _impl(ctx): """ Implementation function of GCC toolchains. """ - dbg_feature = feature(name = "dbg") - opt_feature = feature(name = "opt") - - no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True) - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - assemble_action = action_config( action_name = ACTION_NAMES.assemble, tools = [tool(tool = ctx.executable.cc_binary)], @@ -154,443 +136,6 @@ def _impl(ctx): strip_action, ] - # Core compilation features - random_seed_feature = feature( - name = "random_seed", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ], - flag_groups = [ - flag_group( - expand_if_available = "output_file", - flags = ["-frandom-seed=%{output_file}"], - ), - ], - ), - ], - ) - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "quote_include_paths", - flags = ["-iquote", "%{quote_include_paths}"], - expand_if_available = "quote_include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "include_paths", - flags = ["-I%{include_paths}"], - expand_if_available = "include_paths", - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "system_include_paths", - flags = ["-isystem", "%{system_include_paths}"], - expand_if_available = "system_include_paths", - ), - ], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "preprocessor_defines", - flags = ["-D%{preprocessor_defines}"], - expand_if_available = "preprocessor_defines", - ), - ], - ), - ], - ) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - iterate_over = "user_compile_flags", - flags = ["%{user_compile_flags}"], - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ) - - compiler_output_flags_feature = feature( - name = "compiler_output_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["-S"], - expand_if_available = "output_assembly_file", - ), - flag_group( - flags = ["-E"], - expand_if_available = "output_preprocess_file", - ), - flag_group( - flags = ["-o", "%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["rcsD", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - flag_group( - iterate_over = "user_archiver_flags", - flags = ["%{user_archiver_flags}"], - expand_if_available = "user_archiver_flags", - ), - ], - ), - ], - ) - - # Core linking features - user_link_flags_feature = feature( - name = "user_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "user_link_flags", - flags = ["%{user_link_flags}"], - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) - - linker_param_file_feature = feature( - name = "linker_param_file", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - ], - ), - ], - ) - - library_search_directories_feature = feature( - name = "library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "library_search_directories", - flag_groups = [ - flag_group( - flags = ["-L%{library_search_directories}"], - ), - ], - expand_if_available = "library_search_directories", - ), - ], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-shared"])], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - libraries_to_link_feature = feature( - name = "libraries_to_link", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--whole-archive", "%{libraries_to_link.name}", "-Wl,--no-whole-archive"], - expand_if_true = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - flag_group( - flags = ["-l:%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "versioned_dynamic_library", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_c_compile_actions + all_cpp_compile_actions, - flag_groups = UNFILTERED_COMPILE_FLAGS, - ), - ], - ) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = DEFAULT_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}"])], - ), - flag_set( - actions = all_c_compile_actions, - flag_groups = DEFAULT_C_COMPILE_FLAGS, - ), - flag_set( - actions = all_cpp_compile_actions, - flag_groups = DEFAULT_CXX_COMPILE_FLAGS, - ), - flag_set( - actions = all_compile_actions, - flag_groups = DBG_COMPILE_FLAGS, - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = OPT_COMPILE_FLAGS, - with_features = [ - with_feature_set(features = ["opt"]), - with_feature_set(features = ["fastbuild"]), - ], - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-V%{tc_version},gcc_nto%{tc_cpu}_cxx"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = DEFAULT_LINK_FLAGS, - ), - ], - ) - - extra_compile_flags = %{extra_compile_flags} - extra_compile_flags_feature = feature( - name = "extra_compile_flags", - enabled = %{extra_compile_flags_switch}, - implies = ["default_compile_flags"], - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = extra_compile_flags, - ), - ], - ) - - extra_link_flags = %{extra_link_flags} - extra_link_flags_feature = feature( - name = "extra_link_flags", - enabled = %{extra_link_flags_switch}, - implies = ["default_link_flags"], - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = extra_link_flags, - ), - ], - ) - supports_pic_feature = feature(name = "supports_pic", enabled = True) - - pic_feature = feature( - name = "pic", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group(flags = ["-fPIC"], expand_if_available = "pic"), - ], - ), - ], - ) - - dependency_file_named_implicitly_feature = feature( - name = "dependency_file_named_implicitly", - enabled = False, - ) - use_license_env_info_feautre = feature( name = "qnx_license_env_info", enabled = %{use_license_info}, @@ -620,143 +165,17 @@ def _impl(ctx): ], ) - dependency_file_feature = feature( - name = "dependency_file", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [flag_group( - flags = [ - "-Wc,-MD,%{dependency_file}", - "-Wp,-MD,%{dependency_file}", - ], - expand_if_available = "dependency_file", - )], - with_features = [ - with_feature_set(not_features = ["dependency_file_named_implicitly"]), - ], - ), - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.clif_match, - ], - flag_groups = [flag_group(flags = [ - "-Wc,-MD", - "-Wp,-MD", - ])], - with_features = [ - with_feature_set(features = ["dependency_file_named_implicitly"]), - ], - ), - ], - ) - - # QNX uses -Wl,-rpath instead of -rpath - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = ["-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}"], - ), - ], - expand_if_available = "runtime_library_search_directories", - ), - ], - ), - ], - ) - - coverage_feature = feature(name = "coverage") - gcc_coverage_map_format_feature = feature( - name = "gcc_coverage_map_format", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.preprocess_assemble, - ], - flag_groups = [flag_group( - expand_if_available = "gcov_gcno_file", - flags = ["-fprofile-arcs", "-ftest-coverage"], - )], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-lgcov"])], - ), - ], - ) - - # The order of the features is relevant, they are applied in this specific order. - # A command line parameter from a feature at the end of the list will appear - # after a command line parameter from a feature at the beginning of the list. - features = [ - dbg_feature, - no_legacy_features_feature, - unfiltered_compile_flags_feature, - default_compile_flags_feature, - random_seed_feature, - include_paths_feature, - preprocessor_defines_feature, - extra_compile_flags_feature, - user_compile_flags_feature, - compiler_input_flags_feature, - compiler_output_flags_feature, - dependency_file_named_implicitly_feature, - dependency_file_feature, - default_link_flags_feature, - archiver_flags_feature, - linker_param_file_feature, - library_search_directories_feature, - shared_flag_feature, - output_execpath_flags_feature, - libraries_to_link_feature, - user_link_flags_feature, - coverage_feature, - extra_link_flags_feature, - opt_feature, - use_license_env_info_feautre, - sdp_env_feature, - supports_dynamic_linker_feature, - supports_pic_feature, - pic_feature, - runtime_library_search_directories_feature, - gcc_coverage_map_format_feature, + convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) + for known_feature in ctx.attr.known_features ] + features.append(use_license_env_info_feautre) + features.append(sdp_env_feature) extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) + cxx_builtin_include_directories = [ "/proc/self/cwd/{}".format(include_directory.path) for include_directory in ctx.files.cxx_builtin_include_directories @@ -795,6 +214,14 @@ cc_toolchain_config = rule( "target_cpu": attr.string(mandatory = True), "target_os": attr.string(mandatory = True), "cxx_builtin_include_directories": attr.label(allow_files = True, mandatory = True), + "known_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True, + ), + "enabled_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True, + ), "extra_enabled_features": attr.label_list( providers = [FeatureInfo], default = [], diff --git a/templates/qnx/cc_toolchain_flags.bzl.template b/templates/qnx/cc_toolchain_flags.bzl.template deleted file mode 100644 index 52c2bf3..0000000 --- a/templates/qnx/cc_toolchain_flags.bzl.template +++ /dev/null @@ -1,81 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2025 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 -# ******************************************************************************* - -""" Common compile and link flags for GCC toolchains. -""" - -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "flag_group") - -def get_flag_group(flags): - """Helper function to create a flag_group. - - Args: - flags (list[str]): A list of compiler or linker flags. - - Returns: - flag_group: A Bazel flag_group object containing the provided flags. - """ - if len(flags): - return [ - flag_group( - flags = flags, - ) - ] - return [] - -# Flags that should always be applied, without filtering. -UNFILTERED_COMPILE_FLAGS = get_flag_group([ - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - "-Wno-builtin-macro-redefined", -]) - -# Default compile flags when no specific build type is selected. -DEFAULT_COMPILE_FLAGS = get_flag_group([ - "-fno-canonical-system-headers", -]) - -# Default compile flags for C language when no specific build type is selected. -DEFAULT_C_COMPILE_FLAGS = get_flag_group([ - "-std=c11", -]) - -# Default compile flags for C++ language when no specific build type is selected. -DEFAULT_CXX_COMPILE_FLAGS = get_flag_group([ - "-D_QNX_SOURCE", - "-std=c++17", -]) - -# Debug compile flags. -DBG_COMPILE_FLAGS = get_flag_group([ - "-Og", - "-g3", -]) - -# Optimization compile flags. -OPT_COMPILE_FLAGS = get_flag_group([ - "-O2", - "-DNDEBUG", -]) - -# Default link flags when no specific build type is selected. -DEFAULT_LINK_FLAGS = get_flag_group([ - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--push-state", - "-Wl,--as-needed", - "-lc++", - "-lm", - "-Wl,--pop-state", -]) diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 15a6923..1c913bb 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1369,7 +1369,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "uUsNFSfSSybb9eE3vhujRJ3STO1XYw/Su0MpWT8DZJI=", + "bzlTransitiveDigest": "jnA5FZBDfPWgQ+FRTBDBlnxBZs87RheTRgVMxqTfbvo=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1508,7 +1508,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": true } }, @@ -1535,7 +1534,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1562,7 +1560,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "15.3.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1589,7 +1586,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1616,7 +1612,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "15.3.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1645,7 +1640,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1672,7 +1666,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1699,7 +1692,6 @@ "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1762,7 +1754,6 @@ "tc_runtime_ecosystem": "autosd10", "gcc_version": "", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } }, @@ -1841,7 +1832,6 @@ "tc_runtime_ecosystem": "ebclfsa", "gcc_version": "", "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", - "cc_toolchain_flags": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_flags.bzl.template", "use_base_constraints_only": false } } From 3b9a38ea90a4d0e9679b9e98ad265d2acc1702ab Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Fri, 28 Aug 2026 16:59:39 +0200 Subject: [PATCH 3/7] Temp commit #3 --- .github/workflows/autosd.yml | 4 ++-- features/qnx_gcc_version_flags/features.bzl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/autosd.yml b/.github/workflows/autosd.yml index 89260af..ff90bfc 100644 --- a/.github/workflows/autosd.yml +++ b/.github/workflows/autosd.yml @@ -41,7 +41,7 @@ jobs: cache-save: ${{ github.event_name == 'push' }} - name: Bazel Build (basic) run: | - bazel build --lockfile_mode=error --config=x86_64-linux-autosd10 -- //:language_and_standards_tests //:feature_verification_tests + bazel build --lockfile_mode=error --config=x86_64-linux-autosd10 --features=-default_link_flags -- //:language_and_standards_tests //:feature_verification_tests - name: Guardrail (no legacy features) run: | - bazel test --lockfile_mode=error --config=x86_64-linux-autosd10 -- //:guardrail_tests + bazel test --lockfile_mode=error --config=x86_64-linux-autosd10 --features=-default_link_flags -- //:guardrail_tests diff --git a/features/qnx_gcc_version_flags/features.bzl b/features/qnx_gcc_version_flags/features.bzl index e0a68ec..05da1fe 100644 --- a/features/qnx_gcc_version_flags/features.bzl +++ b/features/qnx_gcc_version_flags/features.bzl @@ -29,13 +29,13 @@ def make_qnx_gcc_version_flags(tc_version, target_cpu, target_os): cc_args( name = "qnx_gcc_version_compile_args", actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], - args = ["-V{},gcc_nto{}".format(tc_version, target_cpu)], + args = ["-V{},gcc_nto{}".format(tc_version, target_cpu if target_cpu != "aarch64" else "aarch64le")], ) cc_args( name = "qnx_gcc_version_link_args", actions = ["@rules_cc//cc/toolchains/actions:link_actions"], - args = ["-V{},gcc_nto{}_cxx".format(tc_version, target_cpu)], + args = ["-V{},gcc_nto{}_cxx".format(tc_version, target_cpu if target_cpu != "aarch64" else "aarch64le")], ) cc_feature( From 4a2b498bdc2a04e2ed7800be81cc29f0cc16d9a6 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Sat, 29 Aug 2026 11:33:07 +0100 Subject: [PATCH 4/7] Temp commit #4 --- .bazelversion | 2 +- features/BUILD | 134 ++--- .../linux}/BUILD | 0 features/custom/linux/make_cc_features.bzl | 75 +++ .../{extra_link_flags => custom/qnx}/BUILD | 0 features/custom/qnx/gcc_version_flags/BUILD | 43 ++ features/custom/qnx/make_cc_features.bzl | 72 +++ features/make_cc_features.bzl | 116 +--- features/{ => native}/archiver_flags/BUILD | 0 .../{ => native}/compiler_input_flags/BUILD | 0 .../compiler_library_search_paths/BUILD | 0 .../features.bzl | 0 .../{ => native}/compiler_output_flags/BUILD | 0 .../{ => native}/default_compile_flags/BUILD | 30 +- .../{ => native}/default_link_flags/BUILD | 6 +- features/{ => native}/dependency_file/BUILD | 4 +- features/native/extra_compile_flags/BUILD | 0 .../extra_compile_flags/features.bzl | 6 +- features/native/extra_link_flags/BUILD | 0 .../extra_link_flags/features.bzl | 0 features/{ => native}/fission_support/BUILD | 0 features/{ => native}/force_pic_flags/BUILD | 0 features/{ => native}/fully_static_link/BUILD | 0 .../gcc_coverage_map_format/BUILD | 2 +- features/{ => native}/include_paths/BUILD | 0 features/{ => native}/includes/BUILD | 0 features/{ => native}/libraries_to_link/BUILD | 0 .../library_search_directories/BUILD | 0 features/{ => native}/linker_param_file/BUILD | 0 features/{ => native}/linkstamps/BUILD | 0 features/{ => native}/markers/BUILD | 0 .../{ => native}/output_execpath_flags/BUILD | 0 .../{ => native}/per_object_debug_info/BUILD | 0 features/{ => native}/pic/BUILD | 0 .../{ => native}/preprocessor_defines/BUILD | 0 features/{ => native}/random_seed/BUILD | 0 .../runtime_library_search_directories/BUILD | 0 features/{ => native}/shared_flag/BUILD | 0 features/{ => native}/static_libgcc/BUILD | 2 +- .../{ => native}/strip_debug_symbols/BUILD | 0 .../{ => native}/sysroot_link_flags/BUILD | 0 .../sysroot_link_flags/features.bzl | 0 .../unfiltered_compile_flags/BUILD | 0 features/{ => native}/use_pthread/BUILD | 0 .../{ => native}/user_compile_flags/BUILD | 0 features/{ => native}/user_link_flags/BUILD | 0 features/qnx_gcc_version_flags/BUILD | 15 - features/qnx_gcc_version_flags/features.bzl | 46 -- templates/BUILD.template | 22 +- .../linux/cc_toolchain_config.bzl.template | 8 +- .../qnx/cc_toolchain_config.bzl.template | 23 +- tests/.bazelversion | 2 +- tests/MODULE.bazel.lock | 541 ++++++------------ 53 files changed, 492 insertions(+), 657 deletions(-) rename features/{extra_compile_flags => custom/linux}/BUILD (100%) create mode 100644 features/custom/linux/make_cc_features.bzl rename features/{extra_link_flags => custom/qnx}/BUILD (100%) create mode 100644 features/custom/qnx/gcc_version_flags/BUILD create mode 100644 features/custom/qnx/make_cc_features.bzl rename features/{ => native}/archiver_flags/BUILD (100%) rename features/{ => native}/compiler_input_flags/BUILD (100%) rename features/{ => native}/compiler_library_search_paths/BUILD (100%) rename features/{ => native}/compiler_library_search_paths/features.bzl (100%) rename features/{ => native}/compiler_output_flags/BUILD (100%) rename features/{ => native}/default_compile_flags/BUILD (81%) rename features/{ => native}/default_link_flags/BUILD (94%) rename features/{ => native}/dependency_file/BUILD (94%) create mode 100644 features/native/extra_compile_flags/BUILD rename features/{ => native}/extra_compile_flags/features.bzl (87%) create mode 100644 features/native/extra_link_flags/BUILD rename features/{ => native}/extra_link_flags/features.bzl (100%) rename features/{ => native}/fission_support/BUILD (100%) rename features/{ => native}/force_pic_flags/BUILD (100%) rename features/{ => native}/fully_static_link/BUILD (100%) rename features/{ => native}/gcc_coverage_map_format/BUILD (97%) rename features/{ => native}/include_paths/BUILD (100%) rename features/{ => native}/includes/BUILD (100%) rename features/{ => native}/libraries_to_link/BUILD (100%) rename features/{ => native}/library_search_directories/BUILD (100%) rename features/{ => native}/linker_param_file/BUILD (100%) rename features/{ => native}/linkstamps/BUILD (100%) rename features/{ => native}/markers/BUILD (100%) rename features/{ => native}/output_execpath_flags/BUILD (100%) rename features/{ => native}/per_object_debug_info/BUILD (100%) rename features/{ => native}/pic/BUILD (100%) rename features/{ => native}/preprocessor_defines/BUILD (100%) rename features/{ => native}/random_seed/BUILD (100%) rename features/{ => native}/runtime_library_search_directories/BUILD (100%) rename features/{ => native}/shared_flag/BUILD (100%) rename features/{ => native}/static_libgcc/BUILD (95%) rename features/{ => native}/strip_debug_symbols/BUILD (100%) rename features/{ => native}/sysroot_link_flags/BUILD (100%) rename features/{ => native}/sysroot_link_flags/features.bzl (100%) rename features/{ => native}/unfiltered_compile_flags/BUILD (100%) rename features/{ => native}/use_pthread/BUILD (100%) rename features/{ => native}/user_compile_flags/BUILD (100%) rename features/{ => native}/user_link_flags/BUILD (100%) delete mode 100644 features/qnx_gcc_version_flags/BUILD delete mode 100644 features/qnx_gcc_version_flags/features.bzl diff --git a/.bazelversion b/.bazelversion index acd405b..df5119e 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8.6.0 +8.7.0 diff --git a/features/BUILD b/features/BUILD index a353617..4c0c5a2 100644 --- a/features/BUILD +++ b/features/BUILD @@ -18,46 +18,46 @@ load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set") cc_feature_set( name = "linux", all_of = [ - "//features/markers:no_legacy_features", - "//features/compiler_library_search_paths", - "//features/markers:dbg", - "//features/unfiltered_compile_flags", - "//features/markers:gnu11", - "//features/default_compile_flags", - "//features/random_seed", - "//features/include_paths", - "//features/preprocessor_defines", - "//features/user_compile_flags", - "//features/compiler_input_flags", - "//features/compiler_output_flags", - "//features/dependency_file", - "//features/per_object_debug_info", - "//features/includes", - "//features/default_link_flags", - "//features/archiver_flags", - "//features/linker_param_file", - "//features/library_search_directories", - "//features/shared_flag", - "//features/output_execpath_flags", - "//features/runtime_library_search_directories", - "//features/libraries_to_link", - "//features/user_link_flags", - "//features/linkstamps", - "//features/fission_support", - "//features/force_pic_flags", - "//features/strip_debug_symbols", - "//features/static_libgcc", - "//features/fully_static_link", - "//features/sysroot_link_flags", - "//features/use_pthread", - "//features/markers:opt", - "//features/markers:supports_dynamic_linker", - "//features/markers:supports_pic", - "//features/pic", - "//features/markers:supports_header_path_normalization", - "//features/markers:supports_fission", - "//features/markers:coverage", - "//features/gcc_coverage_map_format", + "//features/native/markers:no_legacy_features", + "//features/native/compiler_library_search_paths", + "//features/native/markers:dbg", + "//features/native/unfiltered_compile_flags", + "//features/native/markers:gnu11", + "//features/native/default_compile_flags", + "//features/native/random_seed", + "//features/native/include_paths", + "//features/native/preprocessor_defines", + "//features/native/user_compile_flags", + "//features/native/compiler_input_flags", + "//features/native/compiler_output_flags", + "//features/native/dependency_file", + "//features/native/per_object_debug_info", + "//features/native/includes", + "//features/native/default_link_flags", + "//features/native/archiver_flags", + "//features/native/linker_param_file", + "//features/native/library_search_directories", + "//features/native/shared_flag", + "//features/native/output_execpath_flags", + "//features/native/runtime_library_search_directories", + "//features/native/libraries_to_link", + "//features/native/user_link_flags", + "//features/native/linkstamps", + "//features/native/fission_support", + "//features/native/force_pic_flags", + "//features/native/strip_debug_symbols", + "//features/native/static_libgcc", + "//features/native/fully_static_link", + "//features/native/sysroot_link_flags", + "//features/native/use_pthread", + "//features/native/markers:opt", + "//features/native/markers:supports_dynamic_linker", + "//features/native/markers:supports_pic", + "//features/native/pic", + "//features/native/markers:supports_header_path_normalization", + "//features/native/markers:supports_fission", + "//features/native/markers:coverage", + "//features/native/gcc_coverage_map_format", ], visibility = ["//visibility:public"], ) @@ -67,33 +67,33 @@ cc_feature_set( cc_feature_set( name = "qnx", all_of = [ - "//features/markers:dbg", - "//features/markers:no_legacy_features", - "//features/unfiltered_compile_flags", - "//features/default_compile_flags", - "//features/random_seed", - "//features/include_paths", - "//features/preprocessor_defines", - "//features/user_compile_flags", - "//features/compiler_input_flags", - "//features/compiler_output_flags", - "//features/markers:dependency_file_named_implicitly", - "//features/dependency_file", - "//features/default_link_flags", - "//features/archiver_flags", - "//features/linker_param_file", - "//features/library_search_directories", - "//features/shared_flag", - "//features/output_execpath_flags", - "//features/libraries_to_link", - "//features/user_link_flags", - "//features/markers:coverage", - "//features/markers:opt", - "//features/markers:supports_dynamic_linker", - "//features/markers:supports_pic", - "//features/pic", - "//features/runtime_library_search_directories", - "//features/gcc_coverage_map_format", + "//features/native/markers:dbg", + "//features/native/markers:no_legacy_features", + "//features/native/unfiltered_compile_flags", + "//features/native/default_compile_flags", + "//features/native/random_seed", + "//features/native/include_paths", + "//features/native/preprocessor_defines", + "//features/native/user_compile_flags", + "//features/native/compiler_input_flags", + "//features/native/compiler_output_flags", + "//features/native/markers:dependency_file_named_implicitly", + "//features/native/dependency_file", + "//features/native/default_link_flags", + "//features/native/archiver_flags", + "//features/native/linker_param_file", + "//features/native/library_search_directories", + "//features/native/shared_flag", + "//features/native/output_execpath_flags", + "//features/native/libraries_to_link", + "//features/native/user_link_flags", + "//features/native/markers:coverage", + "//features/native/markers:opt", + "//features/native/markers:supports_dynamic_linker", + "//features/native/markers:supports_pic", + "//features/native/pic", + "//features/native/runtime_library_search_directories", + "//features/native/gcc_coverage_map_format", ], visibility = ["//visibility:public"], ) diff --git a/features/extra_compile_flags/BUILD b/features/custom/linux/BUILD similarity index 100% rename from features/extra_compile_flags/BUILD rename to features/custom/linux/BUILD diff --git a/features/custom/linux/make_cc_features.bzl b/features/custom/linux/make_cc_features.bzl new file mode 100644 index 0000000..6e64324 --- /dev/null +++ b/features/custom/linux/make_cc_features.bzl @@ -0,0 +1,75 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +_LINUX_FEATURES = [ + ("@score_bazel_cpp_toolchains//features/native/markers:no_legacy_features", True), + (":compiler_library_search_paths", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/markers:dbg", False), # Bazel auto-toggles via -c dbg + ("@score_bazel_cpp_toolchains//features/native/unfiltered_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/native/markers:gnu11", False), # opt-in + ("@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), + ("@score_bazel_cpp_toolchains//features/native/preprocessor_defines", True), + (":extra_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/user_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/native/compiler_input_flags", True), + ("@score_bazel_cpp_toolchains//features/native/compiler_output_flags", True), + ("@score_bazel_cpp_toolchains//features/native/dependency_file", True), + ("@score_bazel_cpp_toolchains//features/native/per_object_debug_info", True), + ("@score_bazel_cpp_toolchains//features/native/includes", True), + ("@score_bazel_cpp_toolchains//features/native/default_link_flags", True), + ("@score_bazel_cpp_toolchains//features/native/archiver_flags", True), + ("@score_bazel_cpp_toolchains//features/native/linker_param_file", True), + ("@score_bazel_cpp_toolchains//features/native/library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/native/shared_flag", True), + ("@score_bazel_cpp_toolchains//features/native/output_execpath_flags", True), + ("@score_bazel_cpp_toolchains//features/native/runtime_library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/native/libraries_to_link", True), + ("@score_bazel_cpp_toolchains//features/native/user_link_flags", True), + (":extra_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/linkstamps", True), + ("@score_bazel_cpp_toolchains//features/native/fission_support", True), + ("@score_bazel_cpp_toolchains//features/native/force_pic_flags", True), + ("@score_bazel_cpp_toolchains//features/native/strip_debug_symbols", True), + ("@score_bazel_cpp_toolchains//features/native/static_libgcc", True), + ("@score_bazel_cpp_toolchains//features/native/fully_static_link", False), # opt-in + (":sysroot_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/use_pthread", True), + ("@score_bazel_cpp_toolchains//features/native/markers:opt", False), # Bazel auto-toggles via -c opt + ("@score_bazel_cpp_toolchains//features/native/markers:supports_dynamic_linker", True), + ("@score_bazel_cpp_toolchains//features/native/markers:supports_pic", True), + ("@score_bazel_cpp_toolchains//features/native/pic", True), + ("@score_bazel_cpp_toolchains//features/native/markers:supports_header_path_normalization", True), + ("@score_bazel_cpp_toolchains//features/native/markers:supports_fission", True), + ("@score_bazel_cpp_toolchains//features/native/markers:coverage", False), # opt-in + ("@score_bazel_cpp_toolchains//features/native/gcc_coverage_map_format", False), # opt-in (+ requires "coverage") +] + +def linux_known_features(): + """Full ordered list of Linux feature labels — order drives flag order.""" + return [label for label, _enabled in _LINUX_FEATURES] + +def linux_enabled_features(): + """Subset of Linux feature labels that start enabled — order is irrelevant here.""" + return [label for label, enabled in _LINUX_FEATURES if enabled] + +def get_feature_lists(): + """Returns the flat known/enabled feature label lists for Linux. + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + return linux_known_features(), linux_enabled_features() diff --git a/features/extra_link_flags/BUILD b/features/custom/qnx/BUILD similarity index 100% rename from features/extra_link_flags/BUILD rename to features/custom/qnx/BUILD diff --git a/features/custom/qnx/gcc_version_flags/BUILD b/features/custom/qnx/gcc_version_flags/BUILD new file mode 100644 index 0000000..6e049e2 --- /dev/null +++ b/features/custom/qnx/gcc_version_flags/BUILD @@ -0,0 +1,43 @@ +# ******************************************************************************* +# 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"], +) diff --git a/features/custom/qnx/make_cc_features.bzl b/features/custom/qnx/make_cc_features.bzl new file mode 100644 index 0000000..8c0bc95 --- /dev/null +++ b/features/custom/qnx/make_cc_features.bzl @@ -0,0 +1,72 @@ +def compute_feature_lists(target_os): + """Returns the flat known/enabled feature label lists for target_os. + + Unlike cc_feature_set (which groups features for requires_any_of/requires_all_of + constraints and does not itself provide FeatureInfo), cc_toolchain_config's + known_features/enabled_features attrs require every entry to individually + provide FeatureInfo — so this returns plain lists of cc_feature labels rather + than a single grouping target. + + Per-instance features (extra_compile_flags, extra_c_compile_flags, + extra_cxx_compile_flags, extra_link_flags, sysroot_link_flags, + compiler_library_search_paths) are baked into _LINUX_FEATURES/_QNX_FEATURES + directly since their target names never change across toolchain instances — + see templates/BUILD.template for where those targets get created. + + Args: + target_os: "linux" or "qnx". + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + +_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), + ("@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), + ("@score_bazel_cpp_toolchains//features/native/preprocessor_defines", True), + (":extra_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template + (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/user_compile_flags", True), + ("@score_bazel_cpp_toolchains//features/native/compiler_input_flags", True), + ("@score_bazel_cpp_toolchains//features/native/compiler_output_flags", True), + ("@score_bazel_cpp_toolchains//features/native/markers:dependency_file_named_implicitly", False), + ("@score_bazel_cpp_toolchains//features/native/dependency_file", True), + ("@score_bazel_cpp_toolchains//features/native/default_link_flags", True), + ("@score_bazel_cpp_toolchains//features/native/archiver_flags", True), + ("@score_bazel_cpp_toolchains//features/native/linker_param_file", True), + ("@score_bazel_cpp_toolchains//features/native/library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/native/shared_flag", True), + ("@score_bazel_cpp_toolchains//features/native/output_execpath_flags", True), + ("@score_bazel_cpp_toolchains//features/native/libraries_to_link", True), + ("@score_bazel_cpp_toolchains//features/native/user_link_flags", True), + (":extra_link_flags", True), # per-instance, see templates/BUILD.template + ("@score_bazel_cpp_toolchains//features/native/markers:coverage", False), # opt-in + ("@score_bazel_cpp_toolchains//features/native/markers:opt", False), # Bazel auto-toggles via -c opt + ("@score_bazel_cpp_toolchains//features/native/markers:supports_dynamic_linker", True), + ("@score_bazel_cpp_toolchains//features/native/markers:supports_pic", True), + ("@score_bazel_cpp_toolchains//features/native/pic", True), + ("@score_bazel_cpp_toolchains//features/native/runtime_library_search_directories", True), + ("@score_bazel_cpp_toolchains//features/native/gcc_coverage_map_format", False), # opt-in +] + +def qnx_known_features(): + """Full ordered list of QNX feature labels — order drives flag order.""" + return [label for label, _enabled in _QNX_FEATURES] + +def qnx_enabled_features(): + """Subset of QNX feature labels that start enabled — order is irrelevant here.""" + return [label for label, enabled in _QNX_FEATURES if enabled] + +def get_feature_lists(): + """Returns the flat known/enabled feature label lists for QNX. + + Returns: + (known_features, enabled_features) tuple of flat label lists. + """ + return qnx_known_features(), qnx_enabled_features() diff --git a/features/make_cc_features.bzl b/features/make_cc_features.bzl index fafda76..2fabe32 100644 --- a/features/make_cc_features.bzl +++ b/features/make_cc_features.bzl @@ -1,117 +1,3 @@ -# ******************************************************************************* -# 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 -# ******************************************************************************* - -_LINUX_FEATURES = [ - ("@score_bazel_cpp_toolchains//features/markers:no_legacy_features", True), - (":compiler_library_search_paths", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/markers:dbg", False), # Bazel auto-toggles via -c dbg - ("@score_bazel_cpp_toolchains//features/unfiltered_compile_flags", True), - ("@score_bazel_cpp_toolchains//features/markers:gnu11", False), # opt-in - ("@score_bazel_cpp_toolchains//features/default_compile_flags", True), - ("@score_bazel_cpp_toolchains//features/random_seed", True), - ("@score_bazel_cpp_toolchains//features/include_paths", True), - ("@score_bazel_cpp_toolchains//features/preprocessor_defines", True), - (":extra_compile_flags", True), # per-instance, see templates/BUILD.template - (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template - (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/user_compile_flags", True), - ("@score_bazel_cpp_toolchains//features/compiler_input_flags", True), - ("@score_bazel_cpp_toolchains//features/compiler_output_flags", True), - ("@score_bazel_cpp_toolchains//features/dependency_file", True), - ("@score_bazel_cpp_toolchains//features/per_object_debug_info", True), - ("@score_bazel_cpp_toolchains//features/includes", True), - ("@score_bazel_cpp_toolchains//features/default_link_flags", True), - ("@score_bazel_cpp_toolchains//features/archiver_flags", True), - ("@score_bazel_cpp_toolchains//features/linker_param_file", True), - ("@score_bazel_cpp_toolchains//features/library_search_directories", True), - ("@score_bazel_cpp_toolchains//features/shared_flag", True), - ("@score_bazel_cpp_toolchains//features/output_execpath_flags", True), - ("@score_bazel_cpp_toolchains//features/runtime_library_search_directories", True), - ("@score_bazel_cpp_toolchains//features/libraries_to_link", True), - ("@score_bazel_cpp_toolchains//features/user_link_flags", True), - (":extra_link_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/linkstamps", True), - ("@score_bazel_cpp_toolchains//features/fission_support", True), - ("@score_bazel_cpp_toolchains//features/force_pic_flags", True), - ("@score_bazel_cpp_toolchains//features/strip_debug_symbols", True), - ("@score_bazel_cpp_toolchains//features/static_libgcc", True), - ("@score_bazel_cpp_toolchains//features/fully_static_link", False), # opt-in - (":sysroot_link_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/use_pthread", True), - ("@score_bazel_cpp_toolchains//features/markers:opt", False), # Bazel auto-toggles via -c opt - ("@score_bazel_cpp_toolchains//features/markers:supports_dynamic_linker", True), - ("@score_bazel_cpp_toolchains//features/markers:supports_pic", True), - ("@score_bazel_cpp_toolchains//features/pic", True), - ("@score_bazel_cpp_toolchains//features/markers:supports_header_path_normalization", True), - ("@score_bazel_cpp_toolchains//features/markers:supports_fission", True), - ("@score_bazel_cpp_toolchains//features/markers:coverage", False), # opt-in - ("@score_bazel_cpp_toolchains//features/gcc_coverage_map_format", False), # opt-in (+ requires "coverage") -] - -def linux_known_features(): - """Full ordered list of Linux feature labels — order drives flag order.""" - return [label for label, _enabled in _LINUX_FEATURES] - -def linux_enabled_features(): - """Subset of Linux feature labels that start enabled — order is irrelevant here.""" - return [label for label, enabled in _LINUX_FEATURES if enabled] - -# Single source of truth: ordered (label, enabled_by_default) pairs. -# Order here IS the command-line flag order — mirrors -# templates/qnx/cc_toolchain_config.bzl.template's `features = [...]` list. -_QNX_FEATURES = [ - ("@score_bazel_cpp_toolchains//features/markers:dbg", False), # Bazel auto-toggles via -c dbg - ("@score_bazel_cpp_toolchains//features/markers:no_legacy_features", True), - ("@score_bazel_cpp_toolchains//features/unfiltered_compile_flags", True), - (":qnx_gcc_version_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/default_compile_flags", True), - ("@score_bazel_cpp_toolchains//features/random_seed", True), - ("@score_bazel_cpp_toolchains//features/include_paths", True), - ("@score_bazel_cpp_toolchains//features/preprocessor_defines", True), - (":extra_compile_flags", True), # per-instance, see templates/BUILD.template - (":extra_c_compile_flags", True), # per-instance, see templates/BUILD.template - (":extra_cxx_compile_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/user_compile_flags", True), - ("@score_bazel_cpp_toolchains//features/compiler_input_flags", True), - ("@score_bazel_cpp_toolchains//features/compiler_output_flags", True), - ("@score_bazel_cpp_toolchains//features/markers:dependency_file_named_implicitly", False), - ("@score_bazel_cpp_toolchains//features/dependency_file", True), - ("@score_bazel_cpp_toolchains//features/default_link_flags", True), - ("@score_bazel_cpp_toolchains//features/archiver_flags", True), - ("@score_bazel_cpp_toolchains//features/linker_param_file", True), - ("@score_bazel_cpp_toolchains//features/library_search_directories", True), - ("@score_bazel_cpp_toolchains//features/shared_flag", True), - ("@score_bazel_cpp_toolchains//features/output_execpath_flags", True), - ("@score_bazel_cpp_toolchains//features/libraries_to_link", True), - ("@score_bazel_cpp_toolchains//features/user_link_flags", True), - (":extra_link_flags", True), # per-instance, see templates/BUILD.template - ("@score_bazel_cpp_toolchains//features/markers:coverage", False), # opt-in - ("@score_bazel_cpp_toolchains//features/markers:opt", False), # Bazel auto-toggles via -c opt - ("@score_bazel_cpp_toolchains//features/markers:supports_dynamic_linker", True), - ("@score_bazel_cpp_toolchains//features/markers:supports_pic", True), - ("@score_bazel_cpp_toolchains//features/pic", True), - ("@score_bazel_cpp_toolchains//features/runtime_library_search_directories", True), - ("@score_bazel_cpp_toolchains//features/gcc_coverage_map_format", False), # opt-in -] - -def qnx_known_features(): - """Full ordered list of QNX feature labels — order drives flag order.""" - return [label for label, _enabled in _QNX_FEATURES] - -def qnx_enabled_features(): - """Subset of QNX feature labels that start enabled — order is irrelevant here.""" - return [label for label, enabled in _QNX_FEATURES if enabled] - def compute_feature_lists(target_os): """Returns the flat known/enabled feature label lists for target_os. @@ -138,4 +24,4 @@ def compute_feature_lists(target_os): elif target_os == "qnx": return qnx_known_features(), qnx_enabled_features() else: - fail("Unsupported target_os '{}', expected 'linux' or 'qnx'".format(target_os)) \ No newline at end of file + fail("Unsupported target_os '{}', expected 'linux' or 'qnx'".format(target_os)) diff --git a/features/archiver_flags/BUILD b/features/native/archiver_flags/BUILD similarity index 100% rename from features/archiver_flags/BUILD rename to features/native/archiver_flags/BUILD diff --git a/features/compiler_input_flags/BUILD b/features/native/compiler_input_flags/BUILD similarity index 100% rename from features/compiler_input_flags/BUILD rename to features/native/compiler_input_flags/BUILD diff --git a/features/compiler_library_search_paths/BUILD b/features/native/compiler_library_search_paths/BUILD similarity index 100% rename from features/compiler_library_search_paths/BUILD rename to features/native/compiler_library_search_paths/BUILD diff --git a/features/compiler_library_search_paths/features.bzl b/features/native/compiler_library_search_paths/features.bzl similarity index 100% rename from features/compiler_library_search_paths/features.bzl rename to features/native/compiler_library_search_paths/features.bzl diff --git a/features/compiler_output_flags/BUILD b/features/native/compiler_output_flags/BUILD similarity index 100% rename from features/compiler_output_flags/BUILD rename to features/native/compiler_output_flags/BUILD diff --git a/features/default_compile_flags/BUILD b/features/native/default_compile_flags/BUILD similarity index 81% rename from features/default_compile_flags/BUILD rename to features/native/default_compile_flags/BUILD index 0b25a6e..45c0eb2 100644 --- a/features/default_compile_flags/BUILD +++ b/features/native/default_compile_flags/BUILD @@ -53,12 +53,12 @@ cc_args( cc_feature_constraint( name = "not_gnu11", - none_of = ["//features/markers:gnu11"], + none_of = ["//features/native/markers:gnu11"], ) cc_feature_constraint( name = "is_gnu11", - all_of = ["//features/markers:gnu11"], + all_of = ["//features/native/markers:gnu11"], ) cc_args( @@ -89,7 +89,7 @@ cc_args( cc_feature_constraint( name = "is_dbg", - all_of = ["//features/markers:dbg"], + all_of = ["//features/native/markers:dbg"], ) cc_args( @@ -104,12 +104,12 @@ cc_args( cc_feature_constraint( name = "is_opt", - all_of = ["//features/markers:opt"], + all_of = ["//features/native/markers:opt"], ) cc_feature_constraint( name = "is_fastbuild", - all_of = ["//features/markers:fastbuild"], + all_of = ["//features/native/markers:fastbuild"], ) cc_args( @@ -125,6 +125,26 @@ cc_args( ], ) +cc_args( + name = "gcc_compile_flag_version_args", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = select({ + "@score_bazel_platform//settings:aarch64-qnx8": [ + "-V{version},gcc_nto{cpu}".format( + cpu = "aarch64le", + version = "12.2.0", + ), + ], + "@score_bazel_platform//settings:x86_64-qnx8": [ + "-V{version},gcc_nto{cpu}".format( + cpu = "x86_64", + version = "12.2.0", + ), + ], + "//conditions:default": [], + }), +) + cc_feature( name = "default_compile_flags", args = [ diff --git a/features/default_link_flags/BUILD b/features/native/default_link_flags/BUILD similarity index 94% rename from features/default_link_flags/BUILD rename to features/native/default_link_flags/BUILD index ce841cb..f586f61 100644 --- a/features/default_link_flags/BUILD +++ b/features/native/default_link_flags/BUILD @@ -17,15 +17,15 @@ load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") cc_feature_constraint( name = "is_opt", - all_of = ["//features/markers:opt"], + all_of = ["//features/native/markers:opt"], ) # compress-debug only when neither opt nor fastbuild cc_feature_constraint( name = "not_opt_not_fastbuild", none_of = [ - "//features/markers:opt", - "//features/markers:fastbuild", + "//features/native/markers:opt", + "//features/native/markers:fastbuild", ], ) diff --git a/features/dependency_file/BUILD b/features/native/dependency_file/BUILD similarity index 94% rename from features/dependency_file/BUILD rename to features/native/dependency_file/BUILD index dedcb16..5abf755 100644 --- a/features/dependency_file/BUILD +++ b/features/native/dependency_file/BUILD @@ -41,7 +41,7 @@ cc_args( # QNX: QCC-wrapped flags — explicit filename (dependency_file_named_implicitly is NOT active) cc_feature_constraint( name = "not_dep_named_implicitly", - none_of = ["//features/markers:dependency_file_named_implicitly"], + none_of = ["//features/native/markers:dependency_file_named_implicitly"], ) cc_args( @@ -60,7 +60,7 @@ cc_args( # QNX: QCC-wrapped flags — implicit filename (dependency_file_named_implicitly IS active) cc_feature_constraint( name = "is_dep_named_implicitly", - all_of = ["//features/markers:dependency_file_named_implicitly"], + all_of = ["//features/native/markers:dependency_file_named_implicitly"], ) cc_args( diff --git a/features/native/extra_compile_flags/BUILD b/features/native/extra_compile_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/extra_compile_flags/features.bzl b/features/native/extra_compile_flags/features.bzl similarity index 87% rename from features/extra_compile_flags/features.bzl rename to features/native/extra_compile_flags/features.bzl index fafd227..6458017 100644 --- a/features/extra_compile_flags/features.bzl +++ b/features/native/extra_compile_flags/features.bzl @@ -30,7 +30,7 @@ def make_extra_compile_features( name = "extra_compile_flags", args = [":extra_compile_flags_args"], feature_name = "extra_compile_flags", - implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], ) cc_args( @@ -43,7 +43,7 @@ def make_extra_compile_features( name = "extra_c_compile_flags", args = [":extra_c_compile_flags_args"], feature_name = "extra_c_compile_flags", - implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], ) cc_args( @@ -56,5 +56,5 @@ def make_extra_compile_features( name = "extra_cxx_compile_flags", args = [":extra_cxx_compile_flags_args"], feature_name = "extra_cxx_compile_flags", - implies = ["@score_bazel_cpp_toolchains//features/default_compile_flags"], + implies = ["@score_bazel_cpp_toolchains//features/native/default_compile_flags"], ) \ No newline at end of file diff --git a/features/native/extra_link_flags/BUILD b/features/native/extra_link_flags/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/extra_link_flags/features.bzl b/features/native/extra_link_flags/features.bzl similarity index 100% rename from features/extra_link_flags/features.bzl rename to features/native/extra_link_flags/features.bzl diff --git a/features/fission_support/BUILD b/features/native/fission_support/BUILD similarity index 100% rename from features/fission_support/BUILD rename to features/native/fission_support/BUILD diff --git a/features/force_pic_flags/BUILD b/features/native/force_pic_flags/BUILD similarity index 100% rename from features/force_pic_flags/BUILD rename to features/native/force_pic_flags/BUILD diff --git a/features/fully_static_link/BUILD b/features/native/fully_static_link/BUILD similarity index 100% rename from features/fully_static_link/BUILD rename to features/native/fully_static_link/BUILD diff --git a/features/gcc_coverage_map_format/BUILD b/features/native/gcc_coverage_map_format/BUILD similarity index 97% rename from features/gcc_coverage_map_format/BUILD rename to features/native/gcc_coverage_map_format/BUILD index c5dae21..71816a7 100644 --- a/features/gcc_coverage_map_format/BUILD +++ b/features/native/gcc_coverage_map_format/BUILD @@ -17,7 +17,7 @@ load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set") cc_feature_set( name = "requires_coverage", - all_of = ["//features/markers:coverage"], + all_of = ["//features/native/markers:coverage"], visibility = ["//visibility:public"], ) diff --git a/features/include_paths/BUILD b/features/native/include_paths/BUILD similarity index 100% rename from features/include_paths/BUILD rename to features/native/include_paths/BUILD diff --git a/features/includes/BUILD b/features/native/includes/BUILD similarity index 100% rename from features/includes/BUILD rename to features/native/includes/BUILD diff --git a/features/libraries_to_link/BUILD b/features/native/libraries_to_link/BUILD similarity index 100% rename from features/libraries_to_link/BUILD rename to features/native/libraries_to_link/BUILD diff --git a/features/library_search_directories/BUILD b/features/native/library_search_directories/BUILD similarity index 100% rename from features/library_search_directories/BUILD rename to features/native/library_search_directories/BUILD diff --git a/features/linker_param_file/BUILD b/features/native/linker_param_file/BUILD similarity index 100% rename from features/linker_param_file/BUILD rename to features/native/linker_param_file/BUILD diff --git a/features/linkstamps/BUILD b/features/native/linkstamps/BUILD similarity index 100% rename from features/linkstamps/BUILD rename to features/native/linkstamps/BUILD diff --git a/features/markers/BUILD b/features/native/markers/BUILD similarity index 100% rename from features/markers/BUILD rename to features/native/markers/BUILD diff --git a/features/output_execpath_flags/BUILD b/features/native/output_execpath_flags/BUILD similarity index 100% rename from features/output_execpath_flags/BUILD rename to features/native/output_execpath_flags/BUILD diff --git a/features/per_object_debug_info/BUILD b/features/native/per_object_debug_info/BUILD similarity index 100% rename from features/per_object_debug_info/BUILD rename to features/native/per_object_debug_info/BUILD diff --git a/features/pic/BUILD b/features/native/pic/BUILD similarity index 100% rename from features/pic/BUILD rename to features/native/pic/BUILD diff --git a/features/preprocessor_defines/BUILD b/features/native/preprocessor_defines/BUILD similarity index 100% rename from features/preprocessor_defines/BUILD rename to features/native/preprocessor_defines/BUILD diff --git a/features/random_seed/BUILD b/features/native/random_seed/BUILD similarity index 100% rename from features/random_seed/BUILD rename to features/native/random_seed/BUILD diff --git a/features/runtime_library_search_directories/BUILD b/features/native/runtime_library_search_directories/BUILD similarity index 100% rename from features/runtime_library_search_directories/BUILD rename to features/native/runtime_library_search_directories/BUILD diff --git a/features/shared_flag/BUILD b/features/native/shared_flag/BUILD similarity index 100% rename from features/shared_flag/BUILD rename to features/native/shared_flag/BUILD diff --git a/features/static_libgcc/BUILD b/features/native/static_libgcc/BUILD similarity index 95% rename from features/static_libgcc/BUILD rename to features/native/static_libgcc/BUILD index d1e9d55..af35773 100644 --- a/features/static_libgcc/BUILD +++ b/features/native/static_libgcc/BUILD @@ -17,7 +17,7 @@ load("@rules_cc//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint") cc_feature_constraint( name = "is_static_link_cpp_runtimes", - all_of = ["//features/markers:static_link_cpp_runtimes"], + all_of = ["//features/native/markers:static_link_cpp_runtimes"], ) cc_args( diff --git a/features/strip_debug_symbols/BUILD b/features/native/strip_debug_symbols/BUILD similarity index 100% rename from features/strip_debug_symbols/BUILD rename to features/native/strip_debug_symbols/BUILD diff --git a/features/sysroot_link_flags/BUILD b/features/native/sysroot_link_flags/BUILD similarity index 100% rename from features/sysroot_link_flags/BUILD rename to features/native/sysroot_link_flags/BUILD diff --git a/features/sysroot_link_flags/features.bzl b/features/native/sysroot_link_flags/features.bzl similarity index 100% rename from features/sysroot_link_flags/features.bzl rename to features/native/sysroot_link_flags/features.bzl diff --git a/features/unfiltered_compile_flags/BUILD b/features/native/unfiltered_compile_flags/BUILD similarity index 100% rename from features/unfiltered_compile_flags/BUILD rename to features/native/unfiltered_compile_flags/BUILD diff --git a/features/use_pthread/BUILD b/features/native/use_pthread/BUILD similarity index 100% rename from features/use_pthread/BUILD rename to features/native/use_pthread/BUILD diff --git a/features/user_compile_flags/BUILD b/features/native/user_compile_flags/BUILD similarity index 100% rename from features/user_compile_flags/BUILD rename to features/native/user_compile_flags/BUILD diff --git a/features/user_link_flags/BUILD b/features/native/user_link_flags/BUILD similarity index 100% rename from features/user_link_flags/BUILD rename to features/native/user_link_flags/BUILD diff --git a/features/qnx_gcc_version_flags/BUILD b/features/qnx_gcc_version_flags/BUILD deleted file mode 100644 index 3d851ce..0000000 --- a/features/qnx_gcc_version_flags/BUILD +++ /dev/null @@ -1,15 +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 -# ******************************************************************************* - -# Instantiated per-toolchain via make_qnx_gcc_version_flags() in features.bzl, -# since the version/cpu differ per toolchain instance — see templates/BUILD.template. diff --git a/features/qnx_gcc_version_flags/features.bzl b/features/qnx_gcc_version_flags/features.bzl deleted file mode 100644 index 05da1fe..0000000 --- a/features/qnx_gcc_version_flags/features.bzl +++ /dev/null @@ -1,46 +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") - -def make_qnx_gcc_version_flags(tc_version, target_cpu, target_os): - """Creates the QCC "-V,gcc_nto[_cxx]" toolchain-routing flags. - - QCC needs an explicit -V flag to select which underlying GCC version/target - it should compile/link with; the value is per-toolchain-instance data. - - Args: - tc_version: GCC version string for this toolchain instance. - target_cpu: target CPU string for this toolchain instance. - target_os: target OS string for this toolchain instance. - """ - if target_os == "qnx": - cc_args( - name = "qnx_gcc_version_compile_args", - actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], - args = ["-V{},gcc_nto{}".format(tc_version, target_cpu if target_cpu != "aarch64" else "aarch64le")], - ) - - cc_args( - name = "qnx_gcc_version_link_args", - actions = ["@rules_cc//cc/toolchains/actions:link_actions"], - args = ["-V{},gcc_nto{}_cxx".format(tc_version, target_cpu if target_cpu != "aarch64" else "aarch64le")], - ) - - cc_feature( - name = "qnx_gcc_version_flags", - args = [":qnx_gcc_version_compile_args", ":qnx_gcc_version_link_args"], - feature_name = "qnx_gcc_version_flags", - ) - diff --git a/templates/BUILD.template b/templates/BUILD.template index f6c13a1..a39c414 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -15,12 +15,11 @@ """ load("@rules_cc//cc:defs.bzl", "cc_toolchain") -load("@score_bazel_cpp_toolchains//features/extra_compile_flags:features.bzl", "make_extra_compile_features") -load("@score_bazel_cpp_toolchains//features/extra_link_flags:features.bzl", "make_extra_link_features") -load("@score_bazel_cpp_toolchains//features/compiler_library_search_paths:features.bzl", "make_compiler_library_search_paths") -load("@score_bazel_cpp_toolchains//features/sysroot_link_flags:features.bzl", "make_sysroot_link_flags") -load("@score_bazel_cpp_toolchains//features/qnx_gcc_version_flags:features.bzl", "make_qnx_gcc_version_flags") -load("@score_bazel_cpp_toolchains//features:make_cc_features.bzl", "compute_feature_lists") +load("@score_bazel_cpp_toolchains//features/custom/%{tc_os}:make_cc_features.bzl", "get_feature_lists") +load("@score_bazel_cpp_toolchains//features/native/extra_compile_flags:features.bzl", "make_extra_compile_features") +load("@score_bazel_cpp_toolchains//features/native/extra_link_flags:features.bzl", "make_extra_link_features") +load("@score_bazel_cpp_toolchains//features/native/compiler_library_search_paths:features.bzl", "make_compiler_library_search_paths") +load("@score_bazel_cpp_toolchains//features/native/sysroot_link_flags:features.bzl", "make_sysroot_link_flags") load(":cc_toolchain_config.bzl", "cc_toolchain_config") make_extra_compile_features( @@ -42,18 +41,9 @@ make_sysroot_link_flags( sysroot = "%{tc_sysroot}", ) -# TODO: Change the name of this macro -make_qnx_gcc_version_flags( - tc_version = "%{tc_version}", - target_cpu = "%{tc_cpu}", - target_os = "%{tc_os}", -) - # known_features must list every feature (enabled or opt-in); enabled_features is # the order-irrelevant subset that should start on. See compute_feature_lists(). -_KNOWN_FEATURES, _ENABLED_FEATURES = compute_feature_lists( - target_os = "%{tc_os}", -) +_KNOWN_FEATURES, _ENABLED_FEATURES = get_feature_lists() filegroup( name = "empty", diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template index 70e9b0b..671a3c3 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/linux/cc_toolchain_config.bzl.template @@ -110,12 +110,12 @@ def _impl(ctx): if hasattr(ctx.attr, "builtin_include_directories") and ctx.attr.builtin_include_directories: cxx_builtin_include_directories = ctx.attr.builtin_include_directories - # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. - tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] - sysroot = None if ctx.attr.sysroot != None: sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path + + # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. + tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] return cc_common.create_cc_toolchain_config_info( ctx = ctx, @@ -142,9 +142,9 @@ cc_toolchain_config = rule( "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), + "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "target_cpu": attr.string(mandatory = True), "target_os": attr.string(mandatory = True), - "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "sysroot": attr.label(default = None), "host_dir": attr.label(default = None), "target_dir": attr.label(default = None), diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index 139c4bf..52b2a5d 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -135,7 +135,8 @@ def _impl(ctx): preprocess_assemble_action, strip_action, ] - + + # TODO: move all this in features and not hardcoded in config. use_license_env_info_feautre = feature( name = "qnx_license_env_info", enabled = %{use_license_info}, @@ -181,22 +182,27 @@ def _impl(ctx): for include_directory in ctx.files.cxx_builtin_include_directories ] + sysroot = None + if ctx.attr.sysroot != None: + sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path + # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] return cc_common.create_cc_toolchain_config_info( ctx = ctx, - abi_version = "%{tc_cpu}-qnx%{sdp_version}", + abi_version = "%{tc_cpu}-qnx%{sdp_version}", # TODO: Use tc_abi_version version variable abi_libc_version = "unknown", - compiler = "qcc", + builtin_sysroot = sysroot, # TODO: chech what is default value + compiler = "qcc", # TODO: check how to set this dynamic cxx_builtin_include_directories = cxx_builtin_include_directories, features = features, action_configs = action_configs, host_system_name = "local", - target_system_name = "%{tc_cpu}-qnx", - target_cpu = "%{tc_cpu}", + target_system_name = "%{tc_cpu}-%{tc_os}", + target_cpu = ctx.attr.target_cpu, target_libc = "unknown", - toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}", + toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}", # TODO: use tc_identifier variable tool_paths = tool_paths, ) @@ -209,10 +215,11 @@ cc_toolchain_config = rule( "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "host_dir": attr.label(allow_single_file = True, mandatory = True), - "target_dir": attr.label(allow_single_file = True, mandatory = True), "target_cpu": attr.string(mandatory = True), "target_os": attr.string(mandatory = True), + "sysroot": attr.label(default = None), + "host_dir": attr.label(allow_single_file = True, mandatory = True), + "target_dir": attr.label(allow_single_file = True, mandatory = True), "cxx_builtin_include_directories": attr.label(allow_files = True, mandatory = True), "known_features": attr.label_list( providers = [FeatureInfo], diff --git a/tests/.bazelversion b/tests/.bazelversion index e7fdef7..df5119e 100644 --- a/tests/.bazelversion +++ b/tests/.bazelversion @@ -1 +1 @@ -8.4.2 +8.7.0 diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 1c913bb..b47510f 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1,5 +1,5 @@ { - "lockFileVersion": 18, + "lockFileVersion": 24, "registryFileHashes": { "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", @@ -603,107 +603,9 @@ }, "selectedYankedVersions": {}, "moduleExtensions": { - "@@aspect_rules_js+//npm:extensions.bzl%pnpm": { - "general": { - "bzlTransitiveDigest": "c+aduAtzWJ+Sfmy4J0UmLN9iqbGkiP1HPlR9NZBfOdU=", - "usagesDigest": "ZYGEy1FrDUNPBzAzD+ujlHkMEsVPMYOvpHm9RhUexUE=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "pnpm": { - "repoRuleId": "@@aspect_rules_js+//npm/private:npm_import.bzl%npm_import_rule", - "attributes": { - "package": "pnpm", - "version": "8.6.7", - "root_package": "", - "link_workspace": "", - "link_packages": {}, - "integrity": "sha512-vRIWpD/L4phf9Bk2o/O2TDR8fFoJnpYrp2TKqTIZF/qZ2/rgL3qKXzHofHgbXsinwMoSEigz28sqk3pQ+yMEQQ==", - "url": "", - "commit": "", - "patch_args": [ - "-p0" - ], - "patches": [], - "custom_postinstall": "", - "npm_auth": "", - "npm_auth_basic": "", - "npm_auth_username": "", - "npm_auth_password": "", - "lifecycle_hooks": [], - "extra_build_content": "load(\"@aspect_rules_js//js:defs.bzl\", \"js_binary\")\njs_binary(name = \"pnpm\", data = glob([\"package/**\"]), entry_point = \"package/dist/pnpm.cjs\", visibility = [\"//visibility:public\"])", - "generate_bzl_library_targets": false, - "extract_full_archive": true - } - }, - "pnpm__links": { - "repoRuleId": "@@aspect_rules_js+//npm/private:npm_import.bzl%npm_import_links", - "attributes": { - "package": "pnpm", - "version": "8.6.7", - "dev": false, - "root_package": "", - "link_packages": {}, - "deps": {}, - "transitive_closure": {}, - "lifecycle_build_target": false, - "lifecycle_hooks_env": [], - "lifecycle_hooks_execution_requirements": [ - "no-sandbox" - ], - "lifecycle_hooks_use_default_shell_env": false, - "bins": {}, - "npm_translate_lock_repo": "", - "package_visibility": [ - "//visibility:public" - ], - "replace_package": "" - } - } - }, - "recordedRepoMappingEntries": [ - [ - "aspect_bazel_lib+", - "bazel_skylib", - "bazel_skylib+" - ], - [ - "aspect_bazel_lib+", - "bazel_tools", - "bazel_tools" - ], - [ - "aspect_rules_js+", - "aspect_bazel_lib", - "aspect_bazel_lib+" - ], - [ - "aspect_rules_js+", - "bazel_features", - "bazel_features+" - ], - [ - "aspect_rules_js+", - "bazel_skylib", - "bazel_skylib+" - ], - [ - "aspect_rules_js+", - "bazel_tools", - "bazel_tools" - ], - [ - "bazel_features+", - "bazel_tools", - "bazel_tools" - ] - ] - } - }, "@@aspect_rules_py+//py:extensions.bzl%py_tools": { "general": { - "bzlTransitiveDigest": "dAWBz6nfg2GIP7kchPavcBdWoHNQ67aXhXo4MPJJqNk=", + "bzlTransitiveDigest": "13DN9p/N8uOU1SMHBh9nZIlptJtS3qP63UkXe+NH8SQ=", "usagesDigest": "NC1b49l5tenTBVWEUGzzC0j5Kg1GH+l5lBw5JRCldIU=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -843,39 +745,9 @@ ] } }, - "@@pybind11_bazel+//:internal_configure.bzl%internal_configure_extension": { - "general": { - "bzlTransitiveDigest": "G7xCmtNWXRuBtChRgB5OK5+gmM8Uoy8Mec/B7j3fhqs=", - "usagesDigest": "D1r3lfzMuUBFxgG8V6o0bQTLMk3GkaGOaPzw53wrwyw=", - "recordedFileInputs": { - "@@pybind11_bazel+//MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34" - }, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "pybind11": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "build_file": "@@pybind11_bazel+//:pybind11-BUILD.bazel", - "strip_prefix": "pybind11-2.12.0", - "urls": [ - "https://github.com/pybind/pybind11/archive/v2.12.0.zip" - ] - } - } - }, - "recordedRepoMappingEntries": [ - [ - "pybind11_bazel+", - "bazel_tools", - "bazel_tools" - ] - ] - } - }, "@@rules_buf+//buf:extensions.bzl%buf": { "general": { - "bzlTransitiveDigest": "nziVPz62Pjv2JecWM9NXmhpU/OjKhPz1MT9++4ObLUw=", + "bzlTransitiveDigest": "dSWqckK2ILN7aDIDHfv+Qrl1fb1hF7o7MDXY6T8C41s=", "usagesDigest": "vxN6C2h72rUERbAmd1476FWpxdxo1NhYoY5JSFXJT3g=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -898,92 +770,9 @@ ] } }, - "@@rules_fuzzing+//fuzzing/private:extensions.bzl%non_module_dependencies": { - "general": { - "bzlTransitiveDigest": "v2H25KPHEkN56IHR41S67Kzp5Xjxd75GBiazhON8jzc=", - "usagesDigest": "wy6ISK6UOcBEjj/mvJ/S3WeXoO67X+1llb9yPyFtPgc=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "platforms": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "urls": [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz" - ], - "sha256": "8150406605389ececb6da07cbcb509d5637a3ab9a24bc69b1101531367d89d74" - } - }, - "rules_python": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "sha256": "d70cd72a7a4880f0000a6346253414825c19cdd40a28289bdf67b8e6480edff8", - "strip_prefix": "rules_python-0.28.0", - "url": "https://github.com/bazelbuild/rules_python/releases/download/0.28.0/rules_python-0.28.0.tar.gz" - } - }, - "bazel_skylib": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "sha256": "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", - "urls": [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz" - ] - } - }, - "com_google_absl": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "urls": [ - "https://github.com/abseil/abseil-cpp/archive/refs/tags/20240116.1.zip" - ], - "strip_prefix": "abseil-cpp-20240116.1", - "integrity": "sha256-7capMWOvWyoYbUaHF/b+I2U6XLMaHmky8KugWvfXYuk=" - } - }, - "rules_fuzzing_oss_fuzz": { - "repoRuleId": "@@rules_fuzzing+//fuzzing/private/oss_fuzz:repository.bzl%oss_fuzz_repository", - "attributes": {} - }, - "honggfuzz": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", - "attributes": { - "build_file": "@@rules_fuzzing+//:honggfuzz.BUILD", - "sha256": "6b18ba13bc1f36b7b950c72d80f19ea67fbadc0ac0bb297ec89ad91f2eaa423e", - "url": "https://github.com/google/honggfuzz/archive/2.5.zip", - "strip_prefix": "honggfuzz-2.5" - } - }, - "rules_fuzzing_jazzer": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_jar", - "attributes": { - "sha256": "ee6feb569d88962d59cb59e8a31eb9d007c82683f3ebc64955fd5b96f277eec2", - "url": "https://repo1.maven.org/maven2/com/code-intelligence/jazzer/0.20.1/jazzer-0.20.1.jar" - } - }, - "rules_fuzzing_jazzer_api": { - "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_jar", - "attributes": { - "sha256": "f5a60242bc408f7fa20fccf10d6c5c5ea1fcb3c6f44642fec5af88373ae7aa1b", - "url": "https://repo1.maven.org/maven2/com/code-intelligence/jazzer-api/0.20.1/jazzer-api-0.20.1.jar" - } - } - }, - "recordedRepoMappingEntries": [ - [ - "rules_fuzzing+", - "bazel_tools", - "bazel_tools" - ] - ] - } - }, "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { "general": { - "bzlTransitiveDigest": "OlvsB0HsvxbR8ZN+J9Vf00X/+WVz/Y/5Xrq2LgcVfdo=", + "bzlTransitiveDigest": "03Qju4tW0vE+0RBuZGuV2A4Hx6AiSkdNahYvworx2aM=", "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1215,161 +1004,9 @@ ] } }, - "@@rules_rust+//crate_universe/private:internal_extensions.bzl%cu_nr": { - "general": { - "bzlTransitiveDigest": "oRwNDJU+OUmkvm5VgB12Uzf5d82zFgjjyx2akug8OTs=", - "usagesDigest": "dQ7SQZ7uSSL3vVKSMBKRxKJUm9OVrZZA+S1/QQfT570=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "cargo_bazel_bootstrap": { - "repoRuleId": "@@rules_rust+//cargo/private:cargo_bootstrap.bzl%cargo_bootstrap_repository", - "attributes": { - "srcs": [ - "@@rules_rust+//crate_universe:src/api.rs", - "@@rules_rust+//crate_universe:src/api/lockfile.rs", - "@@rules_rust+//crate_universe:src/cli.rs", - "@@rules_rust+//crate_universe:src/cli/generate.rs", - "@@rules_rust+//crate_universe:src/cli/query.rs", - "@@rules_rust+//crate_universe:src/cli/render.rs", - "@@rules_rust+//crate_universe:src/cli/splice.rs", - "@@rules_rust+//crate_universe:src/cli/vendor.rs", - "@@rules_rust+//crate_universe:src/config.rs", - "@@rules_rust+//crate_universe:src/context.rs", - "@@rules_rust+//crate_universe:src/context/crate_context.rs", - "@@rules_rust+//crate_universe:src/context/platforms.rs", - "@@rules_rust+//crate_universe:src/lib.rs", - "@@rules_rust+//crate_universe:src/lockfile.rs", - "@@rules_rust+//crate_universe:src/main.rs", - "@@rules_rust+//crate_universe:src/metadata.rs", - "@@rules_rust+//crate_universe:src/metadata/cargo_bin.rs", - "@@rules_rust+//crate_universe:src/metadata/cargo_tree_resolver.rs", - "@@rules_rust+//crate_universe:src/metadata/cargo_tree_rustc_wrapper.bat", - "@@rules_rust+//crate_universe:src/metadata/cargo_tree_rustc_wrapper.sh", - "@@rules_rust+//crate_universe:src/metadata/dependency.rs", - "@@rules_rust+//crate_universe:src/metadata/metadata_annotation.rs", - "@@rules_rust+//crate_universe:src/rendering.rs", - "@@rules_rust+//crate_universe:src/rendering/template_engine.rs", - "@@rules_rust+//crate_universe:src/rendering/templates/module_bzl.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/partials/header.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/partials/module/aliases_map.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/partials/module/deps_map.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/partials/module/repo_git.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/partials/module/repo_http.j2", - "@@rules_rust+//crate_universe:src/rendering/templates/vendor_module.j2", - "@@rules_rust+//crate_universe:src/rendering/verbatim/alias_rules.bzl", - "@@rules_rust+//crate_universe:src/select.rs", - "@@rules_rust+//crate_universe:src/splicing.rs", - "@@rules_rust+//crate_universe:src/splicing/cargo_config.rs", - "@@rules_rust+//crate_universe:src/splicing/crate_index_lookup.rs", - "@@rules_rust+//crate_universe:src/splicing/splicer.rs", - "@@rules_rust+//crate_universe:src/test.rs", - "@@rules_rust+//crate_universe:src/utils.rs", - "@@rules_rust+//crate_universe:src/utils/starlark.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/glob.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/label.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/select.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/select_dict.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/select_list.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/select_scalar.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/select_set.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/serialize.rs", - "@@rules_rust+//crate_universe:src/utils/starlark/target_compatible_with.rs", - "@@rules_rust+//crate_universe:src/utils/symlink.rs", - "@@rules_rust+//crate_universe:src/utils/target_triple.rs" - ], - "binary": "cargo-bazel", - "cargo_lockfile": "@@rules_rust+//crate_universe:Cargo.lock", - "cargo_toml": "@@rules_rust+//crate_universe:Cargo.toml", - "version": "1.86.0", - "timeout": 900, - "rust_toolchain_cargo_template": "@rust_host_tools//:bin/{tool}", - "rust_toolchain_rustc_template": "@rust_host_tools//:bin/{tool}", - "compressed_windows_toolchain_names": false - } - } - }, - "moduleExtensionMetadata": { - "explicitRootModuleDirectDeps": [ - "cargo_bazel_bootstrap" - ], - "explicitRootModuleDirectDevDeps": [], - "useAllRepos": "NO", - "reproducible": false - }, - "recordedRepoMappingEntries": [ - [ - "bazel_features+", - "bazel_features_globals", - "bazel_features++version_extension+bazel_features_globals" - ], - [ - "bazel_features+", - "bazel_features_version", - "bazel_features++version_extension+bazel_features_version" - ], - [ - "rules_cc+", - "bazel_tools", - "bazel_tools" - ], - [ - "rules_cc+", - "cc_compatibility_proxy", - "rules_cc++compatibility_proxy+cc_compatibility_proxy" - ], - [ - "rules_cc+", - "rules_cc", - "rules_cc+" - ], - [ - "rules_cc++compatibility_proxy+cc_compatibility_proxy", - "rules_cc", - "rules_cc+" - ], - [ - "rules_rust+", - "bazel_features", - "bazel_features+" - ], - [ - "rules_rust+", - "bazel_skylib", - "bazel_skylib+" - ], - [ - "rules_rust+", - "bazel_tools", - "bazel_tools" - ], - [ - "rules_rust+", - "cui", - "rules_rust++cu+cui" - ], - [ - "rules_rust+", - "rrc", - "rules_rust++i2+rrc" - ], - [ - "rules_rust+", - "rules_cc", - "rules_cc+" - ], - [ - "rules_rust+", - "rules_rust", - "rules_rust+" - ] - ] - } - }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "jnA5FZBDfPWgQ+FRTBDBlnxBZs87RheTRgVMxqTfbvo=", + "bzlTransitiveDigest": "wdioEpROOK+m+dxv+f8mCIAvzIdMdYvuf0rUXdIpGKU=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1862,7 +1499,7 @@ }, "@@score_rules_imagefs+//extensions:imagefs.bzl%imagefs": { "general": { - "bzlTransitiveDigest": "x/MeLfkCFKL5zGGdqxO8ikFOoWzlkB1VBe5tts2t0NI=", + "bzlTransitiveDigest": "4qMGnB7+T2rXYxW5iSvXX6nlCv/jNBvR6B0r5AHvEQQ=", "usagesDigest": "4LvOoMbWgpZh1KrPMaxsrJ/9n3DRlU6JijkThVx2Cw0=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1913,5 +1550,171 @@ ] } } + }, + "facts": { + "@@rules_go+//go:extensions.bzl%go_sdk": { + "1.25.0": { + "aix_ppc64": [ + "go1.25.0.aix-ppc64.tar.gz", + "e5234a7dac67bc86c528fe9752fc9d63557918627707a733ab4cac1a6faed2d4" + ], + "darwin_amd64": [ + "go1.25.0.darwin-amd64.tar.gz", + "5bd60e823037062c2307c71e8111809865116714d6f6b410597cf5075dfd80ef" + ], + "darwin_arm64": [ + "go1.25.0.darwin-arm64.tar.gz", + "544932844156d8172f7a28f77f2ac9c15a23046698b6243f633b0a0b00c0749c" + ], + "dragonfly_amd64": [ + "go1.25.0.dragonfly-amd64.tar.gz", + "5ed3cf9a810a1483822538674f1336c06b51aa1b94d6d545a1a0319a48177120" + ], + "freebsd_386": [ + "go1.25.0.freebsd-386.tar.gz", + "abea5d5c6697e6b5c224731f2158fe87c602996a2a233ac0c4730cd57bf8374e" + ], + "freebsd_amd64": [ + "go1.25.0.freebsd-amd64.tar.gz", + "86e6fe0a29698d7601c4442052dac48bd58d532c51cccb8f1917df648138730b" + ], + "freebsd_arm": [ + "go1.25.0.freebsd-arm.tar.gz", + "d90b78e41921f72f30e8bbc81d9dec2cff7ff384a33d8d8debb24053e4336bfe" + ], + "freebsd_arm64": [ + "go1.25.0.freebsd-arm64.tar.gz", + "451d0da1affd886bfb291b7c63a6018527b269505db21ce6e14724f22ab0662e" + ], + "freebsd_riscv64": [ + "go1.25.0.freebsd-riscv64.tar.gz", + "7b565f76bd8bda46549eeaaefe0e53b251e644c230577290c0f66b1ecdb3cdbe" + ], + "illumos_amd64": [ + "go1.25.0.illumos-amd64.tar.gz", + "b1e1fdaab1ad25aa1c08d7a36c97d45d74b98b89c3f78c6d2145f77face54a2c" + ], + "linux_386": [ + "go1.25.0.linux-386.tar.gz", + "8c602dd9d99bc9453b3995d20ce4baf382cc50855900a0ece5de9929df4a993a" + ], + "linux_amd64": [ + "go1.25.0.linux-amd64.tar.gz", + "2852af0cb20a13139b3448992e69b868e50ed0f8a1e5940ee1de9e19a123b613" + ], + "linux_arm64": [ + "go1.25.0.linux-arm64.tar.gz", + "05de75d6994a2783699815ee553bd5a9327d8b79991de36e38b66862782f54ae" + ], + "linux_armv6l": [ + "go1.25.0.linux-armv6l.tar.gz", + "a5a8f8198fcf00e1e485b8ecef9ee020778bf32a408a4e8873371bfce458cd09" + ], + "linux_loong64": [ + "go1.25.0.linux-loong64.tar.gz", + "cab86b1cf761b1cb3bac86a8877cfc92e7b036fc0d3084123d77013d61432afc" + ], + "linux_mips": [ + "go1.25.0.linux-mips.tar.gz", + "d66b6fb74c3d91b9829dc95ec10ca1f047ef5e89332152f92e136cf0e2da5be1" + ], + "linux_mips64": [ + "go1.25.0.linux-mips64.tar.gz", + "4082e4381a8661bc2a839ff94ba3daf4f6cde20f8fb771b5b3d4762dc84198a2" + ], + "linux_mips64le": [ + "go1.25.0.linux-mips64le.tar.gz", + "70002c299ec7f7175ac2ef673b1b347eecfa54ae11f34416a6053c17f855afcc" + ], + "linux_mipsle": [ + "go1.25.0.linux-mipsle.tar.gz", + "b00a3a39eff099f6df9f1c7355bf28e4589d0586f42d7d4a394efb763d145a73" + ], + "linux_ppc64": [ + "go1.25.0.linux-ppc64.tar.gz", + "df166f33bd98160662560a72ff0b4ba731f969a80f088922bddcf566a88c1ec1" + ], + "linux_ppc64le": [ + "go1.25.0.linux-ppc64le.tar.gz", + "0f18a89e7576cf2c5fa0b487a1635d9bcbf843df5f110e9982c64df52a983ad0" + ], + "linux_riscv64": [ + "go1.25.0.linux-riscv64.tar.gz", + "c018ff74a2c48d55c8ca9b07c8e24163558ffec8bea08b326d6336905d956b67" + ], + "linux_s390x": [ + "go1.25.0.linux-s390x.tar.gz", + "34e5a2e19f2292fbaf8783e3a241e6e49689276aef6510a8060ea5ef54eee408" + ], + "netbsd_386": [ + "go1.25.0.netbsd-386.tar.gz", + "f8586cdb7aa855657609a5c5f6dbf523efa00c2bbd7c76d3936bec80aa6c0aba" + ], + "netbsd_amd64": [ + "go1.25.0.netbsd-amd64.tar.gz", + "ae8dc1469385b86a157a423bb56304ba45730de8a897615874f57dd096db2c2a" + ], + "netbsd_arm": [ + "go1.25.0.netbsd-arm.tar.gz", + "1ff7e4cc764425fc9dd6825eaee79d02b3c7cafffbb3691687c8d672ade76cb7" + ], + "netbsd_arm64": [ + "go1.25.0.netbsd-arm64.tar.gz", + "e1b310739f26724216aa6d7d7208c4031f9ff54c9b5b9a796ddc8bebcb4a5f16" + ], + "openbsd_386": [ + "go1.25.0.openbsd-386.tar.gz", + "4802a9b20e533da91adb84aab42e94aa56cfe3e5475d0550bed3385b182e69d8" + ], + "openbsd_amd64": [ + "go1.25.0.openbsd-amd64.tar.gz", + "c016cd984bebe317b19a4f297c4f50def120dc9788490540c89f28e42f1dabe1" + ], + "openbsd_arm": [ + "go1.25.0.openbsd-arm.tar.gz", + "a1e31d0bf22172ddde42edf5ec811ef81be43433df0948ece52fecb247ccfd8d" + ], + "openbsd_arm64": [ + "go1.25.0.openbsd-arm64.tar.gz", + "343ea8edd8c218196e15a859c6072d0dd3246fbbb168481ab665eb4c4140458d" + ], + "openbsd_ppc64": [ + "go1.25.0.openbsd-ppc64.tar.gz", + "694c14da1bcaeb5e3332d49bdc2b6d155067648f8fe1540c5de8f3cf8e157154" + ], + "openbsd_riscv64": [ + "go1.25.0.openbsd-riscv64.tar.gz", + "aa510ad25cf54c06cd9c70b6d80ded69cb20188ac6e1735655eef29ff7e7885f" + ], + "plan9_386": [ + "go1.25.0.plan9-386.tar.gz", + "46f8cef02086cf04bf186c5912776b56535178d4cb319cd19c9fdbdd29231986" + ], + "plan9_amd64": [ + "go1.25.0.plan9-amd64.tar.gz", + "29b34391d84095e44608a228f63f2f88113a37b74a79781353ec043dfbcb427b" + ], + "plan9_arm": [ + "go1.25.0.plan9-arm.tar.gz", + "0a047107d13ebe7943aaa6d54b1d7bbd2e45e68ce449b52915a818da715799c2" + ], + "solaris_amd64": [ + "go1.25.0.solaris-amd64.tar.gz", + "9977f9e4351984364a3b2b78f8b88bfd1d339812356d5237678514594b7d3611" + ], + "windows_386": [ + "go1.25.0.windows-386.zip", + "df9f39db82a803af0db639e3613a36681ab7a42866b1384b3f3a1045663961a7" + ], + "windows_amd64": [ + "go1.25.0.windows-amd64.zip", + "89efb4f9b30812eee083cc1770fdd2913c14d301064f6454851428f9707d190b" + ], + "windows_arm64": [ + "go1.25.0.windows-arm64.zip", + "27bab004c72b3d7bd05a69b6ec0fc54a309b4b78cc569dd963d8b3ec28bfdb8c" + ] + } + } } } From a0412fecd2f8bd9bdaa6fb4ca584bbdd4253e174 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Sun, 30 Aug 2026 00:29:45 +0100 Subject: [PATCH 5/7] Temp commit #4 --- features/custom/qnx/make_cc_features.bzl | 14 +++++ features/custom/qnx/sdp_env/BUILD | 0 features/custom/qnx/sdp_env/feature.bzl | 60 +++++++++++++++++++ .../linux/aarch64/autosd/10.0/autosd.BUILD | 4 ++ .../linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD | 4 ++ packages/linux/aarch64/gcc/12.2.0/gcc.BUILD | 4 ++ packages/linux/aarch64/gcc/15.3.0/gcc.BUILD | 4 ++ packages/linux/x86_64/gcc/12.2.0/gcc.BUILD | 4 ++ packages/linux/x86_64/gcc/15.3.0/gcc.BUILD | 4 ++ rules/gcc.bzl | 27 ++++++++- templates/BUILD.template | 3 +- .../linux/cc_toolchain_config.bzl.template | 9 +-- .../qnx/cc_toolchain_config.bzl.template | 6 +- tests/MODULE.bazel.lock | 2 +- 14 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 features/custom/qnx/sdp_env/BUILD create mode 100644 features/custom/qnx/sdp_env/feature.bzl diff --git a/features/custom/qnx/make_cc_features.bzl b/features/custom/qnx/make_cc_features.bzl index 8c0bc95..3f5196f 100644 --- a/features/custom/qnx/make_cc_features.bzl +++ b/features/custom/qnx/make_cc_features.bzl @@ -1,3 +1,16 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + def compute_feature_lists(target_os): """Returns the flat known/enabled feature label lists for target_os. @@ -48,6 +61,7 @@ _QNX_FEATURES = [ (":extra_link_flags", True), # per-instance, see templates/BUILD.template ("@score_bazel_cpp_toolchains//features/native/markers:coverage", False), # opt-in ("@score_bazel_cpp_toolchains//features/native/markers:opt", False), # Bazel auto-toggles via -c opt + (":sdp_env", True), # per-instance, see templates/BUILD.template ("@score_bazel_cpp_toolchains//features/native/markers:supports_dynamic_linker", True), ("@score_bazel_cpp_toolchains//features/native/markers:supports_pic", True), ("@score_bazel_cpp_toolchains//features/native/pic", True), diff --git a/features/custom/qnx/sdp_env/BUILD b/features/custom/qnx/sdp_env/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/features/custom/qnx/sdp_env/feature.bzl b/features/custom/qnx/sdp_env/feature.bzl new file mode 100644 index 0000000..8f1456f --- /dev/null +++ b/features/custom/qnx/sdp_env/feature.bzl @@ -0,0 +1,60 @@ +# ******************************************************************************* +# 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") + +_ACTIONS = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", +] + +def make_sdp_env_feature( + host_dir, + target_dir, + license_path, + license_info_variable, + license_info_value): + """Creates a feature for the sdp_env toolchain. + + Args: + host_dir: str, path to the host directory. + target_dir: str, path to the target directory. + license_path: str, path to the license file. + license_info_variable: str, license information variable name. + license_info_value: str, license information value. + + Returns: + A feature definition for the sdp_env toolchain. + """ + + cc_args( + name = "sdp_env_args", + actions = _ACTIONS, + env = { + "QNX_HOST": "/proc/self/cwd/" + host_dir, + "QNX_TARGET": "/proc/self/cwd/" + target_dir, + "QNX_CONFIGURATION_EXCLUSIVE": "/var/tmp/.qnx", + "QNX_SHARED_LICENSE_FILE": license_path, + }, + format = { + "host_dir": host_dir, + "target_dir": target_dir, + }, + ) + + cc_feature( + name = "sdp_env", + feature_name = "sdp_env", + args = [":sdp_env_args"], + ) diff --git a/packages/linux/aarch64/autosd/10.0/autosd.BUILD b/packages/linux/aarch64/autosd/10.0/autosd.BUILD index daedfc5..44b2e8f 100644 --- a/packages/linux/aarch64/autosd/10.0/autosd.BUILD +++ b/packages/linux/aarch64/autosd/10.0/autosd.BUILD @@ -59,3 +59,7 @@ filegroup( "lib64/**", ]), ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD b/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD index d909382..44a2303 100644 --- a/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD +++ b/packages/linux/aarch64/ebclfsa/0.1.0/ebclfsa.BUILD @@ -71,3 +71,7 @@ filegroup( name = "sysroot_dir", srcs = ["."], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD b/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD index 4725a73..170a138 100644 --- a/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD +++ b/packages/linux/aarch64/gcc/12.2.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["aarch64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD b/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD index 4725a73..170a138 100644 --- a/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD +++ b/packages/linux/aarch64/gcc/15.3.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["aarch64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD b/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD index dc6fbb1..088dab4 100644 --- a/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD +++ b/packages/linux/x86_64/gcc/12.2.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["x86_64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD b/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD index dc6fbb1..088dab4 100644 --- a/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD +++ b/packages/linux/x86_64/gcc/15.3.0/gcc.BUILD @@ -54,3 +54,7 @@ filegroup( name = "sysroot_dir", srcs = ["x86_64-unknown-linux-gnu/sysroot"], ) + +filegroup( + name = "cxx_builtin_include_directories", +) diff --git a/rules/gcc.bzl b/rules/gcc.bzl index 4f15807..ce87fcd 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -14,7 +14,7 @@ """ Module rule for defining GCC toolchains in Bazel. """ -load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "label_list_to_string", "get_flag_strings") +load("@score_bazel_cpp_toolchains//rules:common.bzl", "SDP_VERSION_MAPPING", "get_flag_groups", "get_flag_strings", "label_list_to_string") # Constants _OS_QNX = "qnx" @@ -72,6 +72,7 @@ cc_toolchain_config( 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"], @@ -128,6 +129,27 @@ cc_toolchain_config( tc_extra_enabled_features = label_list_to_string(rctx.attr.extra_enabled_features), ) +def get_custom_cc_features_linux(rctx): + return "" + +def get_custom_cc_features_qnx(rctx): + custom_load = """load("@score_bazel_cpp_toolchains//features/custom/qnx/sdp_env:feature.bzl", "make_sdp_env_feature")""" + custom_features = """ +make_sdp_env_feature( + host_dir = "@{tc_pkg_repo}//:host_dir", + target_dir = "@{tc_pkg_repo}//:target_dir", + license_path = "{license_path}", + license_info_variable = {license_info_variable}, + license_info_value = {license_info_value}, +) +""".format( + tc_pkg_repo = rctx.attr.tc_pkg_repo, + license_path = rctx.attr.license_path, + license_info_variable = rctx.attr.license_info_variable if rctx.attr.license_info_variable != "" else None, + license_info_value = rctx.attr.license_info_value if rctx.attr.license_info_value != "" else None, + ) + return custom_load, custom_features + def _normalize_cpu(cpu): """Converts CPU name to its normalized form for toolchain paths. @@ -213,7 +235,6 @@ def _impl(rctx): tc_identifier_short_2 = "-{}".format(rctx.attr.tc_runtime_ecosystem) tc_identifier_long_2 = "[\"@score_bazel_platforms//runtime_es:{}\"]".format(rctx.attr.tc_runtime_ecosystem) - # Get canonical repository name for the toolchain package canonical_pkg_name = _get_canonical_pkg_name(rctx) @@ -228,6 +249,8 @@ def _impl(rctx): "BUILD", rctx.attr._cc_toolchain_build, { + "%{tc_custom_feature_load}": get_custom_cc_features_qnx(rctx)[0] if rctx.attr.tc_os == _OS_QNX else "", + "%{tc_custom_features}": get_custom_cc_features_qnx(rctx)[1] if rctx.attr.tc_os == _OS_QNX else "", "%{cc_toolchain_config}": cc_toolchain_config, "%{tc_cpu}": rctx.attr.tc_cpu, "%{tc_identifier}": tc_identifier, diff --git a/templates/BUILD.template b/templates/BUILD.template index a39c414..55520bb 100644 --- a/templates/BUILD.template +++ b/templates/BUILD.template @@ -20,6 +20,7 @@ load("@score_bazel_cpp_toolchains//features/native/extra_compile_flags:features. load("@score_bazel_cpp_toolchains//features/native/extra_link_flags:features.bzl", "make_extra_link_features") load("@score_bazel_cpp_toolchains//features/native/compiler_library_search_paths:features.bzl", "make_compiler_library_search_paths") load("@score_bazel_cpp_toolchains//features/native/sysroot_link_flags:features.bzl", "make_sysroot_link_flags") +%{tc_custom_feature_load} load(":cc_toolchain_config.bzl", "cc_toolchain_config") make_extra_compile_features( @@ -40,7 +41,7 @@ make_sysroot_link_flags( target_os = "%{tc_os}", sysroot = "%{tc_sysroot}", ) - +%{tc_custom_features} # known_features must list every feature (enabled or opt-in); enabled_features is # the order-irrelevant subset that should start on. See compute_feature_lists(). _KNOWN_FEATURES, _ENABLED_FEATURES = get_feature_lists() diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/linux/cc_toolchain_config.bzl.template index 671a3c3..2f4a04f 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/linux/cc_toolchain_config.bzl.template @@ -106,9 +106,10 @@ def _impl(ctx): features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) # Get builtin include directories from attribute if provided - cxx_builtin_include_directories = [] - if hasattr(ctx.attr, "builtin_include_directories") and ctx.attr.builtin_include_directories: - cxx_builtin_include_directories = ctx.attr.builtin_include_directories + cxx_builtin_include_directories = [ + "/proc/self/cwd/{}".format(include_directory.path) + for include_directory in ctx.files.cxx_builtin_include_directories + ] sysroot = None if ctx.attr.sysroot != None: @@ -148,7 +149,7 @@ cc_toolchain_config = rule( "sysroot": attr.label(default = None), "host_dir": attr.label(default = None), "target_dir": attr.label(default = None), - "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), + "cxx_builtin_include_directories": attr.label_list(allow_files = True, default = []), "known_features": attr.label_list( providers = [FeatureInfo], mandatory = True diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index 52b2a5d..e2d9f54 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -170,8 +170,8 @@ def _impl(ctx): convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) for known_feature in ctx.attr.known_features ] - features.append(use_license_env_info_feautre) - features.append(sdp_env_feature) + # features.append(use_license_env_info_feautre) + # features.append(sdp_env_feature) extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) @@ -220,7 +220,7 @@ cc_toolchain_config = rule( "sysroot": attr.label(default = None), "host_dir": attr.label(allow_single_file = True, mandatory = True), "target_dir": attr.label(allow_single_file = True, mandatory = True), - "cxx_builtin_include_directories": attr.label(allow_files = True, mandatory = True), + "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), "known_features": attr.label_list( providers = [FeatureInfo], mandatory = True, diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index b47510f..f13851f 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1006,7 +1006,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "wdioEpROOK+m+dxv+f8mCIAvzIdMdYvuf0rUXdIpGKU=", + "bzlTransitiveDigest": "W0S97XHfzOQxSpED3kIx5fVufSfT0IK5kntIM70Ph+E=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, From 3e2477b0ccb0a2a290a921fd0eaa988e1797bbb6 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Sun, 30 Aug 2026 02:50:17 +0200 Subject: [PATCH 6/7] Temp commit #6 --- features/custom/qnx/sdp_env/feature.bzl | 31 ++++++++++--------- rules/gcc.bzl | 27 ++++++++++------ .../qnx/cc_toolchain_config.bzl.template | 30 ------------------ tests/MODULE.bazel.lock | 2 +- 4 files changed, 35 insertions(+), 55 deletions(-) diff --git a/features/custom/qnx/sdp_env/feature.bzl b/features/custom/qnx/sdp_env/feature.bzl index 8f1456f..dcdd34b 100644 --- a/features/custom/qnx/sdp_env/feature.bzl +++ b/features/custom/qnx/sdp_env/feature.bzl @@ -28,29 +28,32 @@ def make_sdp_env_feature( """Creates a feature for the sdp_env toolchain. Args: - host_dir: str, path to the host directory. - target_dir: str, path to the target directory. + host_dir: str, resolved path to the SDP host directory. + target_dir: str, resolved path to the SDP target directory. license_path: str, path to the license file. - license_info_variable: str, license information variable name. - license_info_value: str, license information value. + license_info_variable: str, name of an extra license env var, "" if none. + license_info_value: str, value of that extra license env var, "" if none. Returns: A feature definition for the sdp_env toolchain. """ + # cc_args' `env` has no mechanism to resolve labels/format custom + # placeholders (see validate_env_variables in rules_cc) -- host_dir/ + # target_dir must already be plain resolved path strings. + env = { + "QNX_HOST": host_dir, + "QNX_TARGET": target_dir, + "QNX_CONFIGURATION_EXCLUSIVE": "/var/tmp/.qnx", + "QNX_SHARED_LICENSE_FILE": license_path, + } + if license_info_value: + env[license_info_variable] = license_info_value + cc_args( name = "sdp_env_args", actions = _ACTIONS, - env = { - "QNX_HOST": "/proc/self/cwd/" + host_dir, - "QNX_TARGET": "/proc/self/cwd/" + target_dir, - "QNX_CONFIGURATION_EXCLUSIVE": "/var/tmp/.qnx", - "QNX_SHARED_LICENSE_FILE": license_path, - }, - format = { - "host_dir": host_dir, - "target_dir": target_dir, - }, + env = env, ) cc_feature( diff --git a/rules/gcc.bzl b/rules/gcc.bzl index ce87fcd..cd0b6ab 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -132,21 +132,28 @@ cc_toolchain_config( def get_custom_cc_features_linux(rctx): return "" -def get_custom_cc_features_qnx(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"). + + # 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_features = """ make_sdp_env_feature( - host_dir = "@{tc_pkg_repo}//:host_dir", - target_dir = "@{tc_pkg_repo}//:target_dir", + host_dir = "{host_dir}", + target_dir = "{target_dir}", license_path = "{license_path}", - license_info_variable = {license_info_variable}, - license_info_value = {license_info_value}, + license_info_variable = "{license_info_variable}", + license_info_value = "{license_info_value}", ) """.format( - tc_pkg_repo = rctx.attr.tc_pkg_repo, + 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 if rctx.attr.license_info_variable != "" else None, - license_info_value = rctx.attr.license_info_value if rctx.attr.license_info_value != "" else None, + license_info_variable = rctx.attr.license_info_variable, + license_info_value = rctx.attr.license_info_value, ) return custom_load, custom_features @@ -249,8 +256,8 @@ def _impl(rctx): "BUILD", rctx.attr._cc_toolchain_build, { - "%{tc_custom_feature_load}": get_custom_cc_features_qnx(rctx)[0] if rctx.attr.tc_os == _OS_QNX else "", - "%{tc_custom_features}": get_custom_cc_features_qnx(rctx)[1] if rctx.attr.tc_os == _OS_QNX else "", + "%{tc_custom_feature_load}": get_custom_cc_features_qnx(rctx, canonical_pkg_name)[0] if rctx.attr.tc_os == _OS_QNX else "", + "%{tc_custom_features}": get_custom_cc_features_qnx(rctx, canonical_pkg_name)[1] if rctx.attr.tc_os == _OS_QNX else "", "%{cc_toolchain_config}": cc_toolchain_config, "%{tc_cpu}": rctx.attr.tc_cpu, "%{tc_identifier}": tc_identifier, diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template index e2d9f54..909de2c 100644 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ b/templates/qnx/cc_toolchain_config.bzl.template @@ -135,36 +135,6 @@ def _impl(ctx): preprocess_assemble_action, strip_action, ] - - # TODO: move all this in features and not hardcoded in config. - use_license_env_info_feautre = feature( - name = "qnx_license_env_info", - enabled = %{use_license_info}, - ) - - license_variable = "%{license_info_variable}" - license_value = "%{license_info_value}" - - sdp_env_feature = feature( - name = "sdp_env", - enabled = True, - env_sets = [ - env_set( - actions = all_compile_actions + all_link_actions, - env_entries = [ - env_entry(key = "QNX_HOST", value = "/proc/self/cwd/" + ctx.file.host_dir.path), - env_entry(key = "QNX_TARGET", value = "/proc/self/cwd/" + ctx.file.target_dir.path), - env_entry(key = "QNX_CONFIGURATION_EXCLUSIVE", value = "/var/tmp/.qnx"), - env_entry(key = "QNX_SHARED_LICENSE_FILE", value = "%{license_path}"), - ], - ), - env_set( - actions = all_compile_actions + all_link_actions, - env_entries = [env_entry(key = license_variable, value = license_value)] if license_value != "" else [], - with_features = [with_feature_set(features = ["qnx_license_env_info"])], - ) - ], - ) features = [ convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index f13851f..5204143 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1006,7 +1006,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "W0S97XHfzOQxSpED3kIx5fVufSfT0IK5kntIM70Ph+E=", + "bzlTransitiveDigest": "awppf3jbc5Tr8twcoELxv65ijA8vuocoTvjQlogHV6Q=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, From 45e27702fcb928075d1cb02f9dbcc273c6c44193 Mon Sep 17 00:00:00 2001 From: Nikola Radakovic Date: Sun, 30 Aug 2026 03:06:47 +0200 Subject: [PATCH 7/7] Temp commit #7 --- docs/features.md | 6 +- docs/generation_flow.md | 19 +- docs/maintenance.md | 4 +- docs/migration_guide.md | 4 +- extensions/gcc.bzl | 2 +- features/BUILD | 4 +- rules/gcc.bzl | 9 +- .../cc_toolchain_config.bzl.template | 22 +- .../qnx/cc_toolchain_config.bzl.template | 221 ------------------ tests/MODULE.bazel.lock | 22 +- 10 files changed, 41 insertions(+), 272 deletions(-) rename templates/{linux => }/cc_toolchain_config.bzl.template (95%) delete mode 100644 templates/qnx/cc_toolchain_config.bzl.template diff --git a/docs/features.md b/docs/features.md index 486880e..bb20348 100644 --- a/docs/features.md +++ b/docs/features.md @@ -1,9 +1,7 @@ # Toolchain Features -These are the `cc_toolchain` features defined by the toolchain configs in -[`templates/linux/cc_toolchain_config.bzl.template`](../templates/linux/cc_toolchain_config.bzl.template) -and -[`templates/qnx/cc_toolchain_config.bzl.template`](../templates/qnx/cc_toolchain_config.bzl.template). +These are the `cc_toolchain` features defined by the shared toolchain config in +[`templates/cc_toolchain_config.bzl.template`](../templates/cc_toolchain_config.bzl.template). Both toolchains enable **`no_legacy_features`**, which turns off the features Bazel would otherwise add implicitly. As a result every flag the toolchain emits diff --git a/docs/generation_flow.md b/docs/generation_flow.md index 8765bc3..d4ac19e 100644 --- a/docs/generation_flow.md +++ b/docs/generation_flow.md @@ -44,23 +44,16 @@ representation needed by the templates and repository rules. `rules/gcc.bzl` -Generates the toolchain repository. It decides whether Linux or QNX template -content is required, performs placeholder substitution, and emits the final -`BUILD`, `cc_toolchain_config.bzl`, and Linux `gcov` wrapper -files. +Generates the toolchain repository. It performs placeholder substitution and +emits the final `BUILD`, `cc_toolchain_config.bzl`, and `gcov` wrapper files, +substituting OS-specific values (e.g. `compiler`, `abi_version`, +`toolchain_identifier`) into the shared templates below. ## Template Families -Linux templates: - -- `templates/linux/cc_toolchain_config.bzl.template` - -QNX templates: - -- `templates/qnx/cc_toolchain_config.bzl.template` - -Shared templates: +Shared templates (used by both Linux and QNX): +- `templates/cc_toolchain_config.bzl.template` - `templates/BUILD.template` - `templates/cc_gcov_wrapper.template` diff --git a/docs/maintenance.md b/docs/maintenance.md index f41e79e..8cb4a9b 100644 --- a/docs/maintenance.md +++ b/docs/maintenance.md @@ -78,8 +78,8 @@ means a broken build rather than a silent fallback. `features/` defines the same toolchain features declaratively with `@rules_cc//cc/toolchains` (`cc_feature` / `cc_args` / `cc_feature_set`), as a parallel catalog alongside the legacy `feature()` Starlark in -`templates/*/cc_toolchain_config.bzl.template`. The **real** toolchain -generation still goes exclusively through the legacy templates, rendered by +`templates/cc_toolchain_config.bzl.template`. The **real** toolchain +generation still goes exclusively through the legacy template, rendered by `rules/gcc.bzl`; nothing in the repository currently consumes `//features:linux_features` or `//features:qnx_features`. diff --git a/docs/migration_guide.md b/docs/migration_guide.md index 17e40ef..d2d1ec1 100644 --- a/docs/migration_guide.md +++ b/docs/migration_guide.md @@ -65,9 +65,7 @@ no_legacy_features_feature = feature(name = "no_legacy_features", enabled = True With this enabled, Bazel injects **nothing** implicitly. Every compile, link, and archive flag must come from a feature (or other toolchain wiring) declared explicitly in -[`templates/linux/cc_toolchain_config.bzl.template`](../templates/linux/cc_toolchain_config.bzl.template) -or -[`templates/qnx/cc_toolchain_config.bzl.template`](../templates/qnx/cc_toolchain_config.bzl.template). +[`templates/cc_toolchain_config.bzl.template`](../templates/cc_toolchain_config.bzl.template). The practical consequence: the command line is now fully described by this repository's feature set. What you see documented in diff --git a/extensions/gcc.bzl b/extensions/gcc.bzl index f745d9e..06e64b9 100644 --- a/extensions/gcc.bzl +++ b/extensions/gcc.bzl @@ -203,7 +203,7 @@ def _get_toolchains(tags): toolchains = [] for tag in tags: toolchain = { - "cc_toolchain_config": "@score_bazel_cpp_toolchains//templates/{}:cc_toolchain_config.bzl.template".format(tag.target_os), + "cc_toolchain_config": "@score_bazel_cpp_toolchains//templates:cc_toolchain_config.bzl.template", "gcc_version": tag.version, "name": tag.name, "use_base_constraints_only": tag.use_base_constraints_only, diff --git a/features/BUILD b/features/BUILD index 4c0c5a2..7863c58 100644 --- a/features/BUILD +++ b/features/BUILD @@ -13,7 +13,7 @@ load("@rules_cc//cc/toolchains:feature_set.bzl", "cc_feature_set") -# Order mirrors templates/linux/cc_toolchain_config.bzl.template's `features = [...]` list, +# Order mirrors templates/cc_toolchain_config.bzl.template's `features = [...]` list, # since feature order determines command-line flag order. cc_feature_set( name = "linux", @@ -62,7 +62,7 @@ cc_feature_set( visibility = ["//visibility:public"], ) -# Order mirrors templates/qnx/cc_toolchain_config.bzl.template's `features = [...]` list, +# Order mirrors templates/cc_toolchain_config.bzl.template's `features = [...]` list, # since feature order determines command-line flag order. cc_feature_set( name = "qnx", diff --git a/rules/gcc.bzl b/rules/gcc.bzl index cd0b6ab..7acf67d 100644 --- a/rules/gcc.bzl +++ b/rules/gcc.bzl @@ -110,9 +110,7 @@ cc_toolchain_config( cxx_binary = "@{tc_pkg_repo}//:cxx", gcov_binary = "@{tc_pkg_repo}//:gcov", strip_binary = "@{tc_pkg_repo}//:strip", - host_dir = "@{tc_pkg_repo}//:host_dir", - target_dir = "@{tc_pkg_repo}//:target_dir", - cxx_builtin_include_directories = "@{tc_pkg_repo}//:cxx_builtin_include_directories", + cxx_builtin_include_directories = ["@{tc_pkg_repo}//:cxx_builtin_include_directories"], target_cpu = "{tc_cpu}", target_os = "{tc_os}", known_features = _KNOWN_FEATURES, @@ -294,6 +292,7 @@ def _impl(rctx): "%{extra_cxx_compile_flags}": extra_cxx_compile_flags, "%{extra_link_flags_switch}": "True" if len(rctx.attr.extra_link_flags) else "False", "%{extra_link_flags}": extra_link_flags, + "%{tc_compiler}": "gcc", "%{tc_cpu}": _normalize_cpu(rctx.attr.tc_cpu), "%{tc_identifier}": "gcc", "%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem, @@ -302,12 +301,16 @@ def _impl(rctx): if rctx.attr.tc_os == _OS_QNX: mapped_sdp_version = _apply_sdp_version_mapping(rctx.attr.sdp_version) + qnx_identifier = "{cpu}-qnx{sdp}".format(cpu = _normalize_cpu(rctx.attr.tc_cpu), sdp = mapped_sdp_version) extra_template_dict = { "%{license_info_value}": rctx.attr.license_info_value, "%{license_info_variable}": rctx.attr.license_info_variable, "%{license_path}": rctx.attr.license_path, "%{sdp_version}": mapped_sdp_version, + "%{tc_abi_version}": qnx_identifier, + "%{tc_compiler}": "qcc", "%{tc_cpu_cxx}": _normalize_cpu(rctx.attr.tc_cpu), + "%{tc_identifier}": qnx_identifier, "%{use_license_info}": "False" if rctx.attr.license_info_value == "" else "True", } template_dict = dict_union(template_dict, extra_template_dict) diff --git a/templates/linux/cc_toolchain_config.bzl.template b/templates/cc_toolchain_config.bzl.template similarity index 95% rename from templates/linux/cc_toolchain_config.bzl.template rename to templates/cc_toolchain_config.bzl.template index 2f4a04f..5b9a426 100644 --- a/templates/linux/cc_toolchain_config.bzl.template +++ b/templates/cc_toolchain_config.bzl.template @@ -117,13 +117,13 @@ def _impl(ctx): # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] - + return cc_common.create_cc_toolchain_config_info( ctx = ctx, abi_version = "%{tc_abi_version}", abi_libc_version = "unknown", builtin_sysroot = sysroot, - compiler = "gcc", + compiler = "%{tc_compiler}", cxx_builtin_include_directories = cxx_builtin_include_directories, features = features, action_configs = action_configs, @@ -147,17 +147,15 @@ cc_toolchain_config = rule( "target_cpu": attr.string(mandatory = True), "target_os": attr.string(mandatory = True), "sysroot": attr.label(default = None), - "host_dir": attr.label(default = None), - "target_dir": attr.label(default = None), "cxx_builtin_include_directories": attr.label_list(allow_files = True, default = []), "known_features": attr.label_list( - providers = [FeatureInfo], - mandatory = True - ), - "enabled_features": attr.label_list( - providers = [FeatureInfo], - mandatory = True - ), + providers = [FeatureInfo], + mandatory = True, + ), + "enabled_features": attr.label_list( + providers = [FeatureInfo], + mandatory = True, + ), "extra_enabled_features": attr.label_list( providers = [FeatureInfo], default = [], @@ -177,4 +175,4 @@ This is only offered as a migration bridge for projects transitioning to rule-ba """, ), }, -) \ No newline at end of file +) diff --git a/templates/qnx/cc_toolchain_config.bzl.template b/templates/qnx/cc_toolchain_config.bzl.template deleted file mode 100644 index 909de2c..0000000 --- a/templates/qnx/cc_toolchain_config.bzl.template +++ /dev/null @@ -1,221 +0,0 @@ -# ******************************************************************************* -# Copyright (c) 2025 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 -# ******************************************************************************* - -"""C/C++ toolchain definition""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "env_entry", - "env_set", - "feature", - "flag_group", - "flag_set", - "tool", - "tool_path", - "with_feature_set", -) -load("@rules_cc//cc:defs.bzl", "cc_common", "CcToolchainConfigInfo") -load("@rules_cc//cc/toolchains:feature_injection.bzl", "convert_feature", "FeatureInfo") - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_c_compile_actions = [ - ACTION_NAMES.c_compile, -] - -all_assemble_actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, -] - -all_compile_actions = all_c_compile_actions + all_cpp_compile_actions + all_assemble_actions - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -all_actions = all_compile_actions + all_link_actions + [ - ACTION_NAMES.strip, - ACTION_NAMES.cpp_link_static_library, -] - -def _impl(ctx): - """ Implementation function of GCC toolchains. - """ - - assemble_action = action_config( - action_name = ACTION_NAMES.assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - preprocess_assemble_action = action_config( - action_name = ACTION_NAMES.preprocess_assemble, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - c_compile_action = action_config( - action_name = ACTION_NAMES.c_compile, - tools = [tool(tool = ctx.executable.cc_binary)], - ) - cpp_compile_action = action_config( - action_name = ACTION_NAMES.cpp_compile, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_executable_action = action_config( - action_name = ACTION_NAMES.cpp_link_executable, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_nodeps_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, - tools = [tool(tool = ctx.executable.cxx_binary)], - ) - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - tools = [tool(tool = ctx.executable.ar_binary)], - implies = ["archiver_flags"], - ) - strip_action = action_config( - action_name = ACTION_NAMES.strip, - tools = [tool(tool = ctx.executable.strip_binary)], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - "-g", - "-p", - ], - ), - flag_group( - iterate_over = "stripopts", - flags = ["%{stripopts}"], - ), - flag_group( - flags = [ - "%{input_file}", - "%{output_file}", - ], - ), - ], - ), - ], - ) - - action_configs = [ - assemble_action, - c_compile_action, - cpp_compile_action, - cpp_link_dynamic_library_action, - cpp_link_executable_action, - cpp_link_nodeps_dynamic_library_action, - cpp_link_static_library_action, - preprocess_assemble_action, - strip_action, - ] - - features = [ - convert_feature(known_feature[FeatureInfo], enabled = known_feature in ctx.attr.enabled_features) - for known_feature in ctx.attr.known_features - ] - # features.append(use_license_env_info_feautre) - # features.append(sdp_env_feature) - - extra_rules_based_features = depset(ctx.attr.extra_enabled_features + ctx.attr.extra_known_features) - features.extend([convert_feature(extra_feature[FeatureInfo], enabled = extra_feature in ctx.attr.extra_enabled_features) for extra_feature in extra_rules_based_features.to_list()]) - - - cxx_builtin_include_directories = [ - "/proc/self/cwd/{}".format(include_directory.path) - for include_directory in ctx.files.cxx_builtin_include_directories - ] - - sysroot = None - if ctx.attr.sysroot != None: - sysroot = ctx.attr.sysroot[DefaultInfo].files.to_list()[0].path - - # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this. - tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")] - - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - abi_version = "%{tc_cpu}-qnx%{sdp_version}", # TODO: Use tc_abi_version version variable - abi_libc_version = "unknown", - builtin_sysroot = sysroot, # TODO: chech what is default value - compiler = "qcc", # TODO: check how to set this dynamic - cxx_builtin_include_directories = cxx_builtin_include_directories, - features = features, - action_configs = action_configs, - host_system_name = "local", - target_system_name = "%{tc_cpu}-%{tc_os}", - target_cpu = ctx.attr.target_cpu, - target_libc = "unknown", - toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}", # TODO: use tc_identifier variable - tool_paths = tool_paths, - ) - -cc_toolchain_config = rule( - implementation = _impl, - provides = [CcToolchainConfigInfo], - attrs = { - "ar_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True), - "target_cpu": attr.string(mandatory = True), - "target_os": attr.string(mandatory = True), - "sysroot": attr.label(default = None), - "host_dir": attr.label(allow_single_file = True, mandatory = True), - "target_dir": attr.label(allow_single_file = True, mandatory = True), - "cxx_builtin_include_directories": attr.label(allow_files = True, default = None), - "known_features": attr.label_list( - providers = [FeatureInfo], - mandatory = True, - ), - "enabled_features": attr.label_list( - providers = [FeatureInfo], - mandatory = True, - ), - "extra_enabled_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially enabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - "extra_known_features": attr.label_list( - providers = [FeatureInfo], - default = [], - doc = """ -Extra `cc_feature` features to add to this toolchain in an initially disabled state. -This attribute has limited integration with `cc_feature`, and does not run additional correctness checks or handle things like `data` files. -This is only offered as a migration bridge for projects transitioning to rule-based toolchain configurations, or sharing of simple argument sets with older toolchains. -""", - ), - }, -) diff --git a/tests/MODULE.bazel.lock b/tests/MODULE.bazel.lock index 5204143..aa211b8 100644 --- a/tests/MODULE.bazel.lock +++ b/tests/MODULE.bazel.lock @@ -1006,7 +1006,7 @@ }, "@@score_bazel_cpp_toolchains+//extensions:gcc.bzl%gcc": { "general": { - "bzlTransitiveDigest": "awppf3jbc5Tr8twcoELxv65ijA8vuocoTvjQlogHV6Q=", + "bzlTransitiveDigest": "9jkyV0giRrzeBMZmMRCNvE6Eij63D9zhSVHxzptk9Iw=", "usagesDigest": "dWr2zFjJ8fBvweFk2KWoZzQqJ+aKnb9A8QACQhKlUfw=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, @@ -1144,7 +1144,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": true } }, @@ -1170,7 +1170,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1196,7 +1196,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "15.3.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1222,7 +1222,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1248,7 +1248,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "15.3.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1276,7 +1276,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1302,7 +1302,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1328,7 +1328,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "", "gcc_version": "12.2.0", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/qnx:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1390,7 +1390,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "autosd10", "gcc_version": "", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }, @@ -1468,7 +1468,7 @@ "tc_system_toolchain": false, "tc_runtime_ecosystem": "ebclfsa", "gcc_version": "", - "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates/linux:cc_toolchain_config.bzl.template", + "cc_toolchain_config": "@@score_bazel_cpp_toolchains+//templates:cc_toolchain_config.bzl.template", "use_base_constraints_only": false } }