forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
110 lines (89 loc) · 3.21 KB
/
build.gradle
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
//===----------------------------------------------------------------------===//
//
// 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
plugins {
id("build-logic.java-application-conventions")
}
group = "org.swift.swiftkit"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(22))
}
}
sourceSets {
generated {
java.srcDir "${buildDir}/generated/src/java/"
}
// Make the 'main' and 'test' source sets depend on the generated sources
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
dependencies {
implementation(project(':SwiftKit'))
generatedImplementation(project(':SwiftKit'))
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
configurations {
generatedImplementation.extendsFrom(mainImplementation)
generatedRuntimeOnly.extendsFrom(mainRuntimeOnly)
}
tasks.named("compileJava").configure {
dependsOn("jextract")
}
tasks.test {
useJUnitPlatform()
}
application {
mainClass = "com.example.swift.HelloJava2Swift"
// In order to silence:
// WARNING: A restricted method in java.lang.foreign.SymbolLookup has been called
// WARNING: java.lang.foreign.SymbolLookup::libraryLookup has been called by org.example.swift.JavaKitExample in an unnamed module
// WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
// WARNING: Restricted methods will be blocked in a future release unless native access is enabled
// FIXME: Find out the proper solution to this
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().join(":"),
// Enable tracing downcalls (to Swift)
"-Djextract.trace.downcalls=true"
]
}
task jextract(type: Exec) {
description = "Extracts Java accessor sources using jextract"
outputs.dir(layout.buildDirectory.dir("generated"))
inputs.dir("$rootDir/Sources/ExampleSwiftLibrary") // monitored library
// any changes in the source generator sources also mean the resulting output might change
inputs.dir("$rootDir/Sources/JExtractSwift")
inputs.dir("$rootDir/Sources/JExtractSwiftTool")
workingDir = rootDir
commandLine "make"
args "jextract-generate"
}
tasks.named("compileGeneratedJava").configure {
dependsOn jextract
}