Skip to content

Commit

Permalink
Ci jetpack compose (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bencodes authored Jan 15, 2022
1 parent cd5ec8e commit 5240af8
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 119 deletions.
6 changes: 6 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ tasks:
build_targets:
- //coroutines-helloworld/...
- //express/...
example-jetpack-compose:
name: "Example - Jetpack Compose"
platform: ubuntu1804
working_directory: examples/jetpack_compose
test_targets:
- //...
stardoc:
name: Stardoc api documentation
platform: ubuntu1804
Expand Down
7 changes: 7 additions & 0 deletions examples/jetpack_compose/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Enable d8 merger
build --define=android_dexmerger_tool=d8_dexmerger

# Flags for the D8 dexer
build --define=android_incremental_dexing_tool=d8_dexbuilder
build --define=android_standalone_dexing_tool=d8_compat_dx
build --nouse_workers_with_dexbuilder
15 changes: 14 additions & 1 deletion examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_compiler_plugin", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options", "kt_jvm_import")
load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")

# Java Toolchain
Expand Down Expand Up @@ -41,3 +41,16 @@ kt_compiler_plugin(
"@maven//:androidx_compose_compiler_compiler",
],
)

# Add missing 'sun.misc' files to coroutines artifact
# Used in 'override_targets' by referencing @//:kotlinx_coroutines_core_jvm
kt_jvm_import(
name = "kotlinx_coroutines_core_jvm",
jars = ["@maven_secondary//:v1/https/repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar"],
srcjar = "@maven_secondary//:v1/https/repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1-sources.jar",
visibility = ["//visibility:public"],
deps = [
"//stub:sun_misc",
"@maven//:org_jetbrains_kotlin_kotlin_stdlib",
],
)
148 changes: 51 additions & 97 deletions examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_COMPOSE_VERSION = "1.1.0-beta03"

_KOTLIN_COMPILER_VERSION = "1.5.31"

_KOTLIN_COMPILER_SHA = "661111286f3e5ac06aaf3a9403d869d9a96a176b62b141814be626a47249fe9e"

# Setup Kotlin

