Skip to content

Commit

Permalink
Fixed macos compiling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Karmenzind committed Dec 30, 2023
1 parent 2709fb1 commit 26f694e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 58 deletions.
103 changes: 61 additions & 42 deletions .github/workflows/release-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,79 @@ on:
# branches: [ "main" ]
push:
tags:
- '*'
- "*"

jobs:
release:
linux-part:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
# cache-dependency-path: go.sum
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.x"

- name: Install system dependencies
run: sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-aarch64-linux-gnu

- name: Install dependencies
run: go mod tidy

- name: Build
run: bash scripts/build.sh -a
- name: Install system dependencies
run: sudo apt-get install -y gcc-mingw-w64-x86-64 gcc-aarch64-linux-gnu

# - name: version
# run: echo "::set-output name=version::$(go run cmd/kd.go --version | awk '{print $3}')"
# id: version
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Install dependencies
run: go mod tidy

- name: echo changelog
run: echo ${{steps.build_changelog.outputs.changelog}}
- name: Build
run: |
bash scripts/build.sh linux amd64
bash scripts/build.sh linux arm64
bash scripts/build.sh windows amd64
# - name: Generate Changelog
# run: echo "由changelog生成" > ${{ github.workspace }}-CHANGELOG.txt
- name: "Build Changelog"
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Release
uses: softprops/action-gh-release@v1
# if: startsWith(github.ref, 'refs/tags/')
with:
# name: test-${{ steps.version.outputs.version }}
# body_path: ${{ github.workspace }}-CHANGELOG.txt
body: ${{steps.build_changelog.outputs.changelog}}
fail_on_unmatched_files: true
# tag_name: v0.0.1
prerelease: false
files: build/*
- name: echo changelog
run: echo ${{steps.build_changelog.outputs.changelog}}

- name: info
run: echo ${{ steps.Release.outputs.url }} ${{ steps.Release.outputs.upload_url }} ${{ steps.Release.outputs.id }}

- name: Release
uses: softprops/action-gh-release@v1
# if: startsWith(github.ref, 'refs/tags/')
with:
body: ${{steps.build_changelog.outputs.changelog}}
fail_on_unmatched_files: true
prerelease: false
files: build/*

# - name: info
# run: echo ${{ steps.Release.outputs.url }} ${{ steps.Release.outputs.upload_url }} ${{ steps.Release.outputs.id }}

mac-part:
if: startsWith(github.ref, 'refs/tags/')
runs-on: macos-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21.x"

- name: Install dependencies
run: go mod tidy

- name: Build
run: |
bash scripts/build.sh darwin arm64
bash scripts/build.sh darwin amd64
- name: Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
overwrite: true
file_glob: true
file: build/*
8 changes: 7 additions & 1 deletion plan.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# plan
#master plan

## wip
- mac编译
Expand Down Expand Up @@ -34,6 +34,12 @@

# BUG

## Build failed

mac arm64 / amd64

(action) linux 386

## Risk
- 实际文件名 不改的时候的process_name

Expand Down
18 changes: 18 additions & 0 deletions scripts/Dockerfile-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vim:set noet sts=0 sw=8 ts=8 ft=dockerfile:
# test building
FROM golang:1.21-bookworm
RUN apt-get update -y
RUN apt-get install -y clang
RUN apt-get install -y gcc-mingw-w64-x86-64 gcc-aarch64-linux-gnu
# libc6-dev-i386 \
# linux-headers-generic \
# linux-libc-dev:amd64 \
# linux-libc-dev-arm64-cross
# RUN apt-get install -y gcc-multilib
# RUN apt-get install -y gcc-aarch64-linux-gnu
# RUN apt-get install -y gcc-mingw-w64-x86-64 gcc-multilib
COPY . /app
WORKDIR /app
# RUN go mod tidy
RUN bash scripts/build.sh -a

41 changes: 26 additions & 15 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ cd $PROJECT_DIR
targetdir=${PROJECT_DIR}/build
mkdir -p $targetdir

declare -A d=(
["darwin"]="amd64 arm64"
["linux"]="amd64 arm64 386"
["windows"]="amd64"
)

do_build() {
local os=$1
local arch=$2
local targetfile=$3

local cgo=1 cc=

local filename=kd_${os}_${arch}
[[ $os == "darwin" ]] && filename=kd_macos_${arch}

local targetfile=${targetdir}/${filename}
[[ $os == "windows" ]] && targetfile=${targetfile}.exe

case $os in
windows )
local cc=x86_64-w64-mingw32-gcc
Expand All @@ -46,21 +45,33 @@ do_build() {
fi
}

if [[ $1 == "-a" ]]; then
build_all() {
declare -A d=(
["darwin"]="amd64 arm64"
["linux"]="amd64 arm64"
["windows"]="amd64"
)
rm -rfv $targetdir/*
for os in "${!d[@]}"; do
for arch in ${d[$os]}; do
filename=kd_${os}_${arch}
[[ $os == "darwin" ]] && filename=kd_macos_${arch}

targetfile=${targetdir}/${filename}
[[ $os == "windows" ]] && targetfile=${targetfile}.exe

echo ">>> Building for $os $arch..."
do_build $os $arch $targetfile
done
done
else
}


if [[ $1 == "" ]]; then
echo ">>> Building for current platform..."
do_build '' '' ${PROJECT_DIR}/kd
fi

case $1 in
-a )
build_all
;;
*)
do_build $*
;;
esac

0 comments on commit 26f694e

Please sign in to comment.