Skip to content

Commit

Permalink
Cross compile for Linux, MacOS and Windows on CI (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthereal authored Jul 9, 2023
1 parent 193f432 commit ce3701f
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 47 deletions.
177 changes: 130 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,97 @@ jobs:
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
image: [ubuntu-20.04, ubuntu-22.04]
arch:
[
amd64,
arm64,
armel,
armhf,
i386,
mips,
mips64,
mips64el,
mips64r6,
mips64r6el,
mipsel,
mipsr6,
mipsr6el,
powerpc,
ppc64el,
s390x,
riscv64,
]
include:
- compiler: gcc
image: ubuntu-20.04
configure_flag: ''
- compiler: gcc
image: ubuntu-22.04
configure_flag: --enable-static --enable-all-static
- compiler: clang
image: ubuntu-20.04
configure_flag: ''
- compiler: clang
image: ubuntu-22.04
configure_flag: --enable-static --enable-all-static
runs-on: ${{ matrix.image }}
- arch: amd64
CC: "x86_64-linux-gnu"
- arch: arm64
CC: "aarch64-linux-gnu"
- arch: armel
CC: "arm-linux-gnueabi"
- arch: armhf
CC: "arm-linux-gnueabihf"
- arch: i386
CC: "i686-linux-gnu"
- arch: mips
CC: "mips-linux-gnu"
- 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:
CC: ${{ matrix.compiler }}
SUFFIX: linux-${{ matrix.image }}-${{ matrix.compiler }}
AR: ${{ matrix.CC }}-ar
CHOST: ${{ matrix.cc }}
CC: ${{ matrix.cc }}-gcc
CPP: ${{ matrix.cc }}-cpp
CXX: ${{ matrix.cc }}-g++
LDFLAGS: -s
SUFFIX: linux-${{ matrix.arch }}
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
submodules: true
- name: Install packages
run: |
sudo apt-get update -qq
sudo apt-get install -y automake autoconf
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y automake autoconf libtool crossbuild-essential-${{ matrix.arch }}
- name: Build
run: |
autoreconf -i
./configure \
--host=${{ matrix.CC }} \
--disable-docs \
--disable-maintainer-mode \
--disable-valgrind \
--with-oniguruma=builtin \
${{ matrix.configure_flag }}
make
strip jq
--enable-static \
--enable-all-static
make -j$(nproc)
file ./jq
cp ./jq jq-${{ env.SUFFIX }}
- name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
run: |
make check
git diff --exit-code
Expand All @@ -68,20 +119,28 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}
if-no-files-found: error
retention-days: 7
path: jq

macos:
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
image: [macos-11, macos-12, macos-13]
runs-on: ${{ matrix.image }}
arch:
[
amd64,
arm64,
]
include:
- arch: amd64
target: "x86_64-apple-darwin"
- arch: arm64
target: "arm64-apple-darwin"
runs-on: macos-13
env:
CC: ${{ matrix.compiler }}
SUFFIX: macos-${{ matrix.image }}-${{ matrix.compiler }}
LDFLAGS: -s
SUFFIX: macos-${{ matrix.arch }}
steps:
- name: Clone repository
uses: actions/checkout@v3
Expand All @@ -92,19 +151,26 @@ jobs:
# brew update sometimes fails with "Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!"
brew update || brew update-reset
brew install autoconf automake libtool
- name: "Set CC"
run: |
echo "CC=clang -target ${{ matrix.target }}$(uname -r)" >> $GITHUB_ENV
- name: Build
run: |
autoreconf -i
./configure \
--host=${{ matrix.target }}$(uname -r) \
--disable-docs \
--disable-maintainer-mode \
--disable-valgrind \
--with-oniguruma=builtin \
--enable-static \
--enable-all-static
make
strip jq
make -j$(nproc)
file ./jq
cp ./jq jq-${{ env.SUFFIX }}
- name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
run: |
make check
git diff --exit-code
Expand All @@ -121,20 +187,34 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}
if-no-files-found: error
retention-days: 7
path: jq

windows:
strategy:
fail-fast: false
matrix:
compiler: [gcc]
image: [windows-2019, windows-2022]
runs-on: ${{ matrix.image }}
arch:
[
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:
CC: ${{ matrix.compiler }}
SUFFIX: windows-${{ matrix.image }}-${{ matrix.compiler }}
CHOST: ${{ matrix.CC }}
CC: ${{ matrix.CC }}-gcc
LDFLAGS: -s
SUFFIX: windows-${{ matrix.arch }}
steps:
- name: Clone repository
uses: actions/checkout@v3
Expand All @@ -143,28 +223,33 @@ jobs:
- uses: msys2/setup-msys2@v2
with:
update: true
msystem: ${{ matrix.msystem }}
install: >-
base-devel
git
clang
autoconf
automake
libtool
${{ matrix.toolchain }}
- name: Build
shell: msys2 {0}
run: |
autoreconf -i
./configure \
--host=${{ matrix.CC }} \
--disable-docs \
--disable-maintainer-mode \
--disable-valgrind \
--with-oniguruma=builtin \
--disable-shared \
--enable-static \
--enable-all-static
make
strip jq.exe
make -j$(nproc)
file ./jq.exe
cp ./jq.exe jq-${{ env.SUFFIX }}.exe
- name: Test
# Only run tests for amd64 matching the CI machine arch
if: ${{ matrix.arch == 'amd64' }}
shell: msys2 {0}
run: |
make check
Expand All @@ -182,9 +267,9 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: jq-${{ env.SUFFIX }}
path: jq-${{ env.SUFFIX }}.exe
if-no-files-found: error
retention-days: 7
path: jq.exe

dist:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -265,17 +350,15 @@ jobs:
uses: actions/checkout@v3
- name: Merge built artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Upload release
env:
TAG_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir release
cp artifacts/jq-linux-ubuntu-22.04-gcc/jq release/jq-linux-amd64
cp artifacts/jq-macos-macos-13-gcc/jq release/jq-macos-amd64
cp artifacts/jq-windows-windows-2022-gcc/jq.exe release/jq-windows-amd64.exe
cp artifacts/jq-dist/jq-* release/
mkdir -p "release"
for files in jq-*; do
cp -rf "${files}/"* "release/"
done
gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes
gh release upload "$TAG_NAME" --clobber release/jq-*
4 changes: 4 additions & 0 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ enum {

#include "jv_thread.h"
#ifdef WIN32
#ifndef __MINGW32__
/* Copied from Heimdal: thread-specific keys; see lib/base/dll.c in Heimdal */

/*
Expand Down Expand Up @@ -486,6 +487,9 @@ pthread_getspecific(pthread_key_t key)
#else
#include <pthread.h>
#endif
#else
#include <pthread.h>
#endif

static pthread_key_t dec_ctx_key;
static pthread_key_t dec_ctx_dbl_key;
Expand Down
4 changes: 4 additions & 0 deletions src/jv_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define JV_THREAD_H

#ifdef WIN32
#ifndef __MINGW32__
#include <windows.h>
#include <winnt.h>
#include <errno.h>
Expand Down Expand Up @@ -69,4 +70,7 @@ void *pthread_getspecific(pthread_key_t);
#else
#include <pthread.h>
#endif
#else
#include <pthread.h>
#endif
#endif /* JV_THREAD_H */

0 comments on commit ce3701f

Please sign in to comment.