diff --git a/.github/workflows/allInOne.yml b/.github/workflows/allInOne.yml index 4ee7bb838..d6af0de68 100644 --- a/.github/workflows/allInOne.yml +++ b/.github/workflows/allInOne.yml @@ -2,6 +2,9 @@ name: Build and Publish for all Platforms on: [push] +env: + SWIG_VERSION: 4.0.2 + jobs: validate-gradle-wrapper: runs-on: ubuntu-latest @@ -9,103 +12,111 @@ jobs: - uses: actions/checkout@v4 - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v2 - build-linux-windows-amd64: - runs-on: ubuntu-latest - needs: validate-gradle-wrapper + swig: + strategy: + matrix: + os: [ubuntu-20.04, macos-12, macos-14] + runs-on: ${{ matrix.os }} steps: - - name: Install SWIG - run: sudo apt-get install swig mingw-w64 - - uses: actions/checkout@v4 - with: - submodules: true - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'adopt' - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - - name: Build - run: ./gradlew buildNatives - - name: Upload artifacts - uses: actions/upload-artifact@v4 + - name: SWIG from cache + id: cache-swig + uses: actions/cache@v4 with: - name: linux-windows-amd64-artifacts - path: | - build/natives/*/*.so - build/natives/*/*.dll - build/natives/*/*.dylib - build-macos-amd64: - runs-on: macos-12 - needs: validate-gradle-wrapper - steps: - - name: Install SWIG and CMake + path: ${{ github.workspace }}/swig + key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }} + - name: Install SWIG build dependencies + if: steps.cache-swig.outputs.cache-hit != 'true' + run: | + if [ "${{ runner.os }}" == 'Linux' ]; then + sudo apt-get install -y autoconf automake libtool + elif [ "${{ runner.os }}" == 'macOS' ]; then + brew install autoconf automake libtool pcre + else + echo "Unsupported OS: ${{ runner.os }}" + exit 1 + fi + - name: Build SWIG v${{ env.SWIG_VERSION }} + if: steps.cache-swig.outputs.cache-hit != 'true' run: | - brew install swig - brew install cmake + wget https://github.com/swig/swig/archive/refs/tags/v${{ env.SWIG_VERSION }}.tar.gz + tar xzf v${{ env.SWIG_VERSION }}.tar.gz + cd swig-${{ env.SWIG_VERSION }} + ./autogen.sh + ./configure --prefix=$GITHUB_WORKSPACE/swig + make + make install + - name: Install SWIG runtime dependencies + if: runner.os == 'macOs' + run: | + brew install pcre + - name: Check SWIG version + run: $GITHUB_WORKSPACE/swig/bin/swig -version + build: + strategy: + matrix: + os: [ubuntu-20.04, macos-12, macos-14] + runs-on: ${{ matrix.os }} + needs: [validate-gradle-wrapper, swig] + steps: - uses: actions/checkout@v4 with: submodules: true + - name: Restore SWIG from cache + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/swig + key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }} + fail-on-cache-miss: true + - name: Add SWIG to $PATH + run: echo "${{ github.workspace }}/swig/bin" >> $GITHUB_PATH + - name: Install MinGW-w64 + if: runner.os == 'Linux' + run: sudo apt-get install -y mingw-w64 + - name: Install pcre + if: runner.os == 'macOS' + run: brew install pcre + - name: Check SWIG version + run: swig -version - name: Set up JDK uses: actions/setup-java@v4 with: java-version: '11' - distribution: 'adopt' + distribution: 'temurin' - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 - name: Build - run: ./gradlew native_macosx_amd64_clang + run: ./gradlew build buildNatives - name: Upload artifacts uses: actions/upload-artifact@v4 with: - name: macosx-amd64-artifacts + name: ${{ runner.os }}-${{ runner.arch }}-artifacts path: | build/natives/*/*.so build/natives/*/*.dll build/natives/*/*.dylib - build-macos-aarch64: - runs-on: macos-14 - needs: validate-gradle-wrapper + publish: + runs-on: ubuntu-20.04 + needs: [validate-gradle-wrapper, swig, build] + if: github.ref == 'refs/heads/master' steps: - - name: Install SWIG and CMake - run: | - brew install swig - brew install cmake - uses: actions/checkout@v4 with: submodules: true - - name: Set up JDK - uses: actions/setup-java@v4 + - name: Restore SWIG from cache + uses: actions/cache@v4 with: - java-version: '11' - distribution: 'adopt' - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - - name: Build - run: ./gradlew native_macosx_aarch64_clang - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: macosx-aarch64-artifacts - path: | - build/natives/*/*.so - build/natives/*/*.dll - build/natives/*/*.dylib - publish: - runs-on: ubuntu-latest - needs: [validate-gradle-wrapper,build-linux-windows-amd64, build-macos-amd64, build-macos-aarch64] - if: github.ref == 'refs/heads/master' - steps: - - name: Install SWIG - run: sudo apt-get install swig mingw-w64 + path: ${{ github.workspace }}/swig + key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }} + fail-on-cache-miss: true + - name: Add SWIG to $PATH + run: echo "${{ github.workspace }}/swig/bin" >> $GITHUB_PATH + - name: Check SWIG version + run: swig -version - name: Set up JDK uses: actions/setup-java@v4 with: java-version: '11' - distribution: 'adopt' - - uses: actions/checkout@v4 - with: - submodules: true + distribution: 'temurin' - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 - name: Download all artifacts @@ -114,10 +125,7 @@ jobs: path: build/natives merge-multiple: true - name: Build and Zip Natives - run: ./gradlew build zipNatives - - run: | - ls -R build/natives/ - ls -R build/libs/ + run: ./gradlew build zipNatives - name: Publish run: ./gradlew -Dorg.gradle.internal.publish.checksums.insecure=true publish -PmavenUser=${artifactoryUser} -PmavenPass=${artifactoryPass} env: diff --git a/README.md b/README.md index 47e98e006..dd94fec4e 100644 --- a/README.md +++ b/README.md @@ -4,28 +4,25 @@ TeraBullet is a version of bullet with extensions for direct interactions for vo ## Prerequisites +Make sure the following applications are installed: + +- Java 11 or later +- [CMake](https://cmake.org/) +- [SWIG](https://www.swig.org/) v4.0.2 +- [MinGW-w64](https://www.mingw-w64.org/) (cross-compilation for Windows on Linux) + Clone this repository and initialize all git submodules: ```sh git submodule update --init --recursive ``` -Install Java 11 or later. - -## Linux (for Linux and Windows artifacts) - -Install `swig`, `cmake` and `mingw-w64`. - -## MacOS - -Install `swig` and `cmake`. - ## Build -To build all natives for the current platform run +To build the Java library and all supported natives for the current platform run ```sh -./gradlew buildNatives +./gradlew build buildNatives ``` The native libraries are written to `build/natives/*` and are `.so`, `dll`, or `.dylib` files. @@ -36,7 +33,7 @@ To see a list of all known natives (platforms and operating systems), run ./gradlew listNatives ``` -To build the Java library part of bullet, simply run +To build only the Java library part of bullet, simply run ``` ./gradlew build diff --git a/build.gradle b/build.gradle index e211ca802..8f0f82772 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,15 @@ plugins { import org.apache.tools.ant.taskdefs.condition.Os ext { if(Os.isFamily(Os.FAMILY_MAC)) { - natives = ["macosx_amd64_clang","macosx_aarch64_clang"] + // Compilation succeeds for both targets on either Mac platform, but in both cases the output is for the platform we're on + // Therefore, we only include our own platform as target here. + if (Os.isArch("aarch64")) { + natives = ["macosx_aarch64_clang"] + } else { + natives = ["macosx_amd64_clang"] + } } else if (Os.isFamily(Os.FAMILY_UNIX)) { + // Cross-compilation with MinGW-w64 allows us to also build the Windows target on Linux natives = ["linux_amd64_gcc","linux_windows_amd64_mingw32"] } else { throw new GradleException("This script only works on Linux or Mac")