bazel-contrib / bazel-contrib/rules_go

How to cross compile to a different libc implementation?

Open
#4,007 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

0.46.0

### What version of gazelle are you using?

0.35.0

### What version of Bazel are you using?

Bazelisk version: v1.19.0

### Does this issue reproduce with the latest releases of all the above?

Yes

### What operating system and processor architecture are you using?

Linux x86_64

### Any other potentially useful information about your toolchain?

No

### What did you do?

```python
go_binary(
name = "myprogram",
srcs = [
"myprogram.go",
],
deps = [
...
],
static = "on",
cgo=False,
)

go_cross_binary(
name = "myprogram_rpi0",
platform = "//platforms:rpi0_linux",
target = ":myprogram",
)
```

I want to deploy my binary on a Raspberry Pi Zero and when I just build the `myprogram` target, I se these warnings:

```
/tmp/go-link-2058405138/000004.o:cgo_unix_cgo.cgo2.c:function _cgo_97ab22c4dc7b_C2func_getaddrinfo: warning: Using 'getaddrin
fo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-2058405138/000004.o:cgo_unix_cgo.cgo2.c:function _cgo_97ab22c4dc7b_Cfunc_getaddrinfo: warning: Using 'getaddrinf
o' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
```

My Raspberry Pi Zero platform is defined like this:

```python
platform(
name = "rpi0_linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:armv7",
"@rules_go//go/toolchain:cgo_off",
"@rules_go//go/constraints/arm:5",
],
)
```

Ultimately, I will want to have `musl` libc implementation on my Raspberry Pi Zero. How can I avoid the assumption that the libc implementation is GNU on my target platform when cross compiling?

### What did you expect to see?

I don't want to see `glibc` warnings in my build.

### What did you see instead?

`glibc`-related warnings. I understand that static compilation still has some dynamic linking involved in the final product, but this build assumes `glibc` on the target, I wouldn't want it to do that.

Contributor guide

Open the contributing guide

Research direction

Start with the shown go_binary and go_cross_binary definitions and the //platforms:rpi0_linux platform constraints; then trace how rules_go selects the cross-compilation toolchain and handles libc assumptions. Compare the cgo-off and static settings against the musl target, and document whether the warning can be avoided or what configuration is missing; done means a reproducible answer for this recipe.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.