Skip to content

Commit 86ee639

Browse files
committed
Configure jvm-ir-for-test: track build.gradle.kts and stubs, ignore artifacts
1 parent f0304a8 commit 86ee639

File tree

4 files changed

+394
-0
lines changed

4 files changed

+394
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ kotlin-ide/
6666
.claude/local.md
6767
.claude/CLAUDE.md
6868
libraries/stdlib/jvm-ir-for-test/
69+
libraries/stdlib/jvm-ir-for-test/*
70+
!libraries/stdlib/jvm-ir-for-test/build.gradle.kts
71+
!libraries/stdlib/jvm-ir-for-test/src/
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
description = "Kotlin JVM IR Stdlib for Tests"
2+
3+
plugins {
4+
kotlin("jvm")
5+
base
6+
}
7+
8+
project.configureJvmToolchain(JdkMajorVersion.JDK_1_8)
9+
10+
val stdlibProjectDir = file("$rootDir/libraries/stdlib")
11+
12+
13+
dependencies {
14+
implementation(project(":compiler:cli-jklib"))
15+
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) {
16+
isTransitive = false
17+
}
18+
implementation(intellijCore())
19+
implementation(libs.intellij.fastutil)
20+
implementation(commonDependency("org.codehaus.woodstox:stax2-api"))
21+
implementation(commonDependency("com.fasterxml:aalto-xml"))
22+
}
23+
24+
val copySources by tasks.registering(Sync::class) {
25+
dependsOn(":prepare:build.version:writeStdlibVersion")
26+
into(layout.buildDirectory.dir("src/genesis-all"))
27+
28+
// Common Sources
29+
from(stdlibProjectDir.resolve("common/src")) {
30+
include("**/*")
31+
into("common/common")
32+
}
33+
from(stdlibProjectDir.resolve("src")) {
34+
include("**/*")
35+
into("common/src")
36+
}
37+
from(stdlibProjectDir.resolve("unsigned/src")) {
38+
include("**/*")
39+
into("common/unsigned")
40+
}
41+
42+
// JVM Sources
43+
from(stdlibProjectDir.resolve("jvm/src")) {
44+
include("**/*")
45+
into("jvm/src")
46+
}
47+
from(stdlibProjectDir.resolve("jvm/runtime")) {
48+
include("**/*")
49+
exclude("kotlin/jvm/functions/Functions.kt")
50+
into("jvm/runtime")
51+
}
52+
from(stdlibProjectDir.resolve("jvm/builtins")) {
53+
include("**/*")
54+
into("jvm/builtins")
55+
}
56+
from(stdlibProjectDir.resolve("jvm/compileOnly")) {
57+
include("**/*")
58+
into("jvm/compileOnly")
59+
}
60+
61+
// Stub Sources
62+
from(project.file("src/stubs")) {
63+
include("**/*")
64+
into("jvm/stubs")
65+
}
66+
67+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
68+
}
69+
70+
val outputKlib = layout.buildDirectory.file("libs/kotlin-stdlib-jvm-ir.klib")
71+
72+
// Helper to separate Java compilation
73+
fun createJavaCompilationTask(sourceTask: TaskProvider<Sync>): TaskProvider<Jar> {
74+
val variantName = sourceTask.name.replaceFirstChar { it.uppercase() }
75+
val javaCompileName = "compileJava${variantName}"
76+
val jarName = "jarJava${variantName}"
77+
78+
// Use 'project' to ensure we are targeting the project's task container
79+
// strictly speaking 'tasks.register' at script level targets the project's tasks
80+
val javaCompileTask = tasks.register(javaCompileName, JavaCompile::class) {
81+
dependsOn(sourceTask)
82+
source = fileTree(sourceTask.map { it.destinationDir }) {
83+
include("**/*.java")
84+
}
85+
destinationDirectory.set(layout.buildDirectory.dir("classes/java/$variantName"))
86+
// Resolve dependencies for Java compilation
87+
val runtimeClasspath = project.configurations.getByName("runtimeClasspath")
88+
// We add the full runtime classpath to satisfy dependencies like kotlin-reflect and annotations
89+
classpath = runtimeClasspath
90+
91+
sourceCompatibility = "1.8"
92+
targetCompatibility = "1.8"
93+
options.compilerArgs.add("-Xlint:-options")
94+
options.compilerArgs.add("-Xlint:-deprecation")
95+
options.compilerArgs.add("-Xlint:none")
96+
options.compilerArgs.add("-nowarn")
97+
98+
// Remove -Werror if present to allow build to pass with warnings
99+
options.compilerArgs.remove("-Werror")
100+
options.compilerArgs.remove("-Xwerror")
101+
options.isDeprecation = false
102+
options.isWarnings = false
103+
}
104+
105+
return tasks.register(jarName, Jar::class) {
106+
from(javaCompileTask.map { it.destinationDirectory })
107+
archiveFileName.set("kotlin-stdlib-java-$variantName.jar")
108+
destinationDirectory.set(layout.buildDirectory.dir("libs"))
109+
}
110+
}
111+
112+
val jarJava = createJavaCompilationTask(copySources)
113+
114+
fun JavaExec.configureJklibCompilation(
115+
sourceTask: TaskProvider<Sync>,
116+
klibOutput: Provider<RegularFile>,
117+
classpathJar: Provider<RegularFile>
118+
) {
119+
dependsOn(sourceTask)
120+
121+
// Add dependency on the jar task to ensure it's built
122+
dependsOn(classpathJar)
123+
124+
// Use the standard runtime classpath from the 'main' source set
125+
classpath = sourceSets["main"].runtimeClasspath
126+
mainClass.set("org.jetbrains.kotlin.cli.jklib.K2JKlibCompiler")
127+
128+
// Inputs/Outputs for incremental build
129+
val inputDir = sourceTask.map { it.destinationDir }
130+
val sourceTree = fileTree(inputDir) {
131+
include("**/*")
132+
}
133+
inputs.files(sourceTree)
134+
135+
// Add Jar as input
136+
inputs.file(classpathJar)
137+
138+
outputs.file(klibOutput)
139+
140+
val runtimeClasspath = project.configurations.getByName("runtimeClasspath")
141+
// Capture the file collection at configuration time, but map it to value at execution if needed,
142+
// or just pass the file collection to inputs to be safe.
143+
// Actually, simple way: filter it now.
144+
val kotlinReflectFileCollection = runtimeClasspath.filter { it.name.startsWith("kotlin-reflect") }
145+
146+
// Add to inputs
147+
inputs.files(kotlinReflectFileCollection)
148+
149+
doFirst {
150+
val allFiles = inputs.files.files.filter { it.extension == "kt" }
151+
val jvmFiles = allFiles.filter { it.path.contains("/jvm/") }
152+
val commonFiles = allFiles.filter { it.path.contains("/common/")}
153+
154+
val jvmSourceFiles = jvmFiles.map { it.absolutePath }
155+
val commonSourceFiles = commonFiles.map { it.absolutePath }
156+
157+
logger.lifecycle("Compiling ${jvmSourceFiles.size} JVM files and ${commonSourceFiles.size} Common files, total ${allFiles.size}")
158+
159+
val outputPath = outputs.files.singleFile.absolutePath
160+
161+
args(
162+
"-no-stdlib",
163+
"-Xallow-kotlin-package",
164+
"-Xexpect-actual-classes",
165+
"-module-name", "kotlin-stdlib",
166+
"-language-version", "2.3",
167+
"-api-version", "2.3",
168+
"-Xstdlib-compilation",
169+
"-d", outputPath,
170+
"-Xmulti-platform",
171+
"-opt-in=kotlin.contracts.ExperimentalContracts",
172+
"-opt-in=kotlin.ExperimentalMultiplatform",
173+
"-opt-in=kotlin.contracts.ExperimentalExtendedContracts",
174+
"-Xcontext-parameters",
175+
"-Xcompile-builtins-as-part-of-stdlib",
176+
"-Xreturn-value-checker=full",
177+
"-Xcommon-sources=${(commonSourceFiles).joinToString(",")}",
178+
"-Xoutput-builtins-metadata",
179+
)
180+
181+
// Add separate Java compilation output and kotlin-reflect to classpath
182+
val kotlinReflectJar = kotlinReflectFileCollection.singleOrNull()
183+
val fullClasspath = listOfNotNull(
184+
classpathJar.get().asFile.absolutePath,
185+
kotlinReflectJar?.absolutePath
186+
).joinToString(File.pathSeparator)
187+
188+
args("-classpath", fullClasspath)
189+
190+
args(jvmSourceFiles)
191+
args(commonSourceFiles)
192+
}
193+
}
194+
195+
val compileStdlib by tasks.registering(JavaExec::class) {
196+
configureJklibCompilation(copySources, outputKlib, jarJava.flatMap { it.archiveFile })
197+
}
198+
199+
// Expose the KLIB artifact
200+
val distJKlib by configurations.creating {
201+
isCanBeConsumed = true
202+
isCanBeResolved = false
203+
}
204+
205+
artifacts {
206+
add(distJKlib.name, outputKlib) {
207+
builtBy(compileStdlib)
208+
}
209+
add(distJKlib.name, jarJava)
210+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
// Auto-generated file. DO NOT EDIT!
7+
// Generated by: org.jetbrains.kotlin.generators.builtins.functions.GenerateFunctions
8+
9+
package kotlin
10+
11+
public interface Function<out R>
12+
13+
/** A function that takes 0 arguments. */
14+
public interface Function0<out R> : Function<R> {
15+
/** Invokes the function. */
16+
public operator fun invoke(): R
17+
}
18+
/** A function that takes 1 argument. */
19+
public interface Function1<in P1, out R> : Function<R> {
20+
/** Invokes the function with the specified argument. */
21+
public operator fun invoke(p1: P1): R
22+
}
23+
/** A function that takes 2 arguments. */
24+
public interface Function2<in P1, in P2, out R> : Function<R> {
25+
/** Invokes the function with the specified arguments. */
26+
public operator fun invoke(p1: P1, p2: P2): R
27+
}
28+
/** A function that takes 3 arguments. */
29+
public interface Function3<in P1, in P2, in P3, out R> : Function<R> {
30+
/** Invokes the function with the specified arguments. */
31+
public operator fun invoke(p1: P1, p2: P2, p3: P3): R
32+
}
33+
/** A function that takes 4 arguments. */
34+
public interface Function4<in P1, in P2, in P3, in P4, out R> : Function<R> {
35+
/** Invokes the function with the specified arguments. */
36+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
37+
}
38+
/** A function that takes 5 arguments. */
39+
public interface Function5<in P1, in P2, in P3, in P4, in P5, out R> : Function<R> {
40+
/** Invokes the function with the specified arguments. */
41+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R
42+
}
43+
/** A function that takes 6 arguments. */
44+
public interface Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> : Function<R> {
45+
/** Invokes the function with the specified arguments. */
46+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R
47+
}
48+
/** A function that takes 7 arguments. */
49+
public interface Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> : Function<R> {
50+
/** Invokes the function with the specified arguments. */
51+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R
52+
}
53+
/** A function that takes 8 arguments. */
54+
public interface Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> : Function<R> {
55+
/** Invokes the function with the specified arguments. */
56+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R
57+
}
58+
/** A function that takes 9 arguments. */
59+
public interface Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> : Function<R> {
60+
/** Invokes the function with the specified arguments. */
61+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R
62+
}
63+
/** A function that takes 10 arguments. */
64+
public interface Function10<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> : Function<R> {
65+
/** Invokes the function with the specified arguments. */
66+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R
67+
}
68+
/** A function that takes 11 arguments. */
69+
public interface Function11<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> : Function<R> {
70+
/** Invokes the function with the specified arguments. */
71+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R
72+
}
73+
/** A function that takes 12 arguments. */
74+
public interface Function12<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> : Function<R> {
75+
/** Invokes the function with the specified arguments. */
76+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R
77+
}
78+
/** A function that takes 13 arguments. */
79+
public interface Function13<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> : Function<R> {
80+
/** Invokes the function with the specified arguments. */
81+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R
82+
}
83+
/** A function that takes 14 arguments. */
84+
public interface Function14<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> : Function<R> {
85+
/** Invokes the function with the specified arguments. */
86+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R
87+
}
88+
/** A function that takes 15 arguments. */
89+
public interface Function15<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> : Function<R> {
90+
/** Invokes the function with the specified arguments. */
91+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R
92+
}
93+
/** A function that takes 16 arguments. */
94+
public interface Function16<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> : Function<R> {
95+
/** Invokes the function with the specified arguments. */
96+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R
97+
}
98+
/** A function that takes 17 arguments. */
99+
public interface Function17<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> : Function<R> {
100+
/** Invokes the function with the specified arguments. */
101+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R
102+
}
103+
/** A function that takes 18 arguments. */
104+
public interface Function18<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> : Function<R> {
105+
/** Invokes the function with the specified arguments. */
106+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R
107+
}
108+
/** A function that takes 19 arguments. */
109+
public interface Function19<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> : Function<R> {
110+
/** Invokes the function with the specified arguments. */
111+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R
112+
}
113+
/** A function that takes 20 arguments. */
114+
public interface Function20<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> : Function<R> {
115+
/** Invokes the function with the specified arguments. */
116+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R
117+
}
118+
/** A function that takes 21 arguments. */
119+
public interface Function21<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> : Function<R> {
120+
/** Invokes the function with the specified arguments. */
121+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R
122+
}
123+
/** A function that takes 22 arguments. */
124+
public interface Function22<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> : Function<R> {
125+
/** Invokes the function with the specified arguments. */
126+
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R
127+
}

0 commit comments

Comments
 (0)