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

Repo-level aliasing #19927

Open
matts1 opened this issue Oct 24, 2023 · 3 comments
Open

Repo-level aliasing #19927

matts1 opened this issue Oct 24, 2023 · 3 comments
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@matts1
Copy link
Contributor

matts1 commented Oct 24, 2023

Description of the feature request:

I talked to @Wyverald and he said to file a bug here.

At the moment, in rust, it automatically defines the toolchain repos:

amd64_to_amd64
amd64_to_arm64
...

However, in order to build our host tools, we need to define host_to_host. At the moment, this is an exact copy of amd64_to_amd64 on an amd64 machine, or arm64_to_arm64 on an arm64 machine.

Because it changes, and because we still want to be able to access it via the original amd64_to_amd64, we cannot simply write:

use_repo(toolchains, host_to_host = "amd64_to_amd64")

In our module extension, I'd like to instead be able to write:

def module_extension(module_ctx):
    for host in SUPPORTED_PLATFORMS:
        for target in SUPPORTED_PLATFORMS:
            define_toolchain_repo_rule(name = "{host}_to_{target}".format(host, target), host=host, target=target)
    alias_repo(name = "host_to_host", actual = "{host}_to_{host}".format(get_host())

Which category does this issue belong to?

External Dependency

What underlying problem are you trying to solve with this feature?

Every rule inside the repo rule has to be executed twice, since it isn't a true alias of a repo.

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

6.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@sgowroji sgowroji added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Oct 24, 2023
@fmeum
Copy link
Collaborator

fmeum commented Oct 24, 2023

In rules_go, we work around this by introducing an additional layer of indirection: We generate a "well-known" repo that contains a label pointing into the host-compatible toolchain repo (bazelbuild/rules_go@b8d560e). This is less convenient for consumers though as they can no longer reference static labels.

@matts1
Copy link
Contributor Author

matts1 commented Oct 25, 2023

Unfortunately, a label doesn't work for us because it's not accessible from repo rules, and rust needs to build a rust binary with the cargo in this repo rule to build the @crates repo rule.

Rust needs to access the host_to_host/bin/cargo in order to bootstrap (code)

@fmeum
Copy link
Collaborator

fmeum commented Oct 25, 2023

You can access the label via repository_ctx.path. You can't refer to targets like that, but source files work. We use this label provided by rules_go to bootstrap Gazelle in a repository rule: https://github.com/bazelbuild/bazel-gazelle/blob/a957b8358c44cdf0d6b870c575f0f128ae6b2106/internal/bzlmod/non_module_deps.bzl#L38

If that somehow doesn't work for you, I would like to understand why.

@Wyverald Wyverald added P2 We'll consider working on this in future. (Assignee optional) area-Bzlmod Bzlmod-specific PRs, issues, and feature requests and removed untriaged labels Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants