-
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
Provide the host CPU to repository rules #14685
Comments
I've found the need for this as well, when trying to target x86_64 macOS RBE from arm64 macOS. Repository rules incorrectly provide arm64 binaries which fail to run on RBE. |
Also see rules_rust. |
This seems like a reasonable request. It shouldn't be too hard to add a field to |
I started working on this in #14738, but then noticed that this is more subtle than expected: The natural implementation would be to just return @uhthomas @brentleyjones Could you clarify what exactly you would want to know the architecture of? You also referred to RBE, but I think that repository rules could only ever provide the host CPU, not the exec CPU (which isn't even known during the loading phase since it depends on the result of toolchain resolution). Is that sufficient for your use cases? |
For a M1 mac running through Rosetta x86_64 is right IMO, since the emulation should affect everything. |
The intent of this issue is to solve the multi cpu/os repository problem where rule maintainers are forced to write odd hacks to detect the exec (host?) CPU. For example the Go rules declare a signal repository, It's been suggested that multiple repositories for the corresponding cpu and os should be declared (ref), but this can be really messy and weird.
The M1 situation is a bit weird and I don't really know what the right answer is. I think it should depend on whether the architecture of the Bazel binary, as there is no other way to differentiate between native and rosetta at current. Does what I've written make sense, and is it clear what the goal of this issue is? |
I would like the know the architecture of |
The architecture of the Bazel binary, at least assuming it uses the shipped JDK, the default @brentleyjones I understand your use case, but this seems difficult to do: Strictly speaking, the platform specified by |
Awesome @fmeum, your PR looks great. Thanks for taking a look at this! :) Is there some reference which lists the possible values of For my own sanity also, are repository rules executed on the host platform, or the execution platform? More specifically, will the values of |
Additionally, how does this all fit into platforms? If at all. I think it might be strange to use the Platforms API in most cases, but the repository_os struct in others. What are your thoughts? |
The two sources I usually refer to are the OpenJDK sources and Bazel's CPU and OS classes.
My understanding is that repository rules are always executed locally (i.e., on the host), even with RBE, and don't really have a concept of platforms. Rather, platforms could be used to select the correct repository among the instances of a repository rule for the different platforms. Bazel would then only fetch the repository rules that are relevant for the current configuration. In this context, |
I think #14738 solves exactly the request of this issue. The But we do have a way to make I also agree if Bazel runs in a simulation it should just get the simulated arch. We do provide native arm64 binaries for Linux and macOS, arm64 support for Windows has also been added recently. |
@bazel-io flag |
(I miss-read what that command was for, this isn't a blocker, sorry.) |
OK, I removed the label. But I guess we could still cherry-pick this to 5.1? @Wyverald |
Yeah, that was what I wanted to do. Per the process, it seems we just open the PR instead of flagging it. |
@bazel-io fork 5.1 |
The fork command will create an associate issue to track the cherry-pick, feel free to send a PR! |
Amazing, thank you for the work on this. I look forward to using it! I'll make contributions for the major rules to also take advantage of this new attribute when available. For clarification; this only provides info for the host OS, correct? What happens in a remote execution context? Are those actions still executed locally? I suppose it depends on the declared toolchains. Is there any official guidance on how best to write repository rules for compatibility with remote execution? It seems to me like it may still be the case that rule authors must declare every cpu/os combination as repositories and reference them via toolchains. Maybe I'm missing something 🙂 |
This new field provides access to the Java "os.arch" property to repository rules, which previously had to rely on uname (Unix) or additional env variables (Windows) to detect the architecture. This also fixes a small issue in the existing implementation of repository_ctx.os.name, which should use the root locale when converting the value of the "os.name" property to lowercase. Existing sites of manual architecture detection in shipped repository rules as well as redundant calls to lower() on the value of repository_ctx.os.name are cleaned up. Fixes bazelbuild#14685 Closes bazelbuild#14738. PiperOrigin-RevId: 427147225 (cherry picked from commit 32d1606)
This new field provides access to the Java "os.arch" property to repository rules, which previously had to rely on uname (Unix) or additional env variables (Windows) to detect the architecture. This also fixes a small issue in the existing implementation of repository_ctx.os.name, which should use the root locale when converting the value of the "os.name" property to lowercase. Existing sites of manual architecture detection in shipped repository rules as well as redundant calls to lower() on the value of repository_ctx.os.name are cleaned up. Fixes #14685 Closes #14738. PiperOrigin-RevId: 427147225 (cherry picked from commit 32d1606) Co-authored-by: Fabian Meumertzheim <[email protected]>
Description of the problem / feature request:
Repository rules already have access to
repository_os
which allows rules to change their behaviour based on the exec OS. Repository rules should also know the exec architecture. Repository rules currently work around this limitation byuname -m
, which isn't ideal. See rules_go.Feature requests: what underlying problem are you trying to solve with this feature?
Repository rules create potentially brittle and strange workarounds to get the exec CPU. There is no standardisation and no official guidance on how best to create repository rules which target multiple platforms.
What operating system are you running Bazel on?
Linux x86_64
What's the output of
bazel info release
?❯ bazel info release Starting local Bazel server and connecting to it... release 5.0.0
Have you found anything relevant by searching the web?
Any other information, logs, or outputs that you want to share?
N/A
The text was updated successfully, but these errors were encountered: