Skip to content

Commit

Permalink
Clean up compiler args (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Oct 2, 2023
1 parent 24bafc8 commit ee4d125
Showing 1 changed file with 139 additions and 141 deletions.
280 changes: 139 additions & 141 deletions library/driver/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,151 +112,149 @@ kmpConfiguration {

extensions.configure<CompileToBitcodeExtension>("cklib") {
config.kotlinVersion = libs.versions.gradle.kotlin.get()
create("sqlite3mc") {
language = C
srcDirs = project.files(file("sqlite3mc"))

val kt = KonanTarget.predefinedTargets[target]!!

// -O3 set automatically for C language

listOf(
"-fembed-bitcode",
"-fvisibility=hidden",
).let { compilerArgs.addAll(it) }

// Architecture specific flags
when (kt) {
IOS_X64,
IOS_SIMULATOR_ARM64,
TVOS_X64,
TVOS_SIMULATOR_ARM64,
WATCHOS_X64,
WATCHOS_SIMULATOR_ARM64 -> listOf(
"-arch x86_64",
"-msse4.2",
"-maes",
)
IOS_ARM64,
TVOS_ARM64,
WATCHOS_ARM64,
WATCHOS_DEVICE_ARM64 -> listOf(
"-arch arm64",
)
else -> {
if (kt.architecture == X64 || kt.architecture == X86) {
listOf(
"-msse4.2",
"-maes",
)
} else {
null
}
}
}?.let { compilerArgs.addAll(it) }

// Warning/Error suppression flags
listOf(
"-Wno-missing-braces",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
"-Wno-unused-command-line-argument",
"-Wno-unused-function",
"-Wno-unused-parameter",
"-Wno-unused-variable",

// disable warning about gethostuuid being deprecated on darwin
"-Wno-#warnings",
).let { compilerArgs.addAll(it) }

// TODO: linuxX64
// TODO: macosArm64
// TODO: macosX64
// TODO: mingwX64

// SQLITE flags
when (kt.family) {
IOS,
TVOS,
WATCHOS -> listOf(
// gethostuuid is deprecated
//
// D.Richard Hipp (SQLite architect) suggests for non-macos:
// "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only
// extension that boosts performance when SQLite is used
// on a network filesystem. This is important on macOS because
// some users think it is a good idea to put their home
// directory on a network filesystem.
//
// I'm guessing this is not really a factor on iOS."
"-DSQLITE_ENABLE_LOCKING_STYLE=0",
)
else -> null
}?.let { compilerArgs.addAll(it) }

if (kt.family.isAppleFamily) {
// Options that SQLite is compiled with on
// Darwin devices. macOS 10.11.6+, iOS 9.3.5+
listOf(
"-DSQLITE_ENABLE_API_ARMOR",
"-DOMIT_AUTORESET",
).let { compilerArgs.addAll(it) }
}

listOf(
// 2 (Multi-Threaded) is the default for Darwin
// targets, but on JVM it is using 1 (Serialized).
//
// SQLDelight's NativeSqliteDriver utilizes thread pools
// and nerfs any benefit that Serialized would offer, so.
"-DSQLITE_THREADSAFE=2",

// Remaining flags are what JVM is compiled with
"-DSQLITE_HAVE_ISNAN=1",
"-DHAVE_USLEEP=1",
"-DSQLITE_ENABLE_COLUMN_METADATA=1",
"-DSQLITE_CORE=1",
"-DSQLITE_ENABLE_FTS3=1",
"-DSQLITE_ENABLE_FTS3_PARENTHESIS=1",
"-DSQLITE_ENABLE_FTS5=1",
"-DSQLITE_ENABLE_RTREE=1",
"-DSQLITE_ENABLE_STAT4=1",
"-DSQLITE_ENABLE_DBSTAT_VTAB=1",
"-DSQLITE_ENABLE_MATH_FUNCTIONS=1",
"-DSQLITE_DEFAULT_MEMSTATUS=0",
"-DSQLITE_DEFAULT_FILE_PERMISSIONS=0666",
"-DSQLITE_MAX_VARIABLE_NUMBER=250000",
"-DSQLITE_MAX_MMAP_SIZE=1099511627776",
"-DSQLITE_MAX_LENGTH=2147483647",
"-DSQLITE_MAX_COLUMN=32767",
"-DSQLITE_MAX_SQL_LENGTH=1073741824",
"-DSQLITE_MAX_FUNCTION_ARG=127",
"-DSQLITE_MAX_ATTACHED=125",
"-DSQLITE_MAX_PAGE_COUNT=4294967294",
"-DSQLITE_DQS=0",

// This is a default setting on Darwin, but was also
// added to the compilation for Jvm as a precautionary
// measure. So, it is utilized by all platforms.
"-DOMIT_LOAD_EXTENSION",

"-DCODEC_TYPE=CODEC_TYPE_CHACHA20",
"-DSQLITE_ENABLE_EXTFUNC=1",
"-DSQLITE_ENABLE_REGEXP=1",
"-DSQLITE_TEMP_STORE=2",
"-DSQLITE_USE_URI=1",
).let { compilerArgs.addAll(it) }

// Linker (llvm-link) options
listOf(
"--only-needed",
).let { linkerArgs.addAll(it) }
}
createSqlite3mc()
}
}
}
}

