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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ build:shared --host_platform=@score_bazel_platforms//:x86_64-linux
# Config dedicated to host platform CPU:x86_64 and OS:Linux
# -------------------------------------------------------------------------------
build:x86_64-linux --config=shared
build:x86_64-linux --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix

# -------------------------------------------------------------------------------
# Different toolchain configuration for x86_64-linux
# -------------------------------------------------------------------------------
build:host_config_1 --config=x86_64-linux
build:host_config_1 --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix
build:host_config_1 --extra_toolchains=@score_gcc_toolchain//:x86_64-linux-gcc_12.2.0-posix
build:host_config_1 --features=use_pthread

# -------------------------------------------------------------------------------
# Different toolchain configuration for x86_64-linux
# Different toolchain configuration for x86_64-linux (base platforms only)
# -------------------------------------------------------------------------------
build:host_config_2 --config=x86_64-linux
build:host_config_2 --extra_toolchains=@my_toolchain//:x86_64-linux-gcc_12.2.0-posix
build:host_config_2 --extra_toolchains=@score_gcc_toolchain_bp_only//:x86_64-linux
build:host_config_2 --features=use_pthread

# -------------------------------------------------------------------------------
# Different toolchain configuration for x86_64-linux
# -------------------------------------------------------------------------------
build:host_config_3 --config=x86_64-linux
build:host_config_3 --platforms=@score_bazel_platforms//:x86_64-linux-gcc_12.2.0-posix
build:host_config_3 --extra_toolchains=@my_toolchain//:x86_64-linux-gcc_12.2.0-posix

# -------------------------------------------------------------------------------
# Config dedicated to target platform CPU:aarch64 and OS:linux
Expand All @@ -51,7 +58,6 @@ build:aarch64-linux --platforms=@score_bazel_platforms//:aarch64-linux-gcc_12.2.
build:target_config_3 --config=aarch64-linux
build:target_config_3 --extra_toolchains=@score_aarch64_gcc_toolchain//:aarch64-linux-gcc_12.2.0-posix


# -------------------------------------------------------------------------------
# Config dedicated to target platform CPU:x86_64 and OS:QNX
# -------------------------------------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ gcc.toolchain(
)

# *******************************************************************************
# Setting default GCC (CPU:aarch64|OS:Linux|V:12.2.0|ES:posix)
# Setting GCC (CPU:x86_64|OS:Linux)
# *******************************************************************************
gcc.toolchain(
name = "score_gcc_toolchain_bp_only",
target_cpu = "x86_64",
target_os = "linux",
version = "12.2.0",
use_default_package = True,
use_base_constraints_only = True,
)

