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

New JNI provider #870

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ The dependencies are minimal: you may use JLine without any dependency on *nix s
You can also use fine grained jars:
* `jline-terminal`: the `Terminal` api and implementations
* `jline-terminal-jansi`: terminal implementations leveraging the `Jansi` library
* `jline-terminal-jni`: terminal implementations leveraging the JNI native library
* `jline-terminal-jna`: terminal implementations leveraging the `JNA` library
* `jline-terminal-ffm`: terminal implementations leveraging the Foreign Functions & Mapping layer
* `jline-native`: the native library
* `jline-reader`: the line reader (including completion, history, etc...)
* `jline-style`: styling api
* `jline-remote-ssh`: helpers for using jline with [Mina SSHD](http://mina.apache.org/sshd-project/)
Expand Down
4 changes: 4 additions & 0 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>org.jline</groupId>
<artifactId>jline-terminal-ffm</artifactId>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jni</artifactId>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
Expand Down
21 changes: 21 additions & 0 deletions jline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>jline-terminal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jni</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
Expand Down Expand Up @@ -139,6 +144,14 @@
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jni</artifactId>
<classifier>sources</classifier>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
Expand Down Expand Up @@ -213,6 +226,14 @@
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<excludes>**/*.class</excludes>
</artifactItem>
<artifactItem>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jni</artifactId>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<excludes>**/*.class</excludes>
</artifactItem>
<artifactItem>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jansi</artifactId>
Expand Down
18 changes: 14 additions & 4 deletions native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linux-armv6-digest:=@sha256:7bad6ab302af34bdf6634c8c2b02c8dc6ac932c67da9ecc199c5
linux-x86-digest:=:latest
windows-static-x86-digest:=@sha256:99d7069789560ef77a7504ead4a2b5e3c245cb45a45f964c74fecbf649398d3a
windows-static-x64-digest:=@sha256:f159861bc80b29e5dafb223477167bec53ecec6cdacb051d31e90c5823542100
windows-arm64-digest:=@sha256:f4b3c1a49ec8b53418cef1499dc3f9a54a5570b7a3ecdf42fc8c83eb94b01b7d
cross-build-digest:=@sha256:8dbaa86462270db93ae1b1b319bdd88d89272faf3a68632daf4fa36b414a326e
freebsd-crossbuild-digest:=@sha256:cda62697a15d8bdc0bc26e780b1771ee78f12c55e7d5813e62c478af5a747c43
mcandre-snek-digest:=@sha256:9f84e9fcdf66daafc1f1c3fb772a6c97977714e17800aeac2e3bbe5dc5039dd0
Expand Down Expand Up @@ -68,9 +69,9 @@ $(JLINENATIVE_OUT)/%.o: src/main/native/%.c
ifeq ($(OS_NAME), Windows)
$(JLINENATIVE_OUT)/$(LIBNAME): ducible
endif
$(JLINENATIVE_OUT)/$(LIBNAME): $(JLINENATIVE_OUT)/jlinenative.o
$(JLINENATIVE_OUT)/$(LIBNAME): $(JLINENATIVE_OUT)/jlinenative.o $(JLINENATIVE_OUT)/clibrary.o $(JLINENATIVE_OUT)/kernel32.o
@mkdir -p $(@D)
$(CC) $(CCFLAGS) -o $@ $(JLINENATIVE_OUT)/jlinenative.o $(LINKFLAGS)
$(CC) $(CCFLAGS) -o $@ $(JLINENATIVE_OUT)/jlinenative.o $(JLINENATIVE_OUT)/clibrary.o $(JLINENATIVE_OUT)/kernel32.o $(LINKFLAGS)
ifeq ($(OS_NAME), Windows)
target/ducible/ducible $(JLINENATIVE_OUT)/$(LIBNAME)
endif
Expand All @@ -81,8 +82,11 @@ NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)

# For cross-compilation, install docker. See also https://github.com/dockcross/dockcross
# Disabled linux-armv6 build because of this issue; https://github.com/dockcross/dockcross/issues/190
native-all: linux-x86 linux-x86_64 linux-arm linux-armv6 linux-armv7 \
linux-arm64 linux-ppc64 win-x86 win-x86_64 mac-x86 mac-x86_64 mac-arm64 freebsd-x86 freebsd-x86_64
native-all: \
linux-x86 linux-x86_64 linux-arm linux-armv6 linux-armv7 linux-arm64 linux-ppc64 linux-riscv64 \
win-x86 win-x86_64 win-arm64 \
mac-x86 mac-x86_64 mac-arm64 \
freebsd-x86 freebsd-x86_64

native: $(NATIVE_DLL)

Expand Down Expand Up @@ -139,6 +143,12 @@ target/dockcross/dockcross-windows-static-x64: dockcross
win-x86_64: download-includes target/dockcross/dockcross-windows-static-x64
target/dockcross/dockcross-windows-static-x64 bash -c 'make clean-native native CROSS_PREFIX=x86_64-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86_64'

