cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

simapp build for linux/amd64 docker is an ARM binary

Open webmaster128 opened this issue 3 years ago • 2 comments

In order to test the 0.46 CosmJS client I would love to use interchainio/simapp:v0.46.0. This is uploaded as a linux/amd64 container to DockerHub (https://hub.docker.com/r/interchainio/simapp/tags). However, when running the container on a Linux CI system, it fails with

v0.46.0: Pulling from interchainio/simapp
88ecf269dec3: Pulling fs layer
7caf0c76d8e4: Pulling fs layer
[...]
eb74d548eb9b: Verifying Checksum
eb74d548eb9b: Download complete
88ecf269dec3: Pull complete
7caf0c76d8e4: Pull complete
4f4fb700ef54: Pull complete
eb74d548eb9b: Pull complete
Digest: sha256:f23a1ac61b5d29f177c23ed1120683f80c25e456718425eee83beae19cf12522
Status: Downloaded newer image for interchainio/simapp:v0.46.0
/usr/bin/simd: line 1: 6788�������: not found
/usr/bin/simd: line 1: 6�: not found
/usr/bin/simd: line 1: ELF���@�@8@@@@�����dd�: not found
/usr/bin/simd: line 2: syntax error: unexpected "("

When running file inside of the container it turns out the binary is an ARM binary:

$ apk update
$ apk add file
$ file /usr/bin/simd
/usr/bin/simd: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=KAlB4wSNuFyZju-WIUkA/jk6YWlwLaW-QPpOx1I2P/BZFXEBfh4xUcf1Nwy_5i/XVo5y6r4kB462ku5hna9, stripped

The issue affects v0.45.4, v0.45.5, v0.45.6, v0.46.0-rc1, v0.46.0-rc2, v0.46.0 Not affected: v0.45.2, v0.45.3

webmaster128 avatar Aug 02 '22 16:08 webmaster128

It seems like the GOARCH in https://github.com/cosmos/cosmos-sdk/blob/v0.46.0/Makefile#L128 is broken and is always set to the first part "arm64".

If I create the following debugging target

my-debug-target:
	@echo Find string aarch64: $(findstring aarch64,$(shell uname -m))
	@echo Find string arm64: $(findstring arm64,$(shell uname -m))
	@echo Original: $(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64)
	@echo Linux64: $(if $(findstring aarch64,$(shell echo linux64)) || $(findstring arm64,$(shell echo linux64)),arm64,amd64)

the last line simulates a fallback amd64 machine. But the result is

$ gmake my-debug-target
Find string aarch64:
Find string arm64: arm64
Original: arm64
Linux64: arm64

This shows something is wrong with that if statement.

webmaster128 avatar Aug 03 '22 07:08 webmaster128

Is the build target make build-linux aiming to do cross compilation? If yes, we should have make build-linux-arm64 and make build-linux-amd64 separately and avoid detecting it from the build machine. If no, we can remove both GOOS and GOARCH in order to let the Go build system do the detection.

webmaster128 avatar Aug 03 '22 07:08 webmaster128

this has been fixed, the latest version should work cross platform

tac0turtle avatar Sep 13 '22 11:09 tac0turtle

Thank you Marko! However, there is clearly a bug in the Makefile as pointed out in https://github.com/cosmos/cosmos-sdk/issues/12798#issuecomment-1203568035 and https://github.com/cosmos/cosmos-sdk/pull/10279#issuecomment-1203568749. Was that addressed somewhere?

webmaster128 avatar Sep 13 '22 12:09 webmaster128

looking into that. the makefile command is broken and should be reverted or removed.

tac0turtle avatar Sep 13 '22 12:09 tac0turtle

IMO there are two solid ways to approach this:

  1. Build for the current host. Then both GOOS and GOARCH can be removed entirely.
  2. Cross-build for a specific target. Then we should have make build-linux-arm64 and make build-linux-amd64 separately.

Right now a mix of the two is implemented (build for linux but the current CPU), which is broken due to a scripting bug.

webmaster128 avatar Sep 13 '22 12:09 webmaster128

went with 2

https://github.com/cosmos/cosmos-sdk/pull/13260

tac0turtle avatar Sep 13 '22 12:09 tac0turtle