-
Notifications
You must be signed in to change notification settings - Fork 18
Refactor SQLite compilation tasks #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2de4e4b
Refactor SQLite compilation tasks
simolus3 639c743
Simplify unzipping
simolus3 2fc9312
Improve error messages for sync progress test
simolus3 dce1f5e
Fix progress assertion message
simolus3 d54e337
Increment download count only after saving
simolus3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
plugins/build-plugin/src/main/kotlin/com/powersync/compile/ClangCompile.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.powersync.compile | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.ProviderFactory | ||
import org.gradle.api.tasks.CacheableTask | ||
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.jetbrains.kotlin.konan.target.KonanTarget | ||
import javax.inject.Inject | ||
import kotlin.io.path.name | ||
|
||
@CacheableTask | ||
abstract class ClangCompile: DefaultTask() { | ||
@get:InputFile | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
abstract val inputFile: RegularFileProperty | ||
|
||
@get:Input | ||
abstract val konanTarget: Property<String> | ||
|
||
@get:InputDirectory | ||
@get:PathSensitive(PathSensitivity.NONE) | ||
abstract val include: DirectoryProperty | ||
|
||
@get:OutputFile | ||
abstract val objectFile: RegularFileProperty | ||
|
||
@get:Inject | ||
protected abstract val providers: ProviderFactory | ||
|
||
@TaskAction | ||
fun run() { | ||
val target = requireNotNull(KonanTarget.predefinedTargets[konanTarget.get()]) | ||
|
||
val (llvmTarget, sysRoot) = when (target) { | ||
KonanTarget.IOS_X64 -> "x86_64-apple-ios12.0-simulator" to IOS_SIMULATOR_SDK | ||
KonanTarget.IOS_ARM64 -> "arm64-apple-ios12.0" to IOS_SDK | ||
KonanTarget.IOS_SIMULATOR_ARM64 -> "arm64-apple-ios14.0-simulator" to IOS_SIMULATOR_SDK | ||
KonanTarget.MACOS_ARM64 -> "aarch64-apple-macos" to MACOS_SDK | ||
KonanTarget.MACOS_X64 -> "x86_64-apple-macos" to MACOS_SDK | ||
KonanTarget.WATCHOS_DEVICE_ARM64 -> "aarch64-apple-watchos" to WATCHOS_SDK | ||
KonanTarget.WATCHOS_ARM32 -> "armv7k-apple-watchos" to WATCHOS_SDK | ||
KonanTarget.WATCHOS_ARM64 -> "arm64_32-apple-watchos" to WATCHOS_SDK | ||
KonanTarget.WATCHOS_SIMULATOR_ARM64 -> "aarch64-apple-watchos-simulator" to WATCHOS_SIMULATOR_SDK | ||
KonanTarget.WATCHOS_X64 -> "x86_64-apple-watchos-simulator" to WATCHOS_SIMULATOR_SDK | ||
else -> error("Unexpected target $target") | ||
} | ||
|
||
val output = objectFile.get() | ||
|
||
providers.exec { | ||
executable = "clang" | ||
args( | ||
"-B/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin", | ||
"-fno-stack-protector", | ||
"-target", | ||
llvmTarget, | ||
"-isysroot", | ||
sysRoot, | ||
"-fPIC", | ||
"--compile", | ||
"-I${include.get().asFile.absolutePath}", | ||
inputFile.get().asFile.absolutePath, | ||
"-DHAVE_GETHOSTUUID=0", | ||
"-DSQLITE_ENABLE_DBSTAT_VTAB", | ||
"-DSQLITE_ENABLE_FTS5", | ||
"-DSQLITE_ENABLE_RTREE", | ||
"-O3", | ||
"-o", | ||
output.asFile.toPath().name, | ||
) | ||
|
||
workingDir = output.asFile.parentFile | ||
}.result.get() | ||
} | ||
|
||
companion object { | ||
const val WATCHOS_SDK = "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk" | ||
const val WATCHOS_SIMULATOR_SDK = "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/" | ||
const val IOS_SDK = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" | ||
const val IOS_SIMULATOR_SDK = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" | ||
const val MACOS_SDK = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
plugins/build-plugin/src/main/kotlin/com/powersync/compile/CreateSqliteCInterop.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.powersync.compile | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.work.DisableCachingByDefault | ||
|
||
@DisableCachingByDefault(because = "not worth caching") | ||
abstract class CreateSqliteCInterop: DefaultTask() { | ||
@get:InputFile | ||
abstract val archiveFile: RegularFileProperty | ||
|
||
@get:OutputFile | ||
abstract val definitionFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun run() { | ||
val archive = archiveFile.get().asFile | ||
val parent = archive.parentFile | ||
|
||
definitionFile.get().asFile.writeText(""" | ||
package = com.powersync.sqlite3 | ||
|
||
linkerOpts.linux_x64 = -lpthread -ldl | ||
linkerOpts.macos_x64 = -lpthread -ldl | ||
staticLibraries=${archive.name} | ||
libraryPaths=${parent.relativeTo(project.layout.projectDirectory.asFile.canonicalFile)} | ||
""".trimIndent(), | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
plugins/build-plugin/src/main/kotlin/com/powersync/compile/CreateStaticLibrary.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.powersync.compile | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.ProviderFactory | ||
import org.gradle.api.tasks.CacheableTask | ||
import org.gradle.api.tasks.InputFiles | ||
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 javax.inject.Inject | ||
|
||
@CacheableTask | ||
abstract class CreateStaticLibrary: DefaultTask() { | ||
@get:InputFiles | ||
@get:PathSensitive(PathSensitivity.RELATIVE) | ||
abstract val objects: ConfigurableFileCollection | ||
|
||
@get:OutputFile | ||
abstract val staticLibrary: RegularFileProperty | ||
|
||
@get:Inject | ||
abstract val providers: ProviderFactory | ||
|
||
@TaskAction | ||
fun run() { | ||
providers.exec { | ||
executable = "ar" | ||
args("rc", staticLibrary.get().asFile.absolutePath) | ||
for (file in objects.files) { | ||
args(file.absolutePath) | ||
} | ||
}.result.get() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
plugins/build-plugin/src/main/kotlin/com/powersync/compile/UnzipSqlite.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.powersync.compile | ||
|
||
import org.gradle.api.file.Directory | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.FileTree | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.CacheableTask | ||
import org.gradle.api.tasks.Copy | ||
import org.gradle.api.tasks.OutputDirectory | ||
|
||
/** | ||
* A cacheable [Copy] task providing a typed provider for the output directory. | ||
*/ | ||
@CacheableTask | ||
abstract class UnzipSqlite: Copy() { | ||
@get:OutputDirectory | ||
abstract val destination: DirectoryProperty | ||
|
||
fun unzipSqlite(src: FileTree, dir: Provider<Directory>) { | ||
from( | ||
src.matching { | ||
include("*/sqlite3.*") | ||
exclude { | ||
it.isDirectory | ||
} | ||
eachFile { | ||
this.path = this.name | ||
} | ||
}, | ||
) | ||
|
||
into(dir) | ||
destination.set(dir) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.