diff options
Diffstat (limited to 'z3/subprojects/solver/build.gradle.kts')
-rw-r--r-- | z3/subprojects/solver/build.gradle.kts | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/z3/subprojects/solver/build.gradle.kts b/z3/subprojects/solver/build.gradle.kts new file mode 100644 index 00000000..7e898b3e --- /dev/null +++ b/z3/subprojects/solver/build.gradle.kts | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: Apache-2.0 | ||
5 | */ | ||
6 | |||
7 | import tools.refinery.z3.gradle.ClassFilePatcher | ||
8 | |||
9 | plugins { | ||
10 | id("tools.refinery.z3.gradle.java-library") | ||
11 | } | ||
12 | |||
13 | val classifier = "z3-${version}-x64-glibc-2.31" | ||
14 | val extractedClassesDir = layout.buildDirectory.dir("z3-extracted") | ||
15 | val extractedSourcesDir = layout.buildDirectory.dir("z3-sources") | ||
16 | |||
17 | java { | ||
18 | withJavadocJar() | ||
19 | withSourcesJar() | ||
20 | } | ||
21 | |||
22 | val z3Source: Configuration by configurations.creating { | ||
23 | isCanBeConsumed = false | ||
24 | isCanBeResolved = true | ||
25 | } | ||
26 | |||
27 | val extractZ3Jar by tasks.registering(Sync::class) { | ||
28 | dependsOn(configurations.z3) | ||
29 | from({ | ||
30 | val zipFile = configurations.z3.map { it.singleFile } | ||
31 | val jarFile = zipTree(zipFile).matching { | ||
32 | include("${classifier}/bin/com.microsoft.z3.jar") | ||
33 | }.singleFile | ||
34 | zipTree(jarFile).matching { | ||
35 | exclude("META-INF/MANIFEST.MF") | ||
36 | includeEmptyDirs = false | ||
37 | } | ||
38 | }) | ||
39 | into(extractedClassesDir) | ||
40 | doLast { | ||
41 | // The class initializer off {@see com.microsoft.z3.Native} will try to load the Z3 native libraries | ||
42 | // from the system default library path unless the {@code z3.skipLibraryLoad} system property is set. | ||
43 | // Since we don't control the library path or system properties, we remove the class initializer entirely. | ||
44 | val nativeClassFile = extractedClassesDir.get().file("com/microsoft/z3/Native.class").asFile | ||
45 | ClassFilePatcher.removeClassInitializer(nativeClassFile) | ||
46 | } | ||
47 | } | ||
48 | |||
49 | val extractZ3Source by tasks.registering(Sync::class) { | ||
50 | dependsOn(z3Source) | ||
51 | from({ | ||
52 | val zipFile = z3Source.singleFile | ||
53 | zipTree(zipFile).matching { | ||
54 | include("z3-z3-${version}/src/api/java/**/*") | ||
55 | includeEmptyDirs = false | ||
56 | } | ||
57 | }) | ||
58 | eachFile { | ||
59 | val pathInBin = relativePath.segments.drop(4).toTypedArray() | ||
60 | relativePath = RelativePath(true, "com", "microsoft", "z3", *pathInBin) | ||
61 | } | ||
62 | into(extractedSourcesDir) | ||
63 | } | ||
64 | |||
65 | tasks.jar { | ||
66 | // Add class files to our jar manually. | ||
67 | from(extractZ3Jar) | ||
68 | } | ||
69 | |||
70 | tasks.test { | ||
71 | useJUnitPlatform() | ||
72 | } | ||
73 | |||
74 | tasks.named<Jar>("sourcesJar") { | ||
75 | from(extractZ3Source) | ||
76 | } | ||
77 | |||
78 | tasks.named<Javadoc>("javadoc") { | ||
79 | source(sourceSets.main.map { it.allJava }) | ||
80 | source(fileTree(extractedSourcesDir) { | ||
81 | builtBy(extractZ3Source) | ||
82 | include("**/*.java") | ||
83 | }) | ||
84 | options { | ||
85 | this as StandardJavadocDocletOptions | ||
86 | addBooleanOption("Xdoclint:none", true) | ||
87 | // {@code -Xmaxwarns 0} will print all warnings, so we must keep at least one. | ||
88 | addStringOption("Xmaxwarns", "1") | ||
89 | quiet() | ||
90 | } | ||
91 | } | ||
92 | |||
93 | dependencies { | ||
94 | z3("Z3Prover:z3:${version}:${classifier}@zip") | ||
95 | z3Source("Z3Prover:z3:${version}@zip") | ||
96 | // This dependency doesn't get added to Maven metadata, so we have to add the class files to our jar manually. | ||
97 | api(files(extractZ3Jar)) | ||
98 | implementation(libs.jna) | ||
99 | implementation(project(":refinery-z3-solver-darwin-aarch64")) | ||
100 | implementation(project(":refinery-z3-solver-darwin-x86-64")) | ||
101 | implementation(project(":refinery-z3-solver-linux-aarch64")) | ||
102 | implementation(project(":refinery-z3-solver-linux-x86-64")) | ||
103 | implementation(project(":refinery-z3-solver-win32-x86-64")) | ||
104 | testImplementation(libs.junit.api) | ||
105 | testRuntimeOnly(libs.junit.engine) | ||
106 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") | ||
107 | } | ||