Skip to content

Commit 808c463

Browse files
authored
build(ci): use SWIG v4.0.2 to build on all platforms (#21)
* 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`
1 parent aaa94e2 commit 808c463

File tree

3 files changed

+98
-86
lines changed

3 files changed

+98
-86
lines changed

.github/workflows/allInOne.yml

Lines changed: 80 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,121 @@ name: Build and Publish for all Platforms
22

33
on: [push]
44

5+
env:
6+
SWIG_VERSION: 4.0.2
7+
58
jobs:
69
validate-gradle-wrapper:
710
runs-on: ubuntu-latest
811
steps:
912
- uses: actions/checkout@v4
1013
- name: Validate Gradle Wrapper
1114
uses: gradle/wrapper-validation-action@v2
12-
build-linux-windows-amd64:
13-
runs-on: ubuntu-latest
14-
needs: validate-gradle-wrapper
15+
swig:
16+
strategy:
17+
matrix:
18+
os: [ubuntu-20.04, macos-12, macos-14]
19+
runs-on: ${{ matrix.os }}
1520
steps:
16-
- name: Install SWIG
17-
run: sudo apt-get install swig mingw-w64
18-
- uses: actions/checkout@v4
19-
with:
20-
submodules: true
21-
- name: Set up JDK
22-
uses: actions/setup-java@v4
23-
with:
24-
java-version: '11'
25-
distribution: 'adopt'
26-
- name: Setup Gradle
27-
uses: gradle/actions/setup-gradle@v3
28-
- name: Build
29-
run: ./gradlew buildNatives
30-
- name: Upload artifacts
31-
uses: actions/upload-artifact@v4
21+
- name: SWIG from cache
22+
id: cache-swig
23+
uses: actions/cache@v4
3224
with:
33-
name: linux-windows-amd64-artifacts
34-
path: |
35-
build/natives/*/*.so
36-
build/natives/*/*.dll
37-
build/natives/*/*.dylib
38-
build-macos-amd64:
39-
runs-on: macos-12
40-
needs: validate-gradle-wrapper
41-
steps:
42-
- name: Install SWIG and CMake
25+
path: ${{ github.workspace }}/swig
26+
key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }}
27+
- name: Install SWIG build dependencies
28+
if: steps.cache-swig.outputs.cache-hit != 'true'
29+
run: |
30+
if [ "${{ runner.os }}" == 'Linux' ]; then
31+
sudo apt-get install -y autoconf automake libtool
32+
elif [ "${{ runner.os }}" == 'macOS' ]; then
33+
brew install autoconf automake libtool pcre
34+
else
35+
echo "Unsupported OS: ${{ runner.os }}"
36+
exit 1
37+
fi
38+
- name: Build SWIG v${{ env.SWIG_VERSION }}
39+
if: steps.cache-swig.outputs.cache-hit != 'true'
4340
run: |
44-
brew install swig
45-
brew install cmake
41+
wget https://github.com/swig/swig/archive/refs/tags/v${{ env.SWIG_VERSION }}.tar.gz
42+
tar xzf v${{ env.SWIG_VERSION }}.tar.gz
43+
cd swig-${{ env.SWIG_VERSION }}
44+
./autogen.sh
45+
./configure --prefix=$GITHUB_WORKSPACE/swig
46+
make
47+
make install
48+
- name: Install SWIG runtime dependencies
49+
if: runner.os == 'macOs'
50+
run: |
51+
brew install pcre
52+
- name: Check SWIG version
53+
run: $GITHUB_WORKSPACE/swig/bin/swig -version
54+
build:
55+
strategy:
56+
matrix:
57+
os: [ubuntu-20.04, macos-12, macos-14]
58+
runs-on: ${{ matrix.os }}
59+
needs: [validate-gradle-wrapper, swig]
60+
steps:
4661
- uses: actions/checkout@v4
4762
with:
4863
submodules: true
64+
- name: Restore SWIG from cache
65+
uses: actions/cache@v4
66+
with:
67+
path: ${{ github.workspace }}/swig
68+
key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }}
69+
fail-on-cache-miss: true
70+
- name: Add SWIG to $PATH
71+
run: echo "${{ github.workspace }}/swig/bin" >> $GITHUB_PATH
72+
- name: Install MinGW-w64
73+
if: runner.os == 'Linux'
74+
run: sudo apt-get install -y mingw-w64
75+
- name: Install pcre
76+
if: runner.os == 'macOS'
77+
run: brew install pcre
78+
- name: Check SWIG version
79+
run: swig -version
4980
- name: Set up JDK
5081
uses: actions/setup-java@v4
5182
with:
5283
java-version: '11'
53-
distribution: 'adopt'
84+
distribution: 'temurin'
5485
- name: Setup Gradle
5586
uses: gradle/actions/setup-gradle@v3
5687
- name: Build
57-
run: ./gradlew native_macosx_amd64_clang
88+
run: ./gradlew build buildNatives
5889
- name: Upload artifacts
5990
uses: actions/upload-artifact@v4
6091
with:
61-
name: macosx-amd64-artifacts
92+
name: ${{ runner.os }}-${{ runner.arch }}-artifacts
6293
path: |
6394
build/natives/*/*.so
6495
build/natives/*/*.dll
6596
build/natives/*/*.dylib
66-
build-macos-aarch64:
67-
runs-on: macos-14
68-
needs: validate-gradle-wrapper
97+
publish:
98+
runs-on: ubuntu-20.04
99+
needs: [validate-gradle-wrapper, swig, build]
100+
if: github.ref == 'refs/heads/master'
69101
steps:
70-
- name: Install SWIG and CMake
71-
run: |
72-
brew install swig
73-
brew install cmake
74102
- uses: actions/checkout@v4
75103
with:
76104
submodules: true
77-
- name: Set up JDK
78-
uses: actions/setup-java@v4
105+
- name: Restore SWIG from cache
106+
uses: actions/cache@v4
79107
with:
80-
java-version: '11'
81-
distribution: 'adopt'
82-
- name: Setup Gradle
83-
uses: gradle/actions/setup-gradle@v3
84-
- name: Build
85-
run: ./gradlew native_macosx_aarch64_clang
86-
- name: Upload artifacts
87-
uses: actions/upload-artifact@v4
88-
with:
89-
name: macosx-aarch64-artifacts
90-
path: |
91-
build/natives/*/*.so
92-
build/natives/*/*.dll
93-
build/natives/*/*.dylib
94-
publish:
95-
runs-on: ubuntu-latest
96-
needs: [validate-gradle-wrapper,build-linux-windows-amd64, build-macos-amd64, build-macos-aarch64]
97-
if: github.ref == 'refs/heads/master'
98-
steps:
99-
- name: Install SWIG
100-
run: sudo apt-get install swig mingw-w64
108+
path: ${{ github.workspace }}/swig
109+
key: ${{ runner.os }}-${{ runner.arch }}-swig-${{ env.SWIG_VERSION }}
110+
fail-on-cache-miss: true
111+
- name: Add SWIG to $PATH
112+
run: echo "${{ github.workspace }}/swig/bin" >> $GITHUB_PATH
113+
- name: Check SWIG version
114+
run: swig -version
101115
- name: Set up JDK
102116
uses: actions/setup-java@v4
103117
with:
104118
java-version: '11'
105-
distribution: 'adopt'
106-
- uses: actions/checkout@v4
107-
with:
108-
submodules: true
119+
distribution: 'temurin'
109120
- name: Setup Gradle
110121
uses: gradle/actions/setup-gradle@v3
111122
- name: Download all artifacts
@@ -114,10 +125,7 @@ jobs:
114125
path: build/natives
115126
merge-multiple: true
116127
- name: Build and Zip Natives
117-
run: ./gradlew build zipNatives
118-
- run: |
119-
ls -R build/natives/
120-
ls -R build/libs/
128+
run: ./gradlew build zipNatives
121129
- name: Publish
122130
run: ./gradlew -Dorg.gradle.internal.publish.checksums.insecure=true publish -PmavenUser=${artifactoryUser} -PmavenPass=${artifactoryPass}
123131
env:

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@ TeraBullet is a version of bullet with extensions for direct interactions for vo
44

55
## Prerequisites
66

7+
Make sure the following applications are installed:
8+
9+
- Java 11 or later
10+
- [CMake](https://cmake.org/)
11+
- [SWIG](https://www.swig.org/) v4.0.2
12+
- [MinGW-w64](https://www.mingw-w64.org/) (cross-compilation for Windows on Linux)
13+
714
Clone this repository and initialize all git submodules:
815

916
```sh
1017
git submodule update --init --recursive
1118
```
1219

13-
Install Java 11 or later.
14-
15-
## Linux (for Linux and Windows artifacts)
16-
17-
Install `swig`, `cmake` and `mingw-w64`.
18-
19-
## MacOS
20-
21-
Install `swig` and `cmake`.
22-
2320
## Build
2421

25-
To build all natives for the current platform run
22+
To build the Java library and all supported natives for the current platform run
2623

2724
```sh
28-
./gradlew buildNatives
25+
./gradlew build buildNatives
2926
```
3027

3128
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
3633
./gradlew listNatives
3734
```
3835

39-
To build the Java library part of bullet, simply run
36+
To build only the Java library part of bullet, simply run
4037

4138
```
4239
./gradlew build

build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ plugins {
66
import org.apache.tools.ant.taskdefs.condition.Os
77
ext {
88
if(Os.isFamily(Os.FAMILY_MAC)) {
9-
natives = ["macosx_amd64_clang","macosx_aarch64_clang"]
9+
// Compilation succeeds for both targets on either Mac platform, but in both cases the output is for the platform we're on
10+
// Therefore, we only include our own platform as target here.
11+
if (Os.isArch("aarch64")) {
12+
natives = ["macosx_aarch64_clang"]
13+
} else {
14+
natives = ["macosx_amd64_clang"]
15+
}
1016
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
17+
// Cross-compilation with MinGW-w64 allows us to also build the Windows target on Linux
1118
natives = ["linux_amd64_gcc","linux_windows_amd64_mingw32"]
1219
} else {
1320
throw new GradleException("This script only works on Linux or Mac")

0 commit comments

Comments
 (0)