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

fix: search for the sysroot in compile args #313

Open
wants to merge 1 commit 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
35 changes: 32 additions & 3 deletions cuda/private/cuda_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
load("//cuda/private:action_names.bzl", "ACTION_NAMES")
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
load("//cuda/private:providers.bzl", "ArchSpecInfo", "CudaArchsInfo", "CudaInfo", "Stage2ArchInfo", "cuda_archs")
Expand Down Expand Up @@ -233,6 +234,36 @@ def _create_common_info(
transitive_linking_contexts = transitive_linking_contexts,
)

def _get_sysroot(ctx):
cc_toolchain = find_cpp_toolchain(ctx)

if cc_toolchain.sysroot:
return cc_toolchain.sysroot

feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)

variables = cc_common.create_compile_variables(
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
)

cc_flags = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = CC_ACTION_NAMES.cpp_compile,
variables = variables,
)

for flag in cc_flags:
if flag.startswith("--sysroot="):
return flag.removeprefix("--sysroot=")

return None

def _create_common(ctx):
"""Helper to gather and process various information from `ctx` object to ease the parameter passing for internal macros.

Expand All @@ -246,8 +277,6 @@ def _create_common(ctx):

merged_cc_info = cc_common.merge_cc_infos(cc_infos = [dep[CcInfo] for dep in all_cc_deps])

cc_toolchain = find_cpp_toolchain(ctx)

# gather include info
includes = merged_cc_info.compilation_context.includes.to_list()
system_includes = []
Expand Down Expand Up @@ -296,7 +325,7 @@ def _create_common(ctx):

return _create_common_info(
cuda_archs_info = _get_cuda_archs_info(ctx),
sysroot = getattr(cc_toolchain, "sysroot", None),
sysroot = _get_sysroot(ctx),
includes = includes,
quote_includes = quote_includes,
system_includes = system_includes,
Expand Down