# *******************************************************************************
# Setting GCC (CPU:aarch64|OS:Linux|V:12.2.0|ES:posix)
# *******************************************************************************
gcc.toolchain(
name = "score_aarch64_gcc_toolchain",
Expand Down Expand Up @@ -149,6 +161,7 @@ gcc.toolchain(
use_repo(
gcc,
"score_gcc_toolchain",
"score_gcc_toolchain_bp_only",
"score_aarch64_gcc_toolchain",
"my_toolchain",
"score_qcc_toolchain",
Expand Down
20 changes: 20 additions & 0 deletions examples/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

echo -e "Testing 'host_config_1' ..."
bazel build --config host_config_1 //:main_cpp
bazel clean
echo -e "Testing 'host_config_2' ..."
bazel build --config host_config_2 //:main_cpp
bazel clean
echo -e "Testing 'host_config_3' ..."
bazel build --config host_config_3 //:main_cpp
bazel clean
echo -e "Testing 'target_config_1' ..."
bazel build --config target_config_1 //:main_cpp
bazel clean
echo -e "Testing 'target_config_2' ..."
bazel build --config target_config_2 //:main_cpp
bazel clean
echo -e "Testing 'target_config_3' ..."
bazel build --config target_config_3 //:main_cpp
bazel clean
21 changes: 17 additions & 4 deletions extensions/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ _attrs_tc = {
),
"use_system_toolchain": attr.bool(
default = False,
doc = "TBD",
doc = "Flag for toolchain creation to use host installed binaries. Not yet supported!",
),
"use_base_constraints_only": attr.bool(
default = False,
doc = "Experimental. Attribute for flag toolchain creation to use only base platform constraints. Limits toolchain registration to 1 per base platform definition."
),
"runtime_ecosystem": attr.string(
default = "posix",
mandatory = False,
doc = "TBD",
doc = "Attribute for identifing the system-level runtime environment a binary or target is built to run in.",
),
"target_cpu": attr.string(
mandatory = True,
Expand Down Expand Up @@ -100,10 +104,15 @@ _attrs_tc = {
mandatory = False,
doc = "QNX License info variable.",
),
"sdk_version": attr.string(
default = "",
mandatory = False,
doc = "SDK version info variable.",
),
"sdp_version": attr.string(
default = "8.0.0",
mandatory = False,
doc = "Version of the SDP package.",
doc = "Version of the QNX SDP package.",
),
"license_path": attr.string(
default = "/opt/score_qnx/license/licenses",
Expand Down Expand Up @@ -172,11 +181,13 @@ def _get_toolchains(tags):
"sdp_to_link": tag.sdp_to_link,
"use_default_package": tag.use_default_package,
"use_system_toolchain": tag.use_system_toolchain,
"use_base_constraints_only": tag.use_base_constraints_only,
"tc_extra_compile_flags": tag.extra_compile_flags,
"tc_extra_c_compile_flags": tag.extra_c_compile_flags,
"tc_extra_cxx_compile_flags": tag.extra_cxx_compile_flags,
"tc_extra_link_flags": tag.extra_link_flags,
"sdp_version": tag.sdp_version,
"sdk_version": tag.sdk_version,
"tc_license_info_variable": tag.license_info_variable,
"tc_license_info_url": tag.license_info_url,
"tc_license_path": tag.license_path,
Expand Down Expand Up @@ -277,14 +288,16 @@ def _impl(mctx):
license_info_value = toolchain_info["tc_license_info_url"],
license_path = toolchain_info["tc_license_path"],
sdp_version = toolchain_info["sdp_version"],
tc_sdk_version = toolchain_info["sdk_version"],
tc_cpu = toolchain_info["tc_cpu"],
tc_os = toolchain_info["tc_os"],
tc_pkg_repo = toolchain_info["sdp_to_link"],
tc_system_toolchain = toolchain_info["use_system_toolchain"],
tc_runtime_ecosystem = toolchain_info["tc_runtime_ecosystem"],
gcc_version = toolchain_info["tc_version"],
tc_gcc_version = toolchain_info["tc_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"]
)

gcc = module_extension(
Expand Down
32 changes: 25 additions & 7 deletions rules/gcc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def _impl(rctx):
Args:
rctx: The repository context.
"""
tc_identifier = "gcc_{}".format(rctx.attr.gcc_version)
tc_identifier = "gcc_{}".format(rctx.attr.tc_gcc_version)
if rctx.attr.tc_sdk_version != "":
tc_identifier = "sdk_{}".format(rctx.attr.tc_sdk_version)
if rctx.attr.tc_os == "qnx":
tc_identifier = "sdp_{}".format(rctx.attr.sdp_version)

Expand All @@ -101,6 +103,19 @@ def _impl(rctx):
else:
fail("Unsupported OS detected!")

# The reason for this implementation is to provide support for toolchains defined only by based constraints.
# By default `cpu-os-version-runtime_os` is constraint set used for toolchain target compatible fileds but
# in case of base platform constraints, only cpu and os are involved in toolchain definition.
tc_identifier_short_1 = ""
tc_identifier_long_1 = "[]"
tc_identifier_short_2 = ""
tc_identifier_long_2 = "[]"
if not rctx.attr.use_base_constraints_only:
tc_identifier_short_1 = "-{}".format(tc_identifier)
tc_identifier_long_1 = "[\"@score_bazel_platforms//version:{}\"]".format(tc_identifier)
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)

rctx.template(
"BUILD",
rctx.attr._cc_toolchain_build,
Expand All @@ -109,9 +124,11 @@ def _impl(rctx):
"%{tc_pkg_repo}": rctx.attr.tc_pkg_repo,
"%{tc_cpu}": rctx.attr.tc_cpu,
"%{tc_os}": rctx.attr.tc_os,
"%{tc_version}": rctx.attr.gcc_version,
"%{tc_identifier}": tc_identifier,
"%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem,
"%{tc_version}": rctx.attr.tc_gcc_version,
"%{tc_identifier_short_1}": tc_identifier_short_1,
"%{tc_identifier_short_2}": tc_identifier_short_2,
"%{tc_identifier_long_1}": tc_identifier_long_1,
"%{tc_identifier_long_2}": tc_identifier_long_2,
},
)

Expand All @@ -136,9 +153,8 @@ def _impl(rctx):
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))


template_dict = {
"%{tc_version}": rctx.attr.gcc_version,
"%{tc_version}": rctx.attr.tc_gcc_version,
"%{tc_identifier}": "gcc",
"%{tc_cpu}": "aarch64le" if rctx.attr.tc_cpu == "aarch64" else rctx.attr.tc_cpu,
"%{tc_runtime_es}": rctx.attr.tc_runtime_ecosystem,
Expand Down Expand Up @@ -195,7 +211,8 @@ gcc_toolchain = repository_rule(
"tc_pkg_repo": attr.string(doc="The label name of toolchain tarbal."),
"tc_cpu": attr.string(doc="Target platform CPU."),
"tc_os": attr.string(doc="Target platform OS."),
"gcc_version": attr.string(doc="GCC version number"),
"tc_gcc_version": attr.string(doc="GCC version number"),
"tc_sdk_version": attr.string(doc="SDK version number"),
"extra_compile_flags": attr.string_list(doc="Extra/Additional compile flags."),
"extra_c_compile_flags": attr.string_list(doc="Extra/Additional C-specific compile flags."),
"extra_cxx_compile_flags": attr.string_list(doc="Extra/Additional C++-specific compile flags."),
Expand All @@ -212,6 +229,7 @@ gcc_toolchain = repository_rule(
"cc_toolchain_flags": attr.label(
doc = "Path to the Bazel BUILD file template for the toolchain.",
),
"use_base_constraints_only": attr.bool(doc="Boolean flag to state only base constraints should be used for toolchain compatibility definition"),
"_cc_toolchain_build": attr.label(
default = "@score_bazel_cpp_toolchains//templates:BUILD.template",
doc = "Path to the Bazel BUILD file template for the toolchain.",
Expand Down
9 changes: 5 additions & 4 deletions templates/BUILD.template
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ cc_toolchain(
toolchain_config = ":cc_toolchain_config",
)

# "@score_bazel_platforms//version:%{tc_runtime_es}",
# "@score_bazel_platforms//version:%{tc_identifier}",

toolchain(
name = "%{tc_cpu}-%{tc_os}-%{tc_identifier}-%{tc_runtime_es}",
name = "%{tc_cpu}-%{tc_os}%{tc_identifier_short_1}%{tc_identifier_short_2}",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:%{tc_cpu}",
"@platforms//os:%{tc_os}",
"@score_bazel_platforms//runtime_es:%{tc_runtime_es}",
"@score_bazel_platforms//version:%{tc_identifier}",
],
] + %{tc_identifier_long_1} + %{tc_identifier_long_2},
toolchain = ":cc_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
visibility = [
Expand Down