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

repository_ctx.os.name.lower() inappropriate when remote build. #148

Open
kekxv opened this issue Jan 18, 2024 · 2 comments
Open

repository_ctx.os.name.lower() inappropriate when remote build. #148

kekxv opened this issue Jan 18, 2024 · 2 comments

Comments

@kekxv
Copy link

kekxv commented Jan 18, 2024

local os : macos
remote os : linux

It's supposed to download for Linux, but instead it downloads for macos

image

https://github.com/uber/hermetic_cc_toolchain/blob/cddeaa4c7173f8bf8bd5c14914670af352a68d89/toolchain/defs.bzl#L102C21-L107

@motiejus
Copy link
Collaborator

I don't have/use RBE environment -- can you send a suggestion/PR that fixes it?

@mattyclarkson
Copy link

mattyclarkson commented Sep 11, 2024

I'm hitting the same issue: download is for arm64 but the remote executor is amd64.

This is caused because @zig_sdk is downloaded for the local execution host and then registered to be executable with all platforms, i.e. it does not have exec_compatible_with set here.

What should happen is that we have repositories for each Zig host, arm64-linux, amd64-darwin, etc and register each of those with exec_compatible_with set to the correct constraints. Then Bazel will download and use the correct Zig for the execution platform.

Currently, any remote execution that is not the same constraints as the local executor fails with an "exec format error".

The solution would be something akin to the following in the extension:

load("@hermetic_cc_toolchain//toolchain:defs.bzl", "toolchain")

_HOSTS = (
    "amd64-linux",
    "arm64-linux",
    "...etc...",
)

def _toolchains_impl(ctx):
    for host in _HOSTS:
        toolchain(host = HOST)  # Creates `@amd64-linux-zig_sdk`, etc repositories

    return ctx.extension_metadata(
        ctx,
        root_module_direct_deps = ["{}-zig_sdk".format(h) for h in _HOSTS],
        root_module_direct_dev_deps = (),
        reproducible = True,
    )

toolchains = module_extension(implementation = _toolchains_impl)

Then in the MODULE.bazel we register all the toolchains for the different execution hosts.

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

No branches or pull requests

3 participants