Skip to content

Cross-compile native libraries #3

Cross-compile native libraries

Cross-compile native libraries #3

Workflow file for this run

name: Cross-compile native libraries
on: workflow_dispatch
env:
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
GITHUB_BOT_NAME: github-actions
GITHUB_BOT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: echo "precompiled_branch=$(git branch --show-current)-precompiled-natives" >> $GITHUB_ENV
- name: Create branch for precompiled natives
run: git checkout -b ${{ env.precompiled_branch }}
- name: Sync SerialNativeInterface version with the project pom version
run: |
FILE=src/main/java/jssc/SerialNativeInterface.java
RELEASE_VERSION=$(mvn validate help:evaluate -Dexpression=release.version -q -DforceStdout)
sed -i "s/private static final String libVersion =.*/private static final String libVersion = \"${RELEASE_VERSION}\";/" ${FILE}
if [ $(git ls-files --modified) ]; then
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git commit ${FILE} --message "Update version in source files before building native libraries"
fi
- run: echo "rev=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- run: git push --force origin HEAD
outputs:
precompiled_branch: ${{ env.precompiled_branch }}
base_rev: ${{ env.rev }}
linux-windows:
runs-on: ubuntu-latest
needs: create-branch
strategy:
matrix:
include:
- target: linux_32
os_target_name: linux
os_target_arch: x86_32
os_target_bitness: 32
image: docker.io/dockcross/linux-x86
- target: linux_64
os_target_name: linux
os_target_arch: x86_64
os_target_bitness: 64
image: docker.io/dockcross/linux-x64
- target: linux_arm
os_target_name: linux
os_target_arch: arm_32
os_target_bitness: 32
image: docker.io/dockcross/linux-armv6-lts
- target: linux_arm64
os_target_name: linux
os_target_arch: aarch_64
os_target_bitness: 64
image: docker.io/dockcross/linux-arm64-lts
- target: linux_riscv32
os_target_name: linux
os_target_arch: riscv32
os_target_bitness: 32
image: docker.io/dockcross/linux-riscv32
- target: linux_riscv64
os_target_name: linux
os_target_arch: riscv64
os_target_bitness: 64
image: docker.io/dockcross/linux-riscv64
- target: linux_ppc
os_target_name: linux
os_target_arch: ppc_64
os_target_bitness: 64
image: docker.io/dockcross/linux-ppc64le
- target: windows_32
os_target_name: windows
os_target_arch: x86_32
os_target_bitness: 32
image: docker.io/dockcross/windows-static-x86
- target: windows_64
os_target_name: windows
os_target_arch: x86_64
os_target_bitness: 64
image: docker.io/dockcross/windows-static-x64
- target: windows_arm64
os_target_name: windows
os_target_arch: aarch_64
os_target_bitness: 64
image: docker.io/dockcross/windows-arm64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Pull docker images
run: docker pull ${{ matrix.image }}
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Build for ${{ matrix.target }} in ${{ matrix.image }}
run: |
docker run --rm --workdir=/work \
--volume $PWD:/work \
--volume $HOME/.m2:/root/.m2 \
--env MAVEN_OPTS=${MAVEN_OPTS} \
${{ matrix.image }} \
bash -c \
'apt-get update && apt-get install --yes maven openjdk-11-jdk-headless && \
mvn -B clean install -P dockcross,update-resources-precompiled \
-Dos.target.name=${{ matrix.os_target_name }} \
-Dos.target.arch=${{ matrix.os_target_arch }} \
-Dos.target.bitness=${{ matrix.os_target_bitness }} \
'
- name: Push recompiled binaries
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git add src/main/resources-precompiled/**
git commit --allow-empty -m "Precompiled natives (@${{ needs.create-branch.outputs.base_rev }}) for ${{ matrix.target }}"
while git pull --rebase && ! git push; do sleep 5; done
macos:
runs-on: macos-11
needs: create-branch
strategy:
matrix:
include:
- target: osx_64
profile: 'x86_64'
macos-deployment-target: 10.8
sdk-version: MacOSX10.9.sdk
- target: osx_arm64
profile: 'aarch64'
macos-deployment-target: 11.0
sdk-version: MacOSX11.0.sdk
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Get oldest supported SDK
if: ${{ matrix.sdk-version == 'MacOSX10.9.sdk' }}
run: |
wget -qO- https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX10.9.sdk.tar.xz \
| tar -xjv -C $XCODE_12_DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs
- name: Set SDK version
run: |
export MACOSX_DEPLOYMENT_TARGET=${{ matrix.macos-deployment-target }}
export SDKROOT=$XCODE_12_DEVELOPER_DIR/Platforms/MacOSX.platform/Developer/SDKs/${{ matrix.sdk-version }}
export CMAKE_OSX_SYSROOT=$SDKROOT
- name: Build with Maven
run: mvn -B clean install -P ${{ matrix.profile }},update-resources-precompiled
- name: Push recompiled binaries
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git add src/main/resources-precompiled/**
git commit --allow-empty -m "Precompiled natives (@${{ needs.create-branch.outputs.base_rev }}) for ${{ matrix.target }}"
while git pull --rebase && ! git push; do sleep 5; done
single-commit:
runs-on: ubuntu-latest
needs: [create-branch, linux-windows, macos]
steps:
- uses: actions/checkout@v3
- name: Squash into one commit
run: |
git config --global user.email "${GITHUB_BOT_EMAIL}"
git config --global user.name "${GITHUB_BOT_NAME}"
git fetch && git checkout -t origin/${{ needs.create-branch.outputs.precompiled_branch }}
git reset --soft ${{ needs.create-branch.outputs.base_rev }}
git add src/main/resources-precompiled/**
git commit -m "Precompiled natives @${{ needs.create-branch.outputs.base_rev }}"
git push -f