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

Support custom GOARM architecture levels via platform constraints #3837

Merged
merged 3 commits into from
Jan 20, 2024
Merged

Support custom GOARM architecture levels via platform constraints #3837

merged 3 commits into from
Jan 20, 2024

Conversation

LINKIWI
Copy link
Contributor

@LINKIWI LINKIWI commented Jan 19, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This PR introduces support for specifying the ARM architecture level as GOARM via platform constraints, mirroring the implementation in #3251 which accomplished a similar objective for GOAMD64.

The constraint names are taken from here: https://go.dev/wiki/MinimumRequirements#arm

Which issues(s) does this PR fix?

Fixes #1719

Other notes for review

Verification:

WORKSPACE:

local_repository(
    name = "io_bazel_rules_go",
    path = "/path/to/rules_go/fork",
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.21.6")

BUILD:

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")

platform(
    name = "goarm_5",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:armv7",
        "@io_bazel_rules_go//go/constraints/arm:5",
    ],
)

platform(
    name = "goarm_6",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:armv7",
        "@io_bazel_rules_go//go/constraints/arm:6",
    ],
)

platform(
    name = "goarm_7",
    constraint_values = [
        "@platforms//os:linux",
        "@platforms//cpu:armv7",
        "@io_bazel_rules_go//go/constraints/arm:7",
    ],
)

go_library(
    name = "lib",
    srcs = ["main.go"],
    importpath = "sample",
)

go_binary(
    name = "main_host",
    out = "main",
    embed = [":lib"],
)

go_cross_binary(
    name = "main_arm_5",
    platform = ":goarm_5",
    target = ":main_host",
)

go_cross_binary(
    name = "main_arm_6",
    platform = ":goarm_6",
    target = ":main_host",
)

go_cross_binary(
    name = "main_arm_7",
    platform = ":goarm_7",
    target = ":main_host",
)

main.go:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, world!")
}

Compile steps:

$ bazel build //:main_arm_5
$ bazel build //:main_arm_6
$ bazel build //:main_arm_7

It seems that the Go compiler does not embed ARM attributes in the compiled binaries, so readelf -A <binary> does not produce any output. This would otherwise indicate the ARM architecture level in the Tag_CPU_arch tag.

So instead I copied each of these binaries to an ARM host with the following CPU feature set support:

$ cat /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2835
Revision	: 100000e
Serial		: 00000000557be544
Model		: Raspberry Pi Model B Rev 2

Results:

$ ./main_arm_5
Hello, world!
$ ./main_arm_6
Hello, world!
$ ./main_arm_7
Illegal instruction

