Skip to content

Commit

Permalink
CI: use evergreen runners; update actions.
Browse files Browse the repository at this point in the history
GitHub will continue to merrily deprecate and remove old runner
environments, as is their prerogative. However, the simplest way to
produce a library with a low minimum glibc version requirement is to
build in an environment having an old glibc. Not only does Ubuntu 18.04
have a fairly old glibc (v2.27), but the symbol versions our library
links against require only glibc v2.7 (on x86_64; somewhat higher for
some of the other architectures).

Having previously fixed cross-compilation compatibility with GCC 8, we
are no longer able to build with GCC 7-based compilers. Thankfully,
Ubuntu did package GCC 8 on 18.04; it's just not the default.
  • Loading branch information
MrDOS committed Aug 25, 2023
1 parent d4e0124 commit ced315c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 41 deletions.
64 changes: 39 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ on:
jobs:
natives-linux-windows:
name: Linux (x86/ARM/PPC) and Windows native library compilation
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
container:
image: ubuntu:18.04
env:
GCC: gcc-8

defaults:
run:
working-directory: src/main/c

steps:
- name: Checkout the target branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
# Don't need the dependency cache here (or in any of the other native
# library compilation steps), because we're not invoking the Java
# compiler in this step. We only need the JDK for its headers.
- name: Install build prerequisites
run: |
sudo apt update
sudo make crosstools
apt-get update
apt-get --assume-yes install make $GCC
make crosstools
- name: Build the Linux and Windows native libraries
run: |
Expand All @@ -33,36 +42,37 @@ jobs:
# exactly to the directories inside `src/main/c/resources/native`. That
# way, the Java build job can pull down all artifacts and unpack them
# into that directory to overwrite the versions in-repo. This is sadly
# necessary because the actions/download-artifact@v2 action flattens
# necessary because the actions/download-artifact@v3 action flattens
# paths inside artifacts. If it retained full relative paths, we could
# put Linux and Windows natives inside the same artifact, and we could be
# flexible with the artifact names. But it doesn't, so we can't, and we
# can't.
- name: Upload Linux native libraries
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: linux
path: src/main/c/resources/native/linux
- name: Upload Windows native libraries
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: windows
path: src/main/c/resources/native/windows

natives-macos:
name: macOS native library compilation
runs-on: macos-10.15
runs-on: macos-latest

defaults:
run:
working-directory: src/main/c

steps:
- name: Checkout the target branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8

- name: Build the macOS native libraries
Expand All @@ -71,32 +81,34 @@ jobs:
make osx
- name: Upload macOS native libraries
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: osx
path: src/main/c/resources/native/osx/libNRJavaSerial.jnilib

natives-freebsd:
name: FreeBSD native library compilation
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
container:
image: empterdose/freebsd-cross-build:9.3
env:
JAVA_HOME: /usr/lib/jvm/default-jvm

defaults:
run:
working-directory: src/main/c

steps:
- name: Checkout the target branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Fake the FreeBSD Java headers
# This feels extremely dirty, but the only native header we care about
# is `jni_md.h`, and it is exactly identical between Linux and FreeBSD
# (at least in OpenJDK 8).
run: |
apk add openjdk8
ln -s $JAVA_HOME/include/linux $JAVA_HOME/include/freebsd
- name: Build the FreeBSD native libraries
Expand All @@ -106,14 +118,14 @@ jobs:
settarget x86_64-freebsd9 make freebsd64
- name: Upload FreeBSD native libraries
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: freebsd
path: src/main/c/resources/native/freebsd

java:
name: Java compilation
runs-on: ubuntu-18.04
runs-on: ubuntu-latest

needs:
- natives-linux-windows
Expand All @@ -126,18 +138,20 @@ jobs:
# don't regress formatting when compared with the master branch, we need
# to have a local copy of the master branch for comparison.
- name: Checkout the master branch
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: master
- name: Checkout the target branch
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
cache: gradle

- name: Download native libraries
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
path: src/main/c/resources/native

Expand All @@ -146,9 +160,9 @@ jobs:

