From 26f694e27d11493bc0bf4a0363aff999b649d8ef Mon Sep 17 00:00:00 2001 From: K Date: Sat, 30 Dec 2023 20:54:09 +0800 Subject: [PATCH] Fixed macos compiling issues --- .github/workflows/release-tags.yml | 103 +++++++++++++++++------------ plan.md | 8 ++- scripts/Dockerfile-build | 18 +++++ scripts/build.sh | 41 +++++++----- 4 files changed, 112 insertions(+), 58 deletions(-) create mode 100644 scripts/Dockerfile-build diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml index 6cf6d25..aa62880 100644 --- a/.github/workflows/release-tags.yml +++ b/.github/workflows/release-tags.yml @@ -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/* diff --git a/plan.md b/plan.md index 1275ea5..6b5534c 100644 --- a/plan.md +++ b/plan.md @@ -1,4 +1,4 @@ -# plan +#master plan ## wip - mac编译 @@ -34,6 +34,12 @@ # BUG +## Build failed + +mac arm64 / amd64 + +(action) linux 386 + ## Risk - 实际文件名 不改的时候的process_name diff --git a/scripts/Dockerfile-build b/scripts/Dockerfile-build new file mode 100644 index 0000000..0a3fb28 --- /dev/null +++ b/scripts/Dockerfile-build @@ -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 + diff --git a/scripts/build.sh b/scripts/build.sh index 721dcbf..be9471f 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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 @@ -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 +