Skip to content

Commit

Permalink
add breez-sdk-go and link it correctly for linux
Browse files Browse the repository at this point in the history
macOS, Windows, Android to follow in later commits.

```
go get github.com/breez/breez-sdk-go
go mod tidy
go mod vendor
```

By naively adding breez-sdk-go, it adds a absolute rpath to the Go
executable (in case of `make servewallet`) or the Go
libraries (libserver.so), due to the absolute path here:

```
cgo linux,amd64 LDFLAGS: -Wl,-rpath,${SRCDIR}/lib/linux-amd64 #-L${SRCDIR}/lib/linux-amd64
```

(https://github.com/breez/breez-sdk-go/blob/7b566724daae0fa539f622b301fe840a3e5cbd59/breez_sdk/cgo.go)

`SRCDIR` is an absolute path and it ends up in the libserver.so binary:

```
$ readelf -d frontends/qt/server/libserver.so

Dynamic section at offset 0xe7d810 contains 32 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libresolv.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libbreez_sdk_bindings.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000010 (SYMBOLIC)           0x0
 0x000000000000001d (RUNPATH)            Library runpath: [/opt/go/src/github.com/digitalbitbox/bitbox-wallet-app/vendor/github.com/breez/breez-sdk-go/breez_sdk/lib/linux-amd64]
```

This is good so that `make servewallet` runs out of the box, but bad
because the absolute path ends up in libserver.so as well.

This way the libbreez_sdk_bindings.so could not be found by a deployed
BitBoxApp, as this folder generally does not exist. We have to instead
copy the breez library to the BitBox folder and fix the library
resolution.

To do this, we move both libs to the `./lib` folder relative to the
`BitBoxApp`, where all shared libs reside. `linuxdeployqt` already
handles libraries in the `./lib` directory and rewires their rpaths
and adds `rpath=$ORIGIN/lib` to the `BitBox` executable, so we put the
libserver.so and libbreez_sdk_bindings.so there
instead. `linuxdeployqt` then fixes its rpath:

```
readelf -d lib/libserver.so

Dynamic section at offset 0xe7d810 contains 32 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libresolv.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libbreez_sdk_bindings.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000010 (SYMBOLIC)           0x0
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
```

In BitBox.pro, we can then remove `$ORIGIN` from the rpath of the
`BitBox` executable, as libsever.so is not in the same folder anymore,
so it is not needed anymore.

Checking the rpath in libbreez_sdk_bindings.so:

```
readelf -d lib/libbreez_sdk_bindings.so
[...]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:$ORIGIN/../../../../../../../../.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib]
```

This is a strange relative path that is not needed (if deleted with
`chrpath --delete lib/libbreez_sdk_bindings.so` the app works
fine). We could delete this manually in a later commit.

A note about open-source: https://github.com/breez/breez-sdk-go is a
thin wrapper around https://github.com/breez/breez-sdk-go, which
vendors the shared libary binaries compiled from the Breez SDK. This
is not ideal, but in the end, all libraries are open source and users
can replace the shared libraries with their own compiled binaries. In
the future we could look into building the shared libararies as part
of the BitBoxApp build process.
  • Loading branch information
benma committed Nov 27, 2023
1 parent eb72e1c commit a1b0f62
Show file tree
Hide file tree
Showing 32 changed files with 9,648 additions and 5 deletions.
11 changes: 11 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package backend

import (
"encoding/hex"
"fmt"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/breez/breez-sdk-go/breez_sdk"
"github.com/btcsuite/btcd/chaincfg"
"github.com/digitalbitbox/bitbox-wallet-app/backend/accounts"
accountsTypes "github.com/digitalbitbox/bitbox-wallet-app/backend/accounts/types"
Expand Down Expand Up @@ -202,6 +204,15 @@ func NewBackend(arguments *arguments.Arguments, environment Environment) (*Backe
}
log.Infof("backend config: %+v", config.AppConfig().Backend)
log.Infof("frontend config: %+v", config.AppConfig().Frontend)

// Breez SDK test call. Remove once working on all platforms and the SDK is in use, so `go mod
// tidy` does not remove it.
seed, err := breez_sdk.MnemonicToSeed("cruise clever syrup coil cute execute laundry general cover prevent law sheriff")
if err != nil {
panic(err)
}
log.Debugf("BREEZ TEST API CALL: Seed: %vv", hex.EncodeToString(seed))

backend := &Backend{
arguments: arguments,
environment: environment,
Expand Down
2 changes: 0 additions & 2 deletions frontends/qt/BitBox.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ win32 {
# https://stackoverflow.com/questions/18462420/how-to-specify-mac-platform-in-qmake-qtcreator
unix:!macx {
QMAKE_LFLAGS_RPATH=
# so libserver.so will be found by linuxdeployqt, once copied into the same folder.
QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN\''
QMAKE_LFLAGS += " -pie -Wl,-z,now,-z,relro,-z,noexecstack,-z,defs "
}

Expand Down
6 changes: 3 additions & 3 deletions frontends/qt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ linux:
$(MAKE) clean
cd server && $(MAKE) linux
$(MAKE) base
mkdir build/linux-tmp build/linux
mkdir -p build/linux-tmp/lib build/linux
mv build/BitBox build/linux-tmp
cp build/assets.rcc build/linux-tmp/
cp server/libserver.so build/linux-tmp
cp server/libserver.so build/linux-tmp/lib
cp ../../vendor/github.com/breez/breez-sdk-go/breez_sdk/lib/linux-amd64/libbreez_sdk_bindings.so build/linux-tmp/lib
cd build/linux-tmp && /opt/linuxdeployqt-7-x86_64.AppImage BitBox -bundle-non-qt-libs -unsupported-allow-new-glibc
cp /usr/lib/x86_64-linux-gnu/nss/* build/linux-tmp/lib
cp -aR resources/linux build/tmp-deb
Expand All @@ -43,7 +44,6 @@ linux:
# create AppImage
cd build/linux-tmp && /opt/linuxdeployqt-7-x86_64.AppImage BitBox -appimage -unsupported-allow-new-glibc
mv build/linux-tmp/BitBoxApp-*-x86_64.AppImage build/linux/
rm build/linux-tmp/libserver.so
osx:
$(MAKE) clean
cd server && $(MAKE) macosx
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/breez/breez-sdk-go v0.2.10 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/cespare/cp v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/benma/miniscript-go v0.0.0-20230525042155-decf85f82801/go.mod h1:uvDKYMsmXTBlYkr+p6jciP8fG6h2U2acRhMtlrweYAg=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/breez/breez-sdk-go v0.2.10 h1:D9mEtVTNWhwoV7L6esxpyjoFyFkFoJ2w2l7iZdfE7NA=
github.com/breez/breez-sdk-go v0.2.10/go.mod h1:EalYMEeQVwRzr6UXnF4QpLlpuWNwQQN9xwtDKNIutBo=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/breez/breez-sdk-go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1b0f62

Please sign in to comment.