diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanBuildService.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanBuildService.kt deleted file mode 100644 index 55d098e..0000000 --- a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanBuildService.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2023 Google, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.birbit.ksqlite.build.internal - -import org.gradle.api.Project -import org.gradle.api.provider.Property -import org.gradle.api.provider.Provider -import org.gradle.api.services.BuildService -import org.gradle.api.services.BuildServiceParameters -import org.gradle.process.ExecOperations -import org.jetbrains.kotlin.konan.target.KonanTarget -import java.io.File -import javax.inject.Inject - -internal abstract class KonanBuildService -@Inject constructor( - private val execOperations: ExecOperations -) : - BuildService { - interface Params : BuildServiceParameters { - val compilerPath: Property - } - - fun obtainWrapper( - konanTarget: KonanTarget - ) = KonanUtil.KonanCompilerWrapper( - execOperations = execOperations, - konanTarget = konanTarget - ).also { - KonanUtil.KonanCompilerWrapper.ensureSupportForTarget( - parameters.compilerPath.get(), - execOperations, - konanTarget - ) - } - companion object { - const val KEY = "konanBuildService" - fun register( - project: Project - ): Provider { - val compilerPath = KonanUtil.KonanCompilerWrapper.obtainNativeCompiler( - project - ) - return project.gradle.sharedServices.registerIfAbsent( - KEY, - KonanBuildService::class.java - ) { - it.parameters.compilerPath.set(compilerPath) - } - } - } -} diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoader.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoader.kt deleted file mode 100644 index f8ffbcc..0000000 --- a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoader.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2021 Google, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.birbit.ksqlite.build.internal - -import org.jetbrains.kotlin.konan.target.Family -import org.jetbrains.kotlin.konan.target.HostManager -import org.jetbrains.kotlin.konan.target.KonanTarget -import java.util.Locale -import java.util.Properties - -internal object KonanPropLoader { - private val konanProps = Properties() - val regex = "\\\$([a-zA-Z_.0-9])+".toRegex() - init { - KonanUtil::class.java.getResourceAsStream("/konan-props-copy.properties")?.reader(Charsets.UTF_8).use { - konanProps.load(it) - } - } - - // visible for testing - fun loadPropertyWithKeySubstitution(key: String): String { - val value = require(key) - // see if it has any substitution - return value.replace(regex) { match -> - loadPropertyWithKeySubstitution(match.value.substringAfter('$')) - } - } - - fun require(key: String): String { - // use user insteaad of dev, see commit 8866ab5916c5a7dc2d2ee3579e32e95de660f3ad - // in kotlin repo - @Suppress("NAME_SHADOWING") // intentional - val key = key.replace(".dev", ".user") - val value = konanProps[key] ?: error("cannot find required property: $key") - check(value is String) { - "expected String, found $value (${value::class.java}" - } - return value - } - - fun targetTriple(target: KonanTarget): String { - return loadPropertyWithKeySubstitution("targetTriple.${target.name}") - } - - fun sysroot(target: KonanTarget): String { - if (target.family == Family.ANDROID) { - // android sysroot with sources lives in another property, not sure why but this seems to work - val keyName = (HostManager.host.name.lowercase(Locale.US) + "-" + target.name) - return loadPropertyWithKeySubstitution("targetToolchain.$keyName") + "/sysroot" - } - return loadPropertyWithKeySubstitution("targetSysRoot.${target.name}") - } - - fun clangFlags(target: KonanTarget): String { - return loadPropertyWithKeySubstitution("clangFlags.${target.name}") - } - - fun linkerKonanFlags(target: KonanTarget): String { - return loadPropertyWithKeySubstitution("linkerKonanFlags.${target.name}") - } - - fun llvmHome(target: KonanTarget): String { - return loadPropertyWithKeySubstitution("llvmHome.${target.name}") - } -} diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanUtil.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanUtil.kt deleted file mode 100644 index fea52a4..0000000 --- a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/KonanUtil.kt +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright 2020 Google, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.birbit.ksqlite.build.internal - -import com.android.build.api.dsl.LibraryExtension -import com.android.build.api.variant.LibraryAndroidComponentsExtension -import org.gradle.api.Project -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.ListProperty -import org.gradle.api.provider.Property -import org.gradle.process.ExecOperations -import org.gradle.process.ExecResult -import org.gradle.workers.WorkAction -import org.gradle.workers.WorkParameters -import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader -import org.jetbrains.kotlin.konan.target.Architecture -import org.jetbrains.kotlin.konan.target.Family -import org.jetbrains.kotlin.konan.target.HostManager -import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.konan.util.DependencyDirectories -import java.io.File -import java.util.concurrent.locks.ReentrantLock -import kotlin.concurrent.withLock - -internal object KonanUtil { - private val konanDeps = DependencyDirectories.defaultDependenciesRoot - private val konanProps = KonanPropLoader - private val toolChainFolderName = konanProps.llvmHome(HostManager.host) - private val llvmBinFolder = konanDeps.resolve("$toolChainFolderName/bin") - - internal class TargetInfo( - val targetName: String, - val sysRoot: () -> File, - val clangArgs: List = emptyList() - ) { - val cacheKey: String by lazy { - (clangArgs + targetName).joinToString("-") - } - } - - fun obtainWrapper( - execOperations: ExecOperations, - konanTarget: KonanTarget - ) = KonanCompilerWrapper( - execOperations = execOperations, - konanTarget = konanTarget - ) - - private fun targetInfoFromProps(target: KonanTarget): TargetInfo { - return TargetInfo( - targetName = konanProps.targetTriple(target), - sysRoot = { - val appleSdkRoot = getAppleSdkRoot(target) - if (appleSdkRoot != null) { - File(appleSdkRoot) - } else { - konanDeps.resolve( - konanProps.sysroot(target) - ) - } - }, - clangArgs = emptyList() - ) - } - - private fun Project.ndkSysrootDir(): File { - val libraryComponents = - project.extensions.getByType(LibraryAndroidComponentsExtension::class.java) - val androidLibrary = project.extensions.findByType(LibraryExtension::class.java) - ?: error("cannot find library extension on $project") - // hack, for some reason, sdkComponents.ndkDirectory is NOT set so we default to sdk/ndk - val ndkVersion = androidLibrary.ndkVersion - val ndkDir = - libraryComponents.sdkComponents.sdkDirectory.get().asFile.resolve("ndk/$ndkVersion/sysroot") - check(ndkDir.exists()) { - "NDK directory is missing: ${ndkDir.absolutePath}" - } - return ndkDir - } - - private fun getAppleSdkRoot(target: KonanTarget): String? { - // https://github.com/JetBrains/kotlin-native/blob/bb568a8a7e529a9eae473432a71c13ca105ba5ee/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt - val sdkName = when (target.family) { - Family.IOS -> { - when (target.architecture) { - Architecture.ARM64, Architecture.ARM32 -> "iphoneos" - Architecture.X86, Architecture.X64 -> "iphonesimulator" - else -> "unexpected sdk param: $target" - } - } - - Family.OSX -> "macosx" - Family.WATCHOS -> when (target.architecture) { - Architecture.ARM64, Architecture.ARM32 -> "watchos" - Architecture.X86, Architecture.X64 -> "watchsimulator" - else -> "unexpected sdk param: $target" - } - - Family.TVOS -> when (target.architecture) { - Architecture.ARM64, Architecture.ARM32 -> "appletvos" - Architecture.X86, Architecture.X64 -> "appletvsimulator" - else -> "unexpected sdk param: $target" - } - - else -> null - } - return sdkName?.let { - xcrun("--sdk", it, "--show-sdk-path") - } - } - - private fun xcrun(vararg args: String): String = try { - Runtime.getRuntime().exec(arrayOf("/usr/bin/xcrun") + args).inputStream.reader( - Charsets.UTF_8 - ).readText().trim() - } catch (e: Throwable) { - throw RuntimeException("cannot call xcrun $args", e) - } - - @Suppress("UnstableApiUsage") - abstract class KonanCompilerWorker : WorkAction { - interface Params : WorkParameters { - val args: ListProperty - val target: Property - val buildService: Property - } - - override fun execute() { - parameters.buildService.get().obtainWrapper( - parameters.target.get() - ).compile(parameters.args.get()) - } - } - - @Suppress("UnstableApiUsage") - abstract class KonanArchiveNativeBinaryWorker : WorkAction { - interface Params : WorkParameters { - val buildService: Property - val target: Property - val input: RegularFileProperty - val output: RegularFileProperty - } - - override fun execute() { - parameters.buildService.get().obtainWrapper( - parameters.target.get() - ).archiveNativeBinary(parameters.input.get().asFile, parameters.output.get().asFile) - } - } - - class KonanCompilerWrapper( - val execOperations: ExecOperations, - val konanTarget: KonanTarget - ) { - fun compile( - args: List - ) { - val konanTargetInfo = targetInfoFromProps(konanTarget) - execOperations.exec { - it.environment("PATH", "$llvmBinFolder;${System.getenv("PATH")}") - it.executable(llvmBinFolder.resolve("clang").absolutePath) - val targetInfo = konanTargetInfo - it.args("--compile", "-Wall") - if (konanTarget.family == Family.ANDROID) { - it.args("-Oz") // optimize for size - } else { - it.args("-O3") - } - - if (konanTarget.family != Family.MINGW) { - it.args("-fPIC") - } - it.args("--target=${targetInfo.targetName}") - val sysRoot = targetInfo.sysRoot() - it.args("--sysroot=${sysRoot.absolutePath}") - it.args(targetInfo.clangArgs) - it.args(args) - } - } - - fun archiveNativeBinary( - input: File, - output: File, - ) { - execOperations.exec { - it.executable(llvmBinFolder.resolve("llvm-ar").absolutePath) - it.args( - "rc", output.absolutePath, - input.absolutePath - ) - it.environment("PATH", "$llvmBinFolder;${System.getenv("PATH")}") - } - } - - companion object { - private val downloadNativeCompilerLock = ReentrantLock() - - fun obtainNativeCompiler( - project: Project, - ): File { - return downloadNativeCompilerLock.withLock { - val nativeCompilerDownloader = NativeCompilerDownloader( - project = project - ) - nativeCompilerDownloader.downloadIfNeeded() - val konancName = if (HostManager.hostIsMingw) { - "konanc.bat" - } else { - "konanc" - } - nativeCompilerDownloader.compilerDirectory - .resolve("bin/$konancName") - } - } - - fun ensureSupportForTarget( - konanc: File, - execOperations: ExecOperations, - konanTarget: KonanTarget - ): ExecResult? { - downloadNativeCompilerLock.withLock { - val result = execOperations.exec { - - check(konanc.exists()) { - "Cannot find konan compiler at $konanc" - } - it.executable = konanc.absolutePath - it.args("-Xcheck-dependencies", "-target", konanTarget.visibleName) - } - return result.assertNormalExitValue() - } - } - } - } -} diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/SqliteCompilation.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/SqliteCompilation.kt index eeed7a0..53a6c80 100644 --- a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/SqliteCompilation.kt +++ b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/SqliteCompilation.kt @@ -17,35 +17,21 @@ package com.birbit.ksqlite.build.internal import com.birbit.ksqlite.build.CreateDefFileWithLibraryPathTask import com.birbit.ksqlite.build.SqliteCompilationConfig -import org.gradle.api.DefaultTask +import com.birbit.ksqlite.build.internal.clang.ClangCompileTask +import com.birbit.ksqlite.build.internal.clang.KonanBuildService +import com.birbit.ksqlite.build.internal.clang.LlvmArchiveTask import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.services.ServiceReference -import org.gradle.api.tasks.CacheableTask import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.OutputFile -import org.gradle.api.tasks.PathSensitive -import org.gradle.api.tasks.PathSensitivity -import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskProvider import org.gradle.configurationcache.extensions.capitalized import org.gradle.kotlin.dsl.get -import org.gradle.workers.WorkerExecutor import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.presetName -import javax.inject.Inject internal object SqliteCompilation { fun setup(project: Project, config: SqliteCompilationConfig) { - // TODO convert these to gradle properties val downloadTask = project.tasks.register("downloadSqlite", DownloadTask::class.java) { it.downloadUrl.set(computeDownloadUrl(config.version)) it.downloadTargetFile.set( @@ -64,7 +50,6 @@ internal object SqliteCompilation { // get rid of the amalgamation folder in output dir it.path = it.path.replaceFirst("sqlite-amalgamation-[\\d]+/".toRegex(), "") } - it.dependsOn(downloadTask) } val kotlinExt = project.extensions.getByType(KotlinMultiplatformExtension::class.java) val compileTasks = mutableListOf>() @@ -72,37 +57,44 @@ internal object SqliteCompilation { nativeTarget.konanTarget.isBuiltOnThisMachine() }.forEach { val konanTarget = it.konanTarget + val konanBuildServiceProvider = KonanBuildService.obtain(project) val compileSQLiteTask = project.tasks.register( "compileSQLite${konanTarget.presetName.capitalized()}", - CompileSqliteTask::class.java + ClangCompileTask::class.java ) { compileTask -> - val konanBuildServiceProvider = KonanBuildService.register( - project - ) val srcDir = project.objects.directoryProperty().fileProvider( unzipTask.map { it.destinationDir } ) - val sourceFile = unzipTask.map { it.destinationDir.resolve("sqlite3.c") } - val objFile = - project.layout.buildDirectory.file("sqlite-compilation-output/${konanTarget.name}/sqlite3.o") + compileTask.usesService(konanBuildServiceProvider) - compileTask.dependsOn(unzipTask) - compileTask.konanTarget.set(konanTarget) - compileTask.input.set(project.objects.fileProperty().fileProvider(sourceFile)) - compileTask.output.set(objFile) - compileTask.sourceDir.set(srcDir) + val sourceFile = unzipTask.map { it.destinationDir.resolve("sqlite3.c") } + val objFileDir = project.layout.buildDirectory.dir( + "sqlite-compilation-output/${konanTarget.name}" + ) + compileTask.clangParameters.let { + it.konanTarget.set(konanTarget) + it.sources.from( + sourceFile + ) + it.includes.set(srcDir) + it.output.set(objFileDir) + it.freeArgs.addAll(SQLITE_ARGS) + } } val archiveSQLiteTask = project.tasks.register( "archiveSQLite${konanTarget.presetName.capitalized()}", - ArchiveSqliteTask::class.java + LlvmArchiveTask::class.java ) { archiveTask -> - archiveTask.dependsOn(compileSQLiteTask) - archiveTask.konanTarget.set(konanTarget) - archiveTask.usesService(KonanBuildService.register(project)) - archiveTask.objectFile.set(compileSQLiteTask.flatMap { it.output }) - archiveTask.staticLibFile.set( - project.layout.buildDirectory.file("static-lib-files/${konanTarget.name}/libsqlite3.a") - ) + archiveTask.llvmArParameters.let { + it.konanTarget.set(konanTarget) + it.objectFiles.from( + compileSQLiteTask.flatMap { it.clangParameters.output } + ) + it.outputFile.set( + project.layout.buildDirectory.file("static-lib-files/${konanTarget.name}/libsqlite3.a") + ) + } + archiveTask.usesService(konanBuildServiceProvider) } compileTasks.add(archiveSQLiteTask) it.compilations["main"].cinterops.create("sqlite") { @@ -110,8 +102,6 @@ internal object SqliteCompilation { val generatedDefFileFolder = project.layout.buildDirectory.dir("sqlite-def-files") it.packageName = "sqlite3" val cInteropTask = project.tasks[it.interopProcessingTaskName] - cInteropTask.dependsOn(archiveSQLiteTask) - it.includeDirs(unzipTask.map { it.destinationDir }) val original = it.defFile val newDefFile = generatedDefFileFolder.map { @@ -123,7 +113,7 @@ internal object SqliteCompilation { ) { task -> task.original.set(original) task.target.set(newDefFile) - task.soFile.set(archiveSQLiteTask.flatMap { it.staticLibFile }) + task.soFile.set(archiveSQLiteTask.flatMap { it.llvmArParameters.outputFile }) task.projectDir.set(project.layout.projectDirectory) } // create def file w/ library paths. couldn't figure out how else to add it :/ :) @@ -152,104 +142,27 @@ internal object SqliteCompilation { return "$BASE_URL$fileName" } - @CacheableTask - abstract class ArchiveSqliteTask @Inject constructor( - private val workerExecutor: WorkerExecutor - ) : DefaultTask() { - @Suppress("UnstableApiUsage") - @get:ServiceReference(KonanBuildService.KEY) - abstract val konanBuildService: Property - - @get:Input - abstract val konanTarget: Property - - @get:InputFile - @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val objectFile: RegularFileProperty - - @get:OutputFile - abstract val staticLibFile: RegularFileProperty - - @TaskAction - fun archive() { - println("archiving into ${staticLibFile.get().asFile}") - workerExecutor.noIsolation().submit( - KonanUtil.KonanArchiveNativeBinaryWorker::class.java - ) { - it.buildService.set(konanBuildService) - it.target.set(konanTarget) - it.input.set(objectFile) - it.output.set(staticLibFile) - } - } - } - - @CacheableTask - abstract class CompileSqliteTask @Inject constructor( - private val workerExecutor: WorkerExecutor - ) : DefaultTask() { - @Suppress("UnstableApiUsage") - @get:ServiceReference(KonanBuildService.KEY) - abstract val konanBuildService: Property - - @get:Input - abstract val konanTarget: Property - - @get:InputFile - @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val input: RegularFileProperty - - @get:OutputFile - abstract val output: RegularFileProperty - - @get:InputDirectory - @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val sourceDir: DirectoryProperty - - @Input - fun getSqliteArgs() = SQLITE_ARGS.joinToString(",") - - @TaskAction - fun compile() { - workerExecutor.noIsolation().submit( - KonanUtil.KonanCompilerWorker::class.java - ) { - it.buildService.set(konanBuildService) - it.target.set(konanTarget) - it.args.set( - SQLITE_ARGS + listOf( - "-I${sourceDir.asFile.get().absolutePath}", - "-o", output.asFile.get().absolutePath, - input.asFile.get().absolutePath - ) - ) - } - } - - companion object { - internal val SQLITE_ARGS = listOf( - "-DSQLITE_ENABLE_COLUMN_METADATA=1", - "-DSQLITE_ENABLE_NORMALIZE=1", - // "-DSQLITE_ENABLE_EXPLAIN_COMMENTS=1", - // "-DSQLITE_ENABLE_DBSTAT_VTAB=1", - "-DSQLITE_ENABLE_LOAD_EXTENSION=1", - // "-DSQLITE_HAVE_ISNAN=1", - "-DHAVE_USLEEP=1", - // "-DSQLITE_CORE=1", - "-DSQLITE_ENABLE_FTS3=1", - "-DSQLITE_ENABLE_FTS3_PARENTHESIS=1", - "-DSQLITE_ENABLE_FTS4=1", - "-DSQLITE_ENABLE_FTS5=1", - "-DSQLITE_ENABLE_JSON1=1", - "-DSQLITE_ENABLE_RTREE=1", - "-DSQLITE_ENABLE_STAT4=1", - "-DSQLITE_THREADSAFE=1", - "-DSQLITE_DEFAULT_MEMSTATUS=0", - "-DSQLITE_OMIT_PROGRESS_CALLBACK=0", - "-DSQLITE_ENABLE_RBU=1" - ) - } - } - private const val BASE_URL = "https://www.sqlite.org/2022/sqlite-amalgamation-" + + internal val SQLITE_ARGS = listOf( + "-DSQLITE_ENABLE_COLUMN_METADATA=1", + "-DSQLITE_ENABLE_NORMALIZE=1", + // "-DSQLITE_ENABLE_EXPLAIN_COMMENTS=1", + // "-DSQLITE_ENABLE_DBSTAT_VTAB=1", + "-DSQLITE_ENABLE_LOAD_EXTENSION=1", + // "-DSQLITE_HAVE_ISNAN=1", + "-DHAVE_USLEEP=1", + // "-DSQLITE_CORE=1", + "-DSQLITE_ENABLE_FTS3=1", + "-DSQLITE_ENABLE_FTS3_PARENTHESIS=1", + "-DSQLITE_ENABLE_FTS4=1", + "-DSQLITE_ENABLE_FTS5=1", + "-DSQLITE_ENABLE_JSON1=1", + "-DSQLITE_ENABLE_RTREE=1", + "-DSQLITE_ENABLE_STAT4=1", + "-DSQLITE_THREADSAFE=1", + "-DSQLITE_DEFAULT_MEMSTATUS=0", + "-DSQLITE_OMIT_PROGRESS_CALLBACK=0", + "-DSQLITE_ENABLE_RBU=1" + ) } diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/ClangCompileTask.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/ClangCompileTask.kt new file mode 100644 index 0000000..cd980de --- /dev/null +++ b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/ClangCompileTask.kt @@ -0,0 +1,92 @@ +/* + * Copyright 2023 Google, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.birbit.ksqlite.build.internal.clang + +import org.gradle.api.DefaultTask +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property +import org.gradle.api.services.ServiceReference +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.TaskAction +import org.gradle.workers.WorkAction +import org.gradle.workers.WorkParameters +import org.gradle.workers.WorkerExecutor +import org.jetbrains.kotlin.konan.target.KonanTarget +import javax.inject.Inject + +abstract class ClangCompileParameters { + @get:Input + abstract val konanTarget: Property + + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val sources: ConfigurableFileCollection + + @get:OutputDirectory + abstract val output: DirectoryProperty + + @get:InputDirectory + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val includes: DirectoryProperty + + @get:Input + abstract val freeArgs: ListProperty +} + +abstract class CompileWorker : WorkAction { + interface Params : WorkParameters { + val clangParameters: Property + val buildService: Property + } + + override fun execute() { + val buildService = parameters.buildService.get() + buildService.compile( + parameters.clangParameters.get() + ) + } +} + +@CacheableTask +abstract class ClangCompileTask @Inject constructor( + private val workerExecutor: WorkerExecutor +) : DefaultTask() { + @Suppress("UnstableApiUsage") + @get:ServiceReference(KonanBuildService.KEY) + abstract val konanBuildService: Property + + @get:Nested + abstract val clangParameters: ClangCompileParameters + + @TaskAction + fun compile() { + workerExecutor.noIsolation().submit( + CompileWorker::class.java + ) { + it.buildService.set(konanBuildService) + it.clangParameters.set(clangParameters) + } + } +} diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/KonanBuildService.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/KonanBuildService.kt new file mode 100644 index 0000000..2353297 --- /dev/null +++ b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/KonanBuildService.kt @@ -0,0 +1,120 @@ +/* + * Copyright 2023 Google, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.birbit.ksqlite.build.internal.clang + +import org.gradle.api.Project +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Provider +import org.gradle.api.services.BuildService +import org.gradle.api.services.BuildServiceParameters +import org.gradle.process.ExecOperations +import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader +import org.jetbrains.kotlin.konan.target.Distribution +import org.jetbrains.kotlin.konan.target.KonanTarget +import org.jetbrains.kotlin.konan.target.Platform +import org.jetbrains.kotlin.konan.target.PlatformManager +import javax.inject.Inject + +abstract class KonanBuildService @Inject constructor( + private val execOperations: ExecOperations +) : BuildService { + private val dist = Distribution( + konanHome = parameters.konanHome.get().asFile.absolutePath, + onlyDefaultProfiles = false, + ) + + private val platformManager = PlatformManager( + distribution = dist + ) + + fun compile(clangCompileParameters: ClangCompileParameters) { + val platform = resolveKonanTarget(clangCompileParameters.konanTarget.get()) + val outputDir = clangCompileParameters.output.get().asFile + outputDir.deleteRecursively() + outputDir.mkdirs() + val clang = platform.clang + execOperations.exec { + it.executable = "clang" + it.args(clang.clangArgs.toList()) + it.args(clangCompileParameters.freeArgs.get()) + it.workingDir = clangCompileParameters.output.get().asFile + it.args( + "-I${clangCompileParameters.includes.get().asFile.absolutePath}", + "--compile", + "-v", + ) + it.args(clangCompileParameters.sources.files.map { it.absolutePath }) + } + } + + fun archive(clangArchiveParameters: LlvmArchiveParameters) { + val platform = resolveKonanTarget(clangArchiveParameters.konanTarget.get()) + clangArchiveParameters.outputFile.get().asFile.also { + it.delete() + it.parentFile.mkdirs() + } + execOperations.exec { + it.executable = platform.clang.llvmAr().single() + it.args("rc") + it.args(clangArchiveParameters.outputFile.get().asFile.absolutePath) + it.args( + clangArchiveParameters.objectFiles.files.flatMap { + it.walkTopDown().filter { + it.isFile + }.map { it.canonicalPath } + }.distinct() + ) + } + } + + private fun resolveKonanTarget(konanTarget: KonanTarget): Platform { + val wantedTargetName = konanTarget.name + // for some reason, equals don't work between these, might be classpath issue, hence find it + // again + val wantedTarget = platformManager.enabled.find { + it.name == wantedTargetName + } ?: error("cannot find enabled target with name $wantedTargetName") + val platform = platformManager.platform(wantedTarget) + platform.downloadDependencies() + return platform + } + + interface Params : BuildServiceParameters { + val konanHome: DirectoryProperty + } + + companion object { + const val KEY = "konanBuildService" + fun obtain( + project: Project + ): Provider { + return project.gradle.sharedServices.registerIfAbsent( + KEY, + KonanBuildService::class.java + ) { + // see: + // https://github.com/JetBrains/kotlin/blob/d97e8ae456364d90f0ffbd7f20535983d4d62c5d/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/compilerRunner/nativeToolRunners.kt#L33 + // maybe use that instead + val nativeCompilerDownloader = NativeCompilerDownloader(project) + nativeCompilerDownloader.downloadIfNeeded() + + it.parameters.konanHome.set( + nativeCompilerDownloader.compilerDirectory + ) + } + } + } +} diff --git a/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/LlvmArchiveTask.kt b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/LlvmArchiveTask.kt new file mode 100644 index 0000000..31a09b5 --- /dev/null +++ b/buildPlugin/src/main/kotlin/com/birbit/ksqlite/build/internal/clang/LlvmArchiveTask.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2023 Google, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.birbit.ksqlite.build.internal.clang + +import org.gradle.api.DefaultTask +import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.services.ServiceReference +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.TaskAction +import org.gradle.workers.WorkAction +import org.gradle.workers.WorkParameters +import org.gradle.workers.WorkerExecutor +import org.jetbrains.kotlin.konan.target.KonanTarget +import javax.inject.Inject + +abstract class LlvmArchiveParameters { + @get:Input + abstract val konanTarget: Property + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val objectFiles: ConfigurableFileCollection + @get:OutputFile + abstract val outputFile: RegularFileProperty +} + +private abstract class LlvmArchiveWorker : WorkAction { + interface Params : WorkParameters { + val llvmArParameters: Property + val buildService: Property + } + + override fun execute() { + val buildService = parameters.buildService.get() + buildService.archive( + parameters.llvmArParameters.get() + ) + } +} +@CacheableTask +abstract class LlvmArchiveTask @Inject constructor( + private val workerExecutor: WorkerExecutor +) : DefaultTask() { + @Suppress("UnstableApiUsage") + @get:ServiceReference(KonanBuildService.KEY) + abstract val konanBuildService: Property + + @get:Nested + abstract val llvmArParameters: LlvmArchiveParameters + + @TaskAction + fun archive() { + workerExecutor.noIsolation().submit( + LlvmArchiveWorker::class.java + ) { + it.llvmArParameters.set(llvmArParameters) + it.buildService.set(konanBuildService) + } + } +} diff --git a/buildPlugin/src/main/resources/konan-props-copy.properties b/buildPlugin/src/main/resources/konan-props-copy.properties deleted file mode 100644 index 054a02c..0000000 --- a/buildPlugin/src/main/resources/konan-props-copy.properties +++ /dev/null @@ -1,1015 +0,0 @@ -# -# Copyright 2010-2018 JetBrains s.r.o. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Copied from https://github.com/JetBrains/kotlin/blob/master/kotlin-native/konan/konan.properties - -# TODO: Do we need a $variable substitution mechanism here? -dependenciesUrl = https://download.jetbrains.com/kotlin/native - -# In order of preference: -dependencyProfiles = default alt - -# Don't check dependencies on a server. -# If true, dependency downloader will throw an exception if a dependency isn't found in $KONAN_DATA_DIR/dependencies -airplaneMode = false -# if true, ignores Xcode version check. -ignoreXcodeVersionCheck = false - -minimalXcodeVersion=12.5 - -downloadingAttempts = 10 -downloadingAttemptIntervalMs = 3000 -homeDependencyCache = .konan/cache - -# Appendix that is used for smaller version of LLVM distributions. -reducedLlvmAppendix = compact - -predefinedLlvmDistributions = \ - apple-llvm-20200714-macos-x64-1 \ - apple-llvm-20200714-macos-aarch64-1 \ - llvm-11.1.0-linux-x64-2 \ - llvm-11.1.0-windows-x64-2 \ - apple-llvm-20200714-macos-x64-essentials \ - apple-llvm-20200714-macos-aarch64-essentials \ - llvm-11.1.0-linux-x64-essentials \ - llvm-11.1.0-windows-x64-essentials - -predefinedLibffiVersions = \ - libffi-3.2.1-3-darwin-macos \ - libffi-3.3-1-macos-arm64 \ - libffi-3.2.1-2-linux-x86-64 \ - libffi-3.3-windows-x64-1 - -llvm.linux_x64.dev = llvm-11.1.0-linux-x64-2 -llvm.linux_x64.user = llvm-11.1.0-linux-x64-essentials - -llvm.mingw_x64.dev = llvm-11.1.0-windows-x64-2 -llvm.mingw_x64.user = llvm-11.1.0-windows-x64-essentials - -llvm.macos_x64.dev = apple-llvm-20200714-macos-x64-1 -llvm.macos_x64.user = apple-llvm-20200714-macos-x64-essentials - -llvm.macos_arm64.dev = apple-llvm-20200714-macos-aarch64-1 -llvm.macos_arm64.user = apple-llvm-20200714-macos-aarch64-essentials - -# By default LLVM uses 250 for -03 builds. -# We use a smaller value since default value leads to -# unreasonably bloated runtime code without any measurable -# performance benefits. -# This value still has to be tuned for different targets, though. -llvmInlineThreshold = 100 -clangDebugFlags = -O0 - -linkerGccFlags = -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed - -llvmVersion.linux_x64 = 11.1.0 -llvmVersion.mingw_x64 = 11.1.0 -llvmVersion.macos_x64 = 11.1.0 -llvmVersion.macos_arm64 = 11.1.0 - -toolchainDependency.mingw_x64 = msys2-mingw-w64-x86_64-2 -toolchainDependency.mingw_x86 = msys2-mingw-w64-i686-2 -toolchainDependency.linux_x64 = x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2 -toolchainDependency.linux_arm64 = aarch64-unknown-linux-gnu-gcc-8.3.0-glibc-2.25-kernel-4.9-2 -toolchainDependency.linux_mips32 = mips-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2 -toolchainDependency.linux_mipsel32 = mipsel-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2 -toolchainDependency.linux_arm32_hfp = arm-unknown-linux-gnueabihf-gcc-8.3.0-glibc-2.19-kernel-4.9-2 - -cacheableTargets.macos_x64 = \ - macos_x64 \ - ios_x64 \ - ios_arm64 - -cacheableTargets.linux_x64 = \ - linux_x64 - -cacheableTargets.mingw_x64 = - -cacheableTargets.macos_arm64 = \ - macos_arm64 \ - ios_simulator_arm64 \ - ios_arm64 - -# Targets that support compiler caches, but these caches -# are not considered stable enough to be turned on by default. -optInCacheableTargets = - -# Mac OS X. -# Can be an absolute path instead of predefined value. -llvmHome.macos_x64 = $llvm.macos_x64.dev -targetToolchain.macos_x64 = target-toolchain-xcode_14_1_rc2 -libffiDir.macos_x64 = libffi-3.2.1-3-darwin-macos -additionalToolsDir.macos_x64 = xcode-addon-xcode_14_1_rc2 - -targetToolchain.macos_arm64-macos_x64 = target-toolchain-xcode_14_1_rc2 - -targetTriple.macos_x64 = x86_64-apple-macos -targetSysRoot.macos_x64 = target-sysroot-xcode_14_1_rc2-macosx -targetCpu.macos_x64 = core2 -targetCpuFeatures.macos_x64=+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87 -clangFlags.macos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.macos_x64 = -O1 -clangOptFlags.macos_x64 = -O3 -clangDebugFlags.macos_x64 = -O0 - -linkerKonanFlags.macos_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 13.0.0 -linkerOptimizationFlags.macos_x64 = -dead_strip -linkerNoDebugFlags.macos_x64 = -S -stripFlags.macos_x64 = -S -linkerDynamicFlags.macos_x64 = -dylib - -osVersionMinFlagLd.macos_x64 = -macosx_version_min -osVersionMin.macos_x64 = 10.13 - -dependencies.macos_x64 = \ - lldb-4-macos - -target-sysroot-xcode_14_1_rc2-macosx.default = \ - remote:internal - -target-toolchain-xcode_14_1_rc2.default = \ - remote:internal - -xcode-addon-xcode_14_1_rc2.default = \ - remote:internal - -# macOS Apple Silicon -llvmHome.macos_arm64 = $llvm.macos_arm64.dev -targetToolchain.macos_arm64 = target-toolchain-xcode_14_1_rc2 -libffiDir.macos_arm64 = libffi-3.3-1-macos-arm64 -additionalToolsDir.macos_arm64 = xcode-addon-xcode_14_1_rc2 - -targetToolchain.macos_x64-macos_arm64 = target-toolchain-xcode_14_1_rc2 -targetTriple.macos_arm64 = arm64-apple-macos -targetSysRoot.macos_arm64 = target-sysroot-xcode_14_1_rc2-macosx -# TODO: Check Clang behaviour. -targetCpu.macos_arm64 = apple-a7 -clangFlags.macos_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.macos_arm64 = -O1 -clangOptFlags.macos_arm64 = -O3 -# See clangDebugFlags.ios_arm64 -# TODO: Is it still necessary? -clangDebugFlags.macos_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.macos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 13.0.0 -linkerOptimizationFlags.macos_arm64 = -dead_strip -linkerNoDebugFlags.macos_arm64 = -S -stripFlags.macos_arm64 = -S -linkerDynamicFlags.macos_arm64 = -dylib - -osVersionMinFlagLd.macos_arm64 = -macosx_version_min -osVersionMin.macos_arm64 = 11.0 - -dependencies.macos_arm64 = \ - lldb-4-macos - - -target-sysroot-xcode_14_1_rc2-macos_arm64.default = \ - remote:internal - -target-toolchain-xcode_14_1_rc2-macos_arm64.default = \ - remote:internal - -xcode-addon-xcode_14_1_rc2-macos_arm64.default = \ - remote:internal - -# Apple's 32-bit iOS. -targetToolchain.macos_x64-ios_arm32 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-ios_arm32 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-ios_arm32.default = \ - remote:internal - -targetTriple.ios_arm32 = armv7-apple-ios -# Shared with 64-bit version. -targetSysRoot.ios_arm32 = target-sysroot-xcode_14_1_rc2-iphoneos -targetCpu.ios_arm32 = generic -clangFlags.ios_arm32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.ios_arm32 = -O1 -clangOptFlags.ios_arm32 = -O3 -clangDebugFlags.ios_arm32 = -O0 -llvmInlineThreshold.ios_arm32 = 50 -linkerNoDebugFlags.ios_arm32 = -S -stripFlags.ios_arm32 = -S -linkerDynamicFlags.ios_arm32 = -dylib -linkerKonanFlags.ios_arm32 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 15.0 -linkerOptimizationFlags.ios_arm32 = -dead_strip -osVersionMinFlagLd.ios_arm32 = -iphoneos_version_min -osVersionMin.ios_arm32 = 9.0 - - - -# Apple's 64-bit iOS. -targetToolchain.macos_x64-ios_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-ios_arm64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-iphoneos.default = \ - remote:internal - -targetTriple.ios_arm64 = arm64-apple-ios -targetSysRoot.ios_arm64 = target-sysroot-xcode_14_1_rc2-iphoneos -targetCpu.ios_arm64 = apple-a7 -clangFlags.ios_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.ios_arm64 = -O1 -clangOptFlags.ios_arm64 = -O3 -# We force LLVM to use SelectionDAG because fast isel may miscompile sign extension. -# Related: -# https://github.com/JetBrains/kotlin-native/issues/3290 -clangDebugFlags.ios_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerNoDebugFlags.ios_arm64 = -S -stripFlags.ios_arm64 = -S -linkerDynamicFlags.ios_arm64 = -dylib -linkerKonanFlags.ios_arm64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.ios_arm64 = -dead_strip -osVersionMinFlagLd.ios_arm64 = -iphoneos_version_min -osVersionMin.ios_arm64 = 9.0 - -additionalCacheFlags.ios_arm64 = -Xembed-bitcode-marker - -# Apple's iOS simulator. -targetToolchain.macos_x64-ios_x64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-ios_x64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-iphonesimulator.default = \ - remote:internal - -targetTriple.ios_x64 = x86_64-apple-ios-simulator -targetSysRoot.ios_x64 = target-sysroot-xcode_14_1_rc2-iphonesimulator -targetCpu.ios_x64 = core2 -clangFlags.ios_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.ios_x64 = -O1 -clangOptFlags.ios_x64 = -O3 -clangDebugFlags.ios_x64 = -O0 - -linkerKonanFlags.ios_x64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.ios_x64 = -dead_strip -linkerNoDebugFlags.ios_x64 = -S -stripFlags.ios_x64 = -S -linkerDynamicFlags.ios_x64 = -dylib -osVersionMinFlagLd.ios_x64 = -ios_simulator_version_min -osVersionMin.ios_x64 = 9.0 - - -# iOS simulator on Apple Silicon - -targetToolchain.macos_x64-ios_simulator_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-ios_simulator_arm64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-ios_simulator_arm64.default = \ - remote:internal - -targetTriple.ios_simulator_arm64 = arm64-apple-ios-simulator -targetSysRoot.ios_simulator_arm64 = target-sysroot-xcode_14_1_rc2-iphonesimulator -targetCpu.ios_simulator_arm64 = apple-a7 -clangFlags.ios_simulator_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.ios_simulator_arm64 = -O1 -clangOptFlags.ios_simulator_arm64 = -O3 -clangDebugFlags.ios_simulator_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.ios_simulator_arm64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.ios_simulator_arm64 = -dead_strip -linkerNoDebugFlags.ios_simulator_arm64 = -S -stripFlags.ios_simulator_arm64 = -S -linkerDynamicFlags.ios_simulator_arm64 = -dylib -osVersionMinFlagLd.ios_simulator_arm64 = -ios_simulator_version_min -osVersionMin.ios_simulator_arm64 = 9.0 - - -# Apple's tvOS simulator. -targetToolchain.macos_x64-tvos_x64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-tvos_x64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-appletvsimulator.default = \ - remote:internal - -targetTriple.tvos_x64 = x86_64-apple-tvos-simulator -targetSysRoot.tvos_x64 = target-sysroot-xcode_14_1_rc2-appletvsimulator -targetCpu.tvos_x64 = core2 -clangFlags.tvos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.tvos_x64 = -O1 -clangOptFlags.tvos_x64 = -O3 -clangDebugFlags.tvos_x64 = -O0 - -linkerKonanFlags.tvos_x64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.tvos_x64 = -dead_strip -linkerNoDebugFlags.tvos_x64 = -S -stripFlags.tvos_x64 = -S -linkerDynamicFlags.tvos_x64 = -dylib -osVersionMinFlagLd.tvos_x64 = -tvos_simulator_version_min -osVersionMin.tvos_x64 = 9.0 - - -# Apple's tvOS simulator. -targetToolchain.macos_x64-tvos_simulator_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-tvos_simulator_arm64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-tvos_simulator_arm64.default = \ - remote:internal - -targetTriple.tvos_simulator_arm64 = arm64-apple-tvos-simulator -targetSysRoot.tvos_simulator_arm64 = target-sysroot-xcode_14_1_rc2-appletvsimulator -targetCpu.tvos_simulator_arm64 = apple-a7 -clangFlags.tvos_simulator_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.tvos_simulator_arm64 = -O1 -clangOptFlags.tvos_simulator_arm64 = -O3 -clangDebugFlags.tvos_simulator_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.tvos_simulator_arm64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.tvos_simulator_arm64 = -dead_strip -linkerNoDebugFlags.tvos_simulator_arm64 = -S -stripFlags.tvos_simulator_arm64 = -S -linkerDynamicFlags.tvos_simulator_arm64 = -dylib -osVersionMinFlagLd.tvos_simulator_arm64 = -tvos_simulator_version_min -osVersionMin.tvos_simulator_arm64 = 9.0 - - -# Apple's 64-bit tvOS. -targetToolchain.macos_x64-tvos_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-tvos_arm64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-appletvos.default = \ - remote:internal - -targetTriple.tvos_arm64 = arm64-apple-tvos -targetSysRoot.tvos_arm64 = target-sysroot-xcode_14_1_rc2-appletvos -targetCpu.tvos_arm64 = apple-a7 -clangFlags.tvos_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.tvos_arm64 = -O1 -clangOptFlags.tvos_arm64 = -O3 -clangDebugFlags.tvos_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerNoDebugFlags.tvos_arm64 = -S -stripFlags.tvos_arm64 = -S -linkerDynamicFlags.tvos_arm64 = -dylib -linkerKonanFlags.tvos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -framework UIKit -sdk_version 16.1 -linkerOptimizationFlags.tvos_arm64 = -dead_strip -osVersionMinFlagLd.tvos_arm64 = -tvos_version_min -osVersionMin.tvos_arm64 = 9.0 - - -# watchOS armv7k -targetToolchain.macos_x64-watchos_arm32 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_arm32 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-watchos.default = \ - remote:internal - -targetTriple.watchos_arm32 = armv7k-apple-watchos -targetSysRoot.watchos_arm32 = target-sysroot-xcode_14_1_rc2-watchos -targetCpu.watchos_arm32 = cortex-a7 -clangFlags.watchos_arm32 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.watchos_arm32 = -O1 -clangOptFlags.watchos_arm32 = -O3 -clangDebugFlags.watchos_arm32 = -O0 -llvmInlineThreshold.watchos_arm32 = 50 - -linkerKonanFlags.watchos_arm32 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 9.1 -linkerOptimizationFlags.watchos_arm32 = -dead_strip -linkerNoDebugFlags.watchos_arm32 = -S -stripFlags.watchos_arm32 = -S -linkerDynamicFlags.watchos_arm32 = -dylib -osVersionMinFlagLd.watchos_arm32 = -watchos_version_min -osVersionMin.watchos_arm32 = 5.0 - - -# watchOS arm64_32 -targetToolchain.macos_x64-watchos_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_arm64 = target-toolchain-xcode_14_1_rc2 - -targetTriple.watchos_arm64 = arm64_32-apple-watchos -targetSysRoot.watchos_arm64 = target-sysroot-xcode_14_1_rc2-watchos -targetCpu.watchos_arm64 = apple-s4 -clangFlags.watchos_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -mllvm -aarch64-watch-bitcode-compatibility \ - -mllvm -arm-bitcode-compatibility -clangNooptFlags.watchos_arm64 = -O1 -clangOptFlags.watchos_arm64 = -O3 -clangDebugFlags.watchos_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.watchos_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 9.1 -linkerOptimizationFlags.watchos_arm64 = -dead_strip -linkerNoDebugFlags.watchos_arm64 = -S -stripFlags.watchos_arm64 = -S -linkerDynamicFlags.watchos_arm64 = -dylib -osVersionMinFlagLd.watchos_arm64 = -watchos_version_min -osVersionMin.watchos_arm64 = 5.0 - -# watchOS arm64 -targetToolchain.macos_x64-watchos_device_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_device_arm64 = target-toolchain-xcode_14_1_rc2 - -targetTriple.watchos_device_arm64 = arm64-apple-watchos -targetSysRoot.watchos_device_arm64 = target-sysroot-xcode_14_1_rc2-watchos -targetCpu.watchos_device_arm64 = apple-a7 -clangFlags.watchos_device_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.watchos_device_arm64 = -O1 -clangOptFlags.watchos_device_arm64 = -O3 -clangDebugFlags.watchos_device_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.watchos_device_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 9.1 -linkerOptimizationFlags.watchos_device_arm64 = -dead_strip -linkerNoDebugFlags.watchos_device_arm64 = -S -stripFlags.watchos_device_arm64 = -S -linkerDynamicFlags.watchos_device_arm64 = -dylib -osVersionMinFlagLd.watchos_device_arm64 = -watchos_version_min -osVersionMin.watchos_device_arm64 = 9.0 - - -# Apple's watchOS i386 simulator. -targetToolchain.macos_x64-watchos_x86 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_x86 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-watchsimulator.default = \ - remote:internal - -targetTriple.watchos_x86 = i386-apple-watchos-simulator -targetSysRoot.watchos_x86 = target-sysroot-xcode_14_1_rc2-watchsimulator -# Make sure that SSE2 is available by setting target-cpu to pentium4 -targetCpu.watchos_x86 = pentium4 -clangFlags.watchos_x86 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.watchos_x86 = -O1 -clangOptFlags.watchos_x86 = -O3 -clangDebugFlags.watchos_x86 = -O0 - -linkerKonanFlags.watchos_x86 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 8.0 -linkerOptimizationFlags.watchos_x86 = -dead_strip -linkerNoDebugFlags.watchos_x86 = -S -stripFlags.watchos_x86 = -S -linkerDynamicFlags.watchos_x86 = -dylib -osVersionMinFlagLd.watchos_x86 = -watchos_simulator_version_min -osVersionMin.watchos_x86 = 5.0 - - -# watchOS x86_64 simulator. -targetToolchain.macos_x64-watchos_x64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_x64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-watchos_x64.default = \ - remote:internal - -targetTriple.watchos_x64 = x86_64-apple-watchos-simulator -targetSysRoot.watchos_x64 = target-sysroot-xcode_14_1_rc2-watchsimulator -targetCpu.watchos_x64 = core2 -clangFlags.watchos_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.watchos_x64 = -O1 -clangOptFlags.watchos_x64 = -O3 -clangDebugFlags.watchos_x64 = -O0 - -linkerKonanFlags.watchos_x64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 9.1 -linkerOptimizationFlags.watchos_x64 = -dead_strip -linkerNoDebugFlags.watchos_x64 = -S -stripFlags.watchos_x64 = -S -linkerDynamicFlags.watchos_x64 = -dylib -osVersionMinFlagLd.watchos_x64 = -watchos_simulator_version_min -osVersionMin.watchos_x64 = 7.0 - - -# watchOS Apple Silicon simulator. -targetToolchain.macos_x64-watchos_simulator_arm64 = target-toolchain-xcode_14_1_rc2 -targetToolchain.macos_arm64-watchos_simulator_arm64 = target-toolchain-xcode_14_1_rc2 - -target-sysroot-xcode_14_1_rc2-watchos_simulator_arm64.default = \ - remote:internal - -targetTriple.watchos_simulator_arm64 = arm64-apple-watchos-simulator -targetSysRoot.watchos_simulator_arm64 = target-sysroot-xcode_14_1_rc2-watchsimulator -targetCpu.watchos_simulator_arm64 = apple-a7 -clangFlags.watchos_simulator_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -clangNooptFlags.watchos_simulator_arm64 = -O1 -clangOptFlags.watchos_simulator_arm64 = -O3 -clangDebugFlags.watchos_simulator_arm64 = -O0 -mllvm -fast-isel=false -mllvm -global-isel=false - -linkerKonanFlags.watchos_simulator_arm64 = -lSystem -lc++ -lobjc -framework Foundation -sdk_version 9.1 -linkerOptimizationFlags.watchos_simulator_arm64 = -dead_strip -linkerNoDebugFlags.watchos_simulator_arm64 = -S -stripFlags.watchos_simulator_arm64 = -S -linkerDynamicFlags.watchos_simulator_arm64 = -dylib -osVersionMinFlagLd.watchos_simulator_arm64 = -watchos_simulator_version_min -osVersionMin.watchos_simulator_arm64 = 7.0 - - - -# Linux x86-64. -llvmHome.linux_x64 = $llvm.linux_x64.dev -libffiDir.linux_x64 = libffi-3.2.1-2-linux-x86-64 - -gccToolchain.linux_x64 = $toolchainDependency.linux_x64 -targetToolchain.linux_x64 = $gccToolchain.linux_x64/x86_64-unknown-linux-gnu -dependencies.linux_x64 = \ - $toolchainDependency.linux_x64 \ - lldb-4-linux - -targetToolchain.mingw_x64-linux_x64 = $llvmHome.mingw_x64 -dependencies.mingw_x64-linux_x64 = \ - $toolchainDependency.linux_x64 \ - $toolchainDependency.mingw_x64 - -targetToolchain.macos_x64-linux_x64 = $llvmHome.macos_x64 -dependencies.macos_x64-linux_x64 = \ - $toolchainDependency.linux_x64 - -targetToolchain.macos_arm64-linux_x64 = $llvmHome.macos_arm64 -dependencies.macos_arm64-linux_x64 = \ - $toolchainDependency.linux_x64 - -targetTriple.linux_x64 = x86_64-unknown-linux-gnu -targetSysRoot.linux_x64 = $gccToolchain.linux_x64/x86_64-unknown-linux-gnu/sysroot -# targetSysroot-relative. -libGcc.linux_x64 = ../../lib/gcc/x86_64-unknown-linux-gnu/8.3.0 -targetCpu.linux_x64 = x86-64 -targetCpuFeatures.linux_x64 = +cx8,+fxsr,+mmx,+sse,+sse2,+x87 -clangFlags.linux_x64 = -cc1 -emit-obj -disable-llvm-optzns -x ir \ - -ffunction-sections -fdata-sections -clangNooptFlags.linux_x64 = -O1 -clangOptFlags.linux_x64 = -O3 -clangDebugFlags.linux_x64 = -O0 -dynamicLibraryRelocationMode.linux_x64 = pic -staticLibraryRelocationMode.linux_x64 = pic -linkerKonanFlags.linux_x64 = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread \ - --defsym __cxa_demangle=Konan_cxa_demangle --gc-sections -linkerOptimizationFlags.linux_x64 = -linkerNoDebugFlags.linux_x64 = -S -linkerDynamicFlags.linux_x64 = -shared - -linker.linux_x64 = $targetToolchain.linux_x64/bin/ld.gold -linkerHostSpecificFlags.linux_x64-linux_x64 = -# TODO: Check ld.lld from LLVM. -linker.mingw_x64-linux_x64 = $targetToolchain.mingw_x64/bin/ld.gold -linkerHostSpecificFlags.mingw_x64-linux_x64 = -linker.macos_x64-linux_x64 = $targetToolchain.macos_x64-linux_x64/bin/ld.lld -linkerHostSpecificFlags.macos_x64-linux_x64 = -linker.macos_arm64-linux_x64 = $targetToolchain.macos_arm64-linux_x64/bin/ld.lld -linkerHostSpecificFlags.macos_arm64-linux_x64 = - -dynamicLinker.linux_x64 = /lib64/ld-linux-x86-64.so.2 -# targetSysRoot relative -abiSpecificLibraries.linux_x64 = lib usr/lib ../lib64 lib64 usr/lib64 -# targetSysRoot relative -crtFilesLocation.linux_x64 = usr/lib - - -# Raspberry Pi -gccToolchain.linux_arm32_hfp = $toolchainDependency.linux_arm32_hfp - -targetToolchain.linux_x64-linux_arm32_hfp = $gccToolchain.linux_arm32_hfp/arm-unknown-linux-gnueabihf -targetToolchain.mingw_x64-linux_arm32_hfp = $llvmHome.mingw_x64 -targetToolchain.macos_x64-linux_arm32_hfp = $llvmHome.macos_x64 -targetToolchain.macos_arm64-linux_arm32_hfp = $llvmHome.macos_arm64 - -# TODO: We might use docker on Windows or macOS. -emulatorDependency.linux_x64-linux_arm32_hfp = qemu-arm-static-5.1.0-linux-2 -emulatorExecutable.linux_x64-linux_arm32_hfp = qemu-arm-static-5.1.0-linux-2/qemu-arm - -dependencies.linux_x64-linux_arm32_hfp = \ - $toolchainDependency.linux_arm32_hfp -dependencies.mingw_x64-linux_arm32_hfp = \ - $toolchainDependency.linux_arm32_hfp \ - $toolchainDependency.mingw_x64 -dependencies.macos_x64-linux_arm32_hfp = \ - $toolchainDependency.linux_arm32_hfp -dependencies.macos_arm64-linux_arm32_hfp = \ - $toolchainDependency.linux_arm32_hfp - -targetTriple.linux_arm32_hfp = arm-unknown-linux-gnueabihf -linkerNoDebugFlags.linux_arm32_hfp = -S -linkerDynamicFlags.linux_arm32_hfp = -shared -linkerOptimizationFlags.linux_arm32_hfp = --gc-sections -targetSysRoot.linux_arm32_hfp = $gccToolchain.linux_arm32_hfp/arm-unknown-linux-gnueabihf/sysroot -# We could reuse host toolchain here. -linkerKonanFlags.linux_arm32_hfp = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread \ - --defsym __cxa_demangle=Konan_cxa_demangle -# targetSysroot-relative. -libGcc.linux_arm32_hfp = ../../lib/gcc/arm-unknown-linux-gnueabihf/8.3.0 -targetCpu.linux_arm32_hfp = arm1136jf-s -# Taken from clang-produced bitcode. -# TODO: Not sure if we need so many features. Revise. -targetCpuFeatures.linux_arm32_hfp = +armv6kz,+dsp,+fp64,+strict-align,+vfp2,+vfp2sp,-crypto,-d32,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fullfp16,-neon,-thumb-mode,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp -clangFlags.linux_arm32_hfp = -cc1 -mfloat-abi hard -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.linux_arm32_hfp = -O1 -clangOptFlags.linux_arm32_hfp = -O3 -ffunction-sections -clangDebugFlags.linux_arm32_hfp = -O0 -dynamicLibraryRelocationMode.linux_arm32_hfp = pic -staticLibraryRelocationMode.linux_arm32_hfp = pic - -linker.linux_x64-linux_arm32_hfp = $targetToolchain.linux_x64-linux_arm32_hfp/bin/ld -linkerHostSpecificFlags.linux_x64-linux_arm32_hfp = -# TODO: Check ld.lld from LLVM. -linker.mingw_x64-linux_arm32_hfp = $targetToolchain.mingw_x64/bin/ld.gold -linkerHostSpecificFlags.mingw_x64-linux_arm32_hfp = -linker.macos_x64-linux_arm32_hfp = $targetToolchain.macos_x64-linux_arm32_hfp/bin/ld.lld -linkerHostSpecificFlags.macos_x64-linux_arm32_hfp = -linker.macos_arm64-linux_arm32_hfp = $targetToolchain.macos_arm64-linux_arm32_hfp/bin/ld.lld -linkerHostSpecificFlags.macos_arm64-linux_arm32_hfp = -dynamicLinker.linux_arm32_hfp = /lib/ld-linux-armhf.so.3 -# targetSysRoot relative -abiSpecificLibraries.linux_arm32_hfp = lib usr/lib -# targetSysRoot relative -crtFilesLocation.linux_arm32_hfp = usr/lib - - -# Linux arm64 -gccToolchain.linux_arm64 = $toolchainDependency.linux_arm64 - -targetToolchain.linux_x64-linux_arm64 = $gccToolchain.linux_arm64/aarch64-unknown-linux-gnu -targetToolchain.mingw_x64-linux_arm64 = $llvmHome.mingw_x64 -targetToolchain.macos_x64-linux_arm64 = $llvmHome.macos_x64 -targetToolchain.macos_arm64-linux_arm64 = $llvmHome.macos_arm64 - -emulatorDependency.linux_x64-linux_arm64 = qemu-aarch64-static-5.1.0-linux-2 -emulatorExecutable.linux_x64-linux_arm64 = qemu-aarch64-static-5.1.0-linux-2/qemu-aarch64 - -dependencies.linux_x64-linux_arm64 = \ - $toolchainDependency.linux_arm64 -dependencies.mingw_x64-linux_arm64 = \ - $toolchainDependency.linux_arm64 \ - $toolchainDependency.mingw_x64 -dependencies.macos_x64-linux_arm64 = \ - $toolchainDependency.linux_arm64 -dependencies.macos_arm64-linux_arm64 = \ - $toolchainDependency.linux_arm64 - -targetTriple.linux_arm64 = aarch64-unknown-linux-gnu -linkerNoDebugFlags.linux_arm64 = -S -linkerDynamicFlags.linux_arm64 = -shared -linkerOptimizationFlags.linux_arm64 = --gc-sections -targetSysRoot.linux_arm64 = $gccToolchain.linux_arm64/aarch64-unknown-linux-gnu/sysroot -# We could reuse host toolchain here. -linkerKonanFlags.linux_arm64 = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread \ - --defsym __cxa_demangle=Konan_cxa_demangle -# targetSysroot-relative. -libGcc.linux_arm64 = ../../lib/gcc/aarch64-unknown-linux-gnu/8.3.0 -targetCpu.linux_arm64 = cortex-a57 -clangFlags.linux_arm64 = -cc1 -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.linux_arm64 = -O1 -clangOptFlags.linux_arm64 = -O3 -ffunction-sections -clangDebugFlags.linux_arm64 = -O0 -dynamicLibraryRelocationMode.linux_arm64 = pic -staticLibraryRelocationMode.linux_arm64 = pic - -linker.linux_x64-linux_arm64 = $targetToolchain.linux_x64-linux_arm64/bin/ld.gold -linkerHostSpecificFlags.linux_x64-linux_arm64 = -# TODO: Check ld.lld from LLVM. -linker.mingw_x64-linux_arm64 = $targetToolchain.mingw_x64/bin/ld.gold -linkerHostSpecificFlags.mingw_x64-linux_arm64 = -linker.macos_x64-linux_arm64 = $targetToolchain.macos_x64-linux_arm64/bin/ld.lld -linkerHostSpecificFlags.macos_x64-linux_arm64 = -linker.macos_arm64-linux_arm64 = $targetToolchain.macos_arm64-linux_arm64/bin/ld.lld -linkerHostSpecificFlags.macos_arm64-linux_arm64 = -dynamicLinker.linux_arm64 = /lib/ld-linux-aarch64.so.1 -# targetSysRoot relative -abiSpecificLibraries.linux_arm64 = lib usr/lib -# targetSysRoot relative -crtFilesLocation.linux_arm64 = usr/lib - - -# MIPS -gccToolchain.linux_mips32 = $toolchainDependency.linux_mips32 - -targetToolchain.linux_x64-linux_mips32 = $gccToolchain.linux_mips32/mips-unknown-linux-gnu -targetToolchain.mingw_x64-linux_mips32 = $llvmHome.mingw_x64 -targetToolchain.macos_x64-linux_mips32 = $llvmHome.macos_x64 -targetToolchain.macos_arm64-linux_mips32 = $llvmHome.macos_arm64 - -emulatorDependency.linux_x64-linux_mips32 = qemu-mips-static-5.1.0-linux-2 -emulatorExecutable.linux_x64-linux_mips32 = qemu-mips-static-5.1.0-linux-2/qemu-mips -dependencies.linux_x64-linux_mips32 = \ - $toolchainDependency.linux_mips32 -dependencies.mingw_x64-linux_mips32 = \ - $toolchainDependency.linux_mips32 -dependencies.macos_x64-linux_mips32 = \ - $toolchainDependency.linux_mips32 -dependencies.macos_arm64-linux_mips32 = \ - $toolchainDependency.linux_mips32 - -targetTriple.linux_mips32 = mips-unknown-linux-gnu -linkerOptimizationFlags.linux_mips32 = --gc-sections -linkerDynamicFlags.linux_mips32 = -shared -targetSysRoot.linux_mips32 = $gccToolchain.linux_mips32/mips-unknown-linux-gnu/sysroot -# We could reuse host toolchain here. -linkerKonanFlags.linux_mips32 = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread -latomic \ - --defsym __cxa_demangle=Konan_cxa_demangle -z notext -# targetSysroot-relative. -libGcc.linux_mips32 = ../../lib/gcc/mips-unknown-linux-gnu/8.3.0 -targetCpu.linux_mips32 = mips32r2 -# We generate a single binary with a big GOT. It causes problems for MIPS. -# See https://gcc.gnu.org/onlinedocs/gcc/MIPS-Options.html about mxgot (aka -target-feature +xgot). -targetCpuFeatures.linux_mips32 = +xgot -clangFlags.linux_mips32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.linux_mips32 = -O1 -clangOptFlags.linux_mips32 = -O3 -ffunction-sections -clangDebugFlags.linux_mips32 = -O0 -dynamicLibraryRelocationMode.linux_mips32 = pic -staticLibraryRelocationMode.linux_mips32 = pic -executableRelocationMode.linux_mips32 = static - -linker.linux_x64-linux_mips32 = $targetToolchain.linux_x64-linux_mips32/bin/ld -linker.mingw_x64-linux_mips32 = $targetToolchain.mingw_x64-linux_mips32/bin/ld.lld -linker.macos_x64-linux_mips32 = $targetToolchain.macos_x64-linux_mips32/bin/ld.lld -linker.macos_arm64-linux_mips32 = $targetToolchain.macos_arm64-linux_mips32/bin/ld.lld -linkerHostSpecificFlags.linux_x64-linux_mips32 = -dynamicLinker.linux_mips32 = /lib/ld.so.1 -# targetSysRoot relative -abiSpecificLibraries.linux_mips32 = lib usr/lib -# targetSysRoot relative -crtFilesLocation.linux_mips32 = usr/lib - - -# MIPSel -gccToolchain.linux_mipsel32 = $toolchainDependency.linux_mipsel32 - -targetToolchain.linux_x64-linux_mipsel32 = $gccToolchain.linux_mipsel32/mipsel-unknown-linux-gnu -targetToolchain.mingw_x64-linux_mipsel32 = $llvmHome.mingw_x64 -targetToolchain.macos_x64-linux_mipsel32 = $llvmHome.macos_x64 -targetToolchain.macos_arm64-linux_mipsel32 = $llvmHome.macos_arm64 - -emulatorDependency.linux_x64-linux_mipsel32 = qemu-mipsel-static-5.1.0-linux-2 -emulatorExecutable.linux_x64-linux_mipsel32 = qemu-mipsel-static-5.1.0-linux-2/qemu-mipsel -dependencies.linux_x64-linux_mipsel32 = \ - $toolchainDependency.linux_mipsel32 -dependencies.mingw_x64-linux_mipsel32 = \ - $toolchainDependency.linux_mipsel32 -dependencies.macos_x64-linux_mipsel32 = \ - $toolchainDependency.linux_mipsel32 -dependencies.macos_arm64-linux_mipsel32 = \ - $toolchainDependency.linux_mipsel32 - -targetTriple.linux_mipsel32 = mipsel-unknown-linux-gnu -linkerOptimizationFlags.linux_mipsel32 = --gc-sections -linkerDynamicFlags.linux_mipsel32 = -shared -targetSysRoot.linux_mipsel32 = $gccToolchain.linux_mipsel32/mipsel-unknown-linux-gnu/sysroot -# We could reuse host toolchain here. -linkerKonanFlags.linux_mipsel32 = -Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread -latomic \ - --defsym __cxa_demangle=Konan_cxa_demangle -z notext -# targetSysroot-relative. -libGcc.linux_mipsel32 = ../../lib/gcc/mipsel-unknown-linux-gnu/8.3.0 -targetCpu.linux_mipsel32 = mips32r2 -targetCpuFeatures.linux_mipsel32 = +xgot -clangFlags.linux_mipsel32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.linux_mipsel32 = -O1 -clangOptFlags.linux_mipsel32 = -O3 -ffunction-sections -clangDebugFlags.linux_mipsel32 = -O0 -dynamicLibraryRelocationMode.linux_mipsel32 = pic -staticLibraryRelocationMode.linux_mipsel32 = pic - -linker.linux_x64-linux_mipsel32 = $targetToolchain.linux_x64-linux_mipsel32/bin/ld -linker.mingw_x64-linux_mipsel32 = $targetToolchain.mingw_x64-linux_mipsel32/bin/ld.lld -linker.macos_x64-linux_mipsel32 = $targetToolchain.macos_x64-linux_mipsel32/bin/ld.lld -linker.macos_arm64-linux_mipsel32 = $targetToolchain.macos_arm64-linux_mipsel32/bin/ld.lld -linkerHostSpecificFlags.linux_x64-linux_mipsel32 = -dynamicLinker.linux_mipsel32 = /lib/ld.so.1 -# targetSysRoot relative -abiSpecificLibraries.linux_mipsel32 = lib usr/lib -# targetSysRoot relative -crtFilesLocation.linux_mipsel32 = usr/lib - - -# Android ARM32, based on NDK for android-21. -targetToolchain.macos_x64-android_arm32 = target-toolchain-2-osx-android_ndk -dependencies.macos_x64-android_arm32 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.macos_arm64-android_arm32 = target-toolchain-2-osx-android_ndk -dependencies.macos_arm64-android_arm32 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.linux_x64-android_arm32 = target-toolchain-2-linux-android_ndk -dependencies.linux_x64-android_arm32 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-linux-android_ndk -targetToolchain.mingw_x64-android_arm32 = target-toolchain-2-windows-android_ndk -dependencies.mingw_x64-android_arm32 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-windows-android_ndk - -targetTriple.android_arm32 = arm-unknown-linux-androideabi -targetCpu.android_arm32 = arm7tdmi -targetCpuFeatures.android_arm32 = +soft-float,+strict-align,-crypto,-neon,-thumb-mode -clangFlags.android_arm32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -femulated-tls -mrelocation-model pic -clangOptFlags.android_arm32 = -O3 -ffunction-sections -linkerNoDebugFlags.android_arm32 = -Wl,-S -clangNooptFlags.android_arm32 = -O1 -targetSysRoot.android_arm32 = target-sysroot-1-android_ndk -linkerKonanFlags.android_arm32 = -lm -lc++_static -lc++abi -landroid -llog -latomic - - -# Android ARM64, based on NDK. -targetToolchain.macos_x64-android_arm64 = target-toolchain-2-osx-android_ndk -dependencies.macos_x64-android_arm64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.macos_arm64-android_arm64 = target-toolchain-2-osx-android_ndk -dependencies.macos_arm64-android_arm64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.linux_x64-android_arm64 = target-toolchain-2-linux-android_ndk -dependencies.linux_x64-android_arm64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-linux-android_ndk -targetToolchain.mingw_x64-android_arm64 = target-toolchain-2-windows-android_ndk -dependencies.mingw_x64-android_arm64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-windows-android_ndk - -targetTriple.android_arm64 = aarch64-unknown-linux-android -targetCpu.android_arm64 = cortex-a57 -clangFlags.android_arm64 = -cc1 -emit-obj -disable-llvm-passes -x ir -femulated-tls -mrelocation-model pic -clangOptFlags.android_arm64 = -O3 -ffunction-sections -clangNooptFlags.android_arm64 = -O1 -targetSysRoot.android_arm64 = target-sysroot-1-android_ndk -linkerKonanFlags.android_arm64 = -lm -lc++_static -lc++abi -landroid -llog -latomic -linkerNoDebugFlags.android_arm64 = -Wl,-S - - -# Android X86, based on NDK. -targetToolchain.macos_x64-android_x86 = target-toolchain-2-osx-android_ndk -dependencies.macos_x64-android_x86 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.macos_arm64-android_x86 = target-toolchain-2-osx-android_ndk -dependencies.macos_arm64-android_x86 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.linux_x64-android_x86 = target-toolchain-2-linux-android_ndk -dependencies.linux_x64-android_x86 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-linux-android_ndk -targetToolchain.mingw_x64-android_x86 = target-toolchain-2-windows-android_ndk -dependencies.mingw_x64-android_x86 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-windows-android_ndk - -targetTriple.android_x86 = i686-unknown-linux-android -# Make sure that SSE2 is available by setting target-cpu to pentium4 -targetCpu.android_x86 = pentium4 -clangFlags.android_x86 = -cc1 -emit-obj -disable-llvm-passes -x ir -femulated-tls -mrelocation-model pic -clangOptFlags.android_x86 = -O3 -ffunction-sections -clangNooptFlags.android_x86 = -O1 -targetSysRoot.android_x86 = target-sysroot-1-android_ndk -linkerKonanFlags.android_x86 = -lm -lc++_static -lc++abi -landroid -llog -latomic -linkerNoDebugFlags.android_x86 = -Wl,-S - - -# Android X64, based on NDK. -targetToolchain.macos_x64-android_x64 = target-toolchain-2-osx-android_ndk -dependencies.macos_x64-android_x64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.macos_arm64-android_x64 = target-toolchain-2-osx-android_ndk -dependencies.macos_arm64-android_x64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-osx-android_ndk -targetToolchain.linux_x64-android_x64 = target-toolchain-2-linux-android_ndk -dependencies.linux_x64-android_x64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-linux-android_ndk -targetToolchain.mingw_x64-android_x64 = target-toolchain-2-windows-android_ndk -dependencies.mingw_x64-android_x64 = \ - target-sysroot-1-android_ndk \ - target-toolchain-2-windows-android_ndk - -targetTriple.android_x64 = x86_64-unknown-linux-android -targetCpu.android_x64 = x86-64 -clangFlags.android_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -femulated-tls -mrelocation-model pic -clangOptFlags.android_x64 = -O3 -ffunction-sections -clangNooptFlags.android_x64 = -O1 -targetSysRoot.android_x64 = target-sysroot-1-android_ndk -linkerKonanFlags.android_x64 = -lm -lc++_static -lc++abi -landroid -llog -latomic -linkerNoDebugFlags.android_x64 = -Wl,-S - - -# Windows x86-64, based on mingw-w64. -llvmHome.mingw_x64 = $llvm.mingw_x64.dev -libffiDir.mingw_x64 = libffi-3.3-windows-x64-1 -windowsKitParts.mingw_x64 = windows-kit-x64-v1-alpha2 -msvcParts.mingw_x64 = msvc-x64-v1-alpha2 - -linker.mingw_x64 = lld-12.0.1-windows-x64/ld.lld.exe -linker.linux_x64-mingw_x64 = $targetToolchain.linux_x64-mingw_x64/bin/ld.lld -linker.macos_x64-mingw_x64 = $targetToolchain.macos_x64-mingw_x64/bin/ld.lld -linker.macos_arm64-mingw_x64 = $targetToolchain.macos_arm64-mingw_x64/bin/ld.lld - -windows-kit-x64-v1-alpha2.default = \ - remote:internal - -msvc-x64-v1-alpha2.default = \ - remote:internal - -targetToolchain.mingw_x64 = $toolchainDependency.mingw_x64 -targetToolchain.linux_x64-mingw_x64 = $llvmHome.linux_x64 -targetToolchain.macos_x64-mingw_x64 = $llvmHome.macos_x64 -targetToolchain.macos_arm64-mingw_x64 = $llvmHome.macos_arm64 - -# for Windows we are currently using LLDB 9 -dependencies.mingw_x64 = \ - lldb-2-windows \ - lld-12.0.1-windows-x64 \ - $toolchainDependency.mingw_x64 -dependencies.linux_x64-mingw_x64 = $toolchainDependency.mingw_x64 -dependencies.macos_x64-mingw_x64 = $toolchainDependency.mingw_x64 -dependencies.macos_arm64-mingw_x64 = $toolchainDependency.mingw_x64 - -targetTriple.mingw_x64 = x86_64-pc-windows-gnu -targetSysRoot.mingw_x64 = $toolchainDependency.mingw_x64 -targetCpu.mingw_x64 = x86-64 -targetCpuFeatures.mingw_x64 = +cx8,+fxsr,+mmx,+sse,+sse2,+x87 -# For using with Universal Windows Platform (UWP) we need to use this slower option. -# See https://youtrack.jetbrains.com/issue/KT-27654. -# TODO: remove, once fixed in mingw, check with the bug testcase. -clangFlags.mingw_x64 = -cc1 -emit-obj -disable-llvm-passes -x ir -femulated-tls -clangOptFlags.mingw_x64 = -O3 -ffunction-sections -clangNooptFlags.mingw_x64 = -O1 -linkerNoDebugFlags.mingw_x64 = -Wl,-S -linkerDynamicFlags.mingw_x64 = -shared -linkerKonanFlags.mingw_x64 =-static-libgcc -static-libstdc++ \ - -Wl,--dynamicbase \ - -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic -linkerOptimizationFlags.mingw_x64 = -Wl,--gc-sections -mimallocLinkerDependencies.mingw_x64 = -lbcrypt - - -# Windows i686, based on mingw-w64. -targetToolchain.mingw_x64-mingw_x86 = $toolchainDependency.mingw_x86 -targetToolchain.linux_x64-mingw_x86 = $llvmHome.linux_x64 -targetToolchain.macos_x64-mingw_x86 = $llvmHome.macos_x64 -targetToolchain.macos_arm64-mingw_x86 = $llvmHome.macos_arm64 - -linker.mingw_x64-mingw_x86 = lld-12.0.1-windows-x64/ld.lld.exe -linker.linux_x64-mingw_x86 = $targetToolchain.linux_x64-mingw_x86/bin/ld.lld -linker.macos_x64-mingw_x86 = $targetToolchain.macos_x64-mingw_x86/bin/ld.lld -linker.macos_arm64-mingw_x86 = $targetToolchain.macos_arm64-mingw_x86/bin/ld.lld - -dependencies.mingw_x64-mingw_x86 = \ - $toolchainDependency.mingw_x86 \ - lld-12.0.1-windows-x64 -dependencies.linux_x64-mingw_x86 = \ - $toolchainDependency.mingw_x86 -dependencies.macos_x64-mingw_x86 = \ - $toolchainDependency.mingw_x86 -dependencies.macos_arm64-mingw_x86 = \ - $toolchainDependency.mingw_x86 - -targetTriple.mingw_x86 = i686-pc-windows-gnu -targetSysRoot.mingw_x86 = $toolchainDependency.mingw_x86 -# Make sure that SSE2 is available by setting target-cpu to pentium4 -targetCpu.mingw_x86 = pentium4 -# For using with Universal Windows Platform (UWP) we need to use slower -emulated-tls option. -# See https://youtrack.jetbrains.com/issue/KT-27654. -# TODO: remove, once fixed in mingw, check with the bug testcase. -clangFlags.mingw_x86 = -cc1 -emit-obj -disable-llvm-passes -x ir -femulated-tls -clangOptFlags.mingw_x86 = -O3 -ffunction-sections -clangNooptFlags.mingw_x86 = -O1 -linkerNoDebugFlags.mingw_x86 = -Wl,-S -linkerDynamicFlags.mingw_x86 = -shared -linkerKonanFlags.mingw_x86 = -static-libgcc -static-libstdc++ \ - -Wl,--dynamicbase \ - -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic -mimallocLinkerDependencies.mingw_x86 = -lbcrypt -linkerOptimizationFlags.mingw_x86 = -Wl,--gc-sections - - -# WebAssembly 32-bit. -targetToolchain.macos_x64-wasm32 = target-toolchain-3-macos-wasm -dependencies.macos_x64-wasm32 = \ - target-sysroot-4-embedded \ - target-toolchain-3-macos-wasm - -targetToolchain.macos_arm64-wasm32 = target-toolchain-3-macos-wasm -dependencies.macos_arm64-wasm32 = \ - target-sysroot-4-embedded \ - target-toolchain-3-macos-wasm - -targetToolchain.linux_x64-wasm32 = target-toolchain-2-linux-wasm -dependencies.linux_x64-wasm32 = \ - target-sysroot-4-embedded \ - target-toolchain-2-linux-wasm - -targetToolchain.mingw_x64-wasm32 = target-toolchain-2-mingw-wasm -dependencies.mingw_x64-wasm32 = \ - target-sysroot-4-embedded \ - target-toolchain-2-mingw-wasm - -targetTriple.wasm32 = wasm32-unknown-unknown -targetSysRoot.wasm32 = target-sysroot-4-embedded -targetCpu.wasm32 = generic -clangFlags.wasm32 = -cc1 -emit-obj -disable-llvm-optzns -x ir -clangNooptFlags.wasm32 = -O1 -clangOptFlags.wasm32 = -O3 -clangDebugFlags.wasm32 = -O0 -# TODO: make explicit list of external symbols -lld.wasm32 = --allow-undefined --no-entry --global-base=0 --export-dynamic - -# The version of Kotlin/Native compiler -compilerVersion=@compilerVersion@ \ No newline at end of file diff --git a/buildPlugin/src/test/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoaderTest.kt b/buildPlugin/src/test/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoaderTest.kt deleted file mode 100644 index bc9e379..0000000 --- a/buildPlugin/src/test/kotlin/com/birbit/ksqlite/build/internal/KonanPropLoaderTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 Google, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.birbit.ksqlite.build.internal - -import com.google.common.truth.Truth.assertThat -import org.jetbrains.kotlin.konan.target.HostManager -import org.jetbrains.kotlin.konan.target.KonanTarget -import org.junit.Test - -class KonanPropLoaderTest { - @Test - fun loadToolchain() { - val hostManager = HostManager - assertThat( - KonanPropLoader.require("llvm.linux_x64.dev") - ).isEqualTo("llvm-11.1.0-linux-x64-essentials") - assertThat(KonanPropLoader.llvmHome(KonanTarget.MACOS_X64)) - .isEqualTo("apple-llvm-20200714-macos-x64-essentials") - assertThat(KonanPropLoader.targetTriple(KonanTarget.LINUX_X64)) - .isEqualTo("x86_64-unknown-linux-gnu") - assertThat(KonanPropLoader.targetTriple(KonanTarget.ANDROID_ARM32)) - .isEqualTo("arm-unknown-linux-androideabi") - assertThat(KonanPropLoader.targetTriple(KonanTarget.IOS_X64)) - .isEqualTo("x86_64-apple-ios-simulator") - assertThat(KonanPropLoader.sysroot(KonanTarget.IOS_X64)) - .isEqualTo("target-sysroot-xcode_12_5-iphonesimulator") - assertThat(KonanPropLoader.clangFlags(KonanTarget.IOS_X64)) - .isEqualTo("-cc1 -emit-obj -disable-llvm-passes -x ir") - } -}