Skip to content

Commit 42e8940

Browse files
SvyatoslavScherbinaSpace Team
authored and
Space Team
committed
[K/N][build] Make NativeInteropPlugin ignore some warnings in C code
This code is mostly generated by cinterop, and it is known to make the C compiler emit some warnings. This commit ignores a few categories of such warnings to make the build log cleaner. Another ignored warning is about unused compiler arguments on Windows (which is caused by imprecise implementation of ClangArgs.Jni -- it puts linker args and compiler args into the same list). ^KT-77091
1 parent 8b2271d commit 42e8940

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/interop/NativeInteropPlugin.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,32 @@ open class NativeInteropPlugin : Plugin<Project> {
240240
suffixes {
241241
(".c" to ".$obj") {
242242
tool(*hostPlatform.clangForJni.clangC("").toTypedArray())
243-
val cflags = cCompilerArgs + commonCompilerArgs + includeDirs.map { "-I${it.absolutePath}" } + hostPlatform.clangForJni.hostCompilerArgsForJni
243+
244+
// Ideally, this shouldn't be here.
245+
// https://youtrack.jetbrains.com/issue/KT-77091 tracks that.
246+
val ignoreWarningFlags = buildList {
247+
// cinterop generates code like `#define __DATE__ "__DATE__"`:
248+
add("-Wno-builtin-macro-redefined")
249+
// cinterop generates wrappers calling deprecated declarations:
250+
add("-Wno-deprecated-declarations")
251+
// cinterop generates pointer casts that discard `const`:
252+
add("-Wno-incompatible-pointer-types-discards-qualifiers")
253+
// cinterop generates wrappers that pass `void*` for function pointer parameters:
254+
add("-Wno-pedantic")
255+
256+
if (HostManager.hostIsMingw) {
257+
// hostPlatform.clangForJni.clangC includes -L$path arguments.
258+
// They come from WindowsKit.CustomPath.libraryDirectories through .compilerFlags().
259+
add("-Wno-unused-command-line-argument")
260+
}
261+
}
262+
263+
val cflags = cCompilerArgs +
264+
commonCompilerArgs +
265+
ignoreWarningFlags +
266+
includeDirs.map { "-I${it.absolutePath}" } +
267+
hostPlatform.clangForJni.hostCompilerArgsForJni
268+
244269
flags(*cflags.toTypedArray(), "-c", "-o", ruleOut(), ruleInFirst())
245270
}
246271
(".cpp" to ".$obj") {

0 commit comments

Comments
 (0)