-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bzlmod): allow both root module and our module to call cuda.local…
…_toolchain (#264) - fix(bzlmod): allow both root module and our module to call cuda.local_toolchain - test: add repo integration tests
- Loading branch information
Showing
14 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load("@rules_cuda//cuda:defs.bzl", "cuda_library", "requires_cuda") | ||
|
||
cc_library( | ||
name = "use_library", | ||
tags = ["manual"], | ||
deps = ["@local_cuda//:cuda_runtime"], | ||
) | ||
|
||
cuda_library( | ||
name = "use_rule", | ||
srcs = ["@rules_cuda_examples//basic:kernel.cu"], | ||
hdrs = ["@rules_cuda_examples//basic:kernel.h"], | ||
tags = ["manual"], | ||
) | ||
|
||
cuda_library( | ||
name = "optional_kernel", | ||
srcs = ["@rules_cuda_examples//if_cuda:kernel.cu"], | ||
hdrs = ["@rules_cuda_examples//if_cuda:kernel.h"], | ||
tags = ["manual"], | ||
target_compatible_with = requires_cuda(), | ||
) | ||
|
||
cc_binary( | ||
name = "optinally_use_rule", | ||
srcs = ["@rules_cuda_examples//if_cuda:main.cpp"], | ||
defines = [] + select({ | ||
"@rules_cuda//cuda:is_enabled": ["CUDA_ENABLED"], | ||
"//conditions:default": ["CUDA_DISABLED"], | ||
}), | ||
tags = ["manual"], | ||
deps = [] + select({ | ||
"@rules_cuda//cuda:is_enabled": [":optional_kernel"], | ||
"//conditions:default": [], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module(name = "rules_cuda_integration_tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
workspace(name = "rules_cuda_integration_tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
this_dir=$(realpath $(dirname $0)) | ||
|
||
set -ev | ||
|
||
# toolchain configured by the root module of the user | ||
pushd "$this_dir/toolchain_root" | ||
bazel build //... --@rules_cuda//cuda:enable=False | ||
bazel build //... --@rules_cuda//cuda:enable=True | ||
bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=False | ||
bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=True | ||
bazel build //:use_library | ||
bazel build //:use_rule | ||
bazel clean && bazel shutdown | ||
popd | ||
|
||
# toolchain does not exists | ||
pushd "$this_dir/toolchain_none" | ||
# analysis pass | ||
bazel build //... --@rules_cuda//cuda:enable=False | ||
bazel build //... --@rules_cuda//cuda:enable=True | ||
|
||
# force build optional targets | ||
bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=False | ||
ERR=$(bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=True 2>&1 || true) | ||
if ! [[ $ERR == *"didn't satisfy constraint"*"valid_toolchain_is_configured"* ]]; then exit 1; fi | ||
|
||
# use library fails because the library file does not exist | ||
ERR=$(bazel build //:use_library 2>&1 || true) | ||
if ! [[ $ERR =~ "target 'cuda_runtime' not declared in package" ]]; then exit 1; fi | ||
if ! [[ $ERR =~ "ERROR: Analysis of target '//:use_library' failed" ]]; then exit 1; fi | ||
|
||
# use rule fails because rules_cuda depends non-existent cuda toolkit | ||
ERR=$(bazel build //:use_rule 2>&1 || true) | ||
if ! [[ $ERR =~ "target 'cuda_runtime' not declared in package" ]]; then exit 1; fi | ||
if ! [[ $ERR =~ "ERROR: Analysis of target '//:use_rule' failed" ]]; then exit 1; fi | ||
|
||
bazel clean && bazel shutdown | ||
popd | ||
|
||
# toolchain configured by rules_cuda | ||
pushd "$this_dir/toolchain_rules" | ||
bazel build //... --@rules_cuda//cuda:enable=False | ||
bazel build //... --@rules_cuda//cuda:enable=True | ||
bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=False | ||
bazel build //:optinally_use_rule --@rules_cuda//cuda:enable=True | ||
bazel build //:use_library | ||
bazel build //:use_rule | ||
bazel clean && bazel shutdown | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../BUILD.to_symlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module(name = "toolchain_none") | ||
|
||
bazel_dep(name = "rules_cuda", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda", | ||
path = "../../..", | ||
) | ||
|
||
cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") | ||
cuda.local_toolchain( | ||
name = "local_cuda", | ||
toolkit_path = "/nonexistent/cuda/toolkit/path", | ||
) | ||
use_repo(cuda, "local_cuda") | ||
|
||
bazel_dep(name = "rules_cuda_examples", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda_examples", | ||
path = "../../../examples", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../BUILD.to_symlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module(name = "bzlmod_use_repo_no_toolchain") | ||
|
||
bazel_dep(name = "rules_cuda", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda", | ||
path = "../../..", | ||
) | ||
|
||
cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") | ||
cuda.local_toolchain( | ||
name = "local_cuda", | ||
toolkit_path = "", | ||
) | ||
use_repo(cuda, "local_cuda") | ||
|
||
bazel_dep(name = "rules_cuda_examples", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda_examples", | ||
path = "../../../examples", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../BUILD.to_symlink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module(name = "bzlmod_use_repo") | ||
|
||
bazel_dep(name = "rules_cuda", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda", | ||
path = "../../..", | ||
) | ||
|
||
cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain") | ||
use_repo(cuda, "local_cuda") | ||
|
||
bazel_dep(name = "rules_cuda_examples", version = "0.0.0") | ||
local_path_override( | ||
module_name = "rules_cuda_examples", | ||
path = "../../../examples", | ||
) |