Skip to content

brownian-motion/java-ripgrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java-Rust FFI Demo: Ripgrep

This is a demo of FFI bindings between Java and Rust code using Java Native Access (JNA).

To demonstrate a nontrivial, real-world use case of using native code in Java, this library exposes some of the functionality of the ripgrep Rust library as a Java library.

While this is intended to represent a real-world use case, this repo is primarily a demo and is not intended for production use.

It is licensed under GPL 3, so feel free to use it however you like; just don't blame me for bugs!

Building

Because native code is not portable, native libraries must be re-compiled for each OS/architecture. This requires the full toolchain for the native code used.

Since this code is written in Rust, you must compile it using the Rust toolchain before this library can be built. You can visit https://rustup.rs or use the provided rustup PowerShell script to install the Rust build system. Note that the Rust toolchain on Windows may require you to download and install the Visual Studio C++ toolchain.

This demo was prepared using ripgrep's component libraries (grep v0.2 and walkdir v2) and compiled with rust 1.39 (stable), available on crates.io. This repo uses a Maven build script for Rust code, which uses Maven and Cargo to build the module.

To compile, you need cargo and mvn on your PATH.

Demo

To compile a demo, just run mvn package and execute the produced ripgrep-demo.jar.

Contributing

I will happily accept any contributions that improve the codebase. In particular, if you see a way to fix bugs, add tests or clear demos, or otherwise improve the codebase, please feel free to help out! The best way to contribute would be by opening an Issue or Pull Request on Github.

License

This repo is licensed under the GNU Public License, version 3.

References and related code

The inspiration (and initial reference) for establishing a Rust-Java FFI interface comes from this repo by drrb. I lifted drrb's build script and maven structure directly, and modified it to build using cargo instead of rustc.

For more information about FFI interfaces in Rust, Java, or in general, the following resources may be helpful:

About

Java-Rust FFI demo using JNA to expose ripgrep to Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published