Skip to content

Commit 3692ecb

Browse files
authored
fix: import rules_cc components explicitly (#423)
* fix: import CcInfo explicitly * update workspace * add bazel 9 * fix test * fix docs * write about loading rules_cc into readme * use latest rc * remove bazel 6.5 due to eol Signed-off-by: wep21 <daisuke.nishimatsu1021@gmail.com>
1 parent bfea6ee commit 3692ecb

30 files changed

Lines changed: 87 additions & 4 deletions

File tree

.github/release_notes.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
## `WORKSPACE` code
22
```starlark
33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "rules_cc",
7+
sha256 = "{rules_cc_sha256}",
8+
strip_prefix = "rules_cc-{rules_cc_version}",
9+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/{rules_cc_version}/rules_cc-{rules_cc_version}.tar.gz"],
10+
)
11+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
12+
compatibility_proxy_repo()
13+
414
http_archive(
515
name = "rules_cuda",
616
sha256 = "{archive_sha256}",

.github/workflows/utilities-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
bazel-version:
2020
# NOTE: read from .bazelversion so that we don't randomly break our
2121
# ci due to latest bazel version change
22+
- 9.0.0rc5
2223
- .bazelversion
2324
- 7.5.0
24-
- 6.5.0
2525
env:
2626
USE_BAZEL_VERSION: ${{ matrix.bazel-version }}
2727
steps:

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module(
66

77
bazel_dep(name = "bazel_skylib", version = "1.4.2")
88
bazel_dep(name = "platforms", version = "0.0.6")
9+
bazel_dep(name = "rules_cc", version = "0.2.14")
910

1011
cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain")
1112
cuda.toolkit(

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ Add the following to your `WORKSPACE` file and replace the placeholders with act
1212

1313
```starlark
1414
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
15+
16+
http_archive(
17+
name = "rules_cc",
18+
sha256 = "{rules_cc_sha256}",
19+
strip_prefix = "rules_cc-{rules_cc_version}",
20+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/{rules_cc_version}/rules_cc-{rules_cc_version}.tar.gz"],
21+
)
22+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
23+
compatibility_proxy_repo()
24+
1525
http_archive(
1626
name = "rules_cuda",
1727
sha256 = "{sha256_to_replace}",
@@ -23,6 +33,8 @@ rules_cuda_dependencies()
2333
rules_cuda_toolchains(register_toolchains = True)
2434
```
2535

36+
`rules_cc` needs to be available before loading `rules_cuda`, and `compatibility_proxy_repo()` must be called to populate the compatibility repository that `rules_cc` expects.
37+
2638
**NOTE**: `rules_cuda_toolchains` implicitly calls to `register_detected_cuda_toolchains`, and the use of
2739
`register_detected_cuda_toolchains` depends on the environment variable `CUDA_PATH`. You must also ensure the
2840
host compiler is available. On Windows, this means that you will also need to set the environment variable
@@ -37,6 +49,7 @@ determains how the toolchains are detected.
3749
Add the following to your `MODULE.bazel` file and replace the placeholders with actual values.
3850

3951
```starlark
52+
bazel_dep(name = "rules_cc", version = "{rules_cc_version}")
4053
bazel_dep(name = "rules_cuda", version = "0.2.1")
4154

4255
# pick a specific version (this is optional an can be skipped)
@@ -55,6 +68,8 @@ cuda.toolkit(
5568
use_repo(cuda, "cuda")
5669
```
5770

71+
`rules_cc` provides the C++ toolchain dependency for `rules_cuda`; in Bzlmod the compatibility repository is handled by `rules_cc` itself.
72+
5873
### Rules
5974

6075
- `cuda_library`: Can be used to compile and create static library for CUDA kernel code. The resulting targets can be

WORKSPACE.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ local_repository(
55
path = "examples",
66
)
77

8+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
9+
10+
http_archive(
11+
name = "bazel_features",
12+
sha256 = "5ab1a90d09fd74555e0df22809ad589627ddff263cff82535815aa80ca3e3562",
13+
strip_prefix = "bazel_features-1.39.0",
14+
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.39.0/bazel_features-v1.39.0.tar.gz",
15+
)
16+
17+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
18+
19+
bazel_features_deps()
20+
21+
http_archive(
22+
name = "rules_cc",
23+
sha256 = "a2fdfde2ab9b2176bd6a33afca14458039023edb1dd2e73e6823810809df4027",
24+
strip_prefix = "rules_cc-0.2.14",
25+
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.14/rules_cc-0.2.14.tar.gz",
26+
)
27+
28+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
29+
30+
compatibility_proxy_repo()
31+
832
load("@rules_cuda//cuda:repositories.bzl", "rules_cuda_dependencies", "rules_cuda_toolchains")
933

1034
rules_cuda_dependencies()

cuda/dummy/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
cc_binary(

cuda/private/actions/compile.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
2+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
23
load("//cuda/private:action_names.bzl", "ACTION_NAMES")
34
load("//cuda/private:cuda_helper.bzl", "cuda_helper")
45
load("//cuda/private:rules/common.bzl", "ALLOW_CUDA_SRCS")

cuda/private/actions/dlink.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""
22

33
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
4+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
45
load("//cuda/private:action_names.bzl", "ACTION_NAMES")
56
load("//cuda/private:actions/compile.bzl", "compile")
67
load("//cuda/private:cuda_helper.bzl", "cuda_helper")

cuda/private/cuda_helper.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ load("@bazel_skylib//lib:types.bzl", "types")
55
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
66
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
77
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
8+
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
9+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
810
load("//cuda/private:action_names.bzl", "ACTION_NAMES")
911
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
1012
load("//cuda/private:providers.bzl", "ArchSpecInfo", "CudaArchsInfo", "CudaInfo", "Stage2ArchInfo", "cuda_archs")

cuda/private/macros/cuda_binary.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
12
load("//cuda/private:rules/cuda_library.bzl", _cuda_library = "cuda_library")
23

34
def cuda_binary(name, **attrs):
@@ -43,7 +44,7 @@ def cuda_binary(name, **attrs):
4344
if src in cc_attrs:
4445
cc_attrs[dst] = cc_attrs.pop(src)
4546

46-
native.cc_binary(
47+
cc_binary(
4748
name = name,
4849
deps = [cuda_library_name],
4950
**cc_attrs

0 commit comments

Comments
 (0)