Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
85d17f1dff | ||
|
2d60a1920e | ||
|
6898bac83d | ||
|
bf7f0ef6a4 |
20 changed files with 763 additions and 64 deletions
80
.taskcluster.yml
Normal file
80
.taskcluster.yml
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
version: 0
|
||||||
|
allowPullRequests: public
|
||||||
|
tasks:
|
||||||
|
####################################################################################################
|
||||||
|
# Task: Pull requests
|
||||||
|
####################################################################################################
|
||||||
|
- provisionerId: '{{ taskcluster.docker.provisionerId }}'
|
||||||
|
workerType: '{{ taskcluster.docker.workerType }}'
|
||||||
|
extra:
|
||||||
|
github:
|
||||||
|
env: true
|
||||||
|
events:
|
||||||
|
- pull_request.opened
|
||||||
|
- pull_request.edited
|
||||||
|
- pull_request.synchronize
|
||||||
|
- pull_request.reopened
|
||||||
|
- push
|
||||||
|
scopes:
|
||||||
|
- "queue:create-task:aws-provisioner-v1/github-worker"
|
||||||
|
- "queue:scheduler-id:taskcluster-github"
|
||||||
|
payload:
|
||||||
|
maxRunTime: 3600
|
||||||
|
deadline: "{{ '2 hours' | $fromNow }}"
|
||||||
|
image: 'mozillamobile/mentat:1.0'
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- '--login'
|
||||||
|
- '-cx'
|
||||||
|
- >-
|
||||||
|
export TERM=dumb
|
||||||
|
&& git fetch {{ event.head.repo.url }} {{ event.head.repo.branch }}
|
||||||
|
&& git config advice.detachedHead false
|
||||||
|
&& git checkout {{event.head.sha}}
|
||||||
|
&& python automation/taskcluster/decision_task_pull_request.py
|
||||||
|
features:
|
||||||
|
taskclusterProxy: true
|
||||||
|
metadata:
|
||||||
|
name: Mentat Android SDK - Pull Request
|
||||||
|
description: Building and testing the Mentat Android SDK - triggered by a pull request.
|
||||||
|
owner: '{{ event.head.user.email }}'
|
||||||
|
source: '{{ event.head.repo.url }}'
|
||||||
|
####################################################################################################
|
||||||
|
# Task: Release
|
||||||
|
####################################################################################################
|
||||||
|
- provisionerId: '{{ taskcluster.docker.provisionerId }}'
|
||||||
|
workerType: '{{ taskcluster.docker.workerType }}'
|
||||||
|
extra:
|
||||||
|
github:
|
||||||
|
events:
|
||||||
|
- release
|
||||||
|
scopes:
|
||||||
|
- "secrets:get:project/android-components/publish"
|
||||||
|
payload:
|
||||||
|
maxRunTime: 3600
|
||||||
|
deadline: "{{ '2 hours' | $fromNow }}"
|
||||||
|
image: 'mozillamobile/mentat:1.0'
|
||||||
|
command:
|
||||||
|
- /bin/bash
|
||||||
|
- '--login'
|
||||||
|
- '-cx'
|
||||||
|
- >-
|
||||||
|
export TERM=dumb
|
||||||
|
&& git fetch origin --tags
|
||||||
|
&& git config advice.detachedHead false
|
||||||
|
&& git checkout {{ event.version }}
|
||||||
|
&& python automation/taskcluster/release/fetch-bintray-api-key.py
|
||||||
|
# && cd sdks/android/Mentat
|
||||||
|
# && ./gradlew --no-daemon clean library:assembleRelease
|
||||||
|
# && ./gradlew bintrayUpload --debug
|
||||||
|
features:
|
||||||
|
taskclusterProxy: true
|
||||||
|
metadata:
|
||||||
|
name: Mentat Android SDK - Release ({{ event.version }})
|
||||||
|
description: Building and publishing release versions.
|
||||||
|
owner: '{{ event.head.user.email }}'
|
||||||
|
source: '{{ event.head.repo.url }}'
|
89
automation/docker/Dockerfile
Normal file
89
automation/docker/Dockerfile
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
FROM mozillamobile/android-components:1.4
|
||||||
|
|
||||||
|
MAINTAINER Nick Alexander "nalexander@mozilla.com"
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#-- Configuration -----------------------------------------------------------------------------------------------------
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ENV ANDROID_NDK_VERSION "r17b"
|
||||||
|
ENV PROJECT_REPOSITORY "https://github.com/mozilla/mentat.git"
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#-- System ------------------------------------------------------------------------------------------------------------
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RUN apt-get update -qq
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#-- Rust (cribbed from https://github.com/rust-lang-nursery/docker-rust/blob/ced83778ec6fea7f63091a484946f95eac0ee611/1.27.1/stretch/Dockerfile)
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ENV RUSTUP_HOME=/usr/local/rustup \
|
||||||
|
CARGO_HOME=/usr/local/cargo \
|
||||||
|
PATH=/usr/local/cargo/bin:$PATH \
|
||||||
|
RUST_VERSION=1.27.1
|
||||||
|
|
||||||
|
RUN set -eux; \
|
||||||
|
rustArch='x86_64-unknown-linux-gnu'; rustupSha256='4d382e77fd6760282912d2d9beec5e260ec919efd3cb9bdb64fe1207e84b9d91'; \
|
||||||
|
url="https://static.rust-lang.org/rustup/archive/1.12.0/${rustArch}/rustup-init"; \
|
||||||
|
wget "$url"; \
|
||||||
|
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
|
||||||
|
chmod +x rustup-init; \
|
||||||
|
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \
|
||||||
|
rm rustup-init; \
|
||||||
|
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
|
||||||
|
rustup --version; \
|
||||||
|
cargo --version; \
|
||||||
|
rustc --version; \
|
||||||
|
rustup target add i686-linux-android
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#-- Android NDK (Android SDK comes from base `android-components` image) ----------------------------------------------
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RUN mkdir -p /build
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
# ENV ANDROID_HOME /build/android-sdk
|
||||||
|
# ENV ANDROID_SDK_HOME /build/android-sdk
|
||||||
|
ENV ANDROID_NDK_HOME /build/android-ndk
|
||||||
|
# ENV PATH ${PATH}:${ANDROID_NDK_HOME}/tools:${ANDROID_SDK_HOME}/tools/bin:${ANDROID_SDK_HOME}/platform-tools:/opt/tools:${ANDROID_SDK_HOME}/build-tools/${ANDROID_BUILD_TOOLS}
|
||||||
|
|
||||||
|
RUN curl -L https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip > ndk.zip \
|
||||||
|
&& unzip ndk.zip -d /build \
|
||||||
|
&& rm ndk.zip \
|
||||||
|
&& mv /build/android-ndk-${ANDROID_NDK_VERSION} ${ANDROID_NDK_HOME}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#-- Project -----------------------------------------------------------------------------------------------------------
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RUN git clone $PROJECT_REPOSITORY
|
||||||
|
|
||||||
|
WORKDIR /build/mentat
|
||||||
|
|
||||||
|
# Temporary.
|
||||||
|
RUN git fetch origin build-android-sdk && git checkout origin/build-android-sdk && git show-ref HEAD
|
||||||
|
|
||||||
|
# Populate dependencies.
|
||||||
|
RUN ./sdks/android/Mentat/gradlew --no-daemon -p sdks/android/Mentat tasks
|
||||||
|
|
||||||
|
# Cache toolchains.
|
||||||
|
RUN ./sdks/android/Mentat/gradlew --no-daemon -p sdks/android/Mentat generateToolchains
|
||||||
|
|
||||||
|
# Build Rust.
|
||||||
|
RUN ./sdks/android/Mentat/gradlew --no-daemon -p sdks/android/Mentat cargoBuild && cargo clean
|
||||||
|
|
||||||
|
# Actually build. In the future, we might also test and lint (to cache additional dependencies).
|
||||||
|
RUN ./sdks/android/Mentat/gradlew --no-daemon -p sdks/android/Mentat assemble
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
# -- Cleanup ----------------------------------------------------------------------------------------------------------
|
||||||
|
#----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
RUN apt-get clean
|
122
automation/taskcluster/decision_task_pull_request.py
Normal file
122
automation/taskcluster/decision_task_pull_request.py
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import taskcluster
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Decision task for pull requests
|
||||||
|
"""
|
||||||
|
|
||||||
|
TASK_ID = os.environ.get('TASK_ID')
|
||||||
|
REPO_URL = os.environ.get('GITHUB_HEAD_REPO_URL')
|
||||||
|
BRANCH = os.environ.get('GITHUB_HEAD_BRANCH')
|
||||||
|
COMMIT = os.environ.get('GITHUB_HEAD_SHA')
|
||||||
|
|
||||||
|
def fetch_module_names():
|
||||||
|
process = subprocess.Popen(["./gradlew", "--no-daemon", "printModules"], stdout=subprocess.PIPE,
|
||||||
|
cwd=os.path.join(os.getcwd(), "sdks", "android", "Mentat"))
|
||||||
|
(output, err) = process.communicate()
|
||||||
|
exit_code = process.wait()
|
||||||
|
|
||||||
|
if exit_code is not 0:
|
||||||
|
print "Gradle command returned error:", exit_code
|
||||||
|
|
||||||
|
return re.findall('module: (.*)', output, re.M)
|
||||||
|
|
||||||
|
|
||||||
|
def schedule_task(queue, taskId, task):
|
||||||
|
print "TASK", taskId
|
||||||
|
print json.dumps(task, indent=4, separators=(',', ': '))
|
||||||
|
|
||||||
|
result = queue.createTask(taskId, task)
|
||||||
|
print "RESULT", taskId
|
||||||
|
print json.dumps(result, indent=4, separators=(',', ': '))
|
||||||
|
|
||||||
|
|
||||||
|
def create_task(name, description, command):
|
||||||
|
created = datetime.datetime.now()
|
||||||
|
expires = taskcluster.fromNow('1 year')
|
||||||
|
deadline = taskcluster.fromNow('1 day')
|
||||||
|
|
||||||
|
return {
|
||||||
|
"workerType": 'github-worker',
|
||||||
|
"taskGroupId": TASK_ID,
|
||||||
|
"expires": taskcluster.stringDate(expires),
|
||||||
|
"retries": 5,
|
||||||
|
"created": taskcluster.stringDate(created),
|
||||||
|
"tags": {},
|
||||||
|
"priority": "lowest",
|
||||||
|
"schedulerId": "taskcluster-github",
|
||||||
|
"deadline": taskcluster.stringDate(deadline),
|
||||||
|
"dependencies": [ TASK_ID ],
|
||||||
|
"routes": [],
|
||||||
|
"scopes": [],
|
||||||
|
"requires": "all-completed",
|
||||||
|
"payload": {
|
||||||
|
"features": {},
|
||||||
|
"maxRunTime": 7200,
|
||||||
|
"image": "mozillamobile/mentat:1.0",
|
||||||
|
"command": [
|
||||||
|
"/bin/bash",
|
||||||
|
"--login",
|
||||||
|
"-cx",
|
||||||
|
"export TERM=dumb && git fetch %s %s && git config advice.detachedHead false && git checkout %s && cd sdks/android/Mentat && ./gradlew --no-daemon clean %s" % (REPO_URL, BRANCH, COMMIT, command)
|
||||||
|
],
|
||||||
|
"artifacts": {},
|
||||||
|
"deadline": taskcluster.stringDate(deadline)
|
||||||
|
},
|
||||||
|
"provisionerId": "aws-provisioner-v1",
|
||||||
|
"metadata": {
|
||||||
|
"name": name,
|
||||||
|
"description": description,
|
||||||
|
"owner": "nalexander@mozilla.com",
|
||||||
|
"source": "https://github.com/mozilla/mentat"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def create_module_task(module):
|
||||||
|
return create_task(
|
||||||
|
name='Mentat Android SDK - Module ' + module,
|
||||||
|
description='Building and testing module ' + module,
|
||||||
|
command=" ".join(map(lambda x: module + ":" + x, ['assemble', 'test', 'lint'])))
|
||||||
|
|
||||||
|
|
||||||
|
# def create_detekt_task():
|
||||||
|
# return create_task(
|
||||||
|
# name='Android Components - detekt',
|
||||||
|
# description='Running detekt over all modules',
|
||||||
|
# command='detektCheck')
|
||||||
|
|
||||||
|
|
||||||
|
# def create_ktlint_task():
|
||||||
|
# return create_task(
|
||||||
|
# name='Android Components - ktlint',
|
||||||
|
# description='Running ktlint over all modules',
|
||||||
|
# command='ktlint')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
queue = taskcluster.Queue({ 'baseUrl': 'http://taskcluster/queue/v1' })
|
||||||
|
|
||||||
|
modules = fetch_module_names()
|
||||||
|
|
||||||
|
if len(modules) == 0:
|
||||||
|
print "Could not get module names from gradle"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
for module in modules:
|
||||||
|
task = create_module_task(module)
|
||||||
|
task_id = taskcluster.slugId()
|
||||||
|
schedule_task(queue, task_id, task)
|
||||||
|
|
||||||
|
# schedule_task(queue, taskcluster.slugId(), create_detekt_task())
|
||||||
|
# schedule_task(queue, taskcluster.slugId(), create_ktlint_task())
|
28
automation/taskcluster/release/fetch-bintray-api-key.py
Normal file
28
automation/taskcluster/release/fetch-bintray-api-key.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import taskcluster
|
||||||
|
|
||||||
|
SECRET_NAME = 'project/android-components/publish'
|
||||||
|
TASKCLUSTER_BASE_URL = 'http://taskcluster/secrets/v1'
|
||||||
|
|
||||||
|
def fetch_publish_secrets(secret_name):
|
||||||
|
"""Fetch and return secrets from taskcluster's secret service"""
|
||||||
|
secrets = taskcluster.Secrets({'baseUrl': TASKCLUSTER_BASE_URL})
|
||||||
|
return secrets.get(secret_name)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Fetch the bintray user and api key from taskcluster's secret service
|
||||||
|
and save it to local.properties in the project root directory.
|
||||||
|
"""
|
||||||
|
data = fetch_publish_secrets(SECRET_NAME)
|
||||||
|
|
||||||
|
properties_file_path = os.path.join(os.path.dirname(__file__), '../../../local.properties')
|
||||||
|
with open(properties_file_path, 'w') as properties_file:
|
||||||
|
properties_file.write("bintray.user=%s\n" % data['secret']['bintray_user'])
|
||||||
|
properties_file.write("bintray.apikey=%s\n" % data['secret']['bintray_apikey'])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -4,7 +4,7 @@ buildscript {
|
||||||
ext.kotlin_version = '1.2.41'
|
ext.kotlin_version = '1.2.41'
|
||||||
|
|
||||||
ext.library = [
|
ext.library = [
|
||||||
version: '0.3.1'
|
version: '0.8.1'
|
||||||
]
|
]
|
||||||
|
|
||||||
ext.build = [
|
ext.build = [
|
||||||
|
@ -17,6 +17,7 @@ buildscript {
|
||||||
jcenter()
|
jcenter()
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
@ -40,3 +41,11 @@ allprojects {
|
||||||
task clean(type: Delete) {
|
task clean(type: Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task printModules {
|
||||||
|
doLast {
|
||||||
|
subprojects.each { p ->
|
||||||
|
println "module: " + p.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
64
sdks/android/Mentat/buildSrc/build.gradle
Normal file
64
sdks/android/Mentat/buildSrc/build.gradle
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
google()
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.kotlin_version = '1.2.41'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
google()
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: "java-gradle-plugin"
|
||||||
|
// apply plugin: "maven-publish"
|
||||||
|
apply plugin: "kotlin"
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
simplePlugin {
|
||||||
|
id = "com.nishtahir.rust-android"
|
||||||
|
implementationClass = "com.nishtahir.RustAndroidPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group 'com.nishtahir'
|
||||||
|
// version '0.0.2'
|
||||||
|
|
||||||
|
// publishing {
|
||||||
|
// repositories {
|
||||||
|
// maven {
|
||||||
|
// url "../samples/maven-repo"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// publications {
|
||||||
|
// maven(MavenPublication) {
|
||||||
|
// groupId 'com.nishtahir'
|
||||||
|
// artifactId 'rust-android'
|
||||||
|
// version '0.0.2'
|
||||||
|
|
||||||
|
// from components.java
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly gradleApi()
|
||||||
|
implementation "com.android.tools.build:gradle:3.1.2"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
compileKotlin {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
compileTestKotlin {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.nishtahir;
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
open class CargoBuildTask : DefaultTask() {
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
@TaskAction
|
||||||
|
fun build() = with(project) {
|
||||||
|
extensions[CargoExtension::class].apply {
|
||||||
|
targets.forEach { target ->
|
||||||
|
val toolchain = toolchains.find { (arch) -> arch == target }
|
||||||
|
if (toolchain != null) {
|
||||||
|
buildProjectForTarget(project, toolchain, this)
|
||||||
|
|
||||||
|
val targetDirectory = targetDirectory ?: "${module}/target"
|
||||||
|
|
||||||
|
copy { spec ->
|
||||||
|
spec.into(File(buildDir, "rustJniLibs/${toolchain.folder}"))
|
||||||
|
spec.from(File(project.projectDir, "${targetDirectory}/${toolchain.target}/${profile}"))
|
||||||
|
spec.include(targetInclude)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("No such target $target")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildProjectForTarget(project: Project, toolchain: Toolchain, cargoExtension: CargoExtension) {
|
||||||
|
project.exec { spec ->
|
||||||
|
val cc = "${project.getToolchainDirectory()}/${toolchain.cc()}"
|
||||||
|
val ar = "${project.getToolchainDirectory()}/${toolchain.ar()}"
|
||||||
|
println("using CC: $cc")
|
||||||
|
println("using AR: $ar")
|
||||||
|
with(spec) {
|
||||||
|
standardOutput = System.out
|
||||||
|
workingDir = File(project.project.projectDir, cargoExtension.module)
|
||||||
|
environment("CC", cc)
|
||||||
|
environment("AR", ar)
|
||||||
|
environment("RUSTFLAGS", "-C linker=$cc")
|
||||||
|
commandLine = listOf("cargo", "build", "--target=${toolchain.target}")
|
||||||
|
if (cargoExtension.profile != "debug") {
|
||||||
|
// Cargo is rigid: it accepts "--release" for release (and
|
||||||
|
// nothing for dev). This is a cheap way of allowing only
|
||||||
|
// two values.
|
||||||
|
commandLine.add("--${cargoExtension.profile}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.assertNormalExitValue()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.nishtahir
|
||||||
|
|
||||||
|
open class CargoExtension {
|
||||||
|
var module: String = ""
|
||||||
|
var targets: List<String> = emptyList()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Cargo [release profile](https://doc.rust-lang.org/book/second-edition/ch14-01-release-profiles.html#customizing-builds-with-release-profiles) to build.
|
||||||
|
*
|
||||||
|
* Defaults to `"debug"`.
|
||||||
|
*/
|
||||||
|
var profile: String = "debug"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The target directory into Cargo which writes built outputs.
|
||||||
|
*
|
||||||
|
* Defaults to `${module}/target`.
|
||||||
|
*/
|
||||||
|
var targetDirectory: String? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which Cargo built outputs to consider JNI libraries.
|
||||||
|
*
|
||||||
|
* Defaults to `"*.so"`.
|
||||||
|
*/
|
||||||
|
var targetInclude: String = "*.so"
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.nishtahir
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.plugins.ExtensionContainer
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
const val TOOLS_FOLDER = ".cargo/toolchain"
|
||||||
|
|
||||||
|
operator fun <T : Any> ExtensionContainer.get(type: KClass<T>): T = getByType(type.java)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun Project.getToolchainDirectory(): File = File(projectDir, TOOLS_FOLDER)
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.nishtahir
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
import com.android.build.gradle.*
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
|
||||||
|
open class GenerateToolchainsTask : DefaultTask() {
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
@Suppress("unused")
|
||||||
|
fun generateToolchainTask() {
|
||||||
|
project.plugins.all {
|
||||||
|
when (it) {
|
||||||
|
is AppPlugin -> congfigureTask<AppExtension>(project)
|
||||||
|
is LibraryPlugin -> congfigureTask<LibraryExtension>(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : BaseExtension> congfigureTask(project: Project) {
|
||||||
|
val logger = LoggerFactory.getLogger("rust-android-gradle")
|
||||||
|
logger.info("An info log message logged using SLF4j 2")
|
||||||
|
|
||||||
|
val app = project.extensions[T::class]
|
||||||
|
val minApi = app.defaultConfig.minSdkVersion.apiLevel
|
||||||
|
val ndkPath = app.ndkDirectory
|
||||||
|
|
||||||
|
val targets = project.extensions[CargoExtension::class].targets
|
||||||
|
|
||||||
|
toolchains
|
||||||
|
.filterNot { (arch) -> minApi < 21 && arch.endsWith("64") }
|
||||||
|
.filter { (arch) -> targets.contains(arch) }
|
||||||
|
.forEach { (arch) ->
|
||||||
|
if (File(project.getToolchainDirectory(), arch).exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
project.exec { spec ->
|
||||||
|
spec.standardOutput = System.out
|
||||||
|
spec.errorOutput = System.out
|
||||||
|
spec.commandLine("$ndkPath/build/tools/make_standalone_toolchain.py")
|
||||||
|
spec.args("--arch=$arch", "--api=$minApi",
|
||||||
|
"--install-dir=${project.getToolchainDirectory()}/$arch",
|
||||||
|
"--force")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
package com.nishtahir
|
||||||
|
|
||||||
|
import com.android.build.gradle.*
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.plugins.ide.idea.IdeaPlugin
|
||||||
|
import org.gradle.plugins.ide.idea.model.IdeaModel
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
const val RUST_TASK_GROUP = "rust"
|
||||||
|
|
||||||
|
val toolchains = listOf(
|
||||||
|
Toolchain("arm",
|
||||||
|
"arm-linux-androideabi",
|
||||||
|
"bin/arm-linux-androideabi-clang",
|
||||||
|
"bin/arm-linux-androideabi-ar",
|
||||||
|
"armeabi"),
|
||||||
|
Toolchain("arm64",
|
||||||
|
"aarch64-linux-android",
|
||||||
|
"bin/aarch64-linux-android-clang",
|
||||||
|
"bin/aarch64-linux-android-ar",
|
||||||
|
"aarch64"),
|
||||||
|
Toolchain("mips",
|
||||||
|
"mipsel-linux-android",
|
||||||
|
"bin/mipsel-linux-android-clang",
|
||||||
|
"bin/mipsel-linux-android-ar",
|
||||||
|
"mips"),
|
||||||
|
Toolchain("x86",
|
||||||
|
"i686-linux-android",
|
||||||
|
"bin/i686-linux-android-clang",
|
||||||
|
"bin/i686-linux-android-ar",
|
||||||
|
"x86"),
|
||||||
|
Toolchain("x86_64",
|
||||||
|
"x86_64-linux-android",
|
||||||
|
"bin/x86_64-linux-android-clang",
|
||||||
|
"bin/x86_64-linux-android-ar",
|
||||||
|
"x86_64")
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Toolchain(val platform: String,
|
||||||
|
val target: String,
|
||||||
|
val cc: String,
|
||||||
|
val ar: String,
|
||||||
|
val folder: String) {
|
||||||
|
fun cc(): String = "$platform/$cc"
|
||||||
|
fun ar(): String = "$platform/$ar"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
open class RustAndroidPlugin : Plugin<Project> {
|
||||||
|
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
with(project) {
|
||||||
|
|
||||||
|
extensions.add("cargo", CargoExtension::class.java)
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
plugins.all {
|
||||||
|
when (it) {
|
||||||
|
is AppPlugin -> configurePlugin<AppExtension>(this)
|
||||||
|
is LibraryPlugin -> configurePlugin<LibraryExtension>(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <reified T : BaseExtension> configurePlugin(project: Project) = with(project) {
|
||||||
|
extensions[T::class].apply {
|
||||||
|
sourceSets.getByName("main").jniLibs.srcDir(File("$buildDir/rustJniLibs/"))
|
||||||
|
}
|
||||||
|
|
||||||
|
val generateToolchain = tasks.maybeCreate("generateToolchains",
|
||||||
|
GenerateToolchainsTask::class.java).apply {
|
||||||
|
group = RUST_TASK_GROUP
|
||||||
|
description = "Generate standard toolchain for given architectures"
|
||||||
|
}
|
||||||
|
|
||||||
|
val buildTask = tasks.maybeCreate("cargoBuild",
|
||||||
|
CargoBuildTask::class.java).apply {
|
||||||
|
group = RUST_TASK_GROUP
|
||||||
|
description = "Build library"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTask.dependsOn(generateToolchain)
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,10 +17,11 @@ org.gradle.jvmargs=-Xmx1536m
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
|
||||||
libGroupId=org.mozilla.mentat
|
libGroupId=org.mozilla.mentat
|
||||||
libRepositoryName=Mentat
|
libRepositoryName=Mozilla-Mobile
|
||||||
libProjectName=mentat
|
libProjectName=mentat
|
||||||
libProjectDescription=A persistent, relational store inspired by Datomic and DataScript.
|
libProjectDescription=A persistent, relational store inspired by Datomic and DataScript.
|
||||||
libUrl=https://github.com/mozilla/mentat
|
libUrl=https://github.com/mozilla/mentat
|
||||||
libVcsUrl=https://github.com/mozilla/mentat.git
|
libVcsUrl=https://github.com/mozilla/mentat.git
|
||||||
|
|
||||||
libLicense=MPL-2.0
|
libLicense 'The Apache Software License, Version 2.0'
|
||||||
|
libLicenseUrl 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'com.nishtahir.rust-android'
|
||||||
|
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'com.jfrog.bintray'
|
apply plugin: 'com.jfrog.bintray'
|
||||||
// Simply applying this plugin gets bintray to publish a pom file.
|
// Simply applying this plugin gets bintray to publish a pom file.
|
||||||
|
@ -33,69 +35,43 @@ android {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cargo {
|
||||||
|
module = '../../../../ffi'
|
||||||
|
targetDirectory = '../../../../target'
|
||||||
|
targetInclude = 'libmentat_ffi.so'
|
||||||
|
|
||||||
|
targets = ['x86']
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
||||||
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
|
|
||||||
exclude group: 'com.android.support', module: 'support-annotations'
|
|
||||||
})
|
|
||||||
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
|
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
||||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
|
||||||
implementation 'com.android.support:design:27.1.1'
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
implementation 'net.java.dev.jna:jna:4.5.1'
|
implementation 'net.java.dev.jna:jna:4.5.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publishing to jcenter/bintray.
|
afterEvaluate {
|
||||||
def libGroupId = properties.libGroupId
|
// The `cargoBuild` tasks isn't available until after evaluation.
|
||||||
def libRepoName = properties.libRepositoryName
|
android.libraryVariants.all { variant ->
|
||||||
def libProjectName = properties.libProjectName
|
def productFlavor = ""
|
||||||
def libProjectDescription = properties.libProjectDescription
|
variant.productFlavors.each {
|
||||||
def libUrl = properties.libUrl
|
productFlavor += "${it.name.capitalize()}"
|
||||||
def libVcsUrl = properties.libVcsUrl
|
}
|
||||||
def libLicense = properties.libLicense
|
def buildType = "${variant.buildType.name.capitalize()}"
|
||||||
|
tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
|
||||||
Properties localProperties = null
|
|
||||||
if (project.rootProject.file('local.properties').canRead()) {
|
|
||||||
localProperties = new Properties()
|
|
||||||
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
|
|
||||||
}
|
|
||||||
|
|
||||||
version = rootProject.ext.library['version']
|
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
|
||||||
from android.sourceSets.main.java.srcDirs
|
|
||||||
classifier = 'sources'
|
|
||||||
}
|
|
||||||
|
|
||||||
artifacts {
|
|
||||||
archives sourcesJar
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
group = libGroupId
|
|
||||||
archivesBaseName = libProjectName
|
|
||||||
|
|
||||||
bintray {
|
|
||||||
user = localProperties != null ? localProperties.getProperty("bintray.user") : ""
|
|
||||||
key = localProperties != null ? localProperties.getProperty("bintray.apikey") : ""
|
|
||||||
|
|
||||||
configurations = ['archives']
|
|
||||||
pkg {
|
|
||||||
repo = libRepoName
|
|
||||||
name = libProjectName
|
|
||||||
userOrg = "grisha" // Temporary org name until package is on jcenter. Issue #725.
|
|
||||||
desc = libProjectDescription
|
|
||||||
websiteUrl = libUrl
|
|
||||||
vcsUrl = libVcsUrl
|
|
||||||
licenses = [libLicense]
|
|
||||||
publish = true
|
|
||||||
publicDownloadNumbers = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
archivesBaseName = 'mentat'
|
||||||
|
|
||||||
|
apply from: '../publish.gradle'
|
||||||
|
ext.configurePublish(
|
||||||
|
'org.mozilla',
|
||||||
|
'mentat',
|
||||||
|
'A persistent, embedded knowledge base.')
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.mozilla.mentat">
|
package="org.mozilla.mentat">
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -1 +0,0 @@
|
||||||
../../../../../../../../target/aarch64-linux-android/release/libmentat_ffi.so
|
|
|
@ -1 +0,0 @@
|
||||||
../../../../../../../../target/armv7-linux-androideabi/release/libmentat_ffi.so
|
|
|
@ -1 +0,0 @@
|
||||||
../../../../../../../../target/i686-linux-android/release/libmentat_ffi.so
|
|
|
@ -1,3 +0,0 @@
|
||||||
<resources>
|
|
||||||
<string name="app_name">Mentat</string>
|
|
||||||
</resources>
|
|
99
sdks/android/Mentat/publish.gradle
Normal file
99
sdks/android/Mentat/publish.gradle
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
def libRepoName = properties.libRepositoryName
|
||||||
|
def libUrl = properties.libUrl
|
||||||
|
def libVcsUrl = properties.libVcsUrl
|
||||||
|
def libLicense = properties.libLicense
|
||||||
|
def libLicenseUrl = properties.libLicenseUrl
|
||||||
|
|
||||||
|
ext.configurePublish = { groupIdArg, artifactIdArg, descriptionArg ->
|
||||||
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
|
|
||||||
|
group = groupIdArg
|
||||||
|
|
||||||
|
install {
|
||||||
|
repositories.mavenInstaller {
|
||||||
|
pom {
|
||||||
|
project {
|
||||||
|
packaging 'aar'
|
||||||
|
groupId groupIdArg
|
||||||
|
artifactId artifactIdArg
|
||||||
|
|
||||||
|
name libRepoName
|
||||||
|
description descriptionArg
|
||||||
|
url libUrl
|
||||||
|
|
||||||
|
licenses {
|
||||||
|
license {
|
||||||
|
name libLicense
|
||||||
|
url libLicenseUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
developers {
|
||||||
|
developer {
|
||||||
|
id 'nalexander'
|
||||||
|
name 'Nick Alexander'
|
||||||
|
email 'nalexander@mozilla.com'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scm {
|
||||||
|
connection libVcsUrl
|
||||||
|
developerConnection libVcsUrl
|
||||||
|
url libUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.jfrog.bintray'
|
||||||
|
|
||||||
|
version = rootProject.ext.library['version']
|
||||||
|
|
||||||
|
task sourcesJar(type: Jar) {
|
||||||
|
from android.sourceSets.main.java.srcDirs
|
||||||
|
classifier = 'sources'
|
||||||
|
}
|
||||||
|
|
||||||
|
task javadoc(type: Javadoc) {
|
||||||
|
source = android.sourceSets.main.java.srcDirs
|
||||||
|
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||||
|
}
|
||||||
|
|
||||||
|
task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||||
|
classifier = 'javadoc'
|
||||||
|
from javadoc.destinationDir
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
//archives javadocJar
|
||||||
|
archives sourcesJar
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties localProperties = null;
|
||||||
|
if (project.rootProject.file('local.properties').canRead()) {
|
||||||
|
localProperties = new Properties()
|
||||||
|
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
|
||||||
|
}
|
||||||
|
|
||||||
|
bintray {
|
||||||
|
user = localProperties != null ? localProperties.getProperty("bintray.user") : ""
|
||||||
|
key = localProperties != null ? localProperties.getProperty("bintray.apikey") : ""
|
||||||
|
|
||||||
|
configurations = ['archives']
|
||||||
|
pkg {
|
||||||
|
repo = libRepoName
|
||||||
|
name = artifactIdArg
|
||||||
|
desc = descriptionArg
|
||||||
|
websiteUrl = libUrl
|
||||||
|
vcsUrl = libVcsUrl
|
||||||
|
licenses = [libLicense]
|
||||||
|
publish = true
|
||||||
|
publicDownloadNumbers = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,8 @@ dependencies {
|
||||||
implementation project(':library')
|
implementation project(':library')
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
implementation "com.android.support:appcompat-v7:27.1.1"
|
implementation "com.android.support:appcompat-v7:27.1.1"
|
||||||
|
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||||
|
implementation 'com.android.support:design:27.1.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
Loading…
Reference in a new issue