From 0c77d89bfcd23a9b514a42e4d5d170396e4b5d27 Mon Sep 17 00:00:00 2001 From: Hollow Man Date: Tue, 14 Mar 2023 18:54:05 +0200 Subject: [PATCH] add cross compilation for mac m1 Signed-off-by: Hollow Man --- .../workflows/b-binary-build-and-e2e-tests.yaml | 17 +++++++++++++---- .github/workflows/c-create-release.yaml | 3 +++ .krew.yaml | 6 ++++++ Makefile | 6 ++++++ build.py | 5 ++++- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/b-binary-build-and-e2e-tests.yaml b/.github/workflows/b-binary-build-and-e2e-tests.yaml index a9f25448..448bb99a 100644 --- a/.github/workflows/b-binary-build-and-e2e-tests.yaml +++ b/.github/workflows/b-binary-build-and-e2e-tests.yaml @@ -61,10 +61,17 @@ jobs: name: Create cross-platform build env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOARCH: ${{ matrix.arch }} runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-20.04, macos-latest, windows-latest] + arch: ["", arm64] + exclude: + - os: windows-latest + arch: arm64 + - os: ubuntu-20.04 + arch: arm64 steps: - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # ratchet:actions/checkout@v3 @@ -122,14 +129,16 @@ jobs: if: matrix.os == 'macos-latest' - name: Install libgit2 (Linux/macOS) - run: make libgit2 + run: make libgit2${{ matrix.arch }} if: matrix.os != 'windows-latest' - name: Test core pkg run: go test "-tags=static,gitenabled" -v ./... + if: matrix.arch == '' - name: Test httphandler pkg run: cd httphandler && go test "-tags=static,gitenabled" -v ./... + if: matrix.arch == '' - name: Build env: @@ -143,7 +152,7 @@ jobs: RELEASE: ${{ inputs.RELEASE }} KUBESCAPE_SKIP_UPDATE_CHECK: "true" run: python3 smoke_testing/init.py ${PWD}/build/kubescape-${{ matrix.os }} - if: matrix.os != 'ubuntu-20.04' + if: matrix.os != 'ubuntu-20.04' && matrix.arch == '' - name: Smoke Testing (Linux) env: @@ -165,7 +174,7 @@ jobs: name: Upload artifact (Linux) if: matrix.os == 'ubuntu-20.04' with: - name: kubescape-ubuntu-latest + name: kubescape${{ matrix.arch }}-ubuntu-latest path: build/ if-no-files-found: error @@ -173,7 +182,7 @@ jobs: name: Upload artifact (MacOS, Win) if: matrix.os != 'ubuntu-20.04' with: - name: kubescape-${{ matrix.os }} + name: kubescape${{ matrix.arch }}-${{ matrix.os }} path: build/ if-no-files-found: error diff --git a/.github/workflows/c-create-release.yaml b/.github/workflows/c-create-release.yaml index 325ba664..b35793e0 100644 --- a/.github/workflows/c-create-release.yaml +++ b/.github/workflows/c-create-release.yaml @@ -57,3 +57,6 @@ jobs: ./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }} ./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }}.sha256 ./kubescape-${{ env.WINDOWS_OS }}/kubescape-${{ env.WINDOWS_OS }}.tar.gz + ./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }} + ./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }}.sha256 + ./kubescapearm64-${{ env.MAC_OS }}/kubescape-arm64-${{ env.MAC_OS }}.tar.gz diff --git a/.krew.yaml b/.krew.yaml index 8405da8e..bc831896 100644 --- a/.krew.yaml +++ b/.krew.yaml @@ -16,6 +16,12 @@ spec: arch: amd64 {{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-macos-latest.tar.gz" .TagName }} bin: kubescape + - selector: + matchLabels: + os: darwin + arch: arm64 + {{ addURIAndSha "https://github.com/kubescape/kubescape/releases/download/{{ .TagName }}/kubescape-arm64-macos-latest.tar.gz" .TagName }} + bin: kubescape - selector: matchLabels: os: linux diff --git a/Makefile b/Makefile index 4801e37d..a885c0d1 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ libgit2: -git submodule update --init --recursive cd git2go; make install-static +# build and install libgit2 for macOS m1 +libgit2arm64: + git submodule update --init --recursive + sed -i '' 's/cmake -D/cmake -DCMAKE_OSX_ARCHITECTURES="arm64" -D/' git2go/script/build-libgit2.sh + cd git2go; make install-static + # go build tags TAGS = "gitenabled,static" diff --git a/build.py b/build.py index f1ccb765..b232acfa 100644 --- a/build.py +++ b/build.py @@ -27,7 +27,10 @@ def get_build_dir(): def get_package_name(): if CURRENT_PLATFORM not in platformSuffixes: raise OSError("Platform %s is not supported!" % (CURRENT_PLATFORM)) - return "kubescape-" + platformSuffixes[CURRENT_PLATFORM] + package_name = "kubescape-" + if os.getenv("GOARCH"): + package_name += os.getenv("GOARCH") + "-" + return package_name + platformSuffixes[CURRENT_PLATFORM] def main():