|
2 | 2 | // SPDX-FileCopyrightText: Copyright the Vortex contributors |
3 | 3 |
|
4 | 4 | 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 |
6 | 7 |
|
7 | 8 | plugins { |
8 | 9 | `java-library` |
@@ -111,51 +112,52 @@ tasks.build { |
111 | 112 | dependsOn("shadowJar") |
112 | 113 | } |
113 | 114 |
|
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" |
116 | 152 | group = "verification" |
117 | 153 |
|
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). |
121 | 154 | onlyIf { System.getenv("VORTEX_SKIP_MAKE_TEST_FILES") != "true" } |
| 155 | + dependsOn(buildJniLibrary) |
122 | 156 |
|
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) |
159 | 161 | } |
160 | 162 |
|
161 | 163 | tasks.named("processResources").configure { |
|
0 commit comments