Skip to content

Commit

Permalink
Merge pull request #152 from szaffarano/szaffarano/linux-support
Browse files Browse the repository at this point in the history
Add support for Linux platform
  • Loading branch information
jillesvangurp authored Nov 25, 2024
2 parents 80a87ad + e902b67 commit 652ca60
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
steps:
- name: Checkout the code
uses: actions/checkout@master
# - name: Install cURL Headers
# run: sudo apt-get install libcurl4-openssl-dev
- name: Install cURL Headers
run: sudo apt-get update && sudo apt-get install libcurl4-openssl-dev -y
- name: Setup Java
uses: actions/setup-java@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ secring.gpg
local.properties
localRepo
.ipynb_checkpoints
.direnv
flake.nix
flake.lock
.envrc
61 changes: 34 additions & 27 deletions search-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
Expand Down Expand Up @@ -87,22 +89,30 @@ kotlin {
}
}
}
// several issues with the linux build that prevent this from working
// keep disabled for now.
// if(DefaultNativePlatform.getCurrentOperatingSystem().isLinux) {
// // some weird linking error
// linuxX64()
// // lib curl is not found for this one :-(
// linuxArm64()
// }
if (DefaultNativePlatform.getCurrentOperatingSystem().isLinux) {
fun KotlinNativeTarget.configureLinuxTarget() {
binaries {
all {
linkerOpts = System.getenv()
.getOrDefault("LDFLAGS", "")
.split(":")
.filter { it.isNotBlank() }
.map { "-L$it" }
.toMutableList()
}
}
}
linuxX64 { configureLinuxTarget() }
linuxArm64 { configureLinuxTarget() }
}
mingwX64()
macosX64()
macosArm64()
// iOS targets
iosArm64()
iosX64()
iosSimulatorArm64()
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
testTask {
Expand Down Expand Up @@ -212,6 +222,12 @@ kotlin {
}
}

linuxMain {
dependencies {
implementation(Ktor.client.curl)
}
}

mingwMain {
dependencies {
implementation(Ktor.client.curl)
Expand Down Expand Up @@ -245,7 +261,7 @@ configure<ComposeExtension> {
dockerComposeWorkingDirectory.set(project.parent!!.projectDir)
useComposeFiles.set(listOf(composeFile))

listOf("/usr/bin/docker","/usr/local/bin/docker").firstOrNull {
listOf("/usr/bin/docker", "/usr/local/bin/docker").firstOrNull {
File(it).exists()
}?.let { docker ->
// works around an issue where the docker
Expand All @@ -261,12 +277,9 @@ tasks.named("jsNodeTest") {
// on gh actions jsNodeTest manages to run before tasks of type
// Test are initialized. So explicitly bring up compose before jsNodeTest fixes
// that problem
val isUp = try {
val isUp = kotlin.runCatching {
URI("http://localhost:9999").toURL().openConnection().connect()
true
} catch (e: Exception) {
false
}
}.isSuccess
if (!isUp) {
dependsOn(
"composeUp"
Expand All @@ -275,12 +288,9 @@ tasks.named("jsNodeTest") {
}

tasks.withType<Test> {
val isUp = try {
val isUp = kotlin.runCatching {
URI("http://localhost:9999").toURL().openConnection().connect()
true
} catch (e: Exception) {
false
}
}.isSuccess
if (!isUp) {
dependsOn(
"composeUp"
Expand All @@ -307,14 +317,11 @@ tasks.withType<Test> {
)
addTestListener(object : TestListener {
val failures = mutableListOf<String>()
override fun beforeSuite(desc: TestDescriptor) {
}
override fun beforeSuite(desc: TestDescriptor) = Unit

override fun afterSuite(desc: TestDescriptor, result: TestResult) {
}
override fun afterSuite(desc: TestDescriptor, result: TestResult) = Unit

override fun beforeTest(desc: TestDescriptor) {
}
override fun beforeTest(desc: TestDescriptor) = Unit

override fun afterTest(desc: TestDescriptor, result: TestResult) {
if (result.resultType == TestResult.ResultType.FAILURE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.jillesvangurp.ktsearch

import io.ktor.client.HttpClient
import io.ktor.client.engine.curl.Curl
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.http.headers

actual fun defaultKtorHttpClient(
logging: Boolean,
user: String?,
password: String?,
elasticApiKey: String?
): HttpClient {
return HttpClient(Curl) {
engine {
pipelining = true
}
if (!user.isNullOrBlank() && !password.isNullOrBlank()) {
install(Auth) {
basic {
credentials { BasicAuthCredentials(user, password) }
sendWithoutRequest { true }
}
}
}
if (!elasticApiKey.isNullOrBlank()) {
headers { append("Authorization", "ApiKey $elasticApiKey") }
}
if (logging) {
install(Logging) { level = LogLevel.ALL }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.jillesvangurp.ktsearch

actual fun simpleIndexProvider(initialIndex: Int): IndexProvider = object : IndexProvider {
private var index = 0

override fun get(): Int = index

override fun set(value: Int) {
index = value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jillesvangurp.ktsearch

/**
* On JVM this will return the current thread name, otherwise this will return null and pick a random node
*/
actual fun threadId(): String? = null
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ actual fun coRun(timeout: Duration, block: suspend () -> Unit) {
}
}

@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
actual annotation class IgnoreJs

0 comments on commit 652ca60

Please sign in to comment.