@fmeum fmeum enabled auto-merge (squash) January 20, 2024 08:16
@fmeum fmeum merged commit 54c12e5 into bazel-contrib:master Jan 20, 2024
2 checks passed
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/bazel-starlib Feb 10, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | minor | `v0.45.1` -> `v0.46.0` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.46.0`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.46.0)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.45.1...v0.46.0)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.22.0")

#### What's Changed

- Support custom `GOARM` architecture levels via platform constraints by
[@&#8203;LINKIWI](https://togithub.com/LINKIWI) in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- Emit nogo facts into a separate archive by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/rules_go/pull/3789](https://togithub.com/bazelbuild/rules_go/pull/3789)
- go_test: ensure external source compilation has data by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[https://github.com/bazelbuild/rules_go/pull/3848](https://togithub.com/bazelbuild/rules_go/pull/3848)
- Fix invocation of assembler for go1.22 by
[@&#8203;jquirke](https://togithub.com/jquirke) in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)
- nogo: Create a go_register_nogo wrapper for WORKSPACE users. by
[@&#8203;DolceTriade](https://togithub.com/DolceTriade) in
[https://github.com/bazelbuild/rules_go/pull/3842](https://togithub.com/bazelbuild/rules_go/pull/3842)
- prepare minor release 0.46 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3854](https://togithub.com/bazelbuild/rules_go/pull/3854)

#### New Contributors

- [@&#8203;LINKIWI](https://togithub.com/LINKIWI) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- [@&#8203;jquirke](https://togithub.com/jquirke) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)

**Full Changelog**:
bazel-contrib/rules_go@v0.45.1...v0.46.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
renovate bot referenced this pull request in kreempuff/rules_unreal_engine Feb 10, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | minor | `v0.45.1` -> `v0.46.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.46.0`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.46.0)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.45.1...v0.46.0)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.22.0")

#### What's Changed

- Support custom `GOARM` architecture levels via platform constraints by
[@&#8203;LINKIWI](https://togithub.com/LINKIWI) in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- Emit nogo facts into a separate archive by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/rules_go/pull/3789](https://togithub.com/bazelbuild/rules_go/pull/3789)
- go_test: ensure external source compilation has data by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[https://github.com/bazelbuild/rules_go/pull/3848](https://togithub.com/bazelbuild/rules_go/pull/3848)
- Fix invocation of assembler for go1.22 by
[@&#8203;jquirke](https://togithub.com/jquirke) in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)
- nogo: Create a go_register_nogo wrapper for WORKSPACE users. by
[@&#8203;DolceTriade](https://togithub.com/DolceTriade) in
[https://github.com/bazelbuild/rules_go/pull/3842](https://togithub.com/bazelbuild/rules_go/pull/3842)
- prepare minor release 0.46 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3854](https://togithub.com/bazelbuild/rules_go/pull/3854)

#### New Contributors

- [@&#8203;LINKIWI](https://togithub.com/LINKIWI) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- [@&#8203;jquirke](https://togithub.com/jquirke) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)

**Full Changelog**:
bazel-contrib/rules_go@v0.45.1...v0.46.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/kreempuff/rules_unreal_engine).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNzMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE3My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
cgrindel-self-hosted-renovate bot referenced this pull request in cgrindel/rules_swift_package_manager Feb 10, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [io_bazel_rules_go](https://togithub.com/bazelbuild/rules_go) |
http_archive | minor | `v0.45.1` -> `v0.46.0` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_go (io_bazel_rules_go)</summary>

###
[`v0.46.0`](https://togithub.com/bazelbuild/rules_go/releases/tag/v0.46.0)

[Compare
Source](https://togithub.com/bazelbuild/rules_go/compare/v0.45.1...v0.46.0)

#### `WORKSPACE` code

load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive")

    http_archive(
        name = "io_bazel_rules_go",
sha256 =
"80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
        urls = [

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",

"https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
        ],
    )

load("@&#8203;io_bazel_rules_go//go:deps.bzl", "go_register_toolchains",
"go_rules_dependencies")

    go_rules_dependencies()

    go_register_toolchains(version = "1.22.0")

#### What's Changed

- Support custom `GOARM` architecture levels via platform constraints by
[@&#8203;LINKIWI](https://togithub.com/LINKIWI) in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- Emit nogo facts into a separate archive by
[@&#8203;fmeum](https://togithub.com/fmeum) in
[https://github.com/bazelbuild/rules_go/pull/3789](https://togithub.com/bazelbuild/rules_go/pull/3789)
- go_test: ensure external source compilation has data by
[@&#8203;sluongng](https://togithub.com/sluongng) in
[https://github.com/bazelbuild/rules_go/pull/3848](https://togithub.com/bazelbuild/rules_go/pull/3848)
- Fix invocation of assembler for go1.22 by
[@&#8203;jquirke](https://togithub.com/jquirke) in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)
- nogo: Create a go_register_nogo wrapper for WORKSPACE users. by
[@&#8203;DolceTriade](https://togithub.com/DolceTriade) in
[https://github.com/bazelbuild/rules_go/pull/3842](https://togithub.com/bazelbuild/rules_go/pull/3842)
- prepare minor release 0.46 by
[@&#8203;tyler-french](https://togithub.com/tyler-french) in
[https://github.com/bazelbuild/rules_go/pull/3854](https://togithub.com/bazelbuild/rules_go/pull/3854)

#### New Contributors

- [@&#8203;LINKIWI](https://togithub.com/LINKIWI) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3837](https://togithub.com/bazelbuild/rules_go/pull/3837)
- [@&#8203;jquirke](https://togithub.com/jquirke) made their first
contribution in
[https://github.com/bazelbuild/rules_go/pull/3756](https://togithub.com/bazelbuild/rules_go/pull/3756)

**Full Changelog**:
bazel-contrib/rules_go@v0.45.1...v0.46.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
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 this pull request may close these issues.

Cross Compiling to armv5
2 participants