target/dockcross/dockcross-windows-arm64: dockcross
docker run --rm dockcross/windows-arm64$(windows-arm64-digest) > target/dockcross/dockcross-windows-arm64
chmod +x target/dockcross/dockcross-windows-arm64
win-arm64: download-includes target/dockcross/dockcross-windows-arm64
target/dockcross/dockcross-windows-arm64 bash -c 'make clean-native native CROSS_PREFIX=aarch64-w64-mingw32- OS_NAME=Windows OS_ARCH=arm64'

mac-x86: download-includes
docker run -it --rm -v $$PWD:/workdir --user $$(id -u):$$(id -g) \
-e CROSS_TRIPLE=i386-apple-darwin multiarch/crossbuild$(cross-build-digest) make clean-native native OS_NAME=Mac OS_ARCH=x86
Expand Down
31 changes: 9 additions & 22 deletions native/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# os=Default is meant to be generic unix/linux

known_targets := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-ppc64 Mac-x86 Mac-x86_64 Mac-arm64 DragonFly-x86_64 FreeBSD-x86_64 OpenBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-sparcv9 HPUX-ia64_32
known_targets := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-arm64 Linux-ppc64 Linux-riscv64 Mac-x86 Mac-x86_64 Mac-arm64 DragonFly-x86_64 FreeBSD-x86_64 OpenBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-sparcv9 HPUX-ia64_32
target := $(OS_NAME)-$(OS_ARCH)

ifeq (,$(findstring $(strip $(target)),$(known_targets)))
Expand All @@ -32,105 +32,96 @@ Default_STRIP := $(CROSS_PREFIX)strip
Default_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
Default_LINKFLAGS := -shared
Default_LIBNAME := libjlinenative.so
Default_JANSI_FLAGS :=

Linux-x86_CC := $(CROSS_PREFIX)gcc
Linux-x86_STRIP := $(CROSS_PREFIX)strip
Linux-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -m32 -fvisibility=hidden
Linux-x86_LINKFLAGS := -shared -static-libgcc
Linux-x86_LIBNAME := libjlinenative.so
Linux-x86_JANSI_FLAGS :=

Linux-x86_64_CC := $(CROSS_PREFIX)gcc
Linux-x86_64_STRIP := $(CROSS_PREFIX)strip
Linux-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -m64 -fvisibility=hidden
Linux-x86_64_LINKFLAGS := -shared -static-libgcc
Linux-x86_64_LIBNAME := libjlinenative.so
Linux-x86_64_JANSI_FLAGS :=

Linux-arm_CC := $(CROSS_PREFIX)gcc
Linux-arm_STRIP := $(CROSS_PREFIX)strip
Linux-arm_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -mfloat-abi=softfp -mfpu=vfp -fvisibility=hidden
Linux-arm_LINKFLAGS := -shared -static-libgcc
Linux-arm_LIBNAME := libjlinenative.so
Linux-arm_JANSI_FLAGS :=

Linux-armv6_CC := $(CROSS_PREFIX)gcc
Linux-armv6_STRIP := $(CROSS_PREFIX)strip
Linux-armv6_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
Linux-armv6_LINKFLAGS := -shared -static-libgcc
Linux-armv6_LIBNAME := libjlinenative.so
Linux-armv6_JANSI_FLAGS :=

Linux-armv7_CC := $(CROSS_PREFIX)gcc
Linux-armv7_STRIP := $(CROSS_PREFIX)strip
Linux-armv7_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
Linux-armv7_LINKFLAGS := -shared -static-libgcc
Linux-armv7_LIBNAME := libjlinenative.so
Linux-armv7_JANSI_FLAGS :=

Linux-arm64_CC := $(CROSS_PREFIX)gcc
Linux-arm64_STRIP := $(CROSS_PREFIX)strip
Linux-arm64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -mfloat-abi=hard -mfpu=vfp -fPIC -fvisibility=hidden
Linux-arm64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -march=armv8-a -fPIC -fvisibility=hidden
Linux-arm64_LINKFLAGS := -shared -static-libgcc
Linux-arm64_LIBNAME := libjlinenative.so
Linux-arm64_JANSI_FLAGS :=

Linux-ppc64_CC := $(CROSS_PREFIX)gcc
Linux-ppc64_STRIP := $(CROSS_PREFIX)strip
Linux-ppc64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
Linux-ppc64_LINKFLAGS := -shared -static-libgcc
Linux-ppc64_LIBNAME := libjlinenative.so
Linux-ppc64_JANSI_FLAGS :=

Linux-riscv64_CC := $(CROSS_PREFIX)gcc
Linux-riscv64_STRIP := $(CROSS_PREFIX)strip
Linux-riscv64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -march=rv64g -fPIC -fvisibility=hidden
Linux-riscv64_LINKFLAGS := -shared -static-libgcc
Linux-riscv64_LIBNAME := libjlinenative.so