fun CompileToBitcodeExtension.createSqlite3mc() {
create("sqlite3mc") {
language = C
srcDirs = project.files(file("sqlite3mc"))

val kt = KonanTarget.predefinedTargets[target]!!

// -O3 set automatically for C language

listOf(
"-fembed-bitcode",
"-fvisibility=hidden",
).let { compilerArgs.addAll(it) }

// Architecture specific flags
when (kt.architecture) {
X64, X86 -> listOf(
"-msse4.2",
"-maes",
)
else -> null
}?.let { compilerArgs.addAll(it) }

when (kt) {
WATCHOS_ARM32 -> listOf(
"-arch",
"armv7k",
)
WATCHOS_ARM64 -> listOf(
"-arch",
"arm64",
)
else -> null
}?.let { compilerArgs.addAll(it) }

// TODO: Specify min versions for darwin targets

// Warning/Error suppression flags
listOf(
"-Wno-missing-braces",
"-Wno-missing-field-initializers",
"-Wno-sign-compare",
"-Wno-unused-command-line-argument",
"-Wno-unused-function",
"-Wno-unused-parameter",
"-Wno-unused-variable",
).let { compilerArgs.addAll(it) }

if (kt.family.isAppleFamily) {
// disable warning about gethostuuid being deprecated on darwin
compilerArgs.add("-Wno-#warnings")
}

// SQLITE flags
when (kt.family) {
IOS, TVOS, WATCHOS -> listOf(
// gethostuuid is deprecated
//
// D.Richard Hipp (SQLite architect) suggests for non-macOS:
// "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only
// extension that boosts performance when SQLite is used
// on a network filesystem. This is important on macOS because
// some users think it is a good idea to put their home
// directory on a network filesystem.
//
// I'm guessing this is not really a factor on iOS."
"-DSQLITE_ENABLE_LOCKING_STYLE=0",
)
else -> null
}?.let { compilerArgs.addAll(it) }

if (kt.family.isAppleFamily) {
// Options that SQLite is compiled with on
// Darwin devices. macOS 10.11.6+, iOS 9.3.5+
listOf(
"-DSQLITE_ENABLE_API_ARMOR",
"-DOMIT_AUTORESET",
).let { compilerArgs.addAll(it) }
}

listOf(
// 2 (Multi-Threaded) is the default for Darwin
// targets, but on JVM it is using 1 (Serialized).
//
// SQLDelight's NativeSqliteDriver utilizes thread pools
// and nerfs any benefit that Serialized would offer, so.
//
// This *might* change in the future if migrating away from
// SQLDelight's NativeSqliteDriver and SQLiter
"-DSQLITE_THREADSAFE=2",

// Remaining flags are what JVM is compiled with
"-DSQLITE_HAVE_ISNAN=1",
"-DHAVE_USLEEP=1",
"-DSQLITE_ENABLE_COLUMN_METADATA=1",
"-DSQLITE_CORE=1",
"-DSQLITE_ENABLE_FTS3=1",
"-DSQLITE_ENABLE_FTS3_PARENTHESIS=1",
"-DSQLITE_ENABLE_FTS5=1",
"-DSQLITE_ENABLE_RTREE=1",
"-DSQLITE_ENABLE_STAT4=1",
"-DSQLITE_ENABLE_DBSTAT_VTAB=1",
"-DSQLITE_ENABLE_MATH_FUNCTIONS=1",
"-DSQLITE_DEFAULT_MEMSTATUS=0",
"-DSQLITE_DEFAULT_FILE_PERMISSIONS=0666",
"-DSQLITE_MAX_VARIABLE_NUMBER=250000",

// On Darwin, this is 0. This was altered to match what
// Jvm is being compiled with.
"-DSQLITE_MAX_MMAP_SIZE=1099511627776",
"-DSQLITE_MAX_LENGTH=2147483647",
"-DSQLITE_MAX_COLUMN=32767",
"-DSQLITE_MAX_SQL_LENGTH=1073741824",
"-DSQLITE_MAX_FUNCTION_ARG=127",
"-DSQLITE_MAX_ATTACHED=125",
"-DSQLITE_MAX_PAGE_COUNT=4294967294",
"-DSQLITE_DQS=0",

// This is a default setting on Darwin, but was also
// added to the compilation for Jvm as a precautionary
// measure. So, it is utilized by all platforms.
"-DOMIT_LOAD_EXTENSION",

"-DCODEC_TYPE=CODEC_TYPE_CHACHA20",
"-DSQLITE_ENABLE_EXTFUNC=1",
"-DSQLITE_ENABLE_REGEXP=1",
"-DSQLITE_TEMP_STORE=2",
"-DSQLITE_USE_URI=1",
).let { compilerArgs.addAll(it) }

// Linker (llvm-link) options
listOf(
"--only-needed",
).let { linkerArgs.addAll(it) }
}
}

/**
* Repack dependency jar files.
*
Expand Down Expand Up @@ -297,7 +295,7 @@ private class JdbcRepack {
private fun MinimalExternalModuleDependency.toJarFileName(): String = "$name-$version.jar"

init {
val repackDir = buildDir
val repackDir = layout.buildDirectory.asFile.get()
.resolve("jdbc-repack")
jarSQLDelightDriver = repackDir
.resolve(depSQLDelightDriver.toJarFileName())
Expand Down

0 comments on commit ee4d125

Please sign in to comment.