Skip to content

Commit

Permalink
MacOS ARM64 native binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
rexfleischer committed May 16, 2024
1 parent 3e33dde commit a9f822c
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 40 deletions.
46 changes: 27 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ jobs:
imgui-lwjgl3/build/libs/*.jar
build-natives:
name: Build Native (${{ matrix.type }}${{ matrix.freetype && ', freetype' || '' }})
name: Build Native (${{ matrix.target.type }}${{ matrix.freetype && ', freetype' || '' }})
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
type: [ windows, linux, macos ]
freetype: [ true, false ]
include:
- type: windows
target:
- os: ubuntu-latest
type: windows
expected: /tmp/imgui/libsNative/windows64/imgui-java64.dll
- type: linux
expected: /tmp/imgui/libsNative/linux64/libimgui-java64.so
- type: macos
expected: /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib
exclude:
- os: ubuntu-latest
type: macos
type: linux
expected: /tmp/imgui/libsNative/linux64/libimgui-java64.so
- os: macos-latest
type: windows
type: macos
expected: /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib
- os: macos-latest
type: linux
runs-on: ${{ matrix.os }}
type: macosarm64
expected: /tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib
runs-on: ${{ matrix.target.os }}
steps:
- name: Checkout Repository and Submodules
uses: actions/checkout@v4
Expand All @@ -69,15 +67,15 @@ jobs:
run: ant -version

- name: Install MinGW-w64/GCC/G++ (Linux & Windows)
if: matrix.os == 'ubuntu-latest'
if: matrix.target.os == 'ubuntu-latest'
run: sudo apt install mingw-w64

- name: FreeType - Install (Linux)
if: matrix.os == 'ubuntu-latest' && matrix.type == 'linux' && matrix.freetype == true
if: matrix.target.os == 'ubuntu-latest' && matrix.target.type == 'linux' && matrix.freetype == true
run: sudo apt install libfreetype6-dev

- name: FreeType - Install (Windows)
if: matrix.os == 'ubuntu-latest' && matrix.type == 'windows' && matrix.freetype == true
if: matrix.target.os == 'ubuntu-latest' && matrix.target.type == 'windows' && matrix.freetype == true
run: |
sudo mkdir /freetype
sudo tar -xzf ./vendor/freetype-2.12.1.tar.gz -C /freetype --strip-components=1
Expand All @@ -86,15 +84,25 @@ jobs:
sudo make
sudo make install
- name: FreeType - Install (MacOS-arm64)
if: matrix.target.os == 'macos-latest' && matrix.freetype == true
run: |
sudo mkdir /opt/freetype
sudo tar -xzf ./vendor/freetype-2.12.1.tar.gz -C /opt/freetype --strip-components=1
cd /opt/freetype
sudo ./configure CFLAGS="-arch arm64 -arch x86_64" --with-zlib=no --with-bzip2=no --with-png=no --with-harfbuzz=no --with-brotli=no
sudo make
sudo make install
- name: Build
run: ./gradlew imgui-binding:generateLibs -Denvs=${{ matrix.type }} -Dfreetype=${{ matrix.freetype }}
run: ./gradlew imgui-binding:generateLibs -Denvs=${{ matrix.target.type }} -Dfreetype=${{ matrix.freetype }}

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.freetype && 'native-libraries-with-freetype' || 'native-libraries' }}
if-no-files-found: error
path: ${{ matrix.expected }}
path: ${{ matrix.target.expected }}

update-bin:
name: Update Binaries
Expand Down
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ You can refer to `imgui-app` module to see how things are done there.

For simplicity, example of dependencies for Gradle / Maven only shows how to add natives for Windows. Feel free to add other platforms.

| Native Binaries | System |
|----------------------------|---------|
| imgui-java-natives-windows | Windows |
| imgui-java-natives-linux | Linux |
| imgui-java-natives-macos | macOS |
| Native Binaries | System |
|--------------------------------|-------------|
| imgui-java-natives-windows | Windows |
| imgui-java-natives-linux | Linux |
| imgui-java-natives-macos | macOS |
| imgui-java-natives-macos-arm64 | macOS-arm64 |

Take a note, that you also need to add dependencies to [LWJGL](https://www.lwjgl.org/) library. Examples below shows how to do it as well.

Expand Down Expand Up @@ -298,14 +299,15 @@ Both `imgui.library.path` and `java.library.path` are equal with the difference,

If using Java 9 modules, ImGui Java has Automatic Module Names:

| Package | Module |
|----------------------------|-----------------------|
| imgui-java-app | imgui.app |
| imgui-java-binding | imgui.binding |
| imgui-java-lwjgl3 | imgui.lwjgl3 |
| imgui-java-natives-windows | imgui.natives.windows |
| imgui-java-natives-linux | imgui.natives.linux |
| imgui-java-natives-macos | imgui.natives.macos |
| Package | Module |
|--------------------------------|---------------------------|
| imgui-java-app | imgui.app |
| imgui-java-binding | imgui.binding |
| imgui-java-lwjgl3 | imgui.lwjgl3 |
| imgui-java-natives-windows | imgui.natives.windows |
| imgui-java-natives-linux | imgui.natives.linux |
| imgui-java-natives-macos | imgui.natives.macos |
| imgui-java-natives-macos-arm64 | imgui.natives.macos-arm64 |

## Extensions

Expand Down Expand Up @@ -382,11 +384,12 @@ Use the same native libraries as you would, but with `-ft` suffix in the end.
```
</details>

| Native Binaries With FreeType | System |
|-------------------------------|---------|
| imgui-java-natives-windows-ft | Windows |
| imgui-java-natives-linux-ft | Linux |
| imgui-java-natives-macos-ft | macOS |
| Native Binaries With FreeType | System |
|-----------------------------------|-------------|
| imgui-java-natives-windows-ft | Windows |
| imgui-java-natives-linux-ft | Linux |
| imgui-java-natives-macos-ft | macOS |
| imgui-java-natives-macos-arm64-ft | macOS-arm64 |

If you're using raw dll/so files, go to the [release page](https://github.com/SpaiR/imgui-java/releases/latest) and use libraries from the `native-libraries-with-freetype.zip` archive.

Expand Down Expand Up @@ -427,8 +430,14 @@ Ensure you've downloaded git submodules. That could be achieved:
- Check dependencies from "Linux" section and make sure you have them installed.
- Build with: `./gradlew imgui-binding:generateLibs -Denvs=macos -Dlocal`
- Run with: `./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/macosx64`

### macOS-arm64

- Check dependencies from "Linux" section and make sure you have them installed.
- Build with: `./gradlew imgui-binding:generateLibs -Denvs=macosarm64 -Dlocal`
- Run with: `./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/macosxarm64`

In `envs` parameter next values could be used `windows`, `linux` or `macos`.<br>
In `envs` parameter next values could be used `windows`, `linux` or `macos` or `macosarm64`.<br>
`-Dlocal` is optional and means that natives will be built under the `./imgui-binding/build/` folder. Otherwise `/tmp/imgui` folder will be used.
On Windows always use local build.

Expand Down
Binary file added bin/freetype/libimgui-javaarm64.dylib
Binary file not shown.
Binary file added bin/libimgui-javaarm64.dylib
Binary file not shown.
4 changes: 4 additions & 0 deletions buildSrc/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ echo '>> Natives: [macOS, freetype]'
./gradlew imgui-binding-natives:publishImguiPublicationToMavenCentralRepository -PdeployType=macos -Pfreetype=true
echo '>> Natives: [macOS]'
./gradlew imgui-binding-natives:publishImguiPublicationToMavenCentralRepository -PdeployType=macos -Pfreetype=false
echo '>> Natives: [macOS-arm64, freetype]'
./gradlew imgui-binding-natives:publishImguiPublicationToMavenCentralRepository -PdeployType=macosarm64 -Pfreetype=true
echo '>> Natives: [macOS-arm64]'
./gradlew imgui-binding-natives:publishImguiPublicationToMavenCentralRepository -PdeployType=macosarm64 -Pfreetype=false
13 changes: 13 additions & 0 deletions buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GenerateLibs extends DefaultTask {
private final boolean forWindows = buildEnvs?.contains('windows')
private final boolean forLinux = buildEnvs?.contains('linux')
private final boolean forMac = buildEnvs?.contains('macos')
private final boolean forMacArm64 = buildEnvs?.contains('macosarm64')

private final boolean isLocal = System.properties.containsKey('local')
private final boolean withFreeType = Boolean.valueOf(System.properties.getProperty('freetype', 'false'))
Expand Down Expand Up @@ -105,6 +106,16 @@ class GenerateLibs extends DefaultTask {
buildTargets += mac64
}

if (forMacArm64) {
def minMacOsVersion = '10.15'
def macArm64 = BuildTarget.newDefaultTarget(BuildTarget.TargetOs.MacOsX, true, true)
macArm64.cppFlags += ' -std=c++14'
macArm64.cppFlags = macArm64.cppFlags.replace('10.7', minMacOsVersion)
macArm64.linkerFlags = macArm64.linkerFlags.replace('10.7', minMacOsVersion)
addFreeTypeIfEnabled(macArm64)
buildTargets += macArm64
}

new AntScriptGenerator().generate(buildConfig, buildTargets)

// Generate native libraries
Expand All @@ -118,6 +129,8 @@ class GenerateLibs extends DefaultTask {
BuildExecutor.executeAnt(jniDir + '/build-linux64.xml', commonParams)
if (forMac)
BuildExecutor.executeAnt(jniDir + '/build-macosx64.xml', commonParams)
if (forMacArm64)
BuildExecutor.executeAnt(jniDir + '/build-macosxarm64.xml', commonParams)

BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
}
Expand Down
3 changes: 2 additions & 1 deletion imgui-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
api 'org.lwjgl:lwjgl-glfw'
api 'org.lwjgl:lwjgl-opengl'

['natives-linux', 'natives-windows', 'natives-macos'].each {
['natives-linux', 'natives-windows', 'natives-macos', 'natives-macos-arm64'].each {
api "org.lwjgl:lwjgl::$it"
api "org.lwjgl:lwjgl-glfw::$it"
api "org.lwjgl:lwjgl-opengl::$it"
Expand All @@ -33,6 +33,7 @@ jar {
from('../bin') {
include 'libimgui-java64.so'
include 'libimgui-java64.dylib'
include 'libimgui-javaarm64.dylib'
into 'io/imgui/java/native-bin/'
}
from('../bin/freetype') {
Expand Down
6 changes: 6 additions & 0 deletions imgui-binding-natives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ switch (findProperty('deployType')) {
moduleName = 'imgui.natives.macos'
libName = 'libimgui-java64.dylib'
break
case 'macosarm64':
packageName = 'imgui-java-natives-macos-arm64'
packageDesc = 'Native binaries for imgui-java binding for MacOS arm64'
moduleName = 'imgui.natives.macos-arm64'
libName = 'libimgui-javaarm64.dylib'
break
}

if (findProperty('freetype') == 'true') {
Expand Down
3 changes: 2 additions & 1 deletion imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public class ImGui {
private static final String LIB_PATH_PROP = "imgui.library.path";
private static final String LIB_NAME_PROP = "imgui.library.name";
private static final String LIB_NAME_DEFAULT = System.getProperty("os.arch").contains("64") ? "imgui-java64" : "imgui-java";
private static final boolean isARM = System.getProperty("os.arch").equals("arm") || System.getProperty("os.arch").startsWith("aarch64");
private static final String LIB_NAME_DEFAULT = "imgui-java" + (isARM ? "arm" : "") + "64";
private static final String LIB_TMP_DIR_PREFIX = "imgui-java-natives";

private static final ImGuiContext IMGUI_CONTEXT;
Expand Down

0 comments on commit a9f822c

Please sign in to comment.