cosmos / cosmos-sdk

:chains: A Framework for Building High Value Public Blockchains :sparkles:
https://cosmos.network/
Apache License 2.0
6.24k stars 3.61k forks source link

Cannot build on Mac Pre-Monterey #11364

Closed dwedul-figure closed 2 years ago

dwedul-figure commented 2 years ago

Summary of Bug

Running make build fails on a Mac that isn't yet on Monterey (MacOS V12.0+).

$ make build
Makefile:75: RocksDB support is disabled; to build and test with RocksDB support, set ENABLE_ROCKSDB=true
go build -mod=readonly -tags "netgo ledger" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=sim -X github.com/cosmos/cosmos-sdk/version.AppName=simd -X github.com/cosmos/cosmos-sdk/version.Version=0.46.0-alpha2-160-gf4d50a989 -X github.com/cosmos/cosmos-sdk/version.Commit=f4d50a989fec8ffbc2e640ad492d40f72580064c -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger" -X github.com/tendermint/tendermint/version.TMCoreSemVer=v0.35.2 -w -s' -trimpath -o /Users/danielwedul/git/cosmos-sdk/build/ ./...
# github.com/keybase/go-keychain
cgo-gcc-prolog:203:11: warning: 'SecTrustedApplicationCreateFromPath' is deprecated: first deprecated in macOS 10.15 - No longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrustedApplication.h:59:10: note: 'SecTrustedApplicationCreateFromPath' has been explicitly marked deprecated here
# github.com/zondax/hid
In file included from ../../go/pkg/mod/github.com/zondax/hid@v0.9.1-0.20220302062450-5552068d2266/hid_enabled.go:38:
./hidapi/mac/hid.c:693:34: error: use of undeclared identifier 'kIOMainPortDefault'
        entry = IORegistryEntryFromPath(kIOMainPortDefault, path);
                                        ^
1 error generated.
make: *** [build] Error 2

Version

Master branch, current as of Friday Mar 11, 2022 19:20 UTC. commit hash f4d50a989fec8ffbc2e640ad492d40f72580064c

Steps to Reproduce

  1. Be on a Mac that is still on Big Sur (or earlier).
  2. Download the cosmos-sdk repo and cd into it.
  3. Run make build.

Expected Results: It builds without any errors.

Actual Results:

# github.com/zondax/hid
In file included from ../../go/pkg/mod/github.com/zondax/hid@v0.9.1-0.20220302062450-5552068d2266/hid_enabled.go:38:
./hidapi/mac/hid.c:693:34: error: use of undeclared identifier 'kIOMainPortDefault'
        entry = IORegistryEntryFromPath(kIOMainPortDefault, path);
                                        ^
1 error generated.
make: *** [build] Error 2

Extra Notes: The kIOMainPortDefault variable is only available on MacOS 12.0+ (Monterey). Before that, it was named kIOMasterPortDefault.

$ go mod graph | grep -F 'github.com/zondax/hid'
github.com/cosmos/cosmos-sdk github.com/zondax/hid@v0.9.1-0.20220302062450-5552068d2266
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/zondax/hid@v0.9.0
$ go mod graph | grep -F 'github.com/cosmos/ledger-cosmos-go'
github.com/cosmos/cosmos-sdk github.com/cosmos/ledger-cosmos-go@v0.11.1
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/btcsuite/btcd@v0.0.0-20190115013929-ed77733ec07d
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/cosmos/ledger-go@v0.9.2
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/davecgh/go-spew@v1.1.1
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/pkg/errors@v0.8.1
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/stretchr/testify@v1.3.0
github.com/cosmos/ledger-cosmos-go@v0.11.1 github.com/zondax/hid@v0.9.0

Temporary workaround:

$ LEDGER_ENABLED=false make build

For Admin Use

dwedul-figure commented 2 years ago

Found this issue: https://github.com/Zondax/hid/issues/4 which is applicable, and added a comment about it.

Basically, v0.9.0 uses kIOMasterPortDefault but the master branch uses kIOMainPortDefault. And the master branch is what's getting pulled in. I haven't checked the github.com/cosmos/ledger-cosmos-go repo yet, but I'd guess that it doesn't specify a version, so it's getting master instead of v0.9.0. The github.com/zondax/hid repo only has one branch: master, and one tag: v0.9.0.

Adding replace github.com/zondax/hid => github.com/zondax/hid v0.9.0 to go.mod (in the cosmo-sdk repo) allows the build to succeed.

dwedul-figure commented 2 years ago

Hmm... https://github.com/cosmos/ledger-cosmos-go/blob/master/go.mod#L11 has github.com/zondax/hid v0.9.0 // indirect in it, so I'm not exactly sure why that isn't the version being pulled into cosmos-sdk with that ledger-cosmos-go library.

Looks like it's indirect from github.com/cosmos/ledger-go v0.9.2, identified here: https://github.com/cosmos/ledger-go/blob/master/Gopkg.toml#L1-L3 as specifically v0.9.0.

dwedul-figure commented 2 years ago

Instead of using a replace directive in the cosmos-sdk go.mod file, it's been decided to do this:

  1. Convert https://github.com/cosmos/ledger-go to use go.mod instead of gopkg, define the zondax/hid version to use in there, and release a new version.
  2. Pull that new version into https://github.com/cosmos/ledger-cosmos-go and release a new version.
  3. Pull that into the cosmos-sdk and it should properly use v0.9.0 instead of master as an indirect include.

There are a couple workarounds for folks using cosmos-sdk running into this build problem, only one of which is needed:

  1. Add a replace line to your own go.mod: replace github.com/zondax/hid => github.com/zondax/hid v0.9.0
  2. Do not include the ledger tag in the --tags provided to go build.
tac0turtle commented 2 years ago

unfortunately there isn't a clean way to avoid this due to the keyring library. ill close this for now, let us know if we should reopen