[Wasm] Add box and stdlib tests in wasi mode
This commit is contained in:
committed by
Zalim Bashorov
parent
f42d0b1ed4
commit
983991d46c
@@ -19,6 +19,7 @@ enum class TargetBackend(
|
||||
JS_IR(true, JS),
|
||||
JS_IR_ES6(true, JS_IR),
|
||||
WASM(true),
|
||||
WASM_WASI(true),
|
||||
ANDROID(false, JVM),
|
||||
ANDROID_IR(true, JVM_IR),
|
||||
NATIVE(true),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
+8
-2
@@ -344,10 +344,16 @@ class ClassicFrontendFacade(
|
||||
dependencyDescriptors: List<ModuleDescriptor>,
|
||||
friendsDescriptors: List<ModuleDescriptor>,
|
||||
): AnalysisResult {
|
||||
val suffix = when (configuration.get(JSConfigurationKeys.WASM_TARGET, WasmTarget.JS)) {
|
||||
WasmTarget.JS -> "-js"
|
||||
WasmTarget.WASI -> "-wasi"
|
||||
else -> error("Unexpected wasi target")
|
||||
}
|
||||
|
||||
val runtimeKlibsNames =
|
||||
listOfNotNull(
|
||||
System.getProperty("kotlin.wasm.stdlib.path")!!,
|
||||
System.getProperty("kotlin.wasm.kotlin.test.path")!!
|
||||
System.getProperty("kotlin.wasm$suffix.stdlib.path")!!,
|
||||
System.getProperty("kotlin.wasm$suffix.kotlin.test.path")!!
|
||||
).map {
|
||||
File(it).absolutePath
|
||||
}
|
||||
|
||||
+5
-1
@@ -30,6 +30,8 @@ import org.jetbrains.kotlin.fir.session.FirJvmSessionFactory
|
||||
import org.jetbrains.kotlin.fir.session.FirNativeSessionFactory
|
||||
import org.jetbrains.kotlin.fir.session.FirSessionConfigurator
|
||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.js.config.WasmTarget
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageAndMetadataPartProvider
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -419,7 +421,9 @@ open class FirFrontendFacade(
|
||||
friendDependencies(friendLibraries.map { it.toPath().toAbsolutePath() })
|
||||
}
|
||||
targetPlatform.isWasm() -> {
|
||||
val runtimeKlibsPaths = WasmEnvironmentConfigurator.getRuntimePathsForModule()
|
||||
val runtimeKlibsPaths = WasmEnvironmentConfigurator.getRuntimePathsForModule(
|
||||
configuration.get(JSConfigurationKeys.WASM_TARGET, WasmTarget.JS)
|
||||
)
|
||||
val (transitiveLibraries, friendLibraries) = getTransitivesAndFriends(mainModule, testServices)
|
||||
dependencies(runtimeKlibsPaths.map { Paths.get(it).toAbsolutePath() })
|
||||
dependencies(transitiveLibraries.map { it.toPath().toAbsolutePath() })
|
||||
|
||||
+25
-6
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.fir.session.FirSessionConfigurator
|
||||
import org.jetbrains.kotlin.fir.session.FirWasmSessionFactory
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.ir.backend.js.resolverLogger
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.js.config.WasmTarget
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.test.model.DependencyRelation
|
||||
@@ -36,7 +38,11 @@ object TestFirWasmSessionFactory {
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
registerExtraComponents: ((FirSession) -> Unit),
|
||||
): FirSession {
|
||||
val resolvedLibraries = resolveLibraries(configuration, getAllWasmDependenciesPaths(module, testServices))
|
||||
val target = configuration.get(JSConfigurationKeys.WASM_TARGET, WasmTarget.JS)
|
||||
val resolvedLibraries = resolveLibraries(
|
||||
configuration = configuration,
|
||||
paths = getAllWasmDependenciesPaths(module, testServices, target)
|
||||
)
|
||||
|
||||
return FirWasmSessionFactory.createLibrarySession(
|
||||
mainModuleName,
|
||||
@@ -72,16 +78,29 @@ fun resolveWasmLibraries(
|
||||
testServices: TestServices,
|
||||
configuration: CompilerConfiguration
|
||||
): List<KotlinResolvedLibrary> {
|
||||
return resolveLibraries(configuration, getAllWasmDependenciesPaths(module, testServices))
|
||||
val paths = getAllWasmDependenciesPaths(
|
||||
module = module,
|
||||
testServices = testServices,
|
||||
target = configuration.get(JSConfigurationKeys.WASM_TARGET, WasmTarget.JS)
|
||||
)
|
||||
return resolveLibraries(configuration, paths)
|
||||
}
|
||||
|
||||
fun getAllWasmDependenciesPaths(module: TestModule, testServices: TestServices): List<String> {
|
||||
val (runtimeKlibsPaths, transitiveLibraries, friendLibraries) = getWasmDependencies(module, testServices)
|
||||
fun getAllWasmDependenciesPaths(
|
||||
module: TestModule,
|
||||
testServices: TestServices,
|
||||
target: WasmTarget,
|
||||
): List<String> {
|
||||
val (runtimeKlibsPaths, transitiveLibraries, friendLibraries) = getWasmDependencies(module, testServices, target)
|
||||
return runtimeKlibsPaths + transitiveLibraries.map { it.path } + friendLibraries.map { it.path }
|
||||
}
|
||||
|
||||
fun getWasmDependencies(module: TestModule, testServices: TestServices): Triple<List<String>, List<File>, List<File>> {
|
||||
val runtimeKlibsPaths = WasmEnvironmentConfigurator.getRuntimePathsForModule()
|
||||
fun getWasmDependencies(
|
||||
module: TestModule,
|
||||
testServices: TestServices,
|
||||
target: WasmTarget,
|
||||
): Triple<List<String>, List<File>, List<File>> {
|
||||
val runtimeKlibsPaths = WasmEnvironmentConfigurator.getRuntimePathsForModule(target)
|
||||
val transitiveLibraries = WasmEnvironmentConfigurator.getKlibDependencies(module, testServices, DependencyRelation.RegularDependency)
|
||||
val friendLibraries = WasmEnvironmentConfigurator.getKlibDependencies(module, testServices, DependencyRelation.FriendDependency)
|
||||
return Triple(runtimeKlibsPaths, transitiveLibraries, friendLibraries)
|
||||
|
||||
+22
-3
@@ -33,15 +33,34 @@ import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import java.io.File
|
||||
|
||||
class WasmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||
class WasmEnvironmentConfiguratorJs(testServices: TestServices) : WasmEnvironmentConfigurator(testServices) {
|
||||
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
||||
super.configureCompilerConfiguration(configuration, module)
|
||||
configuration.put(JSConfigurationKeys.WASM_TARGET, WasmTarget.JS)
|
||||
}
|
||||
}
|
||||
|
||||
class WasmEnvironmentConfiguratorWasi(testServices: TestServices) : WasmEnvironmentConfigurator(testServices) {
|
||||
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
||||
super.configureCompilerConfiguration(configuration, module)
|
||||
configuration.put(JSConfigurationKeys.WASM_TARGET, WasmTarget.WASI)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class WasmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
get() = listOf(WasmEnvironmentConfigurationDirectives)
|
||||
|
||||
companion object {
|
||||
private const val OUTPUT_KLIB_DIR_NAME = "outputKlibDir"
|
||||
|
||||
fun getRuntimePathsForModule(): List<String> {
|
||||
return listOf(System.getProperty("kotlin.wasm.stdlib.path")!!, System.getProperty("kotlin.wasm.kotlin.test.path")!!)
|
||||
fun getRuntimePathsForModule(target: WasmTarget): List<String> {
|
||||
val suffix = when (target) {
|
||||
WasmTarget.JS -> "-js"
|
||||
WasmTarget.WASI -> "-wasi"
|
||||
else -> error("Unexpected wasi target")
|
||||
}
|
||||
return listOf(System.getProperty("kotlin.wasm$suffix.stdlib.path")!!, System.getProperty("kotlin.wasm$suffix.kotlin.test.path")!!)
|
||||
}
|
||||
|
||||
fun getKlibDependencies(module: TestModule, testServices: TestServices, kind: DependencyRelation): List<File> {
|
||||
|
||||
Reference in New Issue
Block a user