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

fix: Make multiplatform actually compile the code. #119

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
26 changes: 23 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test")
load("@rules_kotlin//kotlin:lint.bzl", "ktlint_fix", "ktlint_test")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//tools/project:build_defs.bzl", "project")

Expand Down Expand Up @@ -73,20 +75,27 @@ cc_binary(
],
)

kt_kotlinc_options(
name = "kotlinc_options",
x_multi_platform = True,
)

kt_jvm_library(
name = "jvm-toxcore-c",
srcs = glob([
"lib/src/*Main/**/*.java",
"lib/src/*Main/**/*.kt",
"lib/src/commonMain/**/*.kt",
"lib/src/jvmMain/**/*.java",
"lib/src/jvmMain/**/*.kt",
]),
data = ["libtox4j-c.so"],
kotlinc_opts = ":kotlinc_options",
deps = [":jni_java_proto"],
)

kt_jvm_test(
name = "ToxCoreTest",
size = "small",
srcs = ["lib/src/jvmTest/java/im/tox/tox4j/core/ToxCoreTest.kt"],
srcs = ["lib/src/commonTest/kotlin/im/tox/tox4j/core/ToxCoreTest.kt"],
jvm_flags = ["-Djava.library.path=jvm-toxcore-c"],
test_class = "im.tox.tox4j.core.ToxCoreTest",
deps = [
Expand All @@ -95,3 +104,14 @@ kt_jvm_test(
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
],
)

ktlint_fix(
name = "ktlint_fix",
srcs = glob(["lib/src/**/*.kt"]),
)

ktlint_test(
name = "ktlint_test",
size = "small",
srcs = glob(["lib/src/**/*.kt"]),
)
2 changes: 2 additions & 0 deletions docker/build-native
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ set -eux
cat <<EOF >native.txt
-p
library
-Xmulti-platform
EOF

find lib/src/commonMain -name '*.kt' -exec printf '{}\n-Xcommon-sources={}\n' ';' >>native.txt
find lib/src/nativeMain -name '*.kt' -exec printf '{}\n' ';' >>native.txt

kotlinc-native @native.txt
ls
1 change: 1 addition & 0 deletions docker/native.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ENV PATH=$PATH:/opt/kotlin/bin

RUN ["touch", "Boot.kt"]
RUN ["kotlinc-native", "-p", "library", "Boot.kt"]
#RUN ["kotlinc-native", "-help", "-X"]

WORKDIR /work/jvm-toxcore-c
COPY lib/ /work/jvm-toxcore-c/lib/
Expand Down
17 changes: 15 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@ repositories {
mavenCentral()
}

dependencies {
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
sourceSets["main"].proto {
srcDir("src/jvmMain/proto")
dependencies {
implementation("com.google.protobuf:protobuf-java:3.24.4")
}
}

kotlin {
jvm()
// linuxX64()

sourceSets {
val jvmMain by getting {
kotlin.srcDir("${project.layout.buildDirectory}/generated/source/proto/main/java")
dependencies {
implementation("com.google.protobuf:protobuf-java:3.24.4")
}
}
val commonTest by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-test-junit:1.9.22")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}
}
}
}

tasks["compileKotlinJvm"].dependsOn("generateProto")

testing {
suites {
// Configure the built-in test suite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class ToxavAnswerException : ToxException {
SYNC,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ class ToxavBitRateSetException : ToxException {
SYNC,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class ToxavCallControlException : ToxException {
SYNC,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class ToxavCallException : ToxException {
SYNC,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class ToxavNewException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ class ToxavSendFrameException : ToxException {
SYNC,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
3 changes: 3 additions & 0 deletions lib/src/commonMain/kotlin/im/tox/tox4j/core/ToxCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import im.tox.tox4j.core.enums.ToxMessageType
import im.tox.tox4j.core.enums.ToxUserStatus
import im.tox.tox4j.core.options.ToxOptions

@kotlin.ExperimentalStdlibApi
expect fun newToxCore(options: ToxOptions): ToxCore

/**
* Interface for a basic wrapper of tox chat functionality.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class ToxBootstrapException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ class ToxFileControlException : ToxException {
SENDQ,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class ToxFileGetException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class ToxFileSeekException : ToxException {
SENDQ,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ class ToxFileSendChunkException : ToxException {
WRONG_POSITION,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class ToxFileSendException : ToxException {
TOO_MANY,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ class ToxFriendAddException : ToxException {
TOO_LONG,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class ToxFriendByPublicKeyException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ class ToxFriendCustomPacketException : ToxException {
TOO_LONG,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class ToxFriendDeleteException : ToxException {
FRIEND_NOT_FOUND,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class ToxFriendGetPublicKeyException : ToxException {
FRIEND_NOT_FOUND,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class ToxFriendSendMessageException : ToxException {
TOO_LONG,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class ToxGetPortException : ToxException {
NOT_BOUND,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ class ToxNewException : ToxException {
PROXY_NOT_FOUND,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class ToxSetInfoException : ToxException {
TOO_LONG,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class ToxSetTypingException : ToxException {
FRIEND_NOT_FOUND,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class ToxDecryptionException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class ToxEncryptionException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class ToxGetSaltException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ class ToxKeyDerivationException : ToxException {
NULL,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package im.tox.tox4j.exceptions

abstract class ToxException constructor(val code: Enum<*>, private val extraMessage: String) :
Exception(extraMessage) {
final override val message: String
get() =
when (extraMessage) {
"" -> "Error code: " + code.name
else -> extraMessage + ", error code: " + code.name
}
}
final override val message: String
get() =
when (extraMessage) {
"" -> "Error code: " + code.name
else -> extraMessage + ", error code: " + code.name
}
}
3 changes: 2 additions & 1 deletion lib/src/commonMain/kotlin/im/tox/tox4j/mkexceptions
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Tox${prefix}${type}Exception : ToxException {
$codes,
}

constructor(code: Code, message: String = "") : super(code, message)
constructor(code: Code) : this(code, "")
constructor(code: Code, message: String) : super(code, message)
}
KOTLIN

Expand Down
Loading
Loading