Skip to content

Commit

Permalink
Merge branch 'jb-main' into dima.avdeev/ios-single-layer-compose-scene
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-avdeev-jb committed Dec 8, 2023
2 parents 9dc4154 + 281be05 commit 9bfba2f
Show file tree
Hide file tree
Showing 121 changed files with 3,217 additions and 389 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Run Integration Tests
on:
workflow_run:
workflows: ["AndroidX Presubmits"]
types: [completed]
on: {}

jobs:
run_integration_tests:
Expand Down
19 changes: 1 addition & 18 deletions .github/workflows/jbpresubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@

# The aim of this workflow is to run checks and some tests before submitting the CL upstream.
name: JB-COMPOSE-variant of AndroidX Presubmits
on:
push:
branches:
- jb_cl*
- jb_presubmit*

pull_request:
branches:
- jb-main
- jb_presubmit*
- jb_cl*
types:
- opened
- reopened
- synchronize

# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
on: {}

jobs:
setup:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: AndroidX Presubmits
on:
push:
pull_request:
on: {}

env:
# Allow precise monitoring of the save/restore of Gradle User Home by `gradle-build-action`
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/prune_artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: "Prune old artifacts"
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
on: {}

jobs:
delete-artifacts:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/register_workflow_start.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Register Workflow Run with AndroidX
on:
workflow_run:
workflows: ["AndroidX Presubmits"]
types: [requested]
on: {}

jobs:
ping_androidx_dev:
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
name: Scorecards supply-chain security
on:
# Only the default branch is supported.
branch_protection_rule:
schedule:
- cron: '24 14 * * 1'
push:
branches: [ androidx-main ]
on: {}

# Declare default permissions as read only.
permissions: read-all
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/update_prebuilts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@
# To run it, navigate to https://github.com/androidx/androidx/actions/workflows/update_prebuilts.yml
# and click "Run workflow"
name: Update Prebuilts
on:
workflow_dispatch:
inputs:
target-branch:
description: 'The target branch for the PR'
required: false
default: 'androidx-main'
type: string
comment:
description: 'Any comment you would like to add to the PR body'
required: false
default: ''
type: string
on: {}
jobs:
update-prebuilts:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ captures/
__pycache__

# Don't ignore src files under build package
!**/src/**/build
!**/src/**/build
23 changes: 23 additions & 0 deletions .run/mpp/demo/wasm-Demo.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="wasm Demo" type="GradleRunConfiguration" factoryName="Gradle" folderName="mpp/demo">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/compose/mpp/demo" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="wasmJsBrowserRun" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ allprojects {
"-Xsam-conversions=class",
"-opt-in=kotlin.RequiresOptIn", // for JB-fork only - don't upstream
]
languageVersion = "1.5"
apiVersion = "1.5"
languageVersion = "1.8"
apiVersion = "1.8"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,20 @@ class AndroidXComposeImplPlugin : Plugin<Project> {
}

project.tasks.withType(KotlinJsCompile::class.java).configureEach { compile ->
// val isWasm = compile.kotlinOptions.freeCompilerArgs.contains("-Xwasm")

compile.kotlinOptions.freeCompilerArgs += listOf(
"-P", "plugin:androidx.compose.compiler.plugins.kotlin:generateDecoys=true"
"-P", "plugin:androidx.compose.compiler.plugins.kotlin:generateDecoys=false",
"-Xklib-enable-signature-clash-checks=false",
)
}

project.tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile>().configureEach {
it.kotlinOptions {
freeCompilerArgs += "-opt-in=kotlinx.cinterop.ExperimentalForeignApi"
freeCompilerArgs += "-opt-in=kotlin.experimental.ExperimentalNativeApi"
}
}
}

