Skip to content

Commit

Permalink
build(ci): use SWIG v4.0.2 to build on all platforms (#21)
Browse files Browse the repository at this point in the history
* build(ci): build and use SWIG v4.0.2 on all platforms

* build(ci): differentiate platform when caching SWIG

* fix(ci): include SWIG in $PATH also on cache hit

* build(ci): build SWIG into a workspace folder

* build(ci): separate matrix job to build and cache swig

* build(ci): install runtime dependencies for swig on mac

* build: only build for own platform on Mac

* build(ci): use matrix job to build each platform

* debug(ci): more info on `gradlew build`

* doc: update README

* build(ci): stop gradle daemons before building

* build: allow to specify SWIG binary and print env

* fix: do checkout of repo first

* fix(ci): fix publish job to use cached SWIG

* Explicitly use old Ubuntu 20 for better compatibility

* use `temurin` Java instead of `adopt`
  • Loading branch information
skaldarnar authored Apr 13, 2024
1 parent aaa94e2 commit 808c463
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 86 deletions.
152 changes: 80 additions & 72 deletions .github/workflows/allInOne.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,110 +2,121 @@ name: Build and Publish for all Platforms

on: [push]

env:
SWIG_VERSION: 4.0.2

jobs:
validate-gradle-wrapper:
runs-on: ubuntu-latest
steps:
- 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
Expand All @@ -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:
Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 808c463

Please sign in to comment.