diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9de938d..4b89845 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,11 @@ 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: @@ -14,15 +18,20 @@ jobs: 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: | @@ -33,25 +42,25 @@ 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: @@ -59,10 +68,11 @@ jobs: 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 @@ -71,18 +81,16 @@ 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: @@ -90,13 +98,17 @@ jobs: 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 @@ -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 @@ -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 @@ -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 diff --git a/src/main/c/Makefile b/src/main/c/Makefile index ad90255..d0af37f 100644 --- a/src/main/c/Makefile +++ b/src/main/c/Makefile @@ -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). @@ -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. @@ -108,7 +116,7 @@ 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 @@ -116,6 +124,7 @@ linux32: $(MAKE) -f natives.mk # Requires gcc. +linux64: export CC := $(GCC) linux64: export CFLAGS += $(LINUX_CFLAGS) -m64 linux64: export platform := linux/x86_64 linux64: @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: