Skip to content

Commit 30fff30

Browse files
authored
Reduce Java and vortex-jni build sizes (#8734)
## Rationale for this change Part of my on-going war to try and reduce the size of our builds. 1. Only copy the libvortex_jni binary when it actually changed 2. No need to build it as a staticlib, which is very big --------- Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 371c984 commit 30fff30

2 files changed

Lines changed: 45 additions & 43 deletions

File tree

java/vortex-jni/build.gradle.kts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
5-
import org.gradle.kotlin.dsl.support.serviceOf
5+
import org.gradle.api.tasks.Copy
6+
import org.gradle.api.tasks.Exec
67

78
plugins {
89
`java-library`
@@ -111,51 +112,52 @@ tasks.build {
111112
dependsOn("shadowJar")
112113
}
113114

114-
tasks.register("makeTestFiles") {
115-
description = "Generate files used by unit tests"
115+
val rustWorkspaceDir = rootProject.projectDir.absoluteFile.parentFile
116+
val osName = System.getProperty("os.name").lowercase()
117+
val osArch = System.getProperty("os.arch").lowercase()
118+
val osShortName =
119+
when {
120+
osName.contains("mac") -> "darwin"
121+
osName.contains("nix") || osName.contains("nux") -> "linux"
122+
osName.contains("win") -> "win"
123+
else -> throw GradleException("Unsupported OS for makeTestFiles: $osName")
124+
}
125+
val libExt =
126+
when (osShortName) {
127+
"darwin" -> ".dylib"
128+
"linux" -> ".so"
129+
"win" -> ".dll"
130+
else -> throw GradleException("Unsupported OS short name: $osShortName")
131+
}
132+
val nativeLibrary = rustWorkspaceDir.resolve("target/debug/libvortex_jni$libExt")
133+
val nativeLibraryDir = "src/main/resources/native/$osShortName-$osArch"
134+
135+
val buildJniLibrary =
136+
tasks.register<Exec>("buildJniLibrary") {
137+
description = "Build the JNI library for the host architecture"
138+
group = "verification"
139+
140+
// The publish workflow places release, cross-compiled libs for every supported
141+
// architecture before invoking shadowJar; rebuilding the host-arch debug lib
142+
// here would overwrite them (linux-aarch64 ends up holding a linux-amd64 .so).
143+
onlyIf { System.getenv("VORTEX_SKIP_MAKE_TEST_FILES") != "true" }
144+
145+
workingDir = rustWorkspaceDir
146+
executable = "cargo"
147+
args("build", "--package", "vortex-jni")
148+
}
149+
150+
tasks.register<Copy>("makeTestFiles") {
151+
description = "Stage the JNI library used by unit tests"
116152
group = "verification"
117153

118-
// The publish workflow places release, cross-compiled libs for every supported
119-
// architecture before invoking shadowJar; rebuilding the host-arch debug lib
120-
// here would overwrite them (linux-aarch64 ends up holding a linux-amd64 .so).
121154
onlyIf { System.getenv("VORTEX_SKIP_MAKE_TEST_FILES") != "true" }
155+
dependsOn(buildJniLibrary)
122156

123-
doLast {
124-
println("makeTestFiles executed")
125-
126-
val execOps = serviceOf<ExecOperations>()
127-
128-
// Build the JNI lib for the host architecture only.
129-
execOps.exec {
130-
workingDir = rootProject.projectDir.absoluteFile.parentFile
131-
executable = "cargo"
132-
args("build", "--package", "vortex-jni")
133-
}
134-
135-
val osName = System.getProperty("os.name").lowercase()
136-
val osArch = System.getProperty("os.arch").lowercase()
137-
val osShortName =
138-
when {
139-
osName.contains("mac") -> "darwin"
140-
osName.contains("nix") || osName.contains("nux") -> "linux"
141-
osName.contains("win") -> "win"
142-
else -> throw GradleException("Unsupported OS for makeTestFiles: $osName")
143-
}
144-
val libExt =
145-
when (osShortName) {
146-
"darwin" -> ".dylib"
147-
"linux" -> ".so"
148-
"win" -> ".dll"
149-
else -> throw GradleException("Unsupported OS short name: $osShortName")
150-
}
151-
152-
// Only populate the host-arch directory so cross-compiled libs for other
153-
// architectures (placed by the publish workflow) are preserved.
154-
copy {
155-
from("${rootProject.projectDir.absoluteFile.parentFile}/target/debug/libvortex_jni$libExt")
156-
into("$projectDir/src/main/resources/native/$osShortName-$osArch")
157-
}
158-
}
157+
// Only populate the host-arch directory so cross-compiled libs for other
158+
// architectures (placed by the publish workflow) are preserved.
159+
from(nativeLibrary)
160+
into(nativeLibraryDir)
159161
}
160162

161163
tasks.named("processResources").configure {

vortex-jni/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vortex-parquet-variant = { workspace = true }
3636
jni = { workspace = true, features = ["invocation"] }
3737

3838
[lib]
39-
crate-type = ["staticlib", "cdylib"]
39+
crate-type = ["cdylib"]
4040

4141
[lints]
4242
workspace = true

0 commit comments

Comments
 (0)