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

Add alwayslink to cuda_binary and cuda_test macros #210

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions cuda/private/macros/cuda_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
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."""
cuda_library_only_attrs = ["deps", "srcs", "hdrs"]
"""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).
**attrs: attrs of cc_binary and cuda_library.
"""
cuda_library_only_attrs = ["deps", "srcs", "hdrs", "alwayslink"]
cuda_library_only_attrs_defaults = {
"alwayslink": True,
}

# https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-binaries
cc_binary_only_attrs = ["args", "env", "output_licenses"]

cuda_library_name = "_" + name
cuda_library_attrs = {k: v for k, v in attrs.items() if k not in cc_binary_only_attrs}
for attr in cuda_library_only_attrs_defaults:
if attr not in cuda_library_attrs:
cuda_library_attrs[attr] = cuda_library_only_attrs_defaults[attr]

cuda_library_name = "_" + name
_cuda_library(
name = cuda_library_name,
**{k: v for k, v in attrs.items() if k not in cc_binary_only_attrs}
**cuda_library_attrs
)

native.cc_binary(
Expand Down
22 changes: 17 additions & 5 deletions cuda/private/macros/cuda_test.bzl
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
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."""
cuda_library_only_attrs = ["deps", "srcs", "hdrs"]
"""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).
**attrs: attrs of cc_test and cuda_library.
"""
cuda_library_only_attrs = ["deps", "srcs", "hdrs", "testonly", "alwayslink"]
cuda_library_only_attrs_defaults = {
"testonly": True,
"alwayslink": True,
}

# https://bazel.build/reference/be/common-definitions?hl=en#common-attributes-tests
cc_test_only_attrs = ["args", "env", "env_inherit", "size", "timeout", "flaky", "shard_count", "local"]

cuda_library_name = "_" + name
cuda_library_attrs = {k: v for k, v in attrs.items() if k not in cc_test_only_attrs}
for attr in cuda_library_only_attrs_defaults:
if attr not in cuda_library_attrs:
cuda_library_attrs[attr] = cuda_library_only_attrs_defaults[attr]

cuda_library_name = "_" + name
_cuda_library(
name = cuda_library_name,
testonly = True,
**{k: v for k, v in attrs.items() if k not in cc_test_only_attrs}
**cuda_library_attrs
)

native.cc_test(
Expand Down