[PL] Disallow partial linkage when compiler is configured to produce KLIB
Partial linkage is intended for producing binaries, not libraries.
This commit is contained in:
committed by
Space Team
parent
1fef48bb60
commit
b7d0209e4b
@@ -172,10 +172,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
configuration.put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, arguments.wasmEnableArrayRangeChecks)
|
configuration.put(JSConfigurationKeys.WASM_ENABLE_ARRAY_RANGE_CHECKS, arguments.wasmEnableArrayRangeChecks)
|
||||||
configuration.put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, arguments.wasmEnableAsserts)
|
configuration.put(JSConfigurationKeys.WASM_ENABLE_ASSERTS, arguments.wasmEnableAsserts)
|
||||||
configuration.put(JSConfigurationKeys.WASM_GENERATE_WAT, arguments.wasmGenerateWat)
|
configuration.put(JSConfigurationKeys.WASM_GENERATE_WAT, arguments.wasmGenerateWat)
|
||||||
configuration.setupPartialLinkageConfig(arguments.partialLinkageMode, arguments.partialLinkageLogLevel) { errorMessage ->
|
|
||||||
messageCollector.report(ERROR, errorMessage, null)
|
|
||||||
return COMPILATION_ERROR
|
|
||||||
}
|
|
||||||
|
|
||||||
val commonSourcesArray = arguments.commonSources
|
val commonSourcesArray = arguments.commonSources
|
||||||
val commonSources = commonSourcesArray?.toSet() ?: emptySet()
|
val commonSources = commonSourcesArray?.toSet() ?: emptySet()
|
||||||
@@ -262,6 +258,14 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
mainCallArguments = mainCallArguments
|
mainCallArguments = mainCallArguments
|
||||||
)
|
)
|
||||||
|
|
||||||
|
configuration.setupPartialLinkageConfig(
|
||||||
|
mode = arguments.partialLinkageMode,
|
||||||
|
logLevel = arguments.partialLinkageLogLevel,
|
||||||
|
compilerModeAllowsUsingPartialLinkage = arguments.includes != null, // Don't run PL when producing KLIB.
|
||||||
|
onWarning = { messageCollector.report(WARNING, it) },
|
||||||
|
onError = { messageCollector.report(ERROR, it) }
|
||||||
|
)
|
||||||
|
|
||||||
// Run analysis if main module is sources
|
// Run analysis if main module is sources
|
||||||
var sourceModule: ModulesStructure? = null
|
var sourceModule: ModulesStructure? = null
|
||||||
val includes = arguments.includes
|
val includes = arguments.includes
|
||||||
|
|||||||
+19
-5
@@ -44,11 +44,25 @@ enum class PartialLinkageLogLevel {
|
|||||||
val CompilerConfiguration.partialLinkageConfig: PartialLinkageConfig
|
val CompilerConfiguration.partialLinkageConfig: PartialLinkageConfig
|
||||||
get() = this[PartialLinkageConfig.KEY] ?: PartialLinkageConfig.DEFAULT
|
get() = this[PartialLinkageConfig.KEY] ?: PartialLinkageConfig.DEFAULT
|
||||||
|
|
||||||
inline fun CompilerConfiguration.setupPartialLinkageConfig(mode: String?, logLevel: String?, onError: (String) -> Unit) {
|
fun CompilerConfiguration.setupPartialLinkageConfig(
|
||||||
val resolvedMode = if (mode != null)
|
mode: String?,
|
||||||
PartialLinkageMode.resolveMode(mode) ?: return onError("Unknown partial linkage mode '$mode'")
|
logLevel: String?,
|
||||||
else
|
compilerModeAllowsUsingPartialLinkage: Boolean,
|
||||||
PartialLinkageMode.DEFAULT
|
onWarning: (String) -> Unit,
|
||||||
|
onError: (String) -> Unit
|
||||||
|
) {
|
||||||
|
val resolvedMode = when {
|
||||||
|
mode != null -> {
|
||||||
|
val resolvedMode = PartialLinkageMode.resolveMode(mode) ?: return onError("Unknown partial linkage mode '$mode'")
|
||||||
|
if (!compilerModeAllowsUsingPartialLinkage && resolvedMode.isEnabled) {
|
||||||
|
onWarning("Current compiler configuration does not allow using partial linkage mode '$mode'. The partial linkage will be disabled.")
|
||||||
|
PartialLinkageMode.DISABLE
|
||||||
|
} else
|
||||||
|
resolvedMode
|
||||||
|
}
|
||||||
|
!compilerModeAllowsUsingPartialLinkage -> PartialLinkageMode.DISABLE
|
||||||
|
else -> PartialLinkageMode.DEFAULT
|
||||||
|
}
|
||||||
|
|
||||||
val resolvedLogLevel = if (logLevel != null)
|
val resolvedLogLevel = if (logLevel != null)
|
||||||
PartialLinkageLogLevel.resolveLogLevel(logLevel) ?: return onError("Unknown partial linkage compile-time log level '$logLevel'")
|
PartialLinkageLogLevel.resolveLogLevel(logLevel) ?: return onError("Unknown partial linkage compile-time log level '$logLevel'")
|
||||||
|
|||||||
+9
-3
@@ -270,9 +270,15 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
|
|||||||
putIfNotNull(RUNTIME_LOGS, arguments.runtimeLogs)
|
putIfNotNull(RUNTIME_LOGS, arguments.runtimeLogs)
|
||||||
putIfNotNull(BUNDLE_ID, parseBundleId(arguments, outputKind, this@setupFromArguments))
|
putIfNotNull(BUNDLE_ID, parseBundleId(arguments, outputKind, this@setupFromArguments))
|
||||||
arguments.testDumpOutputPath?.let { put(TEST_DUMP_OUTPUT_PATH, it) }
|
arguments.testDumpOutputPath?.let { put(TEST_DUMP_OUTPUT_PATH, it) }
|
||||||
setupPartialLinkageConfig(arguments.partialLinkageMode, arguments.partialLinkageLogLevel) { errorMessage ->
|
|
||||||
report(ERROR, errorMessage)
|
setupPartialLinkageConfig(
|
||||||
}
|
mode = arguments.partialLinkageMode,
|
||||||
|
logLevel = arguments.partialLinkageLogLevel,
|
||||||
|
compilerModeAllowsUsingPartialLinkage = outputKind != CompilerOutputKind.LIBRARY, // Don't run PL when producing KLIB.
|
||||||
|
onWarning = { report(WARNING, it) },
|
||||||
|
onError = { report(ERROR, it) }
|
||||||
|
)
|
||||||
|
|
||||||
put(OMIT_FRAMEWORK_BINARY, arguments.omitFrameworkBinary)
|
put(OMIT_FRAMEWORK_BINARY, arguments.omitFrameworkBinary)
|
||||||
putIfNotNull(COMPILE_FROM_BITCODE, parseCompileFromBitcode(arguments, this@setupFromArguments, outputKind))
|
putIfNotNull(COMPILE_FROM_BITCODE, parseCompileFromBitcode(arguments, this@setupFromArguments, outputKind))
|
||||||
putIfNotNull(SERIALIZED_DEPENDENCIES, parseSerializedDependencies(arguments, this@setupFromArguments))
|
putIfNotNull(SERIALIZED_DEPENDENCIES, parseSerializedDependencies(arguments, this@setupFromArguments))
|
||||||
|
|||||||
Reference in New Issue
Block a user