Linux build in macos

This commit is contained in:
Salomon BRYS 2020-06-29 13:02:45 +02:00
parent 7e79a17a7f
commit 3c317da9f5
2 changed files with 29 additions and 2 deletions

View File

@ -93,6 +93,32 @@ kotlin {
}
// Disable cross compilation
afterEvaluate {
val currentOs = org.gradle.internal.os.OperatingSystem.current()
val targets = when {
currentOs.isLinux -> listOf()
currentOs.isMacOsX -> listOf("linux")
currentOs.isWindows -> listOf("linux")
else -> listOf("linux")
}.mapNotNull { kotlin.targets.findByName(it) as? org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget }
configure(targets) {
compilations.all {
cinterops.all { tasks[interopProcessingTaskName].enabled = false }
compileKotlinTask.enabled = false
tasks[processResourcesTaskName].enabled = false
}
binaries.all { linkTask.enabled = false }
mavenPublication {
val publicationToDisable = this
tasks.withType<AbstractPublishToMaven>().all { onlyIf { publication != publicationToDisable } }
tasks.withType<GenerateModuleMetadata>().all { onlyIf { publication.get() != publicationToDisable } }
}
}
}
android {
defaultConfig {
compileSdkVersion(30)
@ -117,14 +143,14 @@ val buildSecp256k1 by tasks.creating { group = "build" }
sealed class Cross {
abstract fun cmd(target: String, nativeDir: File): List<String>
class DockCross(val cross: String) : Cross() {
override fun cmd(target: String, nativeDir: File): List<String> = listOf("./dockcross-$cross", "bash", "-c", "TARGET=$target ./build.sh")
override fun cmd(target: String, nativeDir: File): List<String> = listOf("./dockcross-$cross", "bash", "-c", "CROSS=1 TARGET=$target ./build.sh")
}
class MultiArch(val crossTriple: String) : Cross() {
override fun cmd(target: String, nativeDir: File): List<String> {
val uid = Runtime.getRuntime().exec("id -u").inputStream.use { it.reader().readText() }.trim().toInt()
return listOf(
"docker", "run", "--rm", "-v", "${nativeDir.absolutePath}:/workdir",
"-e", "CROSS_TRIPLE=$crossTriple", "-e", "TARGET=$target", "-e", "TO_UID=$uid",
"-e", "CROSS_TRIPLE=$crossTriple", "-e", "TARGET=$target", "-e", "TO_UID=$uid", "-e", "CROSS=1",
"multiarch/crossbuild", "./build.sh"
)
}

View File

@ -13,6 +13,7 @@ if [ "$TARGET" == "mingw" ]; then
CONF_OPTS="CFLAGS=-fpic --host=x86_64-w64-mingw32"
elif [ "$TARGET" == "linux" ]; then
CONF_OPTS="CFLAGS=-fpic"
[ "$CROSS" == "1" ] && sudo apt -y install libgmp-dev
elif [ "$TARGET" == "darwin" ]; then
CONF_OPTS="--host=x86_64-w64-darwin"
fi