bazel-contrib / bazel-contrib/rules_go

Failure cross-compiling for ARM

Open
#2,290 6 comments 0 reactions 0 assignees View on GitHub
bug cgo cross-compilation
Dominant language
Go
Stars
1.5k
Forks
762
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

0.20.2

### What version of gazelle are you using?

0.19.1

### What version of Bazel are you using?

1.2.0

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

### What operating system and processor architecture are you using?
darwin/amd64

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

I adopted the toolchain from [Bazel's cc_toolchain test](https://github.com/bazelbuild/bazel/tree/master/src/test/shell/bazel/testdata/bazel_toolchain_test_data).

Made slight modifications to fit the toolchain into my repo, and to match [`rules_go` cross-compile recommendations](https://github.com/bazelbuild/rules_go#how-do-i-cross-compile). Specifically I:
* Placed the toolchain under `//toolchain`.
* Simplified `armeabi-v7a` to `arm` so that rules_go would pick up the toolchain.

### What did you do?

.bazelrc:
```
build:myconfig --platforms=@io_bazel_rules_go//go/toolchain:linux_arm_cgo
build:myconfig --cpu=arm
build:myconfig --crosstool_top=//toolchain/arm_compiler:toolchain
build:myconfig --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
build:myconfig --action_env=GOARM=7
```

Then:
```
> bazel build --config=myconfig //mytarget --sandbox_debug
```

### What did you expect to see?
Cross-compiled binary success.

### What did you see instead?
```
INFO: Analyzed target //mytarget:mytarget (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/external/io_bazel_rules_go/BUILD.bazel:8:1: GoStdlib external/io_bazel_rules_go/linux_arm_stripped/stdlib%/pkg failed (Exit 1) sandbox-exec failed: error executing command
(cd /private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/execroot/com_github_softwaremotor_smc && \
exec env - \
CC=toolchain/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc \
CGO_CFLAGS='--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc -mfloat-abi=hard -nostdinc -isystem external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include -isystem external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include -isystem external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed -isystem external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include -U_FORTIFY_SOURCE -fstack-protector -fPIE -fdiagnostics-color=always -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted"' \
CGO_ENABLED=1 \
CGO_LDFLAGS='--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc -lstdc++ -latomic -lm -lpthread -Ltools/arm_compiler/linaro_linux_gcc/clang_more_libs -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/lib -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/lib -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/lib -Bexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/bin -Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3 -no-canonical-prefixes -pie -Wl,-z,relro,-z,now' \
GOARCH=arm \
GOOS=linux \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=toolchain/arm_compiler/linaro_linux_gcc:/bin:/usr/bin \
TMPDIR=/var/folders/v8/pgq2fh216w997cls2brzl2vc0000gn/T/ \
/usr/bin/sandbox-exec -f /private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/sandbox.sb /var/tmp/_bazel_fedenusy/install/3c8c3e061eca79d4c8e8c05bb2875b69/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/go_sdk/builder stdlib -sdk external/go_sdk -installsuffix linux_arm -out bazel-out/arm-fastbuild/bin/external/io_bazel_rules_go/linux_arm_stripped/stdlib%)
# runtime/cgo
/private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/execroot/com_github_softwaremotor_smc/toolchain/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc: line 3: bazel-out/arm-fastbuild/bin/external/io_bazel_rules_go/linux_arm_stripped/stdlib%/src/runtime/cgo/external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-gcc: No such file or directory
/private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/execroot/com_github_softwaremotor_smc/toolchain/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc: line 3: exec: bazel-out/arm-fastbuild/bin/external/io_bazel_rules_go/linux_arm_stripped/stdlib%/src/runtime/cgo/external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-gcc: cannot execute: No such file or directory
stdlib: error running subcommand: exit status 2
Target //mytarget:mytarget failed to build
ERROR: /Users/fedenusy/dev/go/src/smc/mytarget/BUILD.bazel:18:1 GoStdlib external/io_bazel_rules_go/linux_arm_stripped/stdlib%/pkg failed (Exit 1) sandbox-exec failed: error executing command
(cd /private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/execroot/com_github_softwaremotor_smc && \
exec env - \
CC=toolchain/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc \
CGO_CFLAGS='--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc -mfloat-abi=hard -nostdinc -isystem external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include -isystem external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include -isystem external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed -isystem external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include -U_FORTIFY_SOURCE -fstack-protector -fPIE -fdiagnostics-color=always -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -no-canonical-prefixes -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted"' \
CGO_ENABLED=1 \
CGO_LDFLAGS='--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc -lstdc++ -latomic -lm -lpthread -Ltools/arm_compiler/linaro_linux_gcc/clang_more_libs -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/lib -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/lib -Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/lib -Bexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/bin -Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3 -no-canonical-prefixes -pie -Wl,-z,relro,-z,now' \
GOARCH=arm \
GOOS=linux \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=toolchain/arm_compiler/linaro_linux_gcc:/bin:/usr/bin \
TMPDIR=/var/folders/v8/pgq2fh216w997cls2brzl2vc0000gn/T/ \
/usr/bin/sandbox-exec -f /private/var/tmp/_bazel_fedenusy/82761fbb391b03a602abc1324ff91dda/sandbox/darwin-sandbox/1972/sandbox.sb /var/tmp/_bazel_fedenusy/install/3c8c3e061eca79d4c8e8c05bb2875b69/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/go_sdk/builder stdlib -sdk external/go_sdk -installsuffix linux_arm -out bazel-out/arm-fastbuild/bin/external/io_bazel_rules_go/linux_arm_stripped/stdlib%)
INFO: Elapsed time: 9.846s, Critical Path: 9.55s
INFO: 0 processes.
FAILED: Build did NOT complete successfully
```

Looks like rules_go is not playing nicely with the `cc_toolchain` (gcc is run from the wrong directory?)

Help would be much appreciated!

Contributor guide

Open the contributing guide

Research direction

The report names .bazelrc and a custom toolchain under //toolchain, and reproduces the failure with bazel build --config=myconfig //mytarget. Start by comparing that cc_toolchain setup with Bazel's referenced cc_toolchain test and tracing the runtime/cgo compiler path. Done means the reported Linux ARM target cross-compiles successfully with the configured toolchain.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, go
Domain
build-system, compilers
Issue type
Bug
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.