Skip to content

Commit

Permalink
build: MacOS builds and GitHub actions (#19)
Browse files Browse the repository at this point in the history
* add MacOS aarch64 target (Apple Silicon)
* build(ci): GitHub workflows to build for MacOS (both Intel and Apple Silicon)
* build: remove 32-bit artifacts
* build(ci): remove currently broken Jenkinsfile (replaced by GitHub action)
* doc: update the README

---------

Co-authored-by: Adam Sotona <asotona@openjdk.org>
  • Loading branch information
skaldarnar and asotona authored Mar 16, 2024
1 parent 2691be1 commit 85b1a57
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 136 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/linux_amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install SWIG
run: sudo apt-get install swig
run: sudo apt-get install swig mingw-w64
- uses: actions/checkout@v3
with:
submodules: true
Expand All @@ -20,5 +20,17 @@ jobs:
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: .
- name: Build
run: ./gradlew native_linux_amd64_gcc
run: ./gradlew buildNatives
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: linux-windows-amd64-artifacts
path: |
build/natives/*/*.so
build/natives/*/*.dll
build/natives/*/*.dylib
34 changes: 34 additions & 0 deletions .github/workflows/macosx_aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: MacOS aarch64 (M1)

on: [push]

jobs:
build:
runs-on: macos-14
steps:
- name: Install SWIG and CMake
run: |
brew install swig
brew install cmake
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build
run: ./gradlew native_macosx_aarch64_clang
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: macosx-aarch64-artifacts
path: |
build/natives/*/*.so
build/natives/*/*.dll
build/natives/*/*.dylib
35 changes: 35 additions & 0 deletions .github/workflows/macosx_amd64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow builds and tests the project on a MacOS amd64 machine (Intel Mac).
name: MacOS amd64

on: [push]

jobs:
build:
runs-on: macos-12
steps:
- name: Install SWIG and CMake
run: |
brew install swig
brew install cmake
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build
run: ./gradlew native_macosx_amd64_clang
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: macosx-amd64-artifacts
path: |
build/natives/*/*.so
build/natives/*/*.dll
build/natives/*/*.dylib
61 changes: 0 additions & 61 deletions Jenkinsfile

This file was deleted.

95 changes: 27 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,55 @@

TeraBullet is a version of bullet with extensions for direct interactions for voxel worlds. Written for use with Terasology. this is an implementation of bullet wraps around native bullet using SWIG.

# Gradle
## Prerequisites

## Build Natives
- `./gradlew native_linux_amd64_gcc`
- `./gradlew native_linux_i686_gcc`
- `./gradlew native_linux_windows_amd64_mingw32`
- `./gradlew native_linux_windows_i686_mingw32`
Clone this repository and initialize all git submodules:

# Building



## CMAKE
* \<toolchain\>
- android_armeabi_gcc.cmake
- linux_amd64_gcc.cmake
- linux_i386_gcc.cmake
- linux_windows_amd64_mingw32.cmake
- linux_windows_i686_mingw32.cmake
- macosx_amd64_clang.cmake
- windows_amd64_msvc.cmake
- windows_i386_msvc.cmake


```
cd build
cmake ../ -DCMAKE_TOOLCHAIN_FILE=../toolchains/<toolchain>.cmake
make
```sh
git submodule update --init --recursive
```

## linux - linux and windows
Install Java 11 or later.

To build the natives on linux you need:
## Linux (for Linux and Windows artifacts)

- ant - installed on the system to build the natives for the generated wrapper code
- swig - installed on the system to produce both the generated code for the native and java bindings
Install `swig`, `cmake` and `mingw-w64`.

* linux
- i686
1. gcc
2. gcc-c++
3. libstdc++.i686
4. glibc-devel.i686
- amd64
1. gcc
2. gcc-c++
3. glibc-devel
4. libstdc++
* windows
- i686
1. mingw32-winpthreads
2. mingw32-winpthreads-static
3. mingw32-gcc
4. mingw32-gcc-c++
- amd64
1. mingw64-winpthreads
2. mingw64-winpthreads-static
3. mingw64-gcc
4. mingw64-gcc-c++
## MacOS

Then simply run `ant` to generated the binding code between java along with compiling the necessary libraries.
Install `swig` and `cmake`.

## Build

the output is produced under the `native-build` folder and is formatted in this fashion:
`libbullet-[linux,windows]-[i686,amd64].[dll,so]``

To build all natives for the current platform run

```sh
./gradlew buildNatives
```

To build the java portion of bullet, simply run `./gradlew build`
The native libraries are written to `build/natives/*` and are `.so`, `dll`, or `.dylib` files.

## OSX
To see a list of all known natives (platforms and operating systems), run

* mac
- i686
- amd64
```
./gradlew listNatives
```

### System prerequisites
To build the Java library part of bullet, simply run

To allow the build to succeed on Macs install the following (potentially in addition to the prep for [JNLua](https://github.com/MovingBlocks/JNLua/blob/master/README.md))
```
./gradlew build
```

* `brew install swig`
* `brew install cmake`
## Publishing

Be sure to have retrieved the submodule in the repo: `git submodule update --init --recursive`
...

**Note:** On Mac the `jniHelpers.h` file triggered a compile error. It was then _removed_ along with its sibling `jniHelpers.cpp` and two includes in `mathtypes.h` and `gdxCommon.i` - it did not seem like that was in use, but noting it here for future reference just in case.
## Testing

To test be sure to make the version in `gradle.properties` unique so you can ensure you use it by updating the corresponding version in Terasology's root `build.gradle` (natives) as well as its `engine/build.gradle` (Java wrapper). Use `./gradlew build zipNatives publishToMavenLocal` to get binaries created locally for JNBullet that Terasology can then read, and make sure to refresh its natives (delete the `natives` directory and rerun `gradlew extractNatives`)

# License
## License

This library is Licensed under the [Apache 2 License](http://www.apache.org/licenses/LICENSE-2.0.html) and is a rework of bullet wrapper
from [libgdx](https://github.com/libgdx/libgdx)
26 changes: 23 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ plugins {
import org.apache.tools.ant.taskdefs.condition.Os
ext {
if(Os.isFamily(Os.FAMILY_MAC)) {
natives = ["macosx_amd64_clang"]
natives = ["macosx_amd64_clang","macosx_aarch64_clang"]
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
natives = ["linux_amd64_gcc","linux_i686_gcc","linux_windows_amd64_mingw32","linux_windows_i686_mingw32"]
natives = ["linux_amd64_gcc","linux_windows_amd64_mingw32"]
} else {
throw new GradleException("This script only works on Linux or Mac")
}

allNatives = ["linux_amd64_gcc","linux_i686_gcc","linux_windows_amd64_mingw32","linux_windows_i686_mingw32","macosx_amd64_clang"]
allNatives = [
"linux_amd64_gcc",
"linux_windows_amd64_mingw32",
"macosx_aarch64_clang",
"macosx_amd64_clang"
]

generatedSrcDir = 'src/generated/java'
}
Expand Down Expand Up @@ -112,6 +117,21 @@ task buildNatives{
}
}

task listNatives{
description = "List all supported platforms."
doLast {
println "All known natives (*supported):"
allNatives.each { module ->
// check whether module is contained in natives
if (natives.contains(module)) {
println " *native_${module}"
} else {
println " native_${module}"
}
}
}
}

// TODO: outputs are not defined well enough yet for Gradle to skip this if already done (maybe more the natives task?)
task zipNatives(type: Zip){
description 'Creates a zip archive that contains all TeraBullet native files'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.3-SNAPSHOT
version=1.0.4-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class NativeSupport {
static boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
static boolean isMacOS = System.getProperty("os.name").toLowerCase().contains("mac");
static boolean is64 = System.getProperty("os.arch").endsWith("64");
static boolean isArm = System.getProperty("os.arch").endsWith("aarch64");

private static final Pattern PATH_SEPARATOR = Pattern.compile(File.pathSeparator);

Expand Down Expand Up @@ -80,7 +81,9 @@ public static void load(String name) {
target += "linux-";
}

if (is64) {
if (isArm) {
target += "aarch64";
} else if (is64) {
// Assume x86_64
target += "amd64";
} else {
Expand Down
24 changes: 24 additions & 0 deletions toolchains/macosx_aarch64_clang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2015, alex at staticlibs.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required ( VERSION 2.8.12 )

# default to Debug
set ( CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default build type" )

set ( CMAKE_SYSTEM_NAME Darwin )
set ( CMAKE_SYSTEM_ARCH aarch64)

set ( CMAKE_C_COMPILER clang )
set ( CMAKE_CXX_COMPILER clang++ )

0 comments on commit 85b1a57

Please sign in to comment.