Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1 natives support #111

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build-java:
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15]
os: [ubuntu-20.04, macos-latest]
name: Build Java
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -25,7 +25,7 @@ jobs:
FREETYPE_URL: https://download.savannah.gnu.org/releases/freetype/freetype-2.10.4.tar.gz
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15]
os: [ubuntu-20.04, macos-latest]
type: [win, linux, mac]
freetype: [true, false]
include:
Expand All @@ -35,12 +35,14 @@ jobs:
expected: /tmp/imgui/libsNative/linux64/libimgui-java64.so
- type: mac
expected: /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib
- type: mac
expected: /tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib
exclude:
- os: ubuntu-20.04
type: mac
- os: macos-10.15
- os: macos-latest
type: win
- os: macos-10.15
- os: macos-latest
type: linux
name: Build Native (type=${{ matrix.type }}, freetype=${{ matrix.freetype }})
runs-on: ${{ matrix.os }}
Expand All @@ -62,6 +64,17 @@ jobs:
name: Install MinGW-w64/GCC/G++
run: sudo apt install mingw-w64

- if: matrix.os == 'macos-latest'
name: Build Setup Mac xcode
run: |
# See https://github.com/actions/virtual-environments/issues/2557
sudo mv /Library/Developer/CommandLineTools/SDKs/* /tmp
sudo mv /Applications/Xcode.app /Applications/Xcode.app.bak
sudo mv /Applications/Xcode_12.4.app /Applications/Xcode.app
sudo xcode-select -switch /Applications/Xcode.app
/usr/bin/xcodebuild -version
brew install freetype

- if: matrix.os == 'ubuntu-20.04' && matrix.type == 'linux' && matrix.freetype == true
name: FreeType - Install
run: sudo apt install libfreetype6-dev
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ jobs:
imgui-lwjgl3/build/libs/*.jar
bin/imgui-java64.dll
bin/libimgui-java64.dylib
bin/libimgui-javaarm64.dylib
bin/libimgui-java64.so
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ dependencies {
- imgui-java64.dll - Windows
- libimgui-java64.so - Linux
- libimgui-java64.dylib - MacOS
- libimgui-javaarm64.dylib - MacOS
3. Add jars to your classpath;
4. Provide a VM option: `imgui.library.path` or `java.library.path`. It should point to the folder where you've placed downloaded native libraries.
</details>
Expand Down Expand Up @@ -365,6 +366,7 @@ 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=mac -Dlocal`
- Run with: `./gradlew :example:run -PlibPath=../imgui-binding/build/libsNative/macosx64`
- Alternatively for M1 Run with: `./gradlew :example:run -PlibPath=../imgui-binding/build/libsNative/macosxarm64`

In `envs` parameter next values could be used `win`, `linux` or `mac`.<br>
`-Dlocal` is optional and means that natives will be built under the `./imgui-binding/build/` folder. Otherwise `/tmp/imgui` folder will be used.
Expand Down
1 change: 1 addition & 0 deletions bin/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ You can change that by using 'imgui.library.name' VM option (ex: -Dimgui.library
- imgui-java64.dll << Windows
- libimgui-java64.so << Linux
- libimgui-java64.dylib << MacOS
- libimgui-javaarm64.dylib << MacOS

Freetype folder contains same libraries, but with Freetype support.
Binary file added bin/libimgui-javaarm64.dylib
Binary file not shown.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories {
}

ext {
jnigenVersion = '2.0.1'
jnigenVersion = '2.2.1'
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions buildSrc/scripts/copy-ft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ mkdir ./bin/freetype
[ -e "/tmp/imgui/libsNative/linux32/libimgui-java.so" ] && cp /tmp/imgui/libsNative/linux32/libimgui-java.so ./bin/freetype
[ -e "/tmp/imgui/libsNative/linux64/libimgui-java64.so" ] && cp /tmp/imgui/libsNative/linux64/libimgui-java64.so ./bin/freetype
[ -e "/tmp/imgui/libsNative/macosx64/libimgui-java64.dylib" ] && cp /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib ./bin/freetype
[ -e "/tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib" ] && cp /tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib ./bin/freetype
1 change: 1 addition & 0 deletions buildSrc/scripts/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cd $BASEDIR/../.. || exit
[ -e "/tmp/imgui/libsNative/linux32/libimgui-java.so" ] && cp /tmp/imgui/libsNative/linux32/libimgui-java.so ./bin
[ -e "/tmp/imgui/libsNative/linux64/libimgui-java64.so" ] && cp /tmp/imgui/libsNative/linux64/libimgui-java64.so ./bin
[ -e "/tmp/imgui/libsNative/macosx64/libimgui-java64.dylib" ] && cp /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib ./bin
[ -e "/tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib" ] && cp /tmp/imgui/libsNative/macosxarm64/libimgui-javaarm64.dylib ./bin
18 changes: 16 additions & 2 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('win')
private final boolean forLinux = buildEnvs?.contains('linux')
private final boolean forMac = buildEnvs?.contains('mac')
private static final boolean isARM = System.getProperty("os.arch").equals("arm") || System.getProperty("os.arch").startsWith("aarch64");

private final boolean isLocal = System.properties.containsKey('local')
private final boolean withFreeType = Boolean.valueOf(System.properties.getProperty('freetype', 'false'))
Expand Down Expand Up @@ -104,6 +105,13 @@ class GenerateLibs extends DefaultTask {
mac64.linkerFlags = mac64.linkerFlags.replace('10.7', minMacOsVersion)
addFreeTypeIfEnabled(mac64)
buildTargets += mac64

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

new AntScriptGenerator().generate(buildConfig, buildTargets)
Expand All @@ -117,8 +125,10 @@ class GenerateLibs extends DefaultTask {
BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', commonParams)
if (forLinux)
BuildExecutor.executeAnt(jniDir + '/build-linux64.xml', commonParams)
if (forMac)
if (forMac) {
BuildExecutor.executeAnt(jniDir + '/build-macosx64.xml', commonParams)
BuildExecutor.executeAnt(jniDir + '/build-macosxarm64.xml', commonParams)
}

BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
}
Expand All @@ -136,7 +146,11 @@ class GenerateLibs extends DefaultTask {
target.cppFlags += ' -I/usr/include/freetype2'
break
case BuildTarget.TargetOs.MacOsX:
target.cppFlags += ' -I/usr/local/include/freetype2'
if (isARM) {
target.cppFlags += " -I/opt/homebrew/Cellar/freetype/2.11.1/include/freetype2"
} else {
target.cppFlags += ' -I/usr/local/include/freetype2'
}
break
}

Expand Down
3 changes: 2 additions & 1 deletion imgui-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 @@ -31,6 +31,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
10 changes: 5 additions & 5 deletions imgui-binding-natives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ plugins {
def packageName = 'imgui-java-natives-linux'
def packageDesc = 'Native binaries for imgui-java binding for Linux'
def fromDir = '../bin'
def libName = 'libimgui-java64.so'
def libNames = ['libimgui-java64.so']

switch (findProperty('deployType')) {
case 'win':
packageName = 'imgui-java-natives-windows'
packageDesc = 'Native binaries for imgui-java binding for Windows'
libName = 'imgui-java64.dll'
libName = ['imgui-java64.dll']
break
case 'linux':
packageName = 'imgui-java-natives-linux'
packageDesc = 'Native binaries for imgui-java binding for Linux'
libName = 'libimgui-java64.so'
libNames = ['libimgui-java64.so']
break
case 'mac':
packageName = 'imgui-java-natives-macos'
packageDesc = 'Native binaries for imgui-java binding for MacOS'
libName = 'libimgui-java64.dylib'
libNames = ['libimgui-java64.dylib', 'libimgui-javaarm64.dylib']
break
}

Expand All @@ -35,7 +35,7 @@ if (findProperty('freetype') == 'true') {

jar {
from(fromDir) {
include "$libName" // this is fine
include libNames // this is fine
into 'io/imgui/java/native-bin/'
}
manifest {
Expand Down
28 changes: 25 additions & 3 deletions imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
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 String LIB_NAME_BASE = "imgui-java";
private static final boolean is64Bit = System.getProperty("os.arch").contains("64") || System.getProperty("os.arch").startsWith("armv8");
private static final boolean isARM = System.getProperty("os.arch").equals("arm") || System.getProperty("os.arch").startsWith("aarch64");

private static final String LIB_TMP_DIR_PREFIX = "imgui-java-natives_" + System.currentTimeMillis();

private static final ImGuiContext IMGUI_CONTEXT;
Expand All @@ -45,7 +48,16 @@ public class ImGui {

static {
final String libPath = System.getProperty(LIB_PATH_PROP);
final String libName = System.getProperty(LIB_NAME_PROP, LIB_NAME_DEFAULT);
String genLibName = LIB_NAME_BASE;

if (isARM) {
genLibName += "arm";
}
if (is64Bit) {
genLibName += "64";
}

final String libName = System.getProperty(LIB_NAME_PROP, genLibName);
final String fullLibName = resolveFullLibName();

final String extractedLibAbsPath = tryLoadFromClasspath(fullLibName);
Expand Down Expand Up @@ -104,7 +116,17 @@ private static String resolveFullLibName() {
libSuffix = ".so";
}

return System.getProperty(LIB_NAME_PROP, libPrefix + LIB_NAME_DEFAULT + libSuffix);
String genLibName = LIB_NAME_BASE;

if (isARM) {
genLibName += "arm";
}
if (is64Bit) {
genLibName += "64";
}


return System.getProperty(LIB_NAME_PROP, libPrefix + genLibName + libSuffix);
}

// This method tries to unpack the library binary from classpath into the temp dir.
Expand Down