Skip to content

Commit

Permalink
Add alwayslink to cuda_binary and cuda_test macros
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhan committed Jan 4, 2024
1 parent 9b7eccd commit c3fc554
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions cuda/private/macros/cuda_binary.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
)

Expand Down
11 changes: 9 additions & 2 deletions cuda/private/macros/cuda_test.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}
)
Expand Down

0 comments on commit c3fc554

Please sign in to comment.