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

feat: RISCV native build support #7275

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ jobs:
sudo apt install -y --force-yes gcc g++
sudo apt install -y --force-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
sudo apt install -y --force-yes gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross
sudo apt install -y --force-yes gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross

- name: Build Linux natives
run: |
./gradlew jniGen jnigenBuildLinux64 jnigenBuildLinuxARM jnigenBuildLinuxARM64
./gradlew jniGen jnigenBuildLinux64 jnigenBuildLinuxARM jnigenBuildLinuxARM64 jnigenBuildLinuxRISCV64

- name: Pack artifacts
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;

import com.badlogic.gdx.backends.lwjgl.audio.LwjglAudio;
import com.badlogic.gdx.utils.*;
import org.lwjgl.opengl.AWTGLCanvas;
import org.lwjgl.opengl.Display;

Expand All @@ -36,10 +37,6 @@
import com.badlogic.gdx.Net;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.backends.lwjgl.audio.OpenALLwjglAudio;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Clipboard;
import com.badlogic.gdx.utils.Null;
import com.badlogic.gdx.utils.SharedLibraryLoader;

import java.awt.Canvas;
import java.awt.Container;
Expand Down Expand Up @@ -96,7 +93,7 @@ public final void addNotify () {
scaleX = (float)transform.getScaleX();
scaleY = (float)transform.getScaleY();

if (SharedLibraryLoader.isMac) {
if (SharedLibraryLoader.os == Os.MacOsX) {
EventQueue.invokeLater(new Runnable() {
public void run () {
create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import com.badlogic.gdx.utils.Os;
import org.lwjgl.LWJGLException;

import com.badlogic.gdx.Gdx;
Expand All @@ -16,7 +17,7 @@ public class LwjglCursor implements Cursor {
org.lwjgl.input.Cursor lwjglCursor = null;

public LwjglCursor (Pixmap pixmap, int xHotspot, int yHotspot) {
if (((LwjglGraphics)Gdx.graphics).canvas != null && SharedLibraryLoader.isMac) {
if (((LwjglGraphics)Gdx.graphics).canvas != null && SharedLibraryLoader.os == Os.MacOsX) {
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.badlogic.gdx.AbstractGraphics;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.graphics.glutils.GLVersion;
import com.badlogic.gdx.utils.Os;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.ContextAttribs;
Expand Down Expand Up @@ -736,7 +737,7 @@ public com.badlogic.gdx.graphics.Cursor newCursor (Pixmap pixmap, int xHotspot,

@Override
public void setCursor (com.badlogic.gdx.graphics.Cursor cursor) {
if (canvas != null && SharedLibraryLoader.isMac) {
if (canvas != null && SharedLibraryLoader.os == Os.MacOsX) {
return;
}
try {
Expand All @@ -748,7 +749,7 @@ public void setCursor (com.badlogic.gdx.graphics.Cursor cursor) {

@Override
public void setSystemCursor (SystemCursor systemCursor) {
if (canvas != null && SharedLibraryLoader.isMac) {
if (canvas != null && SharedLibraryLoader.os == Os.MacOsX) {
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import static com.badlogic.gdx.utils.SharedLibraryLoader.*;

import com.badlogic.gdx.utils.GdxNativesLoader;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.SharedLibraryLoader;
import com.badlogic.gdx.utils.*;

import java.io.File;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -50,18 +48,41 @@ static public void load () {
SharedLibraryLoader loader = new SharedLibraryLoader();
File nativesDir = null;
try {
if (isWindows) {
nativesDir = loader.extractFile(is64Bit ? "lwjgl64.dll" : "lwjgl.dll", null).getParentFile();
if (!LwjglApplicationConfiguration.disableAudio)
loader.extractFileTo(is64Bit ? "OpenAL64.dll" : "OpenAL32.dll", nativesDir);
} else if (isMac) {
nativesDir = loader.extractFile("liblwjgl.dylib", null).getParentFile();
if (!LwjglApplicationConfiguration.disableAudio) loader.extractFileTo("openal.dylib", nativesDir);
} else if (isLinux) {
nativesDir = loader.extractFile(is64Bit ? "liblwjgl64.so" : "liblwjgl.so", null).getParentFile();
if (!LwjglApplicationConfiguration.disableAudio)
loader.extractFileTo(is64Bit ? "libopenal64.so" : "libopenal.so", nativesDir);
String lwjglLib = null;
String openalLib = null;
switch (os) {
case Windows:
switch (bitness) {
case _32:
lwjglLib = "lwjgl.dll";
openalLib = "OpenAL32.dll";
break;
case _64:
lwjglLib = "lwjgl64.dll";
openalLib = "OpenAL64.dll";
break;
}
break;
case MacOsX:
lwjglLib = "liblwjgl.dylib";
openalLib = "openal.dylib";
break;
case Linux:
switch (bitness) {
case _32:
lwjglLib = "liblwjgl.so";
openalLib = "libopenal.so";
break;
case _64:
lwjglLib = "liblwjgl64.so";
openalLib = "libopenal64.so";
break;
}
break;
}
if (lwjglLib == null) throw new GdxRuntimeException("Unknown LWJGL platform: " + os + ", " + bitness);
nativesDir = loader.extractFile(lwjglLib, null).getParentFile();
if (!LwjglApplicationConfiguration.disableAudio) loader.extractFileTo(openalLib, nativesDir);
} catch (Throwable ex) {
throw new GdxRuntimeException("Unable to extract LWJGL natives.", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.badlogic.gdx.backends.lwjgl3.audio.OpenALLwjgl3Audio;
import com.badlogic.gdx.graphics.glutils.GLVersion;

import com.badlogic.gdx.utils.*;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.AMDDebugOutput;
Expand All @@ -50,11 +51,6 @@
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.backends.lwjgl3.audio.mock.MockAudio;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Clipboard;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.SharedLibraryLoader;
import org.lwjgl.system.Configuration;
import org.lwjgl.system.ThreadLocalUtil;

Expand All @@ -80,11 +76,12 @@ public class Lwjgl3Application implements Lwjgl3ApplicationBase {

static void initializeGlfw () {
if (errorCallback == null) {
if (SharedLibraryLoader.isMac) loadGlfwAwtMacos();
if (SharedLibraryLoader.os == Os.MacOsX) loadGlfwAwtMacos();
Lwjgl3NativesLoader.load();
errorCallback = GLFWErrorCallback.createPrint(Lwjgl3ApplicationConfiguration.errorStream);
GLFW.glfwSetErrorCallback(errorCallback);
if (SharedLibraryLoader.isMac) GLFW.glfwInitHint(GLFW.GLFW_ANGLE_PLATFORM_TYPE, GLFW.GLFW_ANGLE_PLATFORM_TYPE_METAL);
if (SharedLibraryLoader.os == Os.MacOsX)
GLFW.glfwInitHint(GLFW.GLFW_ANGLE_PLATFORM_TYPE, GLFW.GLFW_ANGLE_PLATFORM_TYPE_METAL);
GLFW.glfwInitHint(GLFW.GLFW_JOYSTICK_HAT_BUTTONS, GLFW.GLFW_FALSE);
if (!GLFW.glfwInit()) {
throw new GdxRuntimeException("Unable to initialize GLFW");
Expand Down Expand Up @@ -492,7 +489,7 @@ static long createGlfwWindow (Lwjgl3ApplicationConfiguration config, long shared
|| config.glEmulation == Lwjgl3ApplicationConfiguration.GLEmulation.GL32) {
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, config.gles30ContextMajorVersion);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, config.gles30ContextMinorVersion);
if (SharedLibraryLoader.isMac) {
if (SharedLibraryLoader.os == Os.MacOsX) {
// hints mandatory on OS X for GL 3.2+ context creation, but fail on Windows if the
// WGL_ARB_create_context extension is not available
// see: http://www.glfw.org/docs/latest/compat.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.badlogic.gdx.net.ServerSocketHints;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.net.SocketHints;
import com.badlogic.gdx.utils.Os;
import com.badlogic.gdx.utils.SharedLibraryLoader;

/** LWJGL implementation of the {@link Net} API, it could be reused in other Desktop backends since it doesn't depend on LWJGL.
Expand Down Expand Up @@ -66,7 +67,7 @@ public Socket newClientSocket (Protocol protocol, String host, int port, SocketH

@Override
public boolean openURI (String uri) {
if (SharedLibraryLoader.isMac) {
if (SharedLibraryLoader.os == Os.MacOsX) {
try {
(new ProcessBuilder("open", (new URI(uri).toString()))).start();
return true;
Expand All @@ -80,7 +81,7 @@ public boolean openURI (String uri) {
} catch (Throwable t) {
return false;
}
} else if (SharedLibraryLoader.isLinux) {
} else if (SharedLibraryLoader.os == Os.Linux) {
try {
(new ProcessBuilder("xdg-open", (new URI(uri).toString()))).start();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.IntBuffer;

import com.badlogic.gdx.utils.Os;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWDropCallback;
Expand Down Expand Up @@ -278,7 +279,7 @@ public void setIcon (Pixmap... image) {
}

static void setIcon (long windowHandle, String[] imagePaths, Files.FileType imageFileType) {
if (SharedLibraryLoader.isMac) return;
if (SharedLibraryLoader.os == Os.MacOsX) return;

Pixmap[] pixmaps = new Pixmap[imagePaths.length];
for (int i = 0; i < imagePaths.length; i++) {
Expand All @@ -293,7 +294,7 @@ static void setIcon (long windowHandle, String[] imagePaths, Files.FileType imag
}

static void setIcon (long windowHandle, Pixmap[] images) {
if (SharedLibraryLoader.isMac) return;
if (SharedLibraryLoader.os == Os.MacOsX) return;

GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
Pixmap[] tmpPixmaps = new Pixmap[images.length];
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
}
dependencies {
classpath "com.diffplug.spotless:spotless-plugin-gradle:${versions.spotless}"
classpath "com.badlogicgames.gdx:gdx-jnigen-gradle:2.4.1"
classpath "com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1"
}
}

Expand Down
1 change: 1 addition & 0 deletions extensions/gdx-box2d/gdx-box2d/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jnigen {
add(Linux, x64)
add(Linux, x32, ARM)
add(Linux, x64, ARM)
add(Linux, x64, RISCV)
add(MacOsX, x64)
add(MacOsX, x64, ARM)
add(Android)
Expand Down
1 change: 1 addition & 0 deletions extensions/gdx-bullet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jnigen {
add(Linux, x64)
add(Linux, x32, ARM)
add(Linux, x64, ARM)
add(Linux, x64, RISCV)
add(MacOsX, x64)
add(MacOsX, x64, ARM)
add(Android) {
Expand Down
1 change: 1 addition & 0 deletions extensions/gdx-freetype/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jnigen {
add(Linux, x64)
add(Linux, x32, ARM)
add(Linux, x64, ARM)
add(Linux, x64, RISCV)
add(MacOsX, x64) {
linkerFlags += " -framework CoreServices -framework Carbon"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.UUID;
import java.util.zip.CRC32;

import com.badlogic.gdx.utils.Architecture;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.SharedLibraryLoader;

Expand Down Expand Up @@ -176,7 +177,8 @@ public void run () {
}
}

String source = SharedLibraryLoader.isARM ? "macosarm64/libglfwarm64.dylib" : "macosx64/libglfw.dylib";
String source = SharedLibraryLoader.architecture == Architecture.ARM ? "macosarm64/libglfwarm64.dylib"
: "macosx64/libglfw.dylib";
String crc = crc(GlfwAWTLoader.class.getResourceAsStream("/" + source));
File sharedLib = getExtractedFile(crc, new File(source).getName());

Expand Down
3 changes: 2 additions & 1 deletion gdx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jar {

dependencies {
testImplementation libraries.junit
api "com.badlogicgames.gdx:gdx-jnigen-loader:2.3.1"
api "com.badlogicgames.gdx:gdx-jnigen-loader:2.5.1"
}

test {
Expand All @@ -62,6 +62,7 @@ jnigen {
add(Linux, x64)
add(Linux, x32, ARM)
add(Linux, x64, ARM)
add(Linux, x64, RISCV)
add(Android) {
linkerFlags += " -llog"
}
Expand Down
11 changes: 6 additions & 5 deletions gdx/src/com/badlogic/gdx/scenes/scene2d/utils/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.utils.Os;
import com.badlogic.gdx.utils.SharedLibraryLoader;

public final class UIUtils {
private UIUtils () {
}

static public boolean isAndroid = SharedLibraryLoader.isAndroid;
static public boolean isMac = SharedLibraryLoader.isMac;
static public boolean isWindows = SharedLibraryLoader.isWindows;
static public boolean isLinux = SharedLibraryLoader.isLinux;
static public boolean isIos = SharedLibraryLoader.isIos;
static public boolean isAndroid = SharedLibraryLoader.os == Os.Android;
static public boolean isMac = SharedLibraryLoader.os == Os.MacOsX;
static public boolean isWindows = SharedLibraryLoader.os == Os.Windows;
static public boolean isLinux = SharedLibraryLoader.os == Os.Linux;
static public boolean isIos = SharedLibraryLoader.os == Os.IOS;

static public boolean left () {
return Gdx.input.isButtonPressed(Buttons.LEFT);
Expand Down