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

Tools are fetched for all platforms #13

Closed
alexeagle opened this issue Mar 8, 2024 · 2 comments · Fixed by #16
Closed

Tools are fetched for all platforms #13

alexeagle opened this issue Mar 8, 2024 · 2 comments · Fixed by #16

Comments

@alexeagle
Copy link
Contributor

Follow-up to #12, this time I'll try to be more helpful in resolving it.

cd examples/target-determinator
bazel build :all

results in waiting for three copies of target-determinator to download.

alexeagle added a commit to alexeagle/rules_multitool that referenced this issue Mar 8, 2024
Hopefully a useful first step in making a fix
@alexeagle
Copy link
Contributor Author

#14 proposes a simple way to test this using bazel's downloader config. Here's a sample failure when the CI job ran (on the main build of my fork, since this PR doesn't pick up ci.yaml changes from untrusted sources)

https://github.com/alexeagle/rules_multitool/actions/runs/8197661135/job/22419952253

@alexeagle
Copy link
Contributor Author

I'll try again to explain the design that fixes this problem. Sorry it's pretty challenging - I did try to make a PR here but didn't have enough time.

At the top-level is a repository macro that creates one "hub" repo, and then also one "platform" repo per supported platform.

external/rules_multitool.hub
external/rules_multitool.linux-x86_64
...

The "hub" repo must not fetch any tools. It will contain the

toolchain(
        name = "target-determinator_{os}_{cpu}_toolchain".format(name=name, os=os, cpu=cpu),
        toolchain = ":target-determinator_{os}_{cpu}_toolchain_info".format(name=name, os=os, cpu=cpu),
        toolchain_type = _TOOLCHAIN_TYPE,
        exec_compatible_with = [
            "@platforms//cpu:{cpu}".format(cpu=cpu),
            "@platforms//os:{os}".format(os=os),
        ],
        target_compatible_with = [
            "@platforms//cpu:{cpu}".format(cpu=cpu),
            "@platforms//os:{os}".format(os=os),
        ],
    )

for all platforms. These may be freely registered (either in MODULE.bazel for bzlmod or in the repository macro)

the toolchain attribute is the special sauce. See https://bazel.build/rules/deploying#registering_toolchains:

in the analysis phase Bazel needs to analyze all toolchain targets that are registered. Bazel will not need to analyze all targets referenced by toolchain.toolchain attribute.

So this is the attribute that should be changed to point into the "platform" repos, for example it should look like

"@rules_multitool.{os}-{cpu}//tools:target-determinator_toolchain_info".format(os=os, cpu=cpu)

Bazel won't try to run any of the downloads for the @rules_multitool.{os}-{cpu} repo if it didn't select the toolchain based on the *_compatible_with attributes. So, in the implementation of the "platform" repos you are free to do whatever fetches for that platform.

Come chat me on Bazel Slack if I can be more helpful to explain it?

mark-thm pushed a commit that referenced this issue Mar 8, 2024
Hopefully a useful first step in making a fix
mark-thm added a commit that referenced this issue Mar 8, 2024
Fixes #13.

We now create a repo per 'environment' (os/cpu combo) in addition to the hub repo, and then refer to the downloads of those repos from the hub.
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 a pull request may close this issue.

1 participant