From 5e62be58be0e781c11fd735b5e130e77a2ecd7ad Mon Sep 17 00:00:00 2001 From: Xiao Peng Date: Fri, 4 Aug 2023 00:31:59 +0800 Subject: [PATCH] Add flag "--host_copts" to specify global host copts (#141) Add cmd line options support to specify global host copts --- .bazelrc | 1 + README.md | 4 ++++ cuda/BUILD.bazel | 5 +++++ cuda/private/cuda_helper.bzl | 2 +- cuda/private/rules/cuda_library.bzl | 1 + cuda/private/rules/cuda_objects.bzl | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index 474360a0..40a500d5 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,6 +3,7 @@ build --flag_alias=enable_cuda=//cuda:enable build --flag_alias=cuda_archs=//cuda:archs build --flag_alias=cuda_compiler=//cuda:compiler build --flag_alias=cuda_copts=//cuda:copts +build --flag_alias=cuda_host_copts=//cuda:host_copts build --flag_alias=cuda_runtime=//cuda:runtime build --enable_cuda=True diff --git a/README.md b/README.md index 7d6d3c2c..ec906c50 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,10 @@ bazel build --cuda_archs=compute_61:compute_61,sm_61 Add the copts to all cuda compile actions. +- `@rules_cuda//cuda:host_copts` + + Add the copts to the host compiler. + - `@rules_cuda//cuda:runtime` Set the default cudart to link, for example, `--@rules_cuda//cuda:runtime=@local_cuda//:cuda_runtime_static` link the static cuda runtime. diff --git a/cuda/BUILD.bazel b/cuda/BUILD.bazel index 2eba9a5c..59fe56b2 100644 --- a/cuda/BUILD.bazel +++ b/cuda/BUILD.bazel @@ -71,6 +71,11 @@ repeatable_string_flag( build_setting_default = "", ) +repeatable_string_flag( + name = "host_copts", + build_setting_default = "", +) + # Command line flag to specify the CUDA runtime. Use this target as CUDA # runtime dependency. # diff --git a/cuda/private/cuda_helper.bzl b/cuda/private/cuda_helper.bzl index f6d8a382..13cd9456 100644 --- a/cuda/private/cuda_helper.bzl +++ b/cuda/private/cuda_helper.bzl @@ -275,7 +275,7 @@ def _create_common(ctx): link_flags.extend([o for o in attr.linkopts if _check_opts(o)]) host_defines = [] host_local_defines = [i for i in attr.host_local_defines] - host_compile_flags = [i for i in attr.host_copts] + host_compile_flags = attr._default_host_copts[BuildSettingInfo].value + [i for i in attr.host_copts] host_link_flags = [] if hasattr(attr, "host_linkopts"): host_link_flags.extend([i for i in attr.host_linkopts]) diff --git a/cuda/private/rules/cuda_library.bzl b/cuda/private/rules/cuda_library.bzl index bdb40127..06e1f1a7 100644 --- a/cuda/private/rules/cuda_library.bzl +++ b/cuda/private/rules/cuda_library.bzl @@ -136,6 +136,7 @@ cuda_library = rule( "_builtin_deps": attr.label_list(default = ["//cuda:runtime"]), "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), # legacy behaviour "_default_cuda_copts": attr.label(default = "//cuda:copts"), + "_default_host_copts": attr.label(default = "//cuda:host_copts"), "_default_cuda_archs": attr.label(default = "//cuda:archs"), }, fragments = ["cpp"], diff --git a/cuda/private/rules/cuda_objects.bzl b/cuda/private/rules/cuda_objects.bzl index b0fccdc3..2cc555ab 100644 --- a/cuda/private/rules/cuda_objects.bzl +++ b/cuda/private/rules/cuda_objects.bzl @@ -86,6 +86,7 @@ code and device link time optimization source files.""", "ptxasopts": attr.string_list(doc = "Add these flags to the ptxas command."), "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), # legacy behaviour "_default_cuda_copts": attr.label(default = "//cuda:copts"), + "_default_host_copts": attr.label(default = "//cuda:host_copts"), "_default_cuda_archs": attr.label(default = "//cuda:archs"), }, fragments = ["cpp"],