From 1fad6ba8d519f1238632076fe6963f38c5f051ff Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Tue, 11 Jun 2024 12:57:29 +0200 Subject: [PATCH] docs: Document how to use rules_cuda with Bzlmod (#252) --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7bf4c185..9970f1fb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ These rules provide some macros and rules that make it easier to build CUDA with ## Getting Started +### Traditional WORKSPACE approach + Add the following to your `WORKSPACE` file and replace the placeholders with actual values. ```starlark @@ -29,11 +31,35 @@ ensure the host compiler is available. On Windows, this means that you will also and [`detect_clang`](https://github.com/bazel-contrib/rules_cuda/blob/5633f0c0f7/cuda/private/repositories.bzl#L143-L166) determains how the toolchains are detected. +### Bzlmod + +Add the following to your `MODULE.bazel` file and replace the placeholders with actual values. + +```starlark +bazel_dep(name = "rules_cuda", version = "0.2.1") + +# pick a specific version (this is optional an can be skipped) +archive_override( + module_name = "rules_cuda", + integrity = "{sha256_to_replace}", + urls = "https://github.com/bazel-contrib/rules_cuda/archive/{git_commit_hash}.tar.gz", + strip_prefix = "rules_cuda-{git_commit_hash}", +) + +cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") +cuda.local_toolchain( + name = "local_cuda", + toolkit_path = "", +) +use_repo(cuda, "local_cuda") +``` + ### Rules - `cuda_library`: Can be used to compile and create static library for CUDA kernel code. The resulting targets can be consumed by [C/C++ Rules](https://bazel.build/reference/be/c-cpp#rules). -- `cuda_objects`: If you don't understand what _device link_ means, you must never use it. This rule produces incomplete object files that can only be consumed by `cuda_library`. It is created for relocatable device code and device link +- `cuda_objects`: If you don't understand what _device link_ means, you must never use it. This rule produces incomplete + object files that can only be consumed by `cuda_library`. It is created for relocatable device code and device link time optimization source files. ### Flags @@ -96,7 +122,7 @@ Checkout the examples to see if it fits your needs. See [examples](./examples) for basic usage. -See [rules_cuda_examples](https://github.com/cloudhan/rules_cuda_examples) for extended real world projects. +See [rules_cuda_examples](https://github.com/cloudhan/rules_cuda_examples) for extended real-world projects. ## Known issue