Commit 4a1a4b90 authored by zhen.jiang's avatar zhen.jiang

增加项目配置开启DebugInfo的垃圾回收和压缩

parent 3112139d
......@@ -10923,6 +10923,37 @@
"deprecatedVersion": null,
"removedVersion": null
}
},
{
"name": "Xnative-debuginfo-gc-compress",
"shortName": null,
"deprecatedName": null,
"description": {
"current": "Value of kotlin.native.debuginfo.gc-compress from gradle.properties (single option, no per-target).",
"valueInVersions": []
},
"delimiter": null,
"valueType": {
"type": "org.jetbrains.kotlin.arguments.dsl.types.StringType",
"isNullable": {
"current": true,
"valueInVersions": []
},
"defaultValue": {
"current": null,
"valueInVersions": []
}
},
"valueDescription": {
"current": "<value>",
"valueInVersions": []
},
"releaseVersionsMetadata": {
"introducedVersion": "2.2.0",
"stabilizedVersion": null,
"deprecatedVersion": null,
"removedVersion": null
}
}
],
"nestedLevels": []
......
......@@ -1064,4 +1064,16 @@ The default value is 1.""".asReleaseDependent()
introducedVersion = KotlinReleaseVersion.v2_0_20,
)
}
compilerArgument {
name = "Xnative-debuginfo-gc-compress"
compilerName = "nativeDebuginfoGcCompress"
description = "Value of kotlin.native.debuginfo.gc-compress from gradle.properties (single option, no per-target).".asReleaseDependent()
valueType = StringType.defaultNull
valueDescription = "<value>".asReleaseDependent()
lifecycle(
introducedVersion = KotlinReleaseVersion.v2_2_0,
)
}
}
......@@ -983,6 +983,17 @@ The default value is 1.""",
field = value
}
@Argument(
value = "-Xnative-debuginfo-gc-compress",
valueDescription = "<value>",
description = "Value of kotlin.native.debuginfo.gc-compress from gradle.properties (single option, no per-target).",
)
var nativeDebuginfoGcCompress: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
}
@get:Transient
@field:kotlin.jvm.Transient
override val configurator: CommonCompilerArgumentsConfigurator = K2NativeCompilerArgumentsConfigurator()
......
......@@ -62,6 +62,7 @@ fun copyK2NativeCompilerArguments(from: K2NativeCompilerArguments, to: K2NativeC
to.manifestNativeTargets = from.manifestNativeTargets?.copyOf()
to.memoryModel = from.memoryModel
to.moduleName = from.moduleName
to.nativeDebuginfoGcCompress = from.nativeDebuginfoGcCompress
to.nativeLibraries = from.nativeLibraries?.copyOf()
to.noObjcGenerics = from.noObjcGenerics
to.nodefaultlibs = from.nodefaultlibs
......
......@@ -153,5 +153,7 @@ class KonanConfigKeys {
val MANIFEST_NATIVE_TARGETS: CompilerConfigurationKey<Collection<KonanTarget>?> = CompilerConfigurationKey.create("value of native_targets property to write in manifest")
val LLVM_MODULE_PASSES: CompilerConfigurationKey<String?> = CompilerConfigurationKey.create("llvm passes to run instead of module optimization pipeline")
val LLVM_LTO_PASSES: CompilerConfigurationKey<String?> = CompilerConfigurationKey.create("llvm passes to run instead of LTO optimization pipeline")
/** Value of kotlin.native.debuginfo.gc-compress from gradle.properties (boolean), passed via -Xnative-debuginfo-gc-compress. No per-target. */
val NATIVE_DEBUGINFO_GC_COMPRESS: CompilerConfigurationKey<Boolean?> = CompilerConfigurationKey.create("native debuginfo gc-compress option")
}
}
......@@ -215,6 +215,7 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
put(FAKE_OVERRIDE_VALIDATOR, arguments.fakeOverrideValidator)
putIfNotNull(PRE_LINK_CACHES, parsePreLinkCachesValue(this@setupFromArguments, arguments.preLinkCaches))
putIfNotNull(OVERRIDE_KONAN_PROPERTIES, parseOverrideKonanProperties(arguments, this@setupFromArguments))
putIfNotNull(NATIVE_DEBUGINFO_GC_COMPRESS, arguments.nativeDebuginfoGcCompress?.toBooleanStrictOrNull())
when (arguments.destroyRuntimeMode) {
null -> {}
"legacy" -> {
......
......@@ -431,11 +431,27 @@ internal fun <C : PhaseContext> PhaseEngine<C>.compileAndLink(
cacheBinaries,
)
runPhase(LinkerPhase, linkerPhaseInput)
handleDebugInfo()
if (context.config.produce.isCache) {
runPhase(FinalizeCachePhase, outputFiles)
}
}
/**
* 在 compileAndLink 中可通过 context 获取 kotlin.native.debuginfo.gc-compress 的取值。
* gradle.properties 为 kotlin.native.debuginfo.gc-compress=<value>(无 per-target),
* Gradle 传 -Xnative-debuginfo-gc-compress=<value>,此处用 NATIVE_DEBUGINFO_GC_COMPRESS 读取。
*/
internal fun <C : PhaseContext> PhaseEngine<C>.handleDebugInfo() {
val nativeDebuginfoGcCompress: Boolean? = context.config.configuration.get(KonanConfigKeys.NATIVE_DEBUGINFO_GC_COMPRESS)
if (nativeDebuginfoGcCompress == true) {
// TODO: 使用 nativeDebuginfoGcCompress 控制 debug info 行为
}
}
internal fun PhaseEngine<NativeGenerationState>.partiallyLowerModuleWithDependencies(module: IrModuleFragment, loweringList: LoweringList) {
val dependenciesToCompile = findDependenciesToCompile()
// TODO: KonanLibraryResolver.TopologicalLibraryOrder actually returns libraries in the reverse topological order.
......
......@@ -37,3 +37,7 @@ internal fun Project.isKonanIncrementalCompilationEnabled(): Boolean {
internal fun Project.getKonanParallelThreads(): Int {
return PropertiesProvider(this).nativeParallelThreads ?: 4
}
internal fun Project.getNativeDebuginfoGcCompress(): Boolean? {
return PropertiesProvider(this).nativeDebuginfoGcCompress
}
......@@ -316,6 +316,13 @@ internal class PropertiesProvider private constructor(private val project: Proje
key.removePrefix(KOTLIN_NATIVE_BINARY_OPTION_PREFIX)
}
/**
* gradle.properties 中 kotlin.native.debuginfo.gc-compress=true/false,传入 -Xnative-debuginfo-gc-compress(无 per-target)。与 [incrementalNative] 同为 Boolean?。
*/
val nativeDebuginfoGcCompress: Boolean?
get() = booleanProperty(PropertyNames.KOTLIN_NATIVE_DEBUGINFO_GC_COMPRESS)
/**
* Allows a user to specify additional arguments of a JVM executing KLIB commonizer.
*/
......@@ -743,6 +750,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
val KOTLIN_NATIVE_DEPENDENCY_PROPAGATION = property("kotlin.native.enableDependencyPropagation")
val KOTLIN_NATIVE_CACHE_ORCHESTRATION = property("kotlin.native.cacheOrchestration")
val KOTLIN_NATIVE_PARALLEL_THREADS = property("kotlin.native.parallelThreads")
val KOTLIN_NATIVE_DEBUGINFO_GC_COMPRESS = property("kotlin.native.debuginfo.gc-compress")
val KOTLIN_NATIVE_INCREMENTAL_COMPILATION = property("kotlin.incremental.native")
val KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION = property("kotlin.mpp.enableOptimisticNumberCommonization")
val KOTLIN_MPP_ENABLE_PLATFORM_INTEGER_COMMONIZATION = property("kotlin.mpp.enablePlatformIntegerCommonization")
......
......@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.compilerRunner.addBuildMetricsForTaskAction
import org.jetbrains.kotlin.compilerRunner.getKonanCacheKind
import org.jetbrains.kotlin.compilerRunner.getKonanCacheOrchestration
import org.jetbrains.kotlin.compilerRunner.getKonanParallelThreads
import org.jetbrains.kotlin.compilerRunner.getNativeDebuginfoGcCompress
import org.jetbrains.kotlin.compilerRunner.isKonanIncrementalCompilationEnabled
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.*
......@@ -293,6 +294,7 @@ constructor(
args.mainPackage = entryPoint
args.singleLinkerArguments = (linkerOpts + additionalLinkerOpts).toTypedArray()
args.binaryOptions = binaryOptions.map { (key, value) -> "$key=$value" }.toTypedArray()
args.nativeDebuginfoGcCompress = project.getNativeDebuginfoGcCompress()?.toString()
args.staticFramework = isStaticFramework
args.konanDataDir = kotlinNativeProvider.get().konanDataDir.orNull
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment