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

replace accesses to cc_toolchain.compiler_executable with calls to cc_toolchain.get_tool_for_action() #274

Merged
merged 12 commits into from
Sep 11, 2024

Conversation

hypdeb
Copy link
Contributor

@hypdeb hypdeb commented Sep 8, 2024

According to the Bazel documentation, compiler_executable is going to be phased out. It is already an issue to use it for people who are trying to work with the new rules_cc implementation of the cc rules.

@hypdeb
Copy link
Contributor Author

hypdeb commented Sep 8, 2024

Would want to mark as draft until I've tested it, but not sure how 🤔 .

Found it.

@hypdeb hypdeb marked this pull request as draft September 8, 2024 19:31
@hypdeb
Copy link
Contributor Author

hypdeb commented Sep 9, 2024

Not as easy as I thought. The current error message suggests that find_cpp_toolchain is returning the cuda toolchain instead of the resolved cpp one. Absolutely no idea how this could happen.

@hypdeb
Copy link
Contributor Author

hypdeb commented Sep 9, 2024

That seems to do it, but I'm not sure exactly what these fragments are. Advice would be greatly appreciated.

@hypdeb hypdeb marked this pull request as ready for review September 9, 2024 14:22
@hypdeb
Copy link
Contributor Author

hypdeb commented Sep 9, 2024

A quick question: are all the include directories of the host compiler supposed to be passed to nvcc? It seems it's not the case with my custom cc_toolchain. It's probably unrelated to this MR though.

docs/developer_docs.bzl Outdated Show resolved Hide resolved
@cloudhan
Copy link
Collaborator

cloudhan commented Sep 10, 2024

Otherwise, looks good to me.

NOTE: If the env_entry supports iteration like flag_group, we can change it to use the configured cc_toolchain from the action and pass it via the compile/link variable.

@cloudhan
Copy link
Collaborator

are all the include directories of the host compiler supposed to be passed to nvcc

@hypdeb Yes. The nvcc is just a wrapper in the host compiling case. So all the envs (automatically transitive if you don't specify some weird env flag) and flags (-Xcompiler) should be passed to host compiler to make it work as expected.

@hypdeb
Copy link
Contributor Author

hypdeb commented Sep 10, 2024

@hypdeb Yes. The nvcc is just a wrapper in the host compiling case. So all the envs (automatically transitive if you don't specify some weird env flag) and flags (-Xcompiler) should be passed to host compiler to make it work as expected.

Alright then there's probably some incompatibility between how rules_cc creates compiler flags and how they are imported here that causes my issue. I'll dig deeper into it. It's not directly related to that PR.

@cloudhan
Copy link
Collaborator

/test

@cloudhan
Copy link
Collaborator

Please rebase. I might trigger the integration test after merge. Seems some actions update contains breaking change for /test comment trigger

@@ -1,9 +1,9 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just now realized what you meant with your first review comment. Just to confirm: we need to use the use_cpp_toolchain defined in rules_cuda because we support versions of Bazel where it is not defined in bazel_tools correct?

There's no way I suppose to define this one conditionally on the Bazel version? Not that I necessarily think it would be better, mostly out of curiosity.

load("//cuda/private:actions/compile.bzl", "compile")
load("//cuda/private:cuda_helper.bzl", "cuda_helper")
load("//cuda/private:providers.bzl", "CudaInfo")
load("//cuda/private:rules/common.bzl", "ALLOW_CUDA_HDRS", "ALLOW_CUDA_SRCS")
load("//cuda/private:toolchain.bzl", "find_cuda_toolchain", "use_cpp_toolchain", "use_cuda_toolchain")
load("//cuda/private:toolchain.bzl", "find_cuda_toolchain", "use_cuda_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

load("//cuda/private:actions/compile.bzl", "compile")
load("//cuda/private:actions/dlink.bzl", "device_link")
load("//cuda/private:cuda_helper.bzl", "cuda_helper")
load("//cuda/private:providers.bzl", "CudaInfo")
load("//cuda/private:rules/common.bzl", "ALLOW_CUDA_HDRS", "ALLOW_CUDA_SRCS")
load("//cuda/private:toolchain.bzl", "find_cuda_toolchain", "use_cpp_toolchain", "use_cuda_toolchain")
load("//cuda/private:toolchain.bzl", "find_cuda_toolchain", "use_cuda_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@@ -1,10 +1,10 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to revert these changes

@@ -1,9 +1,9 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

load("//cuda/private:action_names.bzl", "ACTION_NAMES")
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
load("//cuda/private:providers.bzl", "CudaToolchainConfigInfo", "CudaToolkitInfo")
load("//cuda/private:toolchain.bzl", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

load("//cuda/private:action_names.bzl", "ACTION_NAMES")
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
load("//cuda/private:providers.bzl", "CudaToolchainConfigInfo", "CudaToolkitInfo")
load("//cuda/private:toolchain.bzl", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@@ -1,9 +1,9 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@@ -1,9 +1,9 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", CC_ACTION_NAMES = "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

load("//cuda/private:action_names.bzl", "ACTION_NAMES")
load("//cuda/private:artifact_categories.bzl", "ARTIFACT_CATEGORIES")
load("//cuda/private:providers.bzl", "CudaToolchainConfigInfo", "CudaToolkitInfo")
load("//cuda/private:toolchain.bzl", "use_cpp_toolchain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@cloudhan cloudhan merged commit 4dd02f0 into bazel-contrib:main Sep 11, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants