Cross compile for Linux, MacOS and Windows on CI (#2665)

This commit is contained in:
Owen Ou authored and GitHub committed 2023-07-10 08:05:25 +09:00
1 parent 193f432e08
commit ce3701fe52
3 files changed
+138 -47

No files matched your search

+130 -47
View File
@@ -12,25 +12,70 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
compiler: [gcc, clang] arch:
image: [ubuntu-20.04, ubuntu-22.04] [
amd64,
arm64,
armel,
armhf,
i386,
mips,
mips64,
mips64el,
mips64r6,
mips64r6el,
mipsel,
mipsr6,
mipsr6el,
powerpc,
ppc64el,
s390x,
riscv64,
]
include: include:
- compiler: gcc - arch: amd64
image: ubuntu-20.04 CC: "x86_64-linux-gnu"
configure_flag: '' - arch: arm64
- compiler: gcc CC: "aarch64-linux-gnu"
image: ubuntu-22.04 - arch: armel
configure_flag: --enable-static --enable-all-static CC: "arm-linux-gnueabi"
- compiler: clang - arch: armhf
image: ubuntu-20.04 CC: "arm-linux-gnueabihf"
configure_flag: '' - arch: i386
- compiler: clang CC: "i686-linux-gnu"
image: ubuntu-22.04 - arch: mips
configure_flag: --enable-static --enable-all-static CC: "mips-linux-gnu"
runs-on: ${{ matrix.image }} - arch: mips64
CC: "mips64-linux-gnuabi64"
- arch: mips64el
CC: "mips64el-linux-gnuabi64"
- arch: mips64r6
CC: "mipsisa64r6-linux-gnuabi64"
- arch: mips64r6el
CC: "mipsisa64r6el-linux-gnuabi64"
- arch: mipsel
CC: "mipsel-linux-gnu"
- arch: mipsr6
CC: "mipsisa32r6-linux-gnu"
- arch: mipsr6el
CC: "mipsisa32r6el-linux-gnu"
- arch: powerpc
CC: "powerpc-linux-gnu"
- arch: ppc64el
CC: "powerpc64le-linux-gnu"
- arch: s390x
CC: "s390x-linux-gnu"
- arch: riscv64
CC: "riscv64-linux-gnu"
runs-on: ubuntu-22.04
env: env:
CC: ${{ matrix.compiler }} AR: ${{ matrix.CC }}-ar
SUFFIX: linux-${{ matrix.image }}-${{ matrix.compiler }} CHOST: ${{ matrix.cc }}
CC: ${{ matrix.cc }}-gcc
CPP: ${{ matrix.cc }}-cpp
CXX: ${{ matrix.cc }}-g++
LDFLAGS: -s
SUFFIX: linux-${{ matrix.arch }}
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -38,20 +83,26 @@ jobs:
submodules: true submodules: true
- name: Install packages - name: Install packages
run: | run: |
sudo apt-get update -qq sudo apt-get update
sudo apt-get install -y automake autoconf sudo apt-get upgrade
sudo apt-get install -y automake autoconf libtool crossbuild-essential-${{ matrix.arch }}
- name: Build - name: Build
run: | run: |
autoreconf -i autoreconf -i
./configure \ ./configure \
--host=${{ matrix.CC }} \
--disable-docs \ --disable-docs \
--disable-maintainer-mode \ --disable-maintainer-mode \
--disable-valgrind \ --disable-valgrind \
--with-oniguruma=builtin \ --with-oniguruma=builtin \
${{ matrix.configure_flag }} --enable-static \
make --enable-all-static
strip jq make -j$(nproc)
file ./jq
cp ./jq jq-${{ env.SUFFIX }}
- name: Test - name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
run: | run: |
make check make check
git diff --exit-code git diff --exit-code
@@ -68,20 +119,28 @@ jobs:
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: jq-${{ env.SUFFIX }} name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}
if-no-files-found: error if-no-files-found: error
retention-days: 7 retention-days: 7
path: jq
macos: macos:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
compiler: [gcc, clang] arch:
image: [macos-11, macos-12, macos-13] [
runs-on: ${{ matrix.image }} amd64,
arm64,
]
include:
- arch: amd64
target: "x86_64-apple-darwin"
- arch: arm64
target: "arm64-apple-darwin"
runs-on: macos-13
env: env:
CC: ${{ matrix.compiler }} LDFLAGS: -s
SUFFIX: macos-${{ matrix.image }}-${{ matrix.compiler }} SUFFIX: macos-${{ matrix.arch }}
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -92,19 +151,26 @@ jobs:
# brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!" # brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!"
brew update || brew update-reset brew update || brew update-reset
brew install autoconf automake libtool brew install autoconf automake libtool
- name: "Set CC"
run: |
echo "CC=clang -target ${{ matrix.target }}$(uname -r)" >> $GITHUB_ENV
- name: Build - name: Build
run: | run: |
autoreconf -i autoreconf -i
./configure \ ./configure \
--host=${{ matrix.target }}$(uname -r) \
--disable-docs \ --disable-docs \
--disable-maintainer-mode \ --disable-maintainer-mode \
--disable-valgrind \ --disable-valgrind \
--with-oniguruma=builtin \ --with-oniguruma=builtin \
--enable-static \ --enable-static \
--enable-all-static --enable-all-static
make make -j$(nproc)
strip jq file ./jq
cp ./jq jq-${{ env.SUFFIX }}
- name: Test - name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
run: | run: |
make check make check
git diff --exit-code git diff --exit-code
@@ -121,20 +187,34 @@ jobs:
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: jq-${{ env.SUFFIX }} name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}
if-no-files-found: error if-no-files-found: error
retention-days: 7 retention-days: 7
path: jq
windows: windows:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
compiler: [gcc] arch:
image: [windows-2019, windows-2022] [
runs-on: ${{ matrix.image }} amd64,
i386,
]
include:
- arch: amd64
CC: "x86_64-pc-msys"
toolchain: "gcc"
msystem: msys
- arch: i386
CC: "i686-w64-mingw32"
toolchain: "mingw-w64-i686-toolchain"
msystem: mingw32
runs-on: windows-2022
env: env:
CC: ${{ matrix.compiler }} CHOST: ${{ matrix.CC }}
SUFFIX: windows-${{ matrix.image }}-${{ matrix.compiler }} CC: ${{ matrix.CC }}-gcc
LDFLAGS: -s
SUFFIX: windows-${{ matrix.arch }}
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -143,18 +223,20 @@ jobs:
- uses: msys2/setup-msys2@v2 - uses: msys2/setup-msys2@v2
with: with:
update: true update: true
msystem: ${{ matrix.msystem }}
install: >- install: >-
base-devel base-devel
git git
clang
autoconf autoconf
automake automake
libtool libtool
${{ matrix.toolchain }}
- name: Build - name: Build
shell: msys2 {0} shell: msys2 {0}
run: | run: |
autoreconf -i autoreconf -i
./configure \ ./configure \
--host=${{ matrix.CC }} \
--disable-docs \ --disable-docs \
--disable-maintainer-mode \ --disable-maintainer-mode \
--disable-valgrind \ --disable-valgrind \
@@ -162,9 +244,12 @@ jobs:
--disable-shared \ --disable-shared \
--enable-static \ --enable-static \
--enable-all-static --enable-all-static
make make -j$(nproc)
strip jq.exe file ./jq.exe
cp ./jq.exe jq-${{ env.SUFFIX }}.exe
- name: Test - name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
shell: msys2 {0} shell: msys2 {0}
run: | run: |
make check make check
@@ -182,9 +267,9 @@ jobs:
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: jq-${{ env.SUFFIX }} name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}.exe
if-no-files-found: error if-no-files-found: error
retention-days: 7 retention-days: 7
path: jq.exe
dist: dist:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -265,17 +350,15 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Merge built artifacts - name: Merge built artifacts
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with:
path: artifacts
- name: Upload release - name: Upload release
env: env:
TAG_NAME: ${{ github.ref_name }} TAG_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
mkdir release mkdir -p "release"
cp artifacts/jq-linux-ubuntu-22.04-gcc/jq release/jq-linux-amd64 for files in jq-*; do
cp artifacts/jq-macos-macos-13-gcc/jq release/jq-macos-amd64 cp -rf "${files}/"* "release/"
cp artifacts/jq-windows-windows-2022-gcc/jq.exe release/jq-windows-amd64.exe done
cp artifacts/jq-dist/jq-* release/
gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes
gh release upload "$TAG_NAME" --clobber release/jq-* gh release upload "$TAG_NAME" --clobber release/jq-*
+4
View File
@@ -222,6 +222,7 @@ enum {
#include "jv_thread.h" #include "jv_thread.h"
#ifdef WIN32 #ifdef WIN32
#ifndef __MINGW32__
/* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */ /* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */
/* /*
@@ -486,6 +487,9 @@ pthread_getspecific(pthread_key_t key)
#else #else
#include <pthread.h> #include <pthread.h>
#endif #endif
#else
#include <pthread.h>
#endif
static pthread_key_t dec_ctx_key; static pthread_key_t dec_ctx_key;
static pthread_key_t dec_ctx_dbl_key; static pthread_key_t dec_ctx_dbl_key;
+4
View File
@@ -2,6 +2,7 @@
#define JV_THREAD_H #define JV_THREAD_H
#ifdef WIN32 #ifdef WIN32
#ifndef __MINGW32__
#include <windows.h> #include <windows.h>
#include <winnt.h> #include <winnt.h>
#include <errno.h> #include <errno.h>
@@ -69,4 +70,7 @@ void *pthread_getspecific(pthread_key_t);
#else #else
#include <pthread.h> #include <pthread.h>
#endif #endif
#else
#include <pthread.h>
#endif
#endif /* JV_THREAD_H */ #endif /* JV_THREAD_H */