From ea2ade2b3cbbc417ef9dfd97922a77fde41b911a Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Fri, 10 Nov 2023 12:40:42 -0500 Subject: [PATCH 1/3] Use github actions for testing PRs (#151) Use github actions for testing PRs --- .github/workflows/build.yml | 90 +++++++++++++++++++ .travis.yml | 88 ------------------ CMakeLists.txt | 5 +- pom.xml | 27 ++++++ .../java/jssc/SerialNativeInterfaceTest.java | 3 + toolchain/Riscv32.cmake | 10 +++ toolchain/Riscv64.cmake | 10 +++ 7 files changed, 144 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml create mode 100644 toolchain/Riscv32.cmake create mode 100644 toolchain/Riscv64.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..ea85d122e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,90 @@ +name: build + +on: [push, pull_request] + +env: + MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + +jobs: + ubuntu: + runs-on: [ubuntu-latest] + strategy: + fail-fast: false + matrix: + include: + - profile: x86 + packages: g++-multilib + + - profile: x86_64 + packages: g++- + + - profile: armhf + packages: g++-arm-linux-gnueabihf + + - profile: aarch64 + packages: g++-aarch64-linux-gnu + + - profile: riscv64 + packages: g++-riscv64-linux-gnu + + - profile: ppc64 + packages: g++-powerpc64le-linux-gnu + + - profile: mingw32 + packages: g++-mingw-w64-i686 + + - profile: mingw64 + packages: g++-mingw-w64-x86-64 + + - profile: mingwaarch64 + packages: clang + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: temurin + + - run: sudo apt-get install socat ${{ matrix.packages }} + - run: mvn -P "${{ matrix.profile }}" --batch-mode + + macos: + runs-on: [macos-latest] + strategy: + fail-fast: false + matrix: + include: + - profile: aarch64 + - profile: x86_64 + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: temurin + + - run: brew install socat + - run: mvn -P "${{ matrix.profile }}" --batch-mode + + windows: + runs-on: [windows-latest] + strategy: + fail-fast: false + matrix: + include: + - profile: aarch64 + + - profile: x86_64 + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: temurin + + - run: mvn -P "${{ matrix.profile }}" --batch-mode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b62c60ee9..000000000 --- a/.travis.yml +++ /dev/null @@ -1,88 +0,0 @@ -language: java - -jdk: - - openjdk11 - -cache: - directories: - - $HOME/.m2 - - $HOME/.jabba/jdk - -before_cache: - - rm -rf $HOME/.m2/repository/com/github/java-native - -matrix: - include: - - os: linux - addons: - apt: - packages: - - g++ - - os: linux - env: PROFILE=x86 - addons: - apt: - packages: - - g++-multilib - - os: linux - env: PROFILE=mingw32 - addons: - apt: - packages: - - g++-mingw-w64-i686 - - os: linux - env: PROFILE=mingw64 - addons: - apt: - packages: - - g++-mingw-w64-x86-64 - - os: linux - env: PROFILE=mingwaarch64 - addons: - apt: - packages: - - clang - - os: linux - env: PROFILE=armhf - addons: - apt: - packages: - - g++-arm-linux-gnueabihf - - os: linux - env: PROFILE=aarch64 - addons: - apt: - packages: - - g++-aarch64-linux-gnu - - os: linux - env: PROFILE=ppc64 - addons: - apt: - packages: - - g++-powerpc64le-linux-gnu - - os: osx - - os: osx - osx_image: xcode12.5 # xcode 12+ needed for cross-compile - env: PROFILE=aarch64 - -addons: - homebrew: - packages: - - maven - - ant - - cmake - apt: - packages: - - maven - - ant - - cmake - -install: - - mvn dependency:resolve - -script: if [ -z "$PROFILE" ]; then mvn --batch-mode; else mvn -P "$PROFILE" --batch-mode; fi - -after_success: - - bash <(curl -s https://codecov.io/bash) - - diff --git a/CMakeLists.txt b/CMakeLists.txt index ce202316f..528e37651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,9 +191,12 @@ if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb") add_custom_command(TARGET jssc POST_BUILD COMMAND "${CMAKE_STRIP}" ${STRIP_ARGS} $) endif() -# Copy native library back to source tree + add_custom_command(TARGET jssc POST_BUILD + # Copy native library back to source tree COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources-precompiled/natives/ + # Copy native library back to target/classes tree + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_BINARY_DIR}/../classes/natives/ ) # Handle compiler warnings diff --git a/pom.xml b/pom.xml index 5229404b5..728a27139 100644 --- a/pom.xml +++ b/pom.xml @@ -279,6 +279,7 @@ maven-surefire-plugin ${plugin.surfire.version} + false @@ -495,6 +496,32 @@ + + + riscv64 + + Riscv64 + + linux + riscv64 + 64 + + + + + + riscv32 + + Riscv32 + + linux + riscv32 + 32 + + + + + x86_64 diff --git a/src/test/java/jssc/SerialNativeInterfaceTest.java b/src/test/java/jssc/SerialNativeInterfaceTest.java index 6890aab04..ccbd0f3cd 100644 --- a/src/test/java/jssc/SerialNativeInterfaceTest.java +++ b/src/test/java/jssc/SerialNativeInterfaceTest.java @@ -1,5 +1,6 @@ package jssc; +import org.junit.Assume; import org.junit.Test; import static org.hamcrest.CoreMatchers.is; @@ -41,6 +42,8 @@ public void testPrintVersion() { @Test(expected = java.io.IOException.class) public void reportsWriteErrorsAsIOException() throws Exception { + Assume.assumeFalse(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_WINDOWS); + long fd = -1; /*bad file by intent*/ byte[] buf = new byte[]{ 0x6A, 0x73, 0x73, 0x63, 0x0A }; SerialNativeInterface testTarget = new SerialNativeInterface(); diff --git a/toolchain/Riscv32.cmake b/toolchain/Riscv32.cmake new file mode 100644 index 000000000..2b4a5df01 --- /dev/null +++ b/toolchain/Riscv32.cmake @@ -0,0 +1,10 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(TOOLCHAIN_PREFIX riscv32-linux-gnu) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip CACHE FILEPATH "" FORCE) +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}/) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + diff --git a/toolchain/Riscv64.cmake b/toolchain/Riscv64.cmake new file mode 100644 index 000000000..abfa3e9a2 --- /dev/null +++ b/toolchain/Riscv64.cmake @@ -0,0 +1,10 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(TOOLCHAIN_PREFIX riscv64-linux-gnu) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip CACHE FILEPATH "" FORCE) +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}/) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + From 4fb5e3ffa7b79dfdb6090f6453461f9fc186cea2 Mon Sep 17 00:00:00 2001 From: Mateusz Pietryga Date: Fri, 10 Nov 2023 22:00:22 +0100 Subject: [PATCH 2/3] Copy native libraries to source tree with Maven action executed only on explicit demand and after a test phase (#153) Copy native libraries to source tree only on explicit demand and after a test phase --- .github/workflows/cross-compile.yml | 4 ++-- CMakeLists.txt | 5 +---- ant/build.xml | 6 ++++++ pom.xml | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cross-compile.yml b/.github/workflows/cross-compile.yml index 9a8060f7f..e05f278ae 100644 --- a/.github/workflows/cross-compile.yml +++ b/.github/workflows/cross-compile.yml @@ -118,7 +118,7 @@ jobs: ${{ matrix.image }} \ bash -c \ 'apt-get update && apt-get install --yes maven openjdk-11-jdk-headless && \ - mvn -B clean install -P dockcross \ + 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 }} \ @@ -171,7 +171,7 @@ jobs: 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 }} + run: mvn -B clean install -P ${{ matrix.profile }},update-resources-precompiled - name: Push recompiled binaries run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 528e37651..c7ab0cb24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,11 +191,8 @@ if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb") add_custom_command(TARGET jssc POST_BUILD COMMAND "${CMAKE_STRIP}" ${STRIP_ARGS} $) endif() - +# Copy native library to target/classes for processing by junit, maven add_custom_command(TARGET jssc POST_BUILD - # Copy native library back to source tree - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources-precompiled/natives/ - # Copy native library back to target/classes tree COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_BINARY_DIR}/../classes/natives/ ) diff --git a/ant/build.xml b/ant/build.xml index bd8f85cdd..9fa2b07bf 100644 --- a/ant/build.xml +++ b/ant/build.xml @@ -289,4 +289,10 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 728a27139..f5a20a102 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ 1.1 3.0.1 3.0.0-M4 + true @@ -247,6 +248,18 @@ + + update-resources-precompiled + prepare-package + run + + ${update-resources-precompiled.skip} + + + + + + show-file-info install @@ -432,6 +445,14 @@ + + + update-resources-precompiled + + false + + + package From 0cd6aef0ddf5e8fed6a450906b2f8afa6404086b Mon Sep 17 00:00:00 2001 From: Mateusz Pietryga Date: Sat, 11 Nov 2023 12:19:13 +0100 Subject: [PATCH 3/3] CI: Squash commits from cross-compile pipeline + update actions and runners versions (#154) --- .github/workflows/cross-compile.yml | 23 +++++++++++++++++++---- .github/workflows/release-new-version.yml | 12 ++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cross-compile.yml b/.github/workflows/cross-compile.yml index e05f278ae..b9da06f2e 100644 --- a/.github/workflows/cross-compile.yml +++ b/.github/workflows/cross-compile.yml @@ -8,7 +8,7 @@ env: jobs: create-branch: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: echo "precompiled_branch=$(git branch --show-current)-precompiled-natives" >> $GITHUB_ENV @@ -31,7 +31,7 @@ jobs: base_rev: ${{ env.rev }} linux-windows: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest needs: create-branch strategy: matrix: @@ -104,7 +104,7 @@ jobs: run: docker pull ${{ matrix.image }} - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 11 distribution: temurin @@ -154,7 +154,7 @@ jobs: uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 11 distribution: temurin @@ -181,3 +181,18 @@ jobs: 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 diff --git a/.github/workflows/release-new-version.yml b/.github/workflows/release-new-version.yml index aeaa6c19a..e62e71561 100644 --- a/.github/workflows/release-new-version.yml +++ b/.github/workflows/release-new-version.yml @@ -16,11 +16,11 @@ jobs: maven-central-release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: git config --global user.email "${GITHUB_BOT_EMAIL}" - run: git config --global user.name "${GITHUB_BOT_NAME}" - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 11 distribution: temurin @@ -50,13 +50,13 @@ jobs: runs-on: ubuntu-latest needs: maven-central-release steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ needs.maven-central-release.outputs.releaseTag }} - run: git config --global user.email "${GITHUB_BOT_EMAIL}" - run: git config --global user.name "${GITHUB_BOT_NAME}" - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: 11 distribution: temurin @@ -77,7 +77,7 @@ jobs: env: ver: ${{ needs.maven-central-release.outputs.releaseVersion }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: | git config --global user.email "${GITHUB_BOT_EMAIL}" git config --global user.name "${GITHUB_BOT_NAME}" @@ -95,7 +95,7 @@ jobs: env: ver: ${{ needs.maven-central-release.outputs.releaseVersion }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: repository: ${{github.repository}}.wiki - run: |