Skip to content

Commit

Permalink
fix: release job issue (#145)
Browse files Browse the repository at this point in the history
* chore: remove darwin builds

* test: dynamic linking

* chore: nit

* chore: lint
  • Loading branch information
leovct authored Nov 2, 2023
1 parent c5aa932 commit 7ca79c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: perform cross build and compress binaries

- name: Install packages
run: sudo apt-get update && sudo apt-get install --yes gcc-aarch64-linux-gnu

- name: Perform cross build and compress binaries
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
pwd
make cross
pushd out
echo -n "${{github.ref_name}}" | sed 's/^v//' | tee ref_name.txt
Expand All @@ -51,8 +51,7 @@ jobs:
mv linux-arm64-polycli polycli_${tag_name}_linux_arm64/polycli
tar czf polycli_${tag_name}_linux_arm64.tar.gz polycli_${tag_name}_linux_arm64/
popd
- name: publish binaries
- name: Publish binaries
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
46 changes: 27 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ BUILD_DIR := ./out

GIT_SHA := $(shell git rev-parse HEAD | cut -c 1-8)
GIT_TAG := $(shell git describe --tags)
CUR_DATE := $(shell date +%s)

# Strip debug and suppress warnings.
LD_FLAGS=-s -w
LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.Version=$(GIT_TAG)\"
LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.Commit=$(GIT_SHA)\"
LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.Date=$(CUR_DATE)\"
LD_FLAGS += -X \"github.com/maticnetwork/polygon-cli/cmd/version.BuiltBy=makefile\"
STATIC_LD_FLAGS=$(LD_FLAGS) -extldflags=-static
DATE := $(shell date +%s)
VERSION_FLAGS=\
-X github.com/maticnetwork/polygon-cli/cmd/version.Version=$(GIT_TAG) \
-X github.com/maticnetwork/polygon-cli/cmd/version.Commit=$(GIT_SHA) \
-X github.com/maticnetwork/polygon-cli/cmd/version.Date=$(DATE) \
-X github.com/maticnetwork/polygon-cli/cmd/version.BuiltBy=makefile

.PHONY: help
help: ## Display this help.
Expand All @@ -34,7 +31,7 @@ generate: ## Generate protobuf stubs.

.PHONY: build
build: $(BUILD_DIR) ## Build go binary.
go build -ldflags "-w -X \"github.com/maticnetwork/polygon-cli/cmd/version.Version=dev ($(GIT_SHA))\"" -o $(BUILD_DIR)/$(BIN_NAME) main.go
go build -ldflags "$(VERSION_FLAGS)" -o $(BUILD_DIR)/$(BIN_NAME) main.go

.PHONY: install
install: build ## Install the go binary.
Expand All @@ -44,18 +41,29 @@ install: build ## Install the go binary.

.PHONY: cross
cross: $(BUILD_DIR) ## Cross-compile go binaries using CGO.
env CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "$(STATIC_LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/linux-arm64-$(BIN_NAME) main.go
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "$(STATIC_LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/linux-amd64-$(BIN_NAME) main.go
# MAC builds - this will be functional but will still have secp issues.
env CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -ldflags "$(LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/darwin-arm64-$(BIN_NAME) main.go
env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LD_FLAGS)" -tags netgo -o $(BUILD_DIR)/darwin-amd64-$(BIN_NAME) main.go
# Notes:
# - `-s -w` enables to strip debug and suppress warnings.
# - `-linkmode external -extldflags "-static-libgo"` allows dynamic linking.
echo "Building linux-arm64-$(BIN_NAME)..."
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build \
-ldflags '$(VERSION_FLAGS) -s -w -linkmode external -extldflags "-static-libgo"' \
-tags netgo \
-o $(BUILD_DIR)/linux-arm64-$(BIN_NAME) \
main.go

echo "Building linux-amd64-$(BIN_NAME)..."
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build \
-ldflags '$(VERSION_FLAGS) -s -w -linkmode external -extldflags "-static-libgo"' \
-tags netgo \
-o $(BUILD_DIR)/linux-amd64-$(BIN_NAME) \
main.go

.PHONY: simplecross
simplecross: $(BUILD_DIR) ## Cross-compile go binaries without using CGO.
env GOOS=linux GOARCH=arm64 go build -o $(BUILD_DIR)/linux-arm64-$(BIN_NAME) main.go
env GOOS=darwin GOARCH=arm64 go build -o $(BUILD_DIR)/darwin-arm64-$(BIN_NAME) main.go
env GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/linux-amd64-$(BIN_NAME) main.go
env GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/darwin-amd64-$(BIN_NAME) main.go
GOOS=linux GOARCH=arm64 go build -o $(BUILD_DIR)/linux-arm64-$(BIN_NAME) main.go
GOOS=darwin GOARCH=arm64 go build -o $(BUILD_DIR)/darwin-arm64-$(BIN_NAME) main.go
GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/linux-amd64-$(BIN_NAME) main.go
GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/darwin-amd64-$(BIN_NAME) main.go

.PHONY: clean
clean: ## Clean the binary folder.
Expand Down

0 comments on commit 7ca79c0

Please sign in to comment.