fix cross compilation for arm platforms
follow-up https://github.com/docker/docker-ce-packaging/pull/665#issuecomment-1081864970

cross compilation is currently broken against some arm platforms:

```
#43 0.132 
#43 0.138 ---> Making bundle: cross (in /build/bundles/cross)
#43 0.139 Cross building: /build/bundles/cross/linux/arm/v6
#43 0.182 Building: /build/bundles/cross/linux/arm/v6-daemon/dockerd-0.0.0-20220329083112-174e51c
#43 0.182 GOOS="linux" GOARCH="arm" GOARM="6"
#43 76.80 # github.com/docker/docker/cmd/dockerd
#43 76.80 loadinternal: cannot find runtime/cgo
#43 76.80 /usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
#43 76.80 gcc: error: unrecognized command-line option '-marm'; did you mean '-mabm'?
```

**- What I did**

fix cross compilation for arm platforms by setting correct switches for `CGO_CFLAGS` and `CGO_CXXFLAGS` flags.

also adds a GitHub Action job to check cross targets work, which is not currently done in Jenkins.

**- How to verify it**

```console
$ mkdir -p autogen # workaround that will be fixed by https://github.com/moby/moby/pull/43431
$ DOCKER_CROSSPLATFORMS="linux/arm/v7 linux/arm/v6 linux/arm/v5" docker buildx bake cross
```

**- Description for the changelog**

fix cross compilation for arm platforms

___

in a follow-up we should switch to [xx](https://github.com/tonistiigi/xx/).

cc @thaJeztah 
.github/workflows/ci.yml
name: ci

on:
  workflow_dispatch:
  push:
    branches:
      - 'master'
      - '[0-9]+.[0-9]{2}'
    tags:
      - 'v*'
  pull_request:

env:
  BUNDLES_OUTPUT: ./bundles

jobs:
  build:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        target:
          - binary
          - dynbinary
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Build
        uses: docker/bake-action@v1
        with:
          targets: ${{ matrix.target }}
          set: |
            *.cache-from=type=gha,scope=build-${{ matrix.target }}
            *.cache-to=type=gha,scope=build-${{ matrix.target }}
      -
        name: Upload build artifacts
        uses: actions/upload-artifact@v2
        with:
          name: ${{ matrix.target }}
          path: ${{ env.BUNDLES_OUTPUT }}/${{ matrix.target }}-daemon/*
          if-no-files-found: error

  test-buildkit:
    needs:
      - build
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        pkg:
          - ./client
          - ./cmd/buildctl
          - ./solver
          - ./frontend
          - ./frontend/dockerfile
        typ:
          - integration
        include:
          - pkg: ./...
            skip-integration-tests: 1
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          path: moby
      -
        name: BuildKit ref
        run: |
          ./hack/go-mod-prepare.sh
          echo "BUILDKIT_REF=$(./hack/buildkit-ref)" >> $GITHUB_ENV
        working-directory: moby
      -
        name: Checkout BuildKit ${{ env.BUILDKIT_REF }}
        uses: actions/checkout@v3
        with:
          repository: "moby/buildkit"
          ref: ${{ env.BUILDKIT_REF }}
          path: buildkit
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Download build artifacts
        uses: actions/download-artifact@v2
        with:
          name: binary
          path: ./buildkit/build/moby/
      -
        name: Update daemon.json
        run: |
          sudo rm /etc/docker/daemon.json
          sudo service docker restart
          docker version
          docker info
      -
        name: Test
        run: |
          ./hack/test ${{ matrix.typ }}
        env:
          CONTEXT: "."
          TEST_DOCKERD: "1"
          TEST_DOCKERD_BINARY: "./build/moby/dockerd"
          TESTPKGS: "${{ matrix.pkg }}"
          TESTFLAGS: "-v --parallel=1 --timeout=30m --run=//worker=dockerd$"
          SKIP_INTEGRATION_TESTS: "${{ matrix.skip-integration-tests }}"
        working-directory: buildkit

name: ci

on:
  workflow_dispatch:
  push:
    branches:
      - 'master'
      - '[0-9]+.[0-9]{2}'
    tags:
      - 'v*'
  pull_request:

env:
  BUNDLES_OUTPUT: ./bundles

jobs:
  build:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        target:
          - binary
          - dynbinary
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Build
        uses: docker/bake-action@v1
        with:
          targets: ${{ matrix.target }}
          set: |
            *.cache-from=type=gha,scope=build-${{ matrix.target }}
            *.cache-to=type=gha,scope=build-${{ matrix.target }}
      -
        name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.target }}
          path: ${{ env.BUNDLES_OUTPUT }}
          if-no-files-found: error
          retention-days: 7

  cross:
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        platform:
          - linux/amd64
          - linux/arm/v5
          - linux/arm/v6
          - linux/arm/v7
          - linux/arm64
          - linux/ppc64le
          - linux/s390x
          - windows/amd64
          - windows/arm64
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      -
        name: Prepare
        run: |
          platform=${{ matrix.platform }}
          echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
          mkdir -p autogen
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Build
        uses: docker/bake-action@v1
        with:
          targets: cross
          set: |
            *.cache-from=type=gha,scope=cross-${{ env.PLATFORM_PAIR }}
            *.cache-to=type=gha,scope=cross-${{ env.PLATFORM_PAIR }}
        env:
          DOCKER_CROSSPLATFORMS: ${{ matrix.platform }}
      -
        name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          name: cross-${{ env.PLATFORM_PAIR }}
          path: ${{ env.BUNDLES_OUTPUT }}
          if-no-files-found: error
          retention-days: 7

  test-buildkit:
    needs:
      - build
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
      matrix:
        pkg:
          - ./client
          - ./cmd/buildctl
          - ./solver
          - ./frontend
          - ./frontend/dockerfile
        typ:
          - integration
        include:
          - pkg: ./...
            skip-integration-tests: 1
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
        with:
          path: moby
      -
        name: BuildKit ref
        run: |
          ./hack/go-mod-prepare.sh
          echo "BUILDKIT_REF=$(./hack/buildkit-ref)" >> $GITHUB_ENV
        working-directory: moby
      -
        name: Checkout BuildKit ${{ env.BUILDKIT_REF }}
        uses: actions/checkout@v3
        with:
          repository: "moby/buildkit"
          ref: ${{ env.BUILDKIT_REF }}
          path: buildkit
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Download binary artifacts
        uses: actions/download-artifact@v3
        with:
          name: binary
          path: ./buildkit/build/moby/
      -
        name: Update daemon.json
        run: |
          sudo rm /etc/docker/daemon.json
          sudo service docker restart
          docker version
          docker info
      -
        name: Test
        run: |
          ./hack/test ${{ matrix.typ }}
        env:
          CONTEXT: "."
          TEST_DOCKERD: "1"
          TEST_DOCKERD_BINARY: "./build/moby/binary-daemon/dockerd"
          TESTPKGS: "${{ matrix.pkg }}"
          TESTFLAGS: "-v --parallel=1 --timeout=30m --run=//worker=dockerd$"
          SKIP_INTEGRATION_TESTS: "${{ matrix.skip-integration-tests }}"
        working-directory: buildkit

I think we should remove the `CROSS` and `DOCKER_CROSSPLATFORMS` args in a follow-up and rely only on `--platform` like `docker/cli`, `buildx` so packaging will be easier and also we could remove the cross logic in the `.binary` script. But that needs some work to align the dependencies in the dockerfile.