forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
165 lines (132 loc) · 4.71 KB
/
build.gradle
File metadata and controls
165 lines (132 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import org.swift.swiftkit.gradle.BuildUtils
import java.nio.file.*
plugins {
id("build-logic.java-application-conventions")
id("me.champeau.jmh") version "0.7.2"
}
group = "org.swift.swiftkit"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(22))
}
}
// This is for development, when we edit the Swift swift-java project, the outputs of the generated sources may change.
// Thus, we also need to watch and re-build the top level project.
def compileSwiftJExtractPlugin = tasks.register("compileSwiftJExtractPlugin", Exec) {
description = "Rebuild the swift-java root project"
inputs.file(new File(rootDir, "Package.swift"))
inputs.dir(new File(rootDir, "Sources"))
outputs.dir(new File(rootDir, ".build"))
workingDir = rootDir
commandLine "swift"
args("build",
"--product", "SwiftKitSwift",
"--product", "JExtractSwiftPlugin",
"--product", "JExtractSwiftCommandPlugin")
}
def jextract = tasks.register("jextract", Exec) {
description = "Builds swift sources, including swift-java source generation"
dependsOn compileSwiftJExtractPlugin
// only because we depend on "live developing" the plugin while using this project to test it
inputs.file(new File(rootDir, "Package.swift"))
inputs.dir(new File(rootDir, "Sources"))
inputs.file(new File(projectDir, "Package.swift"))
inputs.dir(new File(projectDir, "Sources"))
// TODO: we can use package describe --type json to figure out which targets depend on JExtractSwiftPlugin and will produce outputs
// Avoid adding this directory, but create the expected one specifically for all targets
// which WILL produce sources because they have the plugin
outputs.dir(layout.buildDirectory.dir("../.build/plugins/outputs/${layout.projectDirectory.asFile.getName().toLowerCase()}"))
File baseSwiftPluginOutputsDir = layout.buildDirectory.dir("../.build/plugins/outputs/").get().asFile
if (!baseSwiftPluginOutputsDir.exists()) {
baseSwiftPluginOutputsDir.mkdirs()
}
Files.walk(layout.buildDirectory.dir("../.build/plugins/outputs/").get().asFile.toPath()).each {
// Add any Java sources generated by the plugin to our sourceSet
if (it.endsWith("JExtractSwiftPlugin/src/generated/java")) {
outputs.dir(it)
}
}
workingDir = layout.projectDirectory
commandLine "swift"
args("package", "jextract", "-v", "--log-level", "debug") // TODO: pass log level from Gradle build
}
// Add the java-swift generated Java sources
sourceSets {
main {
java {
srcDir(jextract)
}
}
test {
java {
srcDir(jextract)
}
}
jmh {
java {
srcDir(jextract)
}
}
}
tasks.build {
dependsOn("jextract")
}
def cleanSwift = tasks.register("cleanSwift", Exec) {
workingDir = layout.projectDirectory
commandLine "swift"
args("package", "clean")
}
tasks.clean {
dependsOn("cleanSwift")
}
dependencies {
implementation(project(':SwiftKit'))
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
tasks.named('test', Test) {
useJUnitPlatform()
}
application {
mainClass = "com.example.swift.HelloJava2Swift"
applicationDefaultJvmArgs = [
"--enable-native-access=ALL-UNNAMED",
// Include the library paths where our dylibs are that we want to load and call
"-Djava.library.path=" +
(BuildUtils.javaLibraryPaths(rootDir) +
BuildUtils.javaLibraryPaths(project.projectDir)).join(":"),
// Enable tracing downcalls (to Swift)
"-Djextract.trace.downcalls=true"
]
}
String jmhIncludes = findProperty("jmhIncludes")
jmh {
if (jmhIncludes != null) {
includes = [jmhIncludes]
}
jvmArgsAppend = [
"--enable-native-access=ALL-UNNAMED",
"-Djava.library.path=" +
(BuildUtils.javaLibraryPaths(rootDir) +
BuildUtils.javaLibraryPaths(project.projectDir)).join(":"),
// Enable tracing downcalls (to Swift)
"-Djextract.trace.downcalls=false"
]
}