Skip to content
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

Kotlin 1.9 - build tests #6

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

check:
name: Check
runs-on: macos-latest
runs-on: macos-14-large
steps:
- name: Check out
uses: actions/checkout@v2
Expand Down
36 changes: 22 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import org.jetbrains.dokka.Platform

plugins {
id("com.android.library") version "7.2.2"
id("com.android.library") version "7.4.2"
kotlin("multiplatform") version Versions.kotlin
id("org.jetbrains.dokka") version Versions.kotlin
id("org.jetbrains.dokka") version Versions.dokka
`maven-publish`
}

buildscript {
dependencies {
classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}")
}
}

group = "fr.acinq.tor"
version = "0.2.0"
version = "0.3.0-SNAPSHOT"

repositories {
maven("https://oss.sonatype.org/content/repositories/snapshots")
google()
mavenCentral()
}

android {
namespace = "fr.acinq.tor.library"
compileSdk = 33
ndkVersion = Versions.ndk
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 21
targetSdk = 33
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
externalNativeBuild {
Expand All @@ -43,17 +44,26 @@ android {
kotlin {
explicitApi()

android {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
}

ios {
iosX64 {
compilations["main"].cinterops.create("tor_in_thread") {
val platform = "IosX64"
includeDirs.headerFilterOnly("$rootDir/native/tor_in_thread")
tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${target!!.name.capitalize()}")
tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${platform.capitalize()}")
}
}

iosArm64 {
compilations["main"].cinterops.create("tor_in_thread") {
val platform = "IosArm64"
includeDirs.headerFilterOnly("$rootDir/native/tor_in_thread")
tasks[interopProcessingTaskName].dependsOn(":native:buildTor_in_thread${platform.capitalize()}")
}
}

Expand All @@ -78,18 +88,15 @@ kotlin {
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-android:${Versions.secp256k1}")
}
}
val androidTest by getting {
val androidUnitTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
implementation("androidx.test.ext:junit:1.1.4")
implementation("androidx.test.espresso:espresso-core:3.5.0")
implementation("androidx.test.ext:junit:1.1.5")
implementation("androidx.test.espresso:espresso-core:3.5.1")
}
}

val iosMain by getting
val iosTest by getting

all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
Expand Down Expand Up @@ -138,6 +145,7 @@ afterEvaluate {
Platform.js -> "js"
Platform.native -> "native"
Platform.common -> "common"
Platform.wasm -> "wasm"
}
displayName.set(platformName)
perPackageOption {
Expand Down
7 changes: 4 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
object Versions {
const val kotlin = "1.6.21"
const val kotlin = "1.9.22"
const val dokka = "1.9.10"
const val ndk = "21.3.6528147"
const val ktor = "2.0.3"
const val secp256k1 = "0.7.0"
const val ktor = "2.3.7"
const val secp256k1 = "0.13.0"
}
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
kotlin.code.style=official
android.useAndroidX=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.binary.memoryModel=experimental
kotlin.mpp.stability.nowarn=true

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionSha256Sum=f6b8596b10cce501591e92f229816aa4046424f3b24d771751b06779d58c8ec4
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion native/ios/libevent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export LDFLAGS="${HOST_FLAGS}"
./configure \
--host="${CHOST}" \
--prefix="${PREFIX}" \
--enable-static --disable-shared \
--enable-static --disable-shared --disable-openssl\
--enable-gcc-hardening --disable-samples \
cross_compiling="yes" ac_cv_func_clock_gettime="no"

Expand Down
2 changes: 1 addition & 1 deletion src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="fr.acinq.tor.library">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
9 changes: 4 additions & 5 deletions src/commonTest/kotlin/fr/acinq/tor/TorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ package fr.acinq.tor
import fr.acinq.tor.socks.socks5Handshake
import io.ktor.network.selector.*
import io.ktor.network.sockets.*
import io.ktor.network.tls.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue


class TorTest {
Expand Down Expand Up @@ -58,7 +56,8 @@ class TorTest {
)

tor.start(this)

tor.state.first { it == TorState.RUNNING }
tor.info.filterNotNull().first { it.networkLiveness == "up" }
try {
SelectorManager().use { selectorManager ->
aSocket(selectorManager).tcp().connect(Tor.SOCKS_ADDRESS, Tor.SOCKS_PORT).use { socket ->
Expand All @@ -69,7 +68,7 @@ class TorTest {
connection.output.flush()

val line = connection.input.readUTF8Line()
assertEquals("HTTP/1.0 200 OK", line)
assertTrue { line.equals("HTTP/1.0 200 OK") || line.equals("HTTP/1.0 302 Found") }
}
}
} finally {
Expand Down
3 changes: 3 additions & 0 deletions src/iosMain/kotlin/fr/acinq/tor/torInThreadIos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package fr.acinq.tor

import fr.acinq.tor.in_thread.tor_in_thread_get_is_running
import fr.acinq.tor.in_thread.tor_in_thread_start
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.toCStringArray


@OptIn(ExperimentalForeignApi::class)
internal actual fun startTorInThread(args: Array<String>) {
memScoped {
tor_in_thread_start(args.size, args.toCStringArray(this))
}
}

@OptIn(ExperimentalForeignApi::class)
internal actual fun isTorInThreadRunning(): Boolean =
tor_in_thread_get_is_running() != 0
2 changes: 2 additions & 0 deletions src/iosMain/kotlin/fr/acinq/tor/utils/platformIos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import platform.Foundation.*
import platform.posix.*


@OptIn(ExperimentalForeignApi::class)
internal actual suspend fun fileContent(path: String): ByteArray? {
val file = fopen(path, "r") ?: return null
fseek(file, 0.convert(), SEEK_END)
Expand All @@ -23,6 +24,7 @@ internal actual suspend fun deleteFile(path: String) {
remove(path)
}

@OptIn(ExperimentalForeignApi::class)
internal actual fun hmacSha256(key: ByteArray, message: ByteArray): ByteArray {
val result = ByteArray(CC_SHA256_DIGEST_LENGTH)
result.usePinned { pinnedResult ->
Expand Down
Loading