-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow cc_toolchain to be defined across multiple repositories #7746
Comments
Re-assigning to team-rules-cpp for triage: this is strictly part of the setup of cc toolchains, and doesn't impact toolchain resolution at all. |
cc/ @hlopko |
I think with Crosstool in Starlark you cat get get quite far, and the last step can be simplified. I played with this a bit. I have a
And I instantiate this rule like this:
Now this allows me for example to get the path of the package where header is for isystem:
This also allows me to get the path to the gcc no matter which external repository it is by:
The problem is that path are assumed to be relative to the package in which Is my understanding correct that solving this last problem is what this issue is about? |
I believe that is the problem
I did try using un-normalized paths and failed running into the same problem as in the pull request you mentioned |
To answer your question; yes, I do believe your understanding of the problem is correct |
The Asylo project (github.com/google/asylo) has a similar use case. We have a toolchain in a repository @com_google_asylo_toolchain that inserts include paths to the @com_google_asylo workspace by duplicating the -I flags across asylo/path and external/com_google_asylo/asylo/path prefixes. The includes are to supplemental POSIX and system header files that trampoline into our runtime for actions like secure I/O and crypographically-secure randomness from /dev/urandom. I ran into the relative path problem a year ago, and resolved it with a repository_rule that takes the absolute path to the toolchain installation directory as an attribute and then creates a symlink so that paths can stay relative https://github.com/google/asylo/blob/master/asylo/bazel/asylo_deps.bzl#L102 Splitting a toolchain across repos is still preferable to extra machinery around the POSIX and system includes to break the cyclic dependency since the solutions I've come up with all involve having to reinstall the toolchain whenever we add more POSIX support. |
@deeglaze if it's only for include paths, cannot you use something like |
@hlopko So, where do we go from here? :)
Update: I happened upon 473ea10 and realized it's a bit more involved than I thought. |
Is there a particular reason why relative paths are used, or is it more of a side effect of the original CROSSTOOL configurations being in proto rather than starlark? The behaviour seems a little odd and from my perspective doesn't feel consistent with the rest of bazel's starlark API. I would be happy to contribute towards a fix. However I have limited understanding of bazel internals and rudimentary experience with java so it may be a long time before I get to it. Any ideas on a general approach for a fix, that might minimise breaking changes and avoid introducing other issues? |
Relative paths are just a side effect of the history. I also think this is odd, but so far we didn't find enough motivation to fix it. So there are 2 use cases:
If @silvergasp you want to contribute smth, then adding |
I have finally had a bit of time to look into this a little further. Mostly just trying to familiarise myself with the source code. I would just like to consolidate my current understanding before I start putting any significant amount of time into this.
I admit I did look through the current java implementations for the cc rules and found it too difficult to follow in the time I have available for this. Is the plan to support both native cc_rules rules and skylark cc_rules, or to move exclusively to skylark? Are there any other updates on this so far? I would like to avoid duplicating effort :) |
There is no ongoing effort on this just yet, so feel free to go ahead.
|
I took a look into implementing this. I have it working locally, but I believe my implementation is incomplete. The part I'm unsure about is the interaction between the CcToolchainFeatures.Tool class and the CToolChain.Tool protobuf. I've added an Artifact member to CcToolchainFeatures.Tool, but I'm not sure how to serialize/deserialize that into and out of the protobuf. I can guess how you might get a string out of it to serialize, but when it comes to deserializing via the private constructor, I really have no idea. I'm assuming that the protobuf code is for sending the toolchain config across the wire for remote execution, but... I'm just guessing there. Obviously this is going to be incomplete without that bit. Any suggestions on how to proceed? I'm happy to cook up a pull request so you can see what I've done, but obviously it wouldn't be a final product yet. |
Is there any update on this? It appears that rules_foreign_cc does not work with non-hermetic toolchains (and wrapper scripts provided to the |
New year, new check for updates ;) |
This has mostly been addressed in #10967. I think there is a little bit more work to do before closing this;
I'd be happy to create a PR updating the docs/tutorials if that is something that would be considered useful? |
An additional point would be that bazelbuild/rules_cc#72 would probably need to be merged to match the main Bazel repository as well. |
I am confused how to use this. My understanding is, now you can use cc_common.create_cc_toolchain_config_info(
...
compiler = tool(tool = ...),
) But when do this I get:
|
You need to use the tool constructor with an action_config. I answered a StackOverflow question earlier today on this, if you are looking for an example. |
Personally I think the tool constructor could probably entirely replace the tool_path constructor. I think having both just gets confusing, with very little added value. |
I agree. The architecture of toolchain config is unduly affected by the gnu/binutils way which in turn was set due to the Unix way having a single separate executable for every singular task. Other toolchains, like zig, which is a very good match for Bazel uses zig approach and writing 4 - 7 wrapper script files to then put them in the tool_paths shouldn't be the default approach of Bazel user for something as common as specifying toolchain for cross-compilation. |
The recently created design doc at https://docs.google.com/document/d/1-etGNsPneQ8W7MBMxtLloEq-Jj9ng1G-Pip-cWtTg_Y/edit?usp=sharing by the author of the issue should probably be mentioned here. |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale. |
Between https://stackoverflow.com/questions/73504780/bazel-reference-binaries-from-packages-in-custom-toolchain-definition/73505313#73505313 and https://github.com/bazelbuild/rules_cc/blob/main/cc/toolchains/README.md, this appears to be mostly resolved (although still under-documented). |
Description of the problem / feature request:
Currently the workflow to define a cc_toolchain is a good fit for a monorepo. However it is difficult to have a toolchain configuration span across multiple repos.
Why would I like to be able to have a toolchain span multiple repos?
I would like to share a configurable toolchain as an open source project. Therefore I would like to be able to download and use a "CcToolchainConfigInfo" provider rule from an external repository (e.g. using http_archive).
Feature requests: what underlying problem are you trying to solve with this feature?
To my knowledge this is not currently possible to span a toolchain config across multiple repositories. This is due to the fact that
tool_path
from"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl"
is relative to the package directory. The problem with this is that when you load a toolchain config rule from an external repository the relative paths are relative to where the rule is instantiated rather than where the rule is defined.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Follow the tutorial on configuring c++ toolchains. Then attempt to load and use cc_toolchain_config from a different workspace. Doing so will result in an error where the given toolpath cannot be found.
What operating system are you running Bazel on?
Manjaro Linux Rolling Release
What's the output of
bazel info release
?release 0.23.0
If
bazel info release
returns "development version" or "(@non-git)", tell us how you built Bazel.N/A
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?N/A
Have you found anything relevant by searching the web?
I have found that repository rules are a potential workaround. This works by passing through the attrs from the repository_rule through to a toolchain config rule. This bypasses the problem of relative paths by instantiating the config rule in the given repository. For our particular use case this is a fairly heavy weight solution as it involves creating a new repository for each of our targets. We currently have about 10 different configurations for different cc_toolchain rules, as we target a number of different embedded devices.
Any other information, logs, or outputs that you want to share?
I think that a potential solution would be to include a new rule that can reference a target rather than a relative path. e.g.
@toolchain_workspace//:BUILD
@toolchain_workspace//:cc_toolchain_config.bzl
This should support the following usage;
//:BUILD
The text was updated successfully, but these errors were encountered: