Cosmos-sdk: CGO / Ledger: Fix build issues

Created on 6 Jul 2018  路  23Comments  路  Source: cosmos/cosmos-sdk

Currently the ledger requires CGO as a dependency. This isn't installed in all machines and should not be the default for the SDK. We need to make this an opt-in build flag, with associated make command.

  • [x] Refactor code that uses the ledger dependency to only require it if a build flag is present
  • [ ] Suppress Ledger build warnings on Macs (ref #1472)
  • [ ] Get static builds working (ref #1502 )
  • [x] Get cross-compilation working again (ref #1577), investigate possibility of cross-compilation w/ ledger code
  • [x] Create make command for using ledger, and an install command that builds w/o ledger
  • [ ] Decide if we should update install scripts we expect users to use to include ledger dependencies / update the udev rules.

Most helpful comment

I'm not. The ledger integration threw off cross-compiling enough that I wanted to wait until things settle and we decide how we want to move forward.

Right now, if I want to use the SDK as an SDK (where I don't need Ledger), I add the following things:

  1. CGO_ENABLED=false
  2. LEDGER_ENABLED=false
  3. BUILD_FLAGS=-tags "netgo ledger" -ldflags "-extldflags \"-static\""

This allows me to build a static binary with no Ledger support. Any cross-compilation efforts with Ledger enabled were met with error messages, so I use docker to cross-compile to linux on my Mac or I compile it directly on Mac for Mac binary.

All 23 comments

~That doesn't appear to be related to the CGO issues. That issue appears (to me) to be a problem with your wireless software/hardware. Also moved your logs to a pastebin, so the issue is still easy to scroll through.~

EDIT: The previous message from another person was deleted.

We need to make this an opt-in build flag, with associated make command.

Interesting choice of words. I just run into the following use-case:

As the developer leveraging the cosmos-sdk, I want to write an application that does not use ledger or any ledger-related code.

So in my case, getting ledger-related errors in a completely unrelated application is frustrating. Can the ledger code be a separate library that I pull in if I need but doesn't get built if I'm not using it? This is more than just a Makefile change, because in this case I'm adding cosmos-sdk as a vendor dependency (no Makefile execution).

So in my case, getting ledger-related errors in a completely unrelated application is frustrating. Can the ledger code be a separate library that I pull in if I need but doesn't get built if I'm not using it? This is more than just a Makefile change, because in this case I'm adding cosmos-sdk as a vendor dependency (no Makefile execution).

Can dep support some kind of build flag? What we want is a way for downstream SDK users to specify whether or not they want to build with Ledger support (which can be disabled by default, perhaps, if the errors are frustrating).

Maybe. Based on my current knowledge, I would keep ledger integration as a separate library and make cosmos-sdk apply an interface (in the Java term, I'm not sure if Go does it the same way) so you can plug it in as a separate modul. We'll need to do more research on this.

The Voyager team isn't able to build the SDK (v0.20.0) for macOS or Windows:

export GOOS=darwin
make get_vendor_deps
make install
...
go install -tags netgo -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=080dd5b9" ./cmd/gaia/cmd/gaiad
# github.com/cosmos/cosmos-sdk/vendor/github.com/zondax/ledger-goclient
vendor/github.com/zondax/ledger-goclient/ledger.go:76:18: undefined: hid.Devices
vendor/github.com/zondax/ledger-goclient/ledger.go:99:18: undefined: hid.Devices
Makefile:40: recipe for target 'install' failed
make: *** [install] Error 2

export GOOS=windows
make get_vendor_deps
make install
...
go install -tags netgo -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=080dd5b9" ./cmd/gaia/cmd/gaiad
# github.com/cosmos/cosmos-sdk/vendor/github.com/zondax/ledger-goclient
vendor/github.com/zondax/ledger-goclient/ledger.go:76:18: undefined: hid.Devices
vendor/github.com/zondax/ledger-goclient/ledger.go:99:18: undefined: hid.Devices
Makefile:40: recipe for target 'install' failed
make: *** [install] Error 2
cp: cannot stat '/go/bin/*_amd64': No such file or directory
error Command failed with exit code 1.

The Voyager team isn't able to build the SDK (v0.20.0) for macOS or Windows:

While we should add a build flag, we definitely want Ledger support on Mac OS and Windows - I'm not sure what flags the upstream library may need for that though - https://github.com/brejski/hid.

Note:
I could build SDK 0.20 on Mac OS. The error we are experiencing happens when building inside Docker.

@faboweb, correct, the build-linux target fails. I believe its still worthwhile making ledger an opt-in via a build tag.

Actually, I built this fine from within a docker container. Seems to be an issue when invoked from a mac. Looking into it further.

Our problem is that we build on Linux using cross compilation. It looks like cross compilation is no longer supported.

Reopening, since not all items are finished.

@ValarDragon / @NodeGuy what exactly do we want to do here? I don't recommend cross compiling when you have dynamic libraries linked (libs) (hence ledger disabled). Cross compiling with CGO is extremely cumbersome from my experience, also of which I do not have much of. Might need someones help on this.

@greg-szabo We started building our own binaries of the SDK when there weren't any for the new version and you were on vacation. Are you still building binaries for all three platforms? Is your process always current with new SDK releases?

I'm not. The ledger integration threw off cross-compiling enough that I wanted to wait until things settle and we decide how we want to move forward.

Right now, if I want to use the SDK as an SDK (where I don't need Ledger), I add the following things:

  1. CGO_ENABLED=false
  2. LEDGER_ENABLED=false
  3. BUILD_FLAGS=-tags "netgo ledger" -ldflags "-extldflags \"-static\""

This allows me to build a static binary with no Ledger support. Any cross-compilation efforts with Ledger enabled were met with error messages, so I use docker to cross-compile to linux on my Mac or I compile it directly on Mac for Mac binary.

What @greg-szabo outlined is pretty much the set process right now. Cross-compiling with Ledger support is a huge pain -- I'm not even sure it can be done?

Would someone please talk to the Ledger people about this?

Would someone please talk to the Ledger people about this?

We've brought it up - but it's a lower priority than a Ledger app for validators.

@greg-szabo What error messages did cross-compile attempts result in?

Linking #2157

Any updates?

Native Golang Ledger isn't presently slated for pre-launch - is it a substantial issue Voyager-side or is cross-compilation workable?

We would need cross-compilation (which isn't working right now) to make it work in Voyager. We already agreed that this is not a pre-launch necessity. I was exploring this again as it was a feature @zmanian was pushing for. I will drop research on it, until this issue is resolved.

@cwgoes I don't think this is actually game of steaks needed. I mistook it for an actual SDK build issue. Thoughts?

It's not even prelaunch I think, see @faboweb's last comment.

Going to close this and track progress here with the SRE team.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fedekunze picture fedekunze  路  3Comments

hendrikhofstadt picture hendrikhofstadt  路  3Comments

rigelrozanski picture rigelrozanski  路  3Comments

ValarDragon picture ValarDragon  路  3Comments

johnmcdowall picture johnmcdowall  路  3Comments