From c3fc55412f727425351bac2109a27306010297ed Mon Sep 17 00:00:00 2001 From: Cloud Han Date: Thu, 4 Jan 2024 09:58:34 +0800 Subject: [PATCH] Add alwayslink to cuda_binary and cuda_test macros --- cuda/private/macros/cuda_binary.bzl | 11 +++++++++-- cuda/private/macros/cuda_test.bzl | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cuda/private/macros/cuda_binary.bzl b/cuda/private/macros/cuda_binary.bzl index 20a158ce..96f6c380 100644 --- a/cuda/private/macros/cuda_binary.bzl +++ b/cuda/private/macros/cuda_binary.bzl @@ -1,7 +1,13 @@ load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library") -def cuda_binary(name, **attrs): - """Wrapper to ensure the binary is compiled with the CUDA compiler.""" +def cuda_binary(name, alwayslink=True, **attrs): + """A macro wraps cuda_library and cc_binary to ensure the binary is compiled with the CUDA compiler. + + Args: + name: A unique name for this target (cc_binary). + alwayslink: pass to the hidden cuda_library target. + **attrs: attrs of cc_binary and cuda_library. + """ cuda_library_only_attrs = ["deps", "srcs", "hdrs"] # https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-binaries @@ -11,6 +17,7 @@ def cuda_binary(name, **attrs): _cuda_library( name = cuda_library_name, + alwayslink = alwayslink, **{k: v for k, v in attrs.items() if k not in cc_binary_only_attrs} ) diff --git a/cuda/private/macros/cuda_test.bzl b/cuda/private/macros/cuda_test.bzl index b69060be..4e6691fc 100644 --- a/cuda/private/macros/cuda_test.bzl +++ b/cuda/private/macros/cuda_test.bzl @@ -1,7 +1,13 @@ load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library") -def cuda_test(name, **attrs): - """Wrapper to ensure the test is compiled with the CUDA compiler.""" +def cuda_test(name, alwayslink=True, **attrs): + """A macro wraps cuda_library and cc_test to ensure the test is compiled with the CUDA compiler. + + Args: + name: A unique name for this target (cc_test). + alwayslink: pass to the hidden cuda_library target. + **attrs: attrs of cc_test and cuda_library. + """ cuda_library_only_attrs = ["deps", "srcs", "hdrs"] # https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-tests @@ -11,6 +17,7 @@ def cuda_test(name, **attrs): _cuda_library( name = cuda_library_name, + alwayslink = alwayslink, testonly = True, **{k: v for k, v in attrs.items() if k not in cc_test_only_attrs} )