- name: Determine commit hash for artifact filename
id: vars
run: echo "::set-output name=short-rev::$(git rev-parse --short HEAD)"
run: echo "short-rev=$(git rev-parse --short HEAD)" >>$GITHUB_OUTPUT
- name: Upload build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: nrjavaserial-${{steps.vars.outputs.short-rev}}
path: build/libs/*.jar
41 changes: 25 additions & 16 deletions src/main/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ include JAVA_HOME.mk

include platform.mk

# Most of the time, GCC is called `gcc` and is installed from a `gcc` package.
# However, sometimes a distribution packages multiple versions of GCC. In this
# case, both the binary and package names of non-default versions are suffixed
# (e.g., `gcc-8`). We can't use the standard CC variable to adapt to this,
# because each target already overrides that variable with the name of the
# appropriate cross compiler.
GCC ?= gcc

# In all cases, we want to include the system JNI headers, our own headers,
# crank the optimization level, and compile position-independent code so that
# it will work as a library (dlopen(3) et al. can load it into any memory).
Expand Down Expand Up @@ -87,13 +95,13 @@ all:
$(error $(NO_TARGET_PLATFORM_SPECIFIED))

crosstools:
apt install --install-recommends \
gcc-i686-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf \
gcc-aarch64-linux-gnu \
apt-get --assume-yes install \
$(GCC)-i686-linux-gnu \
$(GCC)-arm-linux-gnueabi \
$(GCC)-arm-linux-gnueabihf \
$(GCC)-aarch64-linux-gnu \
gcc-mingw-w64 \
gcc-powerpc-linux-gnu
$(GCC)-powerpc-linux-gnu

# Does not include Android, because Android toolchains are large, not commonly
# available, and the resulting library is not typically desired.
Expand All @@ -108,14 +116,15 @@ LINUX_CFLAGS += -U_FORTIFY_SOURCE
endif

# Requires gcc-i686-linux-gnu.
linux32: export CC := i686-linux-gnu-gcc
linux32: export CC := i686-linux-gnu-$(GCC)
linux32: export CFLAGS += $(LINUX_CFLAGS) -m32
linux32: export LDFLAGS += -m32
linux32: export platform := linux/x86_32
linux32:
$(MAKE) -f natives.mk

# Requires gcc.
linux64: export CC := $(GCC)
linux64: export CFLAGS += $(LINUX_CFLAGS) -m64
linux64: export platform := linux/x86_64
linux64:
Expand All @@ -127,7 +136,7 @@ arm: arm32v5 \
arm32v8 arm32v8HF arm64v8

# Requires gcc-arm-linux-gnueabi.
arm32v5: export CC := arm-linux-gnueabi-gcc
arm32v5: export CC := arm-linux-gnueabi-$(GCC)
arm32v5: export CFLAGS += $(LINUX_CFLAGS) -march=armv5t
arm32v5: export LDFLAGS += -march=armv5t
arm32v5: export platform := linux/ARM_32
Expand All @@ -136,7 +145,7 @@ arm32v5:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabi.
arm32v6: export CC := arm-linux-gnueabi-gcc
arm32v6: export CC := arm-linux-gnueabi-$(GCC)
arm32v6: export CFLAGS += $(LINUX_CFLAGS) -march=armv6
arm32v6: export LDFLAGS += -march=armv6
arm32v6: export platform := linux/ARM_32
Expand All @@ -145,7 +154,7 @@ arm32v6:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabihf.
arm32v6HF: export CC := arm-linux-gnueabihf-gcc
arm32v6HF: export CC := arm-linux-gnueabihf-$(GCC)
arm32v6HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv6+fp -marm
arm32v6HF: export LDFLAGS += -march=armv6+fp -marm
arm32v6HF: export platform := linux/ARM_32
Expand All @@ -154,7 +163,7 @@ arm32v6HF:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabi.
arm32v7: export CC := arm-linux-gnueabi-gcc
arm32v7: export CC := arm-linux-gnueabi-$(GCC)
arm32v7: export CFLAGS += $(LINUX_CFLAGS) -march=armv7-a
arm32v7: export LDFLAGS += -march=armv7-a
arm32v7: export platform := linux/ARM_32
Expand All @@ -163,7 +172,7 @@ arm32v7:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabihf.
arm32v7HF: export CC := arm-linux-gnueabihf-gcc
arm32v7HF: export CC := arm-linux-gnueabihf-$(GCC)
arm32v7HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv7-a+fp
arm32v7HF: export LDFLAGS += -march=armv7-a+fp
arm32v7HF: export platform := linux/ARM_32
Expand All @@ -172,7 +181,7 @@ arm32v7HF:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabi.
arm32v8: export CC := arm-linux-gnueabi-gcc
arm32v8: export CC := arm-linux-gnueabi-$(GCC)
arm32v8: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a
arm32v8: export LDFLAGS += -march=armv8-a
arm32v8: export platform := linux/ARM_32
Expand All @@ -181,7 +190,7 @@ arm32v8:
$(MAKE) -f natives.mk

# Requires gcc-arm-linux-gnueabihf.
arm32v8HF: export CC := arm-linux-gnueabihf-gcc
arm32v8HF: export CC := arm-linux-gnueabihf-$(GCC)
arm32v8HF: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a -mfpu=neon-fp-armv8
arm32v8HF: export LDFLAGS += -march=armv8-a -mfpu=neon-fp-armv8
arm32v8HF: export platform := linux/ARM_32
Expand All @@ -190,7 +199,7 @@ arm32v8HF:
$(MAKE) -f natives.mk

# Requires gcc-aarch64-linux-gnu.
arm64v8: export CC := aarch64-linux-gnu-gcc
arm64v8: export CC := aarch64-linux-gnu-$(GCC)
arm64v8: export CFLAGS += $(LINUX_CFLAGS) -march=armv8-a+fp
arm64v8: export LDFLAGS += -march=armv8-a+fp
arm64v8: export platform := linux/ARM_64
Expand All @@ -208,7 +217,7 @@ android:
$(MAKE) -f natives.mk

# Requires gcc-powerpc-linux-gnu.
ppc: export CC := powerpc-linux-gnu-gcc
ppc: export CC := powerpc-linux-gnu-$(GCC)
ppc: export CFLAGS += $(LINUX_CFLAGS)
ppc: export platform := linux/PPC
ppc:
Expand Down

0 comments on commit ced315c

Please sign in to comment.