Skip to content

Create umbrella framework for iOS, because sharing code between modules doesn't work on KMP #59

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

Merged
merged 1 commit into from
May 10, 2022
Merged
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/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
run: ./gradlew build

- name: Build XCFramework
run: ./gradlew assembleJsonLogicCoreXCFramework assembleJsonLogicOperationsApiXCFramework assembleJsonLogicOperationsStdlibXCFramework
run: ./gradlew assembleJsonLogicKMPXCFramework
12 changes: 4 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
podspec_name: "JsonLogicKMP.podspec"
xcframework_zip_name: "JsonLogicKMP_xcframeworks.zip"
xcframework_zip_name: "JsonLogicKMP_xcframework.zip"
xcframework_artifact_key: "xcframeworks"

jobs:
Expand Down Expand Up @@ -43,24 +43,20 @@ jobs:
runs-on: macos-latest
needs: [run_tests]
env:
operations_api_xcframework_path: "operations-api/build/XCFrameworks/release/JsonLogicOperationsApi.xcframework"
operations_stdlib_xcframework_path: "operations-stdlib/build/XCFrameworks/release/JsonLogicOperationsStdlib.xcframework"
core_xcframework_path: "core/build/XCFrameworks/release/JsonLogicCore.xcframework"
umbrella_xcframework_path: "umbrella-framework/build/XCFrameworks/release/JsonLogicKMP.xcframework"
outputs:
sha256: ${{ steps.calculate_checksum.outputs.sha256 }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Build XCFramework
run: ./gradlew assembleJsonLogicCoreXCFramework assembleJsonLogicOperationsApiXCFramework assembleJsonLogicOperationsStdlibXCFramework
run: ./gradlew assembleJsonLogicKMPXCFramework

- name: Zip XCFramework
run: |
mkdir filesToZip
mv "${{ env.operations_api_xcframework_path }}" filesToZip
mv "${{ env.operations_stdlib_xcframework_path }}" filesToZip
mv "${{ env.core_xcframework_path }}" filesToZip
mv "${{ env.umbrella_xcframework_path }}" filesToZip
mv LICENSE filesToZip
cd filesToZip
zip -r "../${{ env.xcframework_zip_name }}" *
Expand Down
15 changes: 2 additions & 13 deletions JsonLogicKMP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,9 @@ Pod::Spec.new do |spec|
spec.platform = :ios
spec.ios.deployment_target = "13.0"

spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/#{spec.name}_xcframeworks.zip",
spec.source = { :http => "#{spec.homepage}/releases/download/#{spec.version}/#{spec.name}.xcframework.zip",
:sha256 => "d91e44efe3208eb072515922bf0dd1a168a261d72320228ae60292335dd8a8b4"
}

spec.subspec 'OperationsApi' do |operationsApi|
operationsApi.vendored_frameworks = "JsonLogicOperationsApi.xcframework"
end

spec.subspec 'OperationsStdlib' do |operationsStdlib|
operationsStdlib.vendored_frameworks = "JsonLogicOperationsStdlib.xcframework"
end

spec.subspec 'Core' do |core|
core.vendored_frameworks = "JsonLogicCore.xcframework"
end

spec.vendored_frameworks = "#{spec.name}.xcframework"
end
8 changes: 2 additions & 6 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ object LibConfig {
const val repositoryUrl = "https://github.com/allegro/json-logic-kmp"
const val name = "JsonLogicKMP"
const val artifactName = "json-logic"
const val xcFrameworkName = "JsonLogicKMP"
}

object Modules {
object XCFrameworkNames {
const val operationsStdlib = "JsonLogicOperationsStdlib"
const val operationsApi = "JsonLogicOperationsApi"
const val core = "JsonLogicCore"
}

const val core = ":core"
const val operationsApi = ":operations-api"
const val operationsStdlib = ":operations-stdlib"
const val utils = ":utils"
const val kotlinTest = "test"
}
Expand Down
19 changes: 3 additions & 16 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@ kotlin {
}
}

val xcFramework = XCFramework(Modules.XCFrameworkNames.core)
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = Modules.XCFrameworkNames.core
isStatic = true
xcFramework.add(this)
}
}
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
Expand Down Expand Up @@ -59,10 +50,6 @@ kotlin {
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)

dependencies {
api(Libs.TouchLab.crashkios)
}
}
}
}
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/operations/string/Cat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package operations.string

import operation.StandardLogicOperation

object Cat : StandardLogicOperation, StringUnwrapStrategy {
internal object Cat : StandardLogicOperation, StringUnwrapStrategy {
override fun evaluateLogic(expression: Any?, data: Any?): Any? = unwrapValueAsString(expression).joinToString("")
}
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/operations/string/Substr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import utils.intOrZero
import utils.secondOrNull
import utils.thirdOrNull

object Substr : StandardLogicOperation, StringUnwrapStrategy {
internal object Substr : StandardLogicOperation, StringUnwrapStrategy {
override fun evaluateLogic(expression: Any?, data: Any?): String {
return with(expression.asList) {
val startIndex = secondOrNull().toString().intOrZero
Expand Down
18 changes: 4 additions & 14 deletions operations-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
kotlin("multiplatform") version Versions.kotlin
id("io.kotest.multiplatform") version Versions.kotest
Expand All @@ -15,18 +13,10 @@ kotlin {
}
}

val xcFramework = XCFramework(Modules.XCFrameworkNames.operationsApi)
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = Modules.XCFrameworkNames.operationsApi
isStatic = true
xcFramework.add(this)
}
}
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
18 changes: 4 additions & 14 deletions operations-stdlib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
kotlin("multiplatform") version Versions.kotlin
id("io.kotest.multiplatform") version Versions.kotest
Expand All @@ -15,18 +13,10 @@ kotlin {
}
}

val xcFramework = XCFramework(Modules.XCFrameworkNames.operationsStdlib)
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = Modules.XCFrameworkNames.operationsStdlib
isStatic = true
xcFramework.add(this)
}
}
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pluginManagement {
}
rootProject.name = "json-logic-kmp"

include("core", "operations-api", "operations-stdlib", "utils")
include("core", "operations-api", "operations-stdlib", "utils", "umbrella-framework")
75 changes: 75 additions & 0 deletions umbrella-framework/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework

plugins {
kotlin("multiplatform") version Versions.kotlin
id("io.kotest.multiplatform") version Versions.kotest
id(Conventions.junit)
id(Conventions.publishing)
}

kotlin {
jvm {
mavenPublication{ setFullModuleArtifactId() }
compilations.all {
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.majorVersion
}
}

val xcFramework = XCFramework(LibConfig.xcFrameworkName)
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = LibConfig.xcFrameworkName
isStatic = true
export(project(Modules.core))
export(project(Modules.operationsApi))
export(project(Modules.operationsStdlib))
xcFramework.add(this)
}
}

sourceSets {
val commonMain by getting {
dependencies {
api(project(Modules.core))
api(project(Modules.operationsApi))
api(project(Modules.operationsStdlib))
implementation(project(Modules.utils))
}
}

val commonTest by getting {
dependencies {
implementation(kotlin(Modules.kotlinTest))
implementation(Libs.Kotest.assertionsCore)
implementation(Libs.Kotest.frameworkEngine)
implementation(Libs.Kotest.frameworkDataset)
implementation(project(Modules.utils))
}
}
val jvmTest by getting {
dependencies {
implementation(Libs.Kotest.jvmJunit5Runner)
}
}

val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)

dependencies {
implementation(Libs.TouchLab.crashkios)
}
}
}
}