Skip to content

Commit

Permalink
Merge pull request #49 from spacemeshos/lrettig-patch-1
Browse files Browse the repository at this point in the history
Fix CI workflow and Makefile
  • Loading branch information
lrettig authored May 15, 2023
2 parents eec3c4f + c2f2558 commit 4f74597
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
on:
pull_request:
push:
branches: [main]
branches: [develop]

jobs:
quicktests:
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
57 changes: 24 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -50,54 +54,42 @@ 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)
PLATFORM = $(MACHINE)-arm64
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
Expand All @@ -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)\"" ./...

Expand All @@ -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)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 4f74597

Please sign in to comment.