Skip to content

Commit 41f90a7

Browse files
authored
feat: initial FFI crate + Java bindings (#2516)
This PR adds a new `vortex-ffi` crate, which builds a shared library that is then consumed by the `vortex-jni` java project. This PR previously included some initial Spark bindings but to prevent this getting any larger I've decided to offload that to another PR. Some things to note - We're using JavaLanguageVersion.of(17) b/c that is the maximum version supported by Spark 3.5 - I based the FFI bindings mostly off of vibes, some similar code I've written before to bridge HF Tokenizers library to Java, and arrow-rs's FFI functions. I have tests in a number of the FFI files but once we're in raw pointers land there be some unavoidable dragons. - The Java project is not hooked up to CI right now, but if you feel inclined to pull and run the tests locally, then as long as you have a JDK 17 installed and the TPCH data generated, you can run `./gradlew test` from the java directory to run the basic scan test. FLUPs: - Hook Java up to CI - Complete v0 Spark data source - FFI compress/write APIs - Iceberg connection
1 parent 4984bfd commit 41f90a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3531
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ jobs:
314314
# For now, we only run Miri against known "fiddly" crates.
315315
if: false
316316
- name: Run Miri
317-
run: cargo miri nextest run --no-fail-fast -p vortex-buffer
317+
run: cargo miri nextest run --no-fail-fast -p vortex-buffer -p vortex-ffi
318318

319319
generated-files:
320320
name: "Check generated proto/fbs files are up to date"

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ members = [
1212
"vortex-dtype",
1313
"vortex-error",
1414
"vortex-expr",
15+
"vortex-ffi",
1516
"vortex-file",
1617
"vortex-flatbuffers",
1718
"vortex-io",
@@ -176,6 +177,7 @@ vortex-dtype = { version = "0.25.2", path = "./vortex-dtype", default-features =
176177
vortex-error = { version = "0.25.2", path = "./vortex-error" }
177178
vortex-expr = { version = "0.25.2", path = "./vortex-expr" }
178179
vortex-fastlanes = { version = "0.25.2", path = "./encodings/fastlanes" }
180+
vortex-ffi = { version = "0.25.2", path = "./vortex-ffi" }
179181
vortex-file = { version = "0.25.2", path = "./vortex-file", default-features = false }
180182
vortex-flatbuffers = { version = "0.25.2", path = "./vortex-flatbuffers" }
181183
vortex-fsst = { version = "0.25.2", path = "./encodings/fsst" }

java/.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
10+
# Binary files should be left untouched
11+
*.jar binary
12+

java/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
6+
7+
# generated source directories
8+
generated_src/

java/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Java Bindings Development
2+
3+
Install a JDK 17 toolchain.
4+
5+
You can run tests like
6+
7+
```
8+
./gradlew test
9+
```
10+
11+
You can build a JAR file with
12+
13+
```
14+
./gradlew jar
15+
```
16+
17+
The JAR files will contain platform native code from `vortex-ffi` to operate on Vortex data.

java/build.gradle.kts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import net.ltgt.gradle.errorprone.errorprone
2+
3+
plugins {
4+
id("com.diffplug.spotless") version "7.0.1"
5+
id("com.palantir.consistent-versions") version "2.31.0"
6+
id("com.palantir.git-version") version "3.1.0"
7+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
8+
id("net.ltgt.errorprone") version "4.1.0" apply false
9+
id("org.inferred.processors") version "3.7.0" apply false
10+
}
11+
12+
val gitVersion: groovy.lang.Closure<String> by extra
13+
version = gitVersion()
14+
15+
nexusPublishing {
16+
repositories {
17+
sonatype {
18+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
19+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
20+
username.set(System.getenv("MAVEN_CENTRAL_USER"))
21+
password.set(System.getenv("MAVEN_CENTRAL_PASSWORD"))
22+
}
23+
}
24+
}
25+
26+
allprojects {
27+
apply(plugin = "com.diffplug.spotless")
28+
29+
group = "dev.vortex"
30+
version = rootProject.version
31+
32+
repositories {
33+
mavenCentral()
34+
}
35+
36+
tasks.withType<Test> {
37+
useJUnitPlatform()
38+
39+
maxHeapSize = "1G"
40+
41+
testLogging {
42+
events("passed")
43+
}
44+
}
45+
46+
plugins.withType<JavaLibraryPlugin> {
47+
apply(plugin = "net.ltgt.errorprone")
48+
apply(plugin = "org.inferred.processors")
49+
50+
dependencies {
51+
"errorprone"("com.google.errorprone:error_prone_core")
52+
"errorprone"("com.jakewharton.nopen:nopen-checker")
53+
"compileOnly"("com.jakewharton.nopen:nopen-annotations")
54+
}
55+
56+
spotless {
57+
java {
58+
palantirJavaFormat()
59+
licenseHeaderFile("${rootProject.projectDir}/.spotless/java-license-header.txt")
60+
}
61+
}
62+
63+
tasks.withType<JavaCompile> {
64+
options.errorprone.disable("UnusedVariable")
65+
options.release = 11
66+
67+
// Needed to make sure that the barista-annotations emits to the correct directory
68+
options.generatedSourceOutputDirectory = projectDir.resolve("generated_src")
69+
}
70+
71+
tasks.withType<Javadoc> {
72+
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:-missing")
73+
}
74+
75+
the<JavaPluginExtension>().toolchain {
76+
languageVersion.set(JavaLanguageVersion.of(17))
77+
vendor.set(JvmVendorSpec.AMAZON)
78+
}
79+
80+
tasks["check"].dependsOn("spotlessCheck")
81+
}
82+
83+
spotless {
84+
kotlinGradle {
85+
ktlint()
86+
}
87+
}
88+
89+
tasks.register("format").get().dependsOn("spotlessApply")
90+
}

java/gradle.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#org.gradle.configuration-cache=true
2+
org.gradle.parallel=true
3+
org.gradle.caching=true
4+
5+
# extra JVM args needed to allow Spotless to access JDK private classes.
6+
org.gradle.jvmargs =--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
7+
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
8+
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
9+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
10+
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#This file is generated by updateDaemonJvm
2+
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ff8d269e2495c538cfa04b4b52d22286/redirect
3+
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/4dfe7aab2abf71db71537e9dca36c154/redirect
4+
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ff8d269e2495c538cfa04b4b52d22286/redirect
5+
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/4dfe7aab2abf71db71537e9dca36c154/redirect
6+
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/9a7f49eb8ed1ea9722ebec95f4befa0e/redirect
7+
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/2a0209399b0a7928a6e5fc680e1c0d35/redirect
8+
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/ff8d269e2495c538cfa04b4b52d22286/redirect
9+
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/4dfe7aab2abf71db71537e9dca36c154/redirect
10+
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7a3c43a8ed30b293ba959c80ccf2a757/redirect
11+
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/a5678544b69a5c533a76c11213c7b7ed/redirect
12+
toolchainVersion=17
42.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)