Skip to content

Commit

Permalink
分离shared
Browse files Browse the repository at this point in the history
  • Loading branch information
xfqwdsj committed May 2, 2024
1 parent 367759c commit a421738
Show file tree
Hide file tree
Showing 50 changed files with 290 additions and 75 deletions.
1 change: 1 addition & 0 deletions client-py/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ kotlin {
sourceSets {
val nativeMain by getting {
dependencies {
implementation(projects.shared)
api(projects.pyCommon)
api(projects.pyInternal)
implementation(libs.kotlinx.datetime)
Expand Down
1 change: 1 addition & 0 deletions client-py/src/nativeMain/kotlin/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.cbor.Cbor
import xyz.xfqlittlefan.fhraise.logger
import kotlin.coroutines.resume
import kotlin.experimental.ExperimentalNativeApi

Expand Down
39 changes: 8 additions & 31 deletions client-py/src/nativeMain/kotlin/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,12 @@

package xyz.xfqlittlefan.fhraise.py

import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

class Logger internal constructor(private val tag: Any) {
@Deprecated("This constructor is for calling from C code only.", level = DeprecationLevel.HIDDEN)
constructor(tag: String) : this("<From C> $tag" as Any)

fun debug(message: String) {
println("Debug", message)
}

fun info(message: String) {
println("Info", message)
}

fun warn(message: String) {
println("Warn", message)
}

fun error(message: String) {
println("Error", message)
}

private fun println(level: String, message: String) {
message.split("\n").forEach {
println("${Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())} [$tag] $level: $it")
}
}
class Logger(tag: String) {
private val delegate = xyz.xfqlittlefan.fhraise.Logger("<From C> $tag")

fun trace(message: String) = delegate.trace(message)
fun debug(message: String) = delegate.debug(message)
fun info(message: String) = delegate.info(message)
fun warn(message: String) = delegate.warn(message)
fun error(message: String) = delegate.error(message)
}

internal val Any.logger: Logger get() = Logger(this::class.let { it.qualifiedName ?: it })
1 change: 1 addition & 0 deletions client-py/src/nativeMain/kotlin/Throwable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package xyz.xfqlittlefan.fhraise.py

import kotlinx.cinterop.*
import xyz.xfqlittlefan.fhraise.logger
import kotlin.experimental.ExperimentalNativeApi

@ExperimentalForeignApi
Expand Down
2 changes: 1 addition & 1 deletion compose-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.shared)
implementation(projects.sharedApp)
implementation(projects.pyCommon)
implementation(compose.runtime)
implementation(compose.foundation)
Expand Down
2 changes: 0 additions & 2 deletions compose-app/compose-android.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-dontwarn java.lang.management.ManagementFactory
-dontwarn java.lang.management.RuntimeMXBean
#-dontwarn org.slf4j.impl.StaticLoggerBinder

-keep class org.slf4j.** { *; }
-keepclassmembers class xyz.xfqlittlefan.fhraise.oauth.OAuthApplication$module$1
2 changes: 1 addition & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ application {
}

dependencies {
implementation(projects.shared)
implementation(projects.sharedApp)
implementation(projects.pyCommon)
implementation(projects.pyInternal)
implementation(libs.kotlinx.coroutines.core)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencyResolutionManagement {
}

include(":shared")
include(":shared-app")

include(":compose-app")
include(":server")
Expand Down
109 changes: 109 additions & 0 deletions shared-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.androidLibrary)
}

kotlin {
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

jvm()

@OptIn(ExperimentalWasmDsl::class) wasmJs {
browser()
}

applyDefaultHierarchyTemplate()

sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.shared)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.datetime)
implementation(libs.ktor.client.core)
implementation(libs.ktor.http)
implementation(libs.ktor.resources)
}
}

val commonJvmMain by creating {
dependsOn(commonMain)
dependencies {
implementation(libs.androidx.datastore.core)
implementation(libs.androidx.datastore.preferences.core)
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.resources)
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
exclude("androidx/datastore/**")
}
}

val androidMain by getting {
dependsOn(commonJvmMain)
dependencies {
implementation(libs.androidx.datastore.preferences)
}
}

val jvmMain by getting {
dependsOn(commonJvmMain)
}

val wasmJsMain by getting {
dependencies {}
}
}
}

val androidCompileSdk: String by project
val androidMinSdk: String by project

android {
namespace = "xyz.xfqlittlefan.fhraise.sharedapp"
compileSdk = androidCompileSdk.toInt()

defaultConfig {
minSdk = androidMinSdk.toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

splits {
abi {
isEnable = true
isUniversalApk = true
}
}
}
41 changes: 23 additions & 18 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ plugins {
}

kotlin {
@OptIn(ExperimentalWasmDsl::class) wasmJs {
browser()
}

androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
Expand All @@ -39,46 +35,54 @@ kotlin {

jvm()

@OptIn(ExperimentalWasmDsl::class) wasmJs {
browser()
}

linuxArm64()
linuxX64()
mingwX64()

applyDefaultHierarchyTemplate()

sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.datetime)
implementation(libs.ktor.client.core)
implementation(libs.ktor.http)
implementation(libs.ktor.resources)
}
}

val commonJvmMain by creating {
dependsOn(commonMain)
dependencies {
implementation(libs.androidx.datastore.core)
implementation(libs.androidx.datastore.preferences.core)
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.resources)
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
exclude("androidx/datastore/**")
implementation(libs.slf4j.api)
}
}

val androidMain by getting {
dependsOn(commonJvmMain)
dependencies {
implementation(libs.androidx.datastore.preferences)
implementation(libs.logback.android)
}
}

val jvmMain by getting {
dependsOn(commonJvmMain)
dependencies {
implementation(libs.logback)
}
}

val notJvmMain by creating {
dependsOn(commonMain)
}

val wasmJsMain by getting {
dependencies {}
dependsOn(notJvmMain)
}

val nativeMain by getting {
dependsOn(notJvmMain)
}
}
}
Expand All @@ -92,6 +96,7 @@ android {

defaultConfig {
minSdk = androidMinSdk.toInt()
consumerProguardFiles("consumer-rules.pro")
}

compileOptions {
Expand Down
1 change: 1 addition & 0 deletions shared/proguard-android.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep class org.slf4j.** { *; }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ sealed interface DesktopPlatform : JvmPlatform {
companion object
}

object WasmPlatform : Platform {
data object WasmPlatform : Platform {
override val name: String = "Web with Kotlin/Wasm"
}

sealed interface NativePlatform : Platform {
data object LinuxArm64 : NativePlatform {
override val name: String = "Linux Arm64"
}

data object LinuxX64 : NativePlatform {
override val name: String = "Linux x64"
}

data object WindowsX64 : NativePlatform {
override val name: String = "Windows x64"
}
}
21 changes: 21 additions & 0 deletions shared/src/linuxArm64Main/kotlin/Platform.linuxArm64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package xyz.xfqlittlefan.fhraise

actual val platform: Platform = NativePlatform.LinuxArm64
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package xyz.xfqlittlefan.fhraise.py
package xyz.xfqlittlefan.fhraise

actual val platform: Platform = NativePlatform.LinuxX64
21 changes: 21 additions & 0 deletions shared/src/mingwX64Main/kotlin/Platform.mingwX64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This file is part of Fhraise.
* Copyright (c) 2024 HSAS Foodies. All Rights Reserved.
*
* Fhraise is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Fhraise is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Fhraise. If not, see <https://www.gnu.org/licenses/>.
*/

package xyz.xfqlittlefan.fhraise

actual val platform: Platform = NativePlatform.WindowsX64
Loading

0 comments on commit a421738

Please sign in to comment.