From 4dd02f08b0c9332f51c2ff002881314271f0dfc5 Mon Sep 17 00:00:00 2001 From: Julien Debache Date: Wed, 11 Sep 2024 16:56:46 +0200 Subject: [PATCH] refactor: replace accesses to cc_toolchain.compiler_executable with calls to cc_toolchain.get_tool_for_action() (#274) According to the Bazel documentation, `compiler_executable` is going to be phased out. It is already an issue to use it for people who are trying to work with the new `rules_cc` implementation of the cc rules. --- cuda/private/actions/compile.bzl | 9 ++++++++- cuda/private/actions/dlink.bzl | 9 ++++++++- cuda/private/toolchain_configs/clang.bzl | 11 ++++++++++- cuda/private/toolchain_configs/nvcc.bzl | 13 +++++++++++-- cuda/private/toolchain_configs/nvcc_msvc.bzl | 13 ++++++++++--- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/cuda/private/actions/compile.bzl b/cuda/private/actions/compile.bzl index e630ebab..5129bdac 100644 --- a/cuda/private/actions/compile.bzl +++ b/cuda/private/actions/compile.bzl @@ -1,3 +1,4 @@ +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:cuda_helper.bzl", "cuda_helper") load("//cuda/private:rules/common.bzl", "ALLOW_CUDA_SRCS") @@ -33,7 +34,13 @@ def compile( An compiled object `File`. """ actions = ctx.actions - host_compiler = cc_toolchain.compiler_executable + cc_feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + host_compiler = cc_common.get_tool_for_action(feature_configuration = cc_feature_configuration, action_name = CC_ACTION_NAMES.cpp_compile) cuda_compiler = cuda_toolchain.compiler_executable cuda_feature_config = cuda_helper.configure_features(ctx, cuda_toolchain, requested_features = [ACTION_NAMES.cuda_compile]) diff --git a/cuda/private/actions/dlink.bzl b/cuda/private/actions/dlink.bzl index 41a7180a..412cf4da 100644 --- a/cuda/private/actions/dlink.bzl +++ b/cuda/private/actions/dlink.bzl @@ -1,5 +1,6 @@ "" +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:actions/compile.bzl", "compile") load("//cuda/private:cuda_helper.bzl", "cuda_helper") @@ -55,7 +56,13 @@ def _compiler_device_link( fail("device link is only meaningful on building relocatable device code") actions = ctx.actions - host_compiler = cc_toolchain.compiler_executable + cc_feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + host_compiler = cc_common.get_tool_for_action(feature_configuration = cc_feature_configuration, action_name = CC_ACTION_NAMES.cpp_compile) cuda_compiler = cuda_toolchain.compiler_executable artifact_category_name = cuda_helper.get_artifact_category_from_action(ACTION_NAMES.device_link, pic, rdc) diff --git a/cuda/private/toolchain_configs/clang.bzl b/cuda/private/toolchain_configs/clang.bzl index 5c3f19e3..844677c0 100644 --- a/cuda/private/toolchain_configs/clang.bzl +++ b/cuda/private/toolchain_configs/clang.bzl @@ -1,4 +1,5 @@ load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("//cuda/private:action_names.bzl", "ACTION_NAMES") load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES") @@ -52,6 +53,13 @@ def _impl(ctx): ] cc_toolchain = find_cpp_toolchain(ctx) + cc_feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + host_compiler = cc_common.get_tool_for_action(feature_configuration = cc_feature_configuration, action_name = CC_ACTION_NAMES.cpp_compile) clang_compile_env_feature = feature( name = "clang_compile_env", @@ -64,7 +72,7 @@ def _impl(ctx): ], env_entries = [ env_entry("INCLUDE", ";".join(cc_toolchain.built_in_include_directories)), - env_entry("PATH", paths.dirname(cc_toolchain.compiler_executable) + ";C:/Windows/system32"), + env_entry("PATH", paths.dirname(host_compiler) + ";C:/Windows/system32"), ], ), ], @@ -509,4 +517,5 @@ cuda_toolchain_config = rule( }, provides = [CudaToolchainConfigInfo], toolchains = use_cpp_toolchain(), + fragments = ["cpp"], ) diff --git a/cuda/private/toolchain_configs/nvcc.bzl b/cuda/private/toolchain_configs/nvcc.bzl index 22f07f26..d2f0c50c 100644 --- a/cuda/private/toolchain_configs/nvcc.bzl +++ b/cuda/private/toolchain_configs/nvcc.bzl @@ -1,4 +1,5 @@ load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("//cuda/private:action_names.bzl", "ACTION_NAMES") load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES") @@ -42,13 +43,20 @@ def _impl(ctx): ] cc_toolchain = find_cpp_toolchain(ctx) + cc_feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + host_compiler = cc_common.get_tool_for_action(feature_configuration = cc_feature_configuration, action_name = CC_ACTION_NAMES.cpp_compile) nvcc_compile_env_feature = feature( name = "nvcc_compile_env", env_sets = [ env_set( actions = [ACTION_NAMES.cuda_compile], - env_entries = [env_entry("PATH", paths.dirname(cc_toolchain.compiler_executable))], + env_entries = [env_entry("PATH", paths.dirname(host_compiler))], ), ], ) @@ -58,7 +66,7 @@ def _impl(ctx): env_sets = [ env_set( actions = [ACTION_NAMES.device_link], - env_entries = [env_entry("PATH", paths.dirname(cc_toolchain.compiler_executable))], + env_entries = [env_entry("PATH", paths.dirname(host_compiler))], ), ], ) @@ -519,4 +527,5 @@ cuda_toolchain_config = rule( }, provides = [CudaToolchainConfigInfo], toolchains = use_cpp_toolchain(), + fragments = ["cpp"], ) diff --git a/cuda/private/toolchain_configs/nvcc_msvc.bzl b/cuda/private/toolchain_configs/nvcc_msvc.bzl index a61a51f2..af4f30e1 100644 --- a/cuda/private/toolchain_configs/nvcc_msvc.bzl +++ b/cuda/private/toolchain_configs/nvcc_msvc.bzl @@ -1,4 +1,5 @@ load("@bazel_skylib//lib:paths.bzl", "paths") +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load("//cuda/private:action_names.bzl", "ACTION_NAMES") load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES") @@ -43,6 +44,13 @@ def _impl(ctx): ] cc_toolchain = find_cpp_toolchain(ctx) + cc_feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + host_compiler = cc_common.get_tool_for_action(feature_configuration = cc_feature_configuration, action_name = CC_ACTION_NAMES.cpp_compile) nvcc_compile_env_feature = feature( name = "nvcc_compile_env", @@ -54,7 +62,7 @@ def _impl(ctx): ], env_entries = [ env_entry("INCLUDE", ";".join(cc_toolchain.built_in_include_directories)), - env_entry("PATH", paths.dirname(cc_toolchain.compiler_executable) + ";C:/Windows/system32"), + env_entry("PATH", paths.dirname(host_compiler) + ";C:/Windows/system32"), env_entry("TEMP", ctx.attr.msvc_env_tmp), env_entry("TMP", ctx.attr.msvc_env_tmp), ], @@ -430,8 +438,6 @@ def _impl(ctx): ], ) - static_link_msvcrt_feature = feature(name = "static_link_msvcrt") - static_link_msvcrt_debug_feature = feature( name = "static_link_msvcrt_debug", flag_sets = [ @@ -609,4 +615,5 @@ cuda_toolchain_config = rule( }, provides = [CudaToolchainConfigInfo], toolchains = use_cpp_toolchain(), + fragments = ["cpp"], )