'Bazel repository rule- Can I access something like Java's "os.arch"?

I need to write a Bazel repository rule which downloads mysql binaries according to the required version, to the operating system and the architecture.

I'll get the required version from the user, the operating system from repository_os.name but I'm not sure how I can access the architecture?

The current non-hermetic code uses os.arch as a good enough heuristic (yes I know it's not precise).



Solution 1:[1]

There is no way to access the architecture, except asking for uname -m using repository_ctx.execute. You can also make it work on Windows by executing a different command depending on repository_ctx.os.name (which is the same as os.name from the JVM so if it contains win you can execute the Windows command). If you think this is needed, please file a feature request on https://github.com/bazelbuild/bazel/issues/new

Solution 2:[2]

The host platform's CPU architecture and operating system name are accessible via repository_ctx.os. The attribute is a repository_os struct with arch and name.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Thomas