local_repository(
name = "release_archive",
path = "../../src/main/starlark/release_archive",
Expand All @@ -9,138 +19,82 @@ archive_repository(
name = "io_bazel_rules_kotlin",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version", "versions")

kotlin_repositories()
kotlin_repositories(
compiler_release = kotlinc_version(
release = _KOTLIN_COMPILER_VERSION,
sha256 = _KOTLIN_COMPILER_SHA,
),
)

register_toolchains("//:kotlin_toolchain")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_KOTLIN_COMPILER_VERSION = "1.4.21"

## JVM External

_RULES_JVM_EXTERNAL_VERSION = "4.0"

_RULES_JVM_EXTERNAL_SHA = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169"

http_archive(
name = "rules_jvm_external",
sha256 = _RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-{}".format(_RULES_JVM_EXTERNAL_VERSION),
urls = [
"https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(_RULES_JVM_EXTERNAL_VERSION),
],
sha256 = versions.RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = [
"org.jetbrains.kotlin:kotlin-stdlib:{}".format(_KOTLIN_COMPILER_VERSION),
"androidx.core:core-ktx:1.3.2",
"androidx.appcompat:appcompat:1.2.0",
"com.google.android.material:material:1.2.1",
"androidx.compose.material:material:1.0.0-alpha09",
"androidx.compose.ui:ui:1.0.0-alpha09",
"androidx.compose.ui:ui-tooling:1.0.0-alpha09",
"androidx.compose.compiler:compiler:1.0.0-alpha09",
"androidx.core:core-ktx:1.6.0",
"androidx.appcompat:appcompat:1.3.0",
"androidx.activity:activity-compose:1.3.0",
"androidx.compose.material:material:{}".format(_COMPOSE_VERSION),
"androidx.compose.ui:ui:{}".format(_COMPOSE_VERSION),
"androidx.compose.ui:ui-tooling:{}".format(_COMPOSE_VERSION),
"androidx.compose.compiler:compiler:{}".format(_COMPOSE_VERSION),
"androidx.compose.runtime:runtime:{}".format(_COMPOSE_VERSION),
],
override_targets = {
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm": "@//:kotlinx_coroutines_core_jvm",
},
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
)

## Stardoc

_STARDOC_VERSION = "0.4.0"

_STARDOC_SHA = "36b8d6c2260068b9ff82faea2f7add164bf3436eac9ba3ec14809f335346d66a"

http_archive(
name = "io_bazel_stardoc",
sha256 = _STARDOC_SHA,
strip_prefix = "stardoc-{}".format(_STARDOC_VERSION),
urls = [
"https://github.com/bazelbuild/stardoc/archive/{}.zip".format(_STARDOC_VERSION),
# Secondary maven repository used mainly for workarounds
maven_install(
name = "maven_secondary",
artifacts = [
# Workaround to add missing 'sun.misc' dependencies to 'kotlinx-coroutines-core-jvm' artifact
# Check root BUILD file and 'override_targets' arg of a primary 'maven_install'
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2",
],
fetch_sources = True,
repositories = ["https://repo1.maven.org/maven2"],
)

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

## Import Skylib

_SKYLIB_VERSION = "1.0.2"

_SKYLIB_SHA = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44"

http_archive(
name = "bazel_skylib",
sha256 = _SKYLIB_SHA,
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/{0}/bazel-skylib-{0}.tar.gz".format(_SKYLIB_VERSION),
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

## Protobuf

_PROTOBUF_VERSION = "3.14.0"

_PROTOBUF_SHA = "bf0e5070b4b99240183b29df78155eee335885e53a8af8683964579c214ad301"

http_archive(
name = "com_google_protobuf",
sha256 = _PROTOBUF_SHA,
strip_prefix = "protobuf-{}".format(_PROTOBUF_VERSION),
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v{}.zip".format(_PROTOBUF_VERSION),
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

## Rules PKG

_RULES_PKG_VERSION = "0.2.4"

_RULES_PKG_SHA = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a"

http_archive(
name = "rules_pkg",
sha256 = _RULES_PKG_SHA,
urls = [
"https://github.com/bazelbuild/rules_pkg/releases/download/{0}/rules_pkg-{0}.tar.gz".format(_RULES_PKG_VERSION),
],
sha256 = versions.SKYLIB_SHA,
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (
versions.SKYLIB_VERSION,
versions.SKYLIB_VERSION,
)],
)

## Android

_RULES_ANDROID_VERSION = "0.1.1"

_RULES_ANDROID_SHA = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806"

http_archive(
name = "build_bazel_rules_android",
sha256 = _RULES_ANDROID_SHA,
strip_prefix = "rules_android-{}".format(_RULES_ANDROID_VERSION),
urls = [
"https://github.com/bazelbuild/rules_android/archive/v{}.zip".format(_RULES_ANDROID_VERSION),
],
name = "rules_android",
sha256 = versions.ANDROID.SHA,
strip_prefix = "rules_android-%s" % versions.ANDROID.VERSION,
urls = ["https://github.com/bazelbuild/rules_android/archive/v%s.zip" % versions.ANDROID.VERSION],
)

load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository")
load("@rules_android//android:rules.bzl", "android_sdk_repository")

android_sdk_repository(
name = "androidsdk",
api_level = 29,
build_tools_version = versions.ANDROID.BUILD_TOOLS, # versions > 30.0.3 do not have the dx.jar anymore.
)
6 changes: 6 additions & 0 deletions examples/jetpack_compose/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cm.ben.android.bazel.compose.example">

<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="29" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
load("@build_bazel_rules_android//android:rules.bzl", "android_binary")
load("@rules_android//android:rules.bzl", "android_binary")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

# An app that consumes android-kt deps
android_binary(
name = "compose_example_app",
custom_package = "cm.ben.android.bazel.compose.example",
dex_shards = 5,
incremental_dexing = 1,
manifest = "AndroidManifest.xml",
multidex = "native",
Expand All @@ -12,3 +14,10 @@ android_binary(
"//compose-ui:lib",
],
)

build_test(
name = "force_build_apks_test",
targets = [
":compose_example_app",
],
)
6 changes: 0 additions & 6 deletions examples/jetpack_compose/compose-app/AndroidManifest.xml

This file was deleted.

23 changes: 16 additions & 7 deletions examples/jetpack_compose/compose-ui/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cm.ben.android.bazel.compose.example.ui">
xmlns:tools="http://schemas.android.com/tools"
package="cm.ben.android.bazel.compose.example.ui">

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="29" />

<application
android:label="Bazel Jetpack Compose Example"
android:theme="@style/Theme.AppCompat.Light">
android:label="Bazel Jetpack Compose Example"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".MainActivity"
android:label="Bazel Jetpack Compose Example">
android:name=".MainActivity"
android:label="Bazel Jetpack Compose Example">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Resolve a conflict issue while building with Bazel. -->
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />
</application>
</manifest>
</manifest>
3 changes: 2 additions & 1 deletion examples/jetpack_compose/compose-ui/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ kt_android_library(
plugins = ["//:jetpack_compose_compiler_plugin"],
visibility = ["//visibility:public"],
deps = [
"@maven//:androidx_activity_activity_compose",
"@maven//:androidx_appcompat_appcompat",
"@maven//:androidx_compose_material_material",
"@maven//:androidx_compose_runtime_runtime",
"@maven//:androidx_compose_ui_ui",
"@maven//:androidx_compose_ui_ui_tooling",
"@maven//:androidx_core_core_ktx",
"@maven//:com_google_android_material_material",
"@maven//:org_jetbrains_kotlin_kotlin_stdlib",
],
)
14 changes: 8 additions & 6 deletions examples/jetpack_compose/compose-ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package cm.ben.android.bazel.compose.example.ui

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.tooling.preview.Preview

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Greeting("world")
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Greeting("world")
}
}
}

@Preview
@Composable
fun Greeting(name: String) = Text(text = "Hello $name!")
11 changes: 11 additions & 0 deletions examples/jetpack_compose/stub/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_java//java:defs.bzl", "java_library")

java_library(
name = "sun_misc",
srcs = [
"sun/misc/Signal.java",
"sun/misc/SignalHandler.java",
],
neverlink = True,
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions examples/jetpack_compose/stub/sun/misc/Signal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package sun.misc;

public final class Signal {
}
4 changes: 4 additions & 0 deletions examples/jetpack_compose/stub/sun/misc/SignalHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package sun.misc;

public interface SignalHandler {
}

0 comments on commit 5240af8

Please sign in to comment.