Giter Club home page Giter Club logo

bridj's Introduction

BEWARE: This project hasn't been maintained since 2015. An effort to refresh it (and JNAerator) is ongoing (Nov 2022) and 0.8.0-SNAPSHOT contains a sneak peek of it, with no guarantees.

BridJ

Maven Central Build Status (Travis: Linux) ![Build Status (AppVeyor: Windows)](https://img.shields.io/appveyor/ci/ochafik/bridj/master.svg?label=windows build) Join the chat at https://gitter.im/nativelibs4java/BridJ

BridJ is a Java / native interoperability library that focuses on speed and ease of use.

It is similar in spirit to JNA (dynamic bindings that don't require any native compilation, unlike JNI), but was designed to support C++, to be blazing fast (thanks to dyncall + hand-optimized assembly tweaks) and to use modern Java features.

A comprehensive documentation is available on its Wiki.

It was previously hosted on ochafik/nativelibs4java.

Quick links

Note: the Wiki is being refreshed.

Building

git clone http://github.com/nativelibs4java/BridJ.git
cd BridJ
mvn clean install

Iterate on native code:

mvn native:javah
./BuildNative && mvn surefire:test

Cross-compiling

Prerequisites

Assuming you have docker:

# One-off to let Docker use QEMU to run exotic architectures.
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes

# Install the cross-compiler for Windows
# sudo apt install mingw-w64
brew install mingw-w64

# https://jdk.java.net/archive/

# Get JDK for Mac ARM64 & X64
wget https://download.java.net/java/GA/jdk19/877d6127e982470ba2a7faa31cc93d04/36/GPL/openjdk-19_macos-{x64,aarch64}_bin.tar.gz && \
  tar zxvf openjdk-19_macos-aarch64_bin.tar.gz && mv jdk-19.jdk{,-darwin_arm64} && \
  tar zxvf openjdk-19_macos-x64_bin.tar.gz && mv jdk-19.jdk{,-darwin_x64} \

# Get JDK for Windows X64
wget https://download.java.net/java/GA/jdk19/877d6127e982470ba2a7faa31cc93d04/36/GPL/openjdk-19_windows-x64_bin.zip && \
    unzip openjdk-19_windows-x64_bin.zip && mv jdk-19{,-windows_x64}

# Get JDK for Windows ARM64
wget https://github.com/microsoft/openjdk-aarch64/releases/download/jdk-16.0.2-ga/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz && \
  tar zxvf openjdk-19_macos-aarch64_bin.tar.gz && mv jdk-16.0.2+7{,-windows_arm64}

wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk/8u352-b08/openlogic-openjdk-8u352-b08-windows-x32.zip && \
    unzip openlogic-openjdk-8u352-b08-windows-x32.zip

Cross-build commands

# Mac host: build Mac M1 & Intel binaries
ARCH=x64 ./BuildNative -DFORCE_JAVA_HOME=$PWD/../jdk-19.jdk-darwin_x64/Contents/Home
ARCH=arm64 ./BuildNative -DFORCE_JAVA_HOME=$PWD/../jdk-19.jdk-darwin_arm64/Contents/Home

# Mac or Linux host: build Windows X64 & X86 binaries w/ MinGW-w64
OS=windows ARCH=x64 ./BuildNative \
  -DCMAKE_TOOLCHAIN_FILE=$PWD/mingw-w64-x86_64.cmake \
  -DFORCE_JAVA_HOME=$PWD/../jdk-19-windows_x64
OS=windows ARCH=x86 ./BuildNative \
  -DCMAKE_TOOLCHAIN_FILE=$PWD/mingw-w64-i686.cmake \
  -DFORCE_JAVA_HOME=$PWD/../openlogic-openjdk-8u352-b08-windows-32

# Mac or Linux host: build & test Linux x86, x64, arm64, arm binaries inside Docker + QEMU:
# TODO: look at armel situation (no openjdk?)
         ./scripts/build-docker-qemu.sh linux/x86_64   debian:bullseye-slim           bridj-linux-x64
ARCH=x86 ./scripts/build-docker-qemu.sh linux/i386     i386/debian:bullseye-slim      bridj-linux-x86
         ./scripts/build-docker-qemu.sh linux/arm64    arm64v8/debian:bullseye-slim   bridj-linux-arm64
         ./scripts/build-docker-qemu.sh linux/arm/v7   arm32v7/debian:bullseye-slim   bridj-linux-arm
         ./scripts/build-docker-qemu.sh linux/ppc64le  ppc64le/debian:bullseye-slim   bridj-linux-ppc64le
#        ./scripts/build-docker-qemu.sh linux/arm/v6 balenalib/rpi-raspbian:bullseye bridj-linux-armel

# Windows x64 host (UNTESTED): build Windows X64 & ARM64 binary
ARCH=x64 ./BuildNative
ARCH=arm64 ./BuildNative -DFORCE_JAVA_HOME=$PWD/../jdk-16.0.2+7-windows_arm64

Debugging

mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=deps-classpath-test.txt
DEBUG=1 mvn clean test-compile

# Or gdb --args java ...
lldb -- java -cp \
  target/generated-resources:target/generated-test-resources:target/test-classes:target/classes:$( cat deps-classpath-test.txt ) \
  org.junit.runner.JUnitCore \
  org.bridj.BridJTest

Formatting

mvn format

Support

Please use the mailing-list and file bugs.

TODO

bridj's People

Contributors

alagopus avatar ctrimble avatar finson avatar gitter-badger avatar jlleitschuh avatar mkw avatar ochafik avatar rkraneis avatar sarxos avatar twitwi avatar washley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.