Skip to content

Commit 034bd31

Browse files
committed
Test macos native ci
1 parent 14a3a8c commit 034bd31

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.github/workflows/multiplatform_snapshot_build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
push:
1212
branches:
1313
- dev
14+
- support_macos_native
1415
paths-ignore:
1516
- 'assets/**'
1617
- '**.md'
@@ -41,6 +42,12 @@ jobs:
4142
- type: macOS
4243
desktop: dmg
4344
os: macos-latest
45+
- type: macosArm64
46+
native: dmg
47+
os: macos-latest
48+
- type: macosX64
49+
native: dmg
50+
os: macos-15
4451
- type: iOS
4552
iOS: ipa
4653
# workaround runner version for iPhoneOS sdk 18.2
@@ -127,6 +134,18 @@ jobs:
127134
name: Gallery-${{ matrix.type }}-${{ github.run_id }}
128135
path: ${{github.workspace}}/gallery/build/compose/binaries/main-release/${{ matrix.desktop }}/*.${{ matrix.desktop }}
129136

137+
# Desktop Native Build Action
138+
- name: Build Gallery for ${{ matrix.type }}
139+
if: ${{ matrix.native }}
140+
run: |
141+
./gradlew :gallery:packageDistributionNativeReleaseForCurrentOS
142+
- name: Upload desktop native build artifacts
143+
if: ${{ matrix.native }}
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: Gallery-${{ matrix.type }}-${{ github.run_id }}
147+
path: ${{github.workspace}}/gallery/build/compose/binaries/main/**/*.${{ matrix.native }}
148+
130149
# iOS Build Action, Note: Due to the long build time, the iOS build only build the debug version.
131150
- name: Set up Xcode
132151
if: ${{ matrix.iOS }}

gallery/build.gradle.kts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.android.build.api.variant.impl.VariantOutputImpl
22
import com.codingfeline.buildkonfig.compiler.FieldSpec
33
import io.github.composefluent.plugin.build.BuildConfig
44
import io.github.composefluent.plugin.build.applyTargets
5+
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
56
import org.jetbrains.compose.desktop.application.dsl.AbstractDistributions
67
import org.jetbrains.compose.desktop.application.dsl.AbstractMacOSPlatformSettings
78
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
@@ -235,4 +236,38 @@ fun AbstractDistributions.applyDistributions(
235236

236237
fun AbstractMacOSPlatformSettings.applyCommonSetup() {
237238
iconFile.set(project.file("icons/icon.icns"))
239+
}
240+
241+
tasks.register("desktopNativeRun") {
242+
group = "run"
243+
dependsOn(tasks.named("runDebugExecutable${getTarget().uppercaseFirstChar()}"))
244+
}
245+
246+
listOf("Release", "Debug").forEach { buildType ->
247+
listOf("createDistributable", "packageDistribution").forEach { name ->
248+
tasks.register("${name}Native${buildType.uppercaseFirstChar()}ForCurrentOS") {
249+
group = "compose desktop (native)"
250+
val target = getTarget()
251+
val taskName = if (name == "packageDistribution") {
252+
val targetFormat = compose.desktop.nativeApplication.distributions.targetFormats.first { it.isCompatibleWithCurrentOS }
253+
"package${targetFormat.name}Native${buildType}${target.uppercaseFirstChar()}"
254+
} else {
255+
"${name}Native${buildType}${target.uppercaseFirstChar()}"
256+
}
257+
dependsOn(tasks.named(taskName))
258+
}
259+
}
260+
}
261+
262+
fun getTarget(): String {
263+
// 1. 动态确定当前平台对应的 Kotlin/Native 目标名称
264+
val os = System.getProperty("os.name")
265+
val arch = System.getProperty("os.arch")
266+
val currentTargetName = when {
267+
os.startsWith("Mac OS X") -> if (arch == "aarch64") "macosArm64" else "macosX64"
268+
os.startsWith("Windows") -> "windowsX64"
269+
os.startsWith("Linux") -> "linuxX64"
270+
else -> throw GradleException("Unsupported OS for native distribution: '$os'")
271+
}
272+
return currentTargetName
238273
}

0 commit comments

Comments
 (0)