DragonFly-x86_64_CC := $(CROSS_PREFIX)cc
DragonFly-x86_64_STRIP := $(CROSS_PREFIX)strip
DragonFly-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -O2 -fPIC -fvisibility=hidden
DragonFly-x86_64_LINKFLAGS := -shared
DragonFly-x86_64_LIBNAME := libjlinenative.so
DragonFly-x86_64_JANSI_FLAGS :=

FreeBSD-x86_CC := $(CROSS_PREFIX)gcc
FreeBSD-x86_STRIP := $(CROSS_PREFIX)strip
FreeBSD-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
FreeBSD-x86_LINKFLAGS := -shared
FreeBSD-x86_LIBNAME := libjlinenative.so
FreeBSD-x86_JANSI_FLAGS :=

FreeBSD-x86_64_CC := $(CROSS_PREFIX)gcc
FreeBSD-x86_64_STRIP := $(CROSS_PREFIX)strip
FreeBSD-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
FreeBSD-x86_64_LINKFLAGS := -shared
FreeBSD-x86_64_LIBNAME := libjlinenative.so
FreeBSD-x86_64_JANSI_FLAGS :=

OpenBSD-x86_64_CC := $(CROSS_PREFIX)gcc
OpenBSD-x86_64_STRIP := $(CROSS_PREFIX)strip
OpenBSD-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -fvisibility=hidden
OpenBSD-x86_64_LINKFLAGS := -shared
OpenBSD-x86_64_LIBNAME := libjlinenative.so
OpenBSD-x86_64_JANSI_FLAGS :=

SunOS-sparcv9_CC := $(CROSS_PREFIX)gcc
SunOS-sparcv9_STRIP := $(CROSS_PREFIX)strip
SunOS-sparcv9_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -O2s-fPIC -m64 -fvisibility=hidden
SunOS-sparcv9_LINKFLAGS := -shared -static-libgcc
SunOS-sparcv9_LIBNAME := libjlinenative.so
SunOS-sparcv9_JANSI_FLAGS :=

HPUX-ia64_32_CC := cc
HPUX-ia64_32_STRIP := strip
HPUX-ia64_32_CCFLAGS := -Itarget/inc -Itarget/inc/unix +Osize +z -Bhidden
HPUX-ia64_32_LINKFLAGS := -b
HPUX-ia64_32_LIBNAME := libjlinenative.so
HPUX-ia64_32_JANSI_FLAGS :=
SHPUX-ia64_32_LIBNAME := libjlinenative.so

Mac-x86_CC := gcc
Mac-x86_STRIP := strip -x
Mac-x86_CCFLAGS := -I$(JAVA_HOME)/include -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=10.4 -fvisibility=hidden
Mac-x86_LINKFLAGS := -dynamiclib
Mac-x86_LIBNAME := libjlinenative.jnilib
Mac-x86_JANSI_FLAGS := -DJANSI_ENABLE_LOCKING_STYLE=0

Mac-x86_64_CC := gcc -arch $(OS_ARCH)
Mac-x86_64_STRIP := strip -x
Expand All @@ -141,29 +132,25 @@ endif
Mac-x86_64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=10.6 -fvisibility=hidden
Mac-x86_64_LINKFLAGS := -dynamiclib
Mac-x86_64_LIBNAME := libjlinenative.jnilib
Mac-x86_64_JANSI_FLAGS :=

Mac-arm64_CC := $(CROSS_PREFIX)clang -v
Mac-arm64_STRIP := $(CROSS_PREFIX)strip -x
MAC_SDK := /usr/local/osxcross/SDK/MacOSX11.3.sdk/
Mac-arm64_CCFLAGS := -I$(MAC_SDK)/System/Library/Frameworks/JavaVM.framework/Headers -Itarget/inc -Itarget/inc/unix -Os -fPIC -mmacosx-version-min=11.0 -fvisibility=hidden
Mac-arm64_LINKFLAGS := -shared
Mac-arm64_LIBNAME := libjlinenative.jnilib
Mac-arm64_JANSI_FLAGS :=

Windows-x86_CC := $(CROSS_PREFIX)gcc
Windows-x86_STRIP := $(CROSS_PREFIX)strip
Windows-x86_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Itarget/inc -Itarget/inc/windows -Os
Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
Windows-x86_LIBNAME := jlinenative.dll
Windows-x86_JANSI_FLAGS :=

Windows-x86_64_CC := $(CROSS_PREFIX)gcc
Windows-x86_64_STRIP := $(CROSS_PREFIX)strip
Windows-x86_64_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Itarget/inc -Itarget/inc/windows -Os
Windows-x86_64_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
Windows-x86_64_LIBNAME := jlinenative.dll
Windows-x86_64_JANSI_FLAGS :=


CC := $($(target)_CC)
Expand Down
Loading
Loading