private fun Project.androidxExtension(): AndroidXExtension? {
Expand Down Expand Up @@ -366,16 +376,10 @@ private fun configureComposeCompilerPlugin(
val configuration = project.configurations.create(COMPILER_PLUGIN_CONFIGURATION)
// Add Compose compiler plugin to kotlinPlugin configuration, making sure it works
// for Playground builds as well
val compilerPluginVersion = project.properties["jetbrains.compose.compiler.version"] as String
project.dependencies.add(
COMPILER_PLUGIN_CONFIGURATION,
if (ProjectLayoutType.isPlayground(project)) {
AndroidXPlaygroundRootImplPlugin.projectOrArtifact(
project.rootProject,
":compose:compiler:compiler"
)
} else {
project.rootProject.resolveProject(":compose:compiler:compiler")
}
"org.jetbrains.compose.compiler:compiler:$compilerPluginVersion"
)
val kotlinPlugin = configuration.incoming.artifactView { view ->
view.attributes { attributes ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.gradle.api.Action
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
import org.gradle.api.attributes.Usage
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getValue
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.DependencyConstraint
Expand All @@ -44,24 +50,36 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.kotlin.dsl.create
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.tomlj.Toml

open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
val project: Project
) : AndroidXComposeMultiplatformExtension() {
private val multiplatformExtension =
project.extensions.getByType(KotlinMultiplatformExtension::class.java)

private val skikoVersion: String

init {
val toml = Toml.parse(
project.rootProject.projectDir.resolve("gradle/libs.versions.toml").toPath()
)
skikoVersion = toml.getTable("versions")!!.getString("skiko")!!
println("Skiko version = $skikoVersion")
}

override val isKotlinWasmTargetEnabled: Boolean
get() = project.properties["kotlinWasmEnabled"] == "true"

override fun android(): Unit = multiplatformExtension.run {
android()
androidTarget()

val androidMain = sourceSets.getByName("androidMain")
val jvmMain = getOrCreateJvmMain()
androidMain.dependsOn(jvmMain)

val androidTest = sourceSets.getByName("androidTest")
val androidTest = sourceSets.getByName("androidUnitTest")
val jvmTest = getOrCreateJvmTest()
androidTest.dependsOn(jvmTest)
}
Expand Down Expand Up @@ -91,13 +109,67 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
@OptIn(ExperimentalWasmDsl::class)
override fun wasm(): Unit = multiplatformExtension.run {
if (!isKotlinWasmTargetEnabled) return@run
wasm {
d8()
wasmJs {
browser {
testTask(Action<KotlinJsTest> {
it.useKarma {
useChromeHeadless()
useConfigDirectory(
project.rootProject.projectDir.resolve("mpp/karma.config.d/wasm")
)
}
})
}
}

val resourcesDir = "${project.buildDir}/resources"
val skikoWasm by project.configurations.creating

// Below code helps configure the tests for k/wasm targets
project.dependencies {
skikoWasm("org.jetbrains.skiko:skiko-js-wasm-runtime:${skikoVersion}")
}

val unzipTask = project.tasks.register("unzipSkikoForKWasm", Copy::class.java) {
it.destinationDir = project.file(resourcesDir)
it.from(skikoWasm.map { project.zipTree(it) })
}

val loadTestsTask = project.tasks.register("loadTests", Copy::class.java) {
it.destinationDir = project.file(resourcesDir)
it.from(
project.rootProject.projectDir.resolve(
"mpp/load-wasm-tests/load-test-template.mjs"
)
)
it.filter {
it.replace("{module-name}", getDashedProjectName())
}
}

project.tasks.getByName("wasmJsTestProcessResources").apply {
dependsOn(loadTestsTask)
}

project.tasks.getByName("wasmJsBrowserTest").apply {
dependsOn(unzipTask)
}

val commonMain = sourceSets.getByName("commonMain")
val wasmMain = sourceSets.getByName("wasmMain")
val wasmMain = sourceSets.getByName("wasmJsMain")
wasmMain.dependsOn(commonMain)

sourceSets.getByName("wasmJsTest").also {
it.resources.setSrcDirs(it.resources.srcDirs)
it.resources.srcDirs(unzipTask.map { it.destinationDir })
}
}

private fun getDashedProjectName(p: Project = project): String {
if (p == project.rootProject) {
return p.name
}
return getDashedProjectName(p = p.parent!!) + "-" + p.name
}

override fun darwin(): Unit = multiplatformExtension.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget

Expand Down Expand Up @@ -107,8 +108,6 @@ open class AndroidXMultiplatformExtension(val project: Project) {
field = value
}

val presets: NamedDomainObjectCollection<KotlinTargetPreset<*>>
get() = kotlinExtension.presets
val targets: NamedDomainObjectCollection<KotlinTarget>
get() = kotlinExtension.targets

Expand Down Expand Up @@ -155,7 +154,7 @@ open class AndroidXMultiplatformExtension(val project: Project) {
): KotlinAndroidTarget? {
requestedPlatforms.add(PlatformIdentifier.ANDROID)
return if (project.enableJvm()) {
kotlinExtension.android {
kotlinExtension.androidTarget {
block?.execute(this)
}
} else { null }
Expand Down Expand Up @@ -294,6 +293,21 @@ open class AndroidXMultiplatformExtension(val project: Project) {
}
}

@OptIn(ExperimentalWasmDsl::class)
@JvmOverloads
fun wasm(
block: Action<KotlinJsTargetDsl>? = null
): KotlinJsTargetDsl? {
requestedPlatforms.add(PlatformIdentifier.WASM)
return if (project.enableWasm()) {
kotlinExtension.wasmJs().also {
block?.execute(it)
}
} else {
null
}
}

companion object {
const val EXTENSION_NAME = "androidXMultiplatform"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const val ENABLED_KMP_TARGET_PLATFORMS = "androidx.enabled.kmp.target.platforms"
enum class PlatformGroup {
JVM,
JS,
WASM,
MAC,
LINUX,
DESKTOP;
Expand All @@ -51,7 +52,7 @@ enum class PlatformGroup {
* Do *not* enable [JS] unless you have read and understand this:
* https://blog.jetbrains.com/kotlin/2021/10/important-ua-parser-js-exploit-and-kotlin-js/
*/
val enabledByDefault = listOf(JVM, DESKTOP)
val enabledByDefault = listOf(JVM, DESKTOP, MAC, JS, WASM)
}
}

Expand All @@ -64,6 +65,7 @@ enum class PlatformIdentifier(
) {
JVM("jvm", PlatformGroup.JVM),
JS("js", PlatformGroup.JS),
WASM("wasm", PlatformGroup.WASM),
ANDROID("android", PlatformGroup.JVM),
MAC_ARM_64("macosarm64", PlatformGroup.MAC),
MAC_OSX_64("macosx64", PlatformGroup.MAC),
Expand Down Expand Up @@ -122,6 +124,7 @@ private open class KmpPlatformsExtension(project: Project) {
}

fun Project.enableJs(): Boolean = enabledKmpPlatforms.contains(PlatformGroup.JS)
fun Project.enableWasm(): Boolean = enabledKmpPlatforms.contains(PlatformGroup.WASM)
fun Project.enableMac(): Boolean =
enabledKmpPlatforms.contains(PlatformGroup.MAC) || Multiplatform.isKotlinNativeEnabled(this)
fun Project.enableLinux(): Boolean =
Expand Down
Loading

0 comments on commit 9bfba2f

Please sign in to comment.