Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick correct compiler for CMAKE_CXX_COMPILER #1030

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions foreign_cc/private/cc_toolchain_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ def is_debug_mode(ctx):
# https://docs.bazel.build/versions/master/command-line-reference.html#flag--compilation_mode
return ctx.var.get("COMPILATION_MODE", "fastbuild") == "dbg"

def pick_cpp_toolchain(cxx):
"""Picks the right toolchain for the given cxx compiler

Args:
cxx: path to the cxx compiler

Returns:
correct path to the cxx compiler
"""
cxx_splitted = cxx.split("/")
if (cxx_splitted[-1].startswith("gcc")):
cxx_splitted[-1] = cxx_splitted[-1].replace("gcc", "g++")
cxx = "/".join(cxx_splitted)
if (cxx_splitted[-1].startswith("clang")):
cxx_splitted[-1] = cxx_splitted[-1].replace("clang", "clang++")
cxx = "/".join(cxx_splitted)
return cxx

def get_tools_info(ctx):
"""Takes information about tools paths from cc_toolchain, returns CxxToolsInfo

Expand All @@ -204,10 +222,10 @@ def get_tools_info(ctx):
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.c_compile,
),
cxx = cc_common.get_tool_for_action(
cxx = pick_cpp_toolchain(cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.cpp_compile,
),
)),
cxx_linker_static = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = ACTION_NAMES.cpp_link_static_library,
Expand Down