diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a76b964..1e29764 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ env: on: pull_request: push: - branches: [main] + branches: [develop] jobs: quicktests: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5025696..1732b7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,7 @@ jobs: release: strategy: matrix: - # build and publish in parallel: linux/amd64, linux/arm64, windows/amd64, darwin/amd64, darwin/arm64 + # build and publish in parallel include: - image: macos-latest name: macos-amd64 @@ -36,18 +36,14 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: Install musl - # only run on GH-hosted runner; self-hosted runner already has the package + - name: Install required packages + # only run on GH-hosted runner; self-hosted runner already has these if: matrix.name == 'linux-amd64' - uses: awalsh128/cache-apt-pkgs-action@v1 - with: - packages: musl-tools # provides musl-gcc - version: 1.0 + run: sudo apt-get install -y libudev-dev - name: Build run: make build - name: Prepare files shell: bash - # if: ${{ !contains(matrix.name, 'windows') }} run: | mkdir artifacts mv LICENSE README.md ${{ env.BINARY_NAME }} artifacts diff --git a/Makefile b/Makefile index 3284a83..cb1d909 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,13 @@ DEPTAG := 0.0.1 DEPLIBNAME := spacemesh-sdk DEPLOC := https://github.com/spacemeshos/$(DEPLIBNAME)/releases/download UNZIP_DEST := deps -REAL_DEST := $(shell realpath .)/$(UNZIP_DEST) +REAL_DEST := $(CURDIR)/$(UNZIP_DEST) DOWNLOAD_DEST := $(UNZIP_DEST)/$(DEPLIBNAME).tar.gz + +LINKLIBS := -L$(REAL_DEST) +CGO_LDFLAGS := $(LINKLIBS) STATICLDFLAGS := -L$(UNZIP_DEST) -led25519_bip32 -lspacemesh_remote_wallet +EXTRACT = tar -xzf # Detect operating system ifeq ($(OS),Windows_NT) @@ -50,39 +54,27 @@ ifeq ($(GOOS),linux) # Linux specific settings # We statically link our own libraries and dynamically link other required libraries - LDFLAGS = -linkmode external -extldflags "-Wl,-Bstatic $(STATICLDFLAGS) -Wl,-Bdynamic -ludev -lm" + LDFLAGS = -ldflags '-linkmode external -extldflags "-Wl,-Bstatic $(STATICLDFLAGS) -Wl,-Bdynamic -ludev -lm"' else ifeq ($(GOOS),darwin) MACHINE = macos # macOS specific settings - # dynamic build using default toolchain - LDFLAGS = -extldflags "$(STATICLDFLAGS)" + # statically link our libs, dynamic build using default toolchain + CGO_LDFLAGS = $(LINKLIBS) $(REAL_DEST)/libed25519_bip32.a $(REAL_DEST)/libspacemesh_remote_wallet.a -framework CoreFoundation -framework IOKit -framework AppKit + LDFLAGS = else ifeq ($(GOOS),windows) # static build using default toolchain # add a few extra required libs - LDFLAGS = -linkmode external -extldflags "-static $(STATICLDFLAGS) -lws2_32 -luserenv -lbcrypt" + LDFLAGS = -ldflags '-linkmode external -extldflags "-static $(STATICLDFLAGS) -lws2_32 -luserenv -lbcrypt"' else $(error Unknown operating system: $(GOOS)) endif ifeq ($(SYSTEM),windows) # Windows settings - # TODO: this is probably unnecessary, most Windows dev environments (including GHA) - # should support bash - RM = del /Q /F - RMDIR = rmdir /S /Q - MKDIR = mkdir - - FN = $(DEPLIBNAME)_windows-amd64.tar.gz - DOWNLOAD_DEST = $(UNZIP_DEST)/$(DEPLIBNAME).zip - EXTRACT = 7z x -y + PLATFORM = windows-amd64 else # Linux and macOS settings - RM = rm -f - RMDIR = rm -rf - MKDIR = mkdir -p - EXTRACT = tar -xzf - ifeq ($(GOARCH),amd64) PLATFORM = $(MACHINE)-amd64 else ifeq ($(GOARCH),arm64) @@ -90,14 +82,14 @@ else else $(error Unknown processor architecture: $(GOARCH)) endif - FN = $(DEPLIBNAME)_$(PLATFORM).tar.gz endif +FN = $(DEPLIBNAME)_$(PLATFORM).tar.gz $(UNZIP_DEST): $(DOWNLOAD_DEST) cd $(UNZIP_DEST) && $(EXTRACT) ../$(DOWNLOAD_DEST) $(DOWNLOAD_DEST): - $(MKDIR) $(UNZIP_DEST) + mkdir -p $(UNZIP_DEST) curl -sSfL $(DEPLOC)/v$(DEPTAG)/$(FN) -o $(DOWNLOAD_DEST) .PHONY: install @@ -114,16 +106,16 @@ tidy: .PHONY: build build: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ GOOS=$(GOOS) \ GOARCH=$(GOARCH) \ CGO_ENABLED=1 \ - go build -ldflags '$(LDFLAGS)' + go build $(LDFLAGS) .PHONY: test test: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ go test -v -count 1 -ldflags "-extldflags \"$(STATICLDFLAGS)\"" ./... @@ -143,34 +135,33 @@ test-fmt: git diff --exit-code || (git --no-pager diff && git checkout . && exit 1) .PHONY: lint -lint: +lint: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml # Auto-fixes golangci-lint issues where possible. .PHONY: lint-fix -lint-fix: +lint-fix: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --fix .PHONY: lint-github-action -lint-github-action: +lint-github-action: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --out-format=github-actions .PHONY: staticcheck staticcheck: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ - CGO_LDFLAGS="-L$(REAL_DEST)" \ + CGO_LDFLAGS="$(CGO_LDFLAGS)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ staticcheck ./... clean: - $(RM) $(DOWNLOAD_DEST) - $(RMDIR) $(UNZIP_DEST) + rm -rf $(UNZIP_DEST) diff --git a/go.mod b/go.mod index 50a3f88..a0ba9d8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/btcsuite/btcutil v1.0.2 github.com/jedib0t/go-pretty/v6 v6.4.6 - github.com/spacemeshos/smkeys v1.0.3 + github.com/spacemeshos/smkeys v1.0.4 github.com/stretchr/testify v1.8.2 ) diff --git a/go.sum b/go.sum index f30086c..9c4337d 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spacemeshos/smkeys v1.0.3 h1:v1O8NgRtSTCMBClvBM/MqxWJ35moKYURadFDwZRQki4= -github.com/spacemeshos/smkeys v1.0.3/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= +github.com/spacemeshos/smkeys v1.0.4 h1:M4A2tO2WSbtaVgmLWMgRNh+gmFPDjtVMkSMBO02GMQo= +github.com/spacemeshos/smkeys v1.0.4/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=