add cross compilation for mac m1

Signed-off-by: Hollow Man <hollowman@opensuse.org>
This commit is contained in:
Hollow Man
2023-03-14 18:54:05 +02:00
parent 875deb7ec3
commit 0c77d89bfc
5 changed files with 32 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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():