mirror of
https://github.com/fluencelabs/asmble
synced 2025-03-16 03:00:51 +00:00
318 lines
9.8 KiB
Groovy
318 lines
9.8 KiB
Groovy
group 'asmble'
|
|
version '0.2.0'
|
|
|
|
buildscript {
|
|
ext.kotlin_version = '1.2.61'
|
|
ext.asm_version = '6.2.1'
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
maven {
|
|
url "https://plugins.gradle.org/m2/"
|
|
}
|
|
}
|
|
dependencies {
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
classpath 'me.champeau.gradle:jmh-gradle-plugin:0.4.5'
|
|
}
|
|
}
|
|
|
|
allprojects {
|
|
apply plugin: 'java'
|
|
group 'com.github.cretz.asmble'
|
|
version '0.4.0-SNAPSHOT'
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
}
|
|
|
|
project(':annotations') {
|
|
javadoc {
|
|
options.links 'https://docs.oracle.com/javase/8/docs/api/'
|
|
// TODO: change when https://github.com/gradle/gradle/issues/2354 is fixed
|
|
options.addStringOption 'Xdoclint:all', '-Xdoclint:-missing'
|
|
}
|
|
|
|
publishSettings(project, 'asmble-annotations', 'Asmble WASM Annotations', true)
|
|
}
|
|
|
|
project(':compiler') {
|
|
apply plugin: 'kotlin'
|
|
apply plugin: 'application'
|
|
|
|
applicationName = "asmble"
|
|
mainClassName = "asmble.cli.MainKt"
|
|
|
|
distTar.archiveName = 'asmble.tar'
|
|
distZip.archiveName = 'asmble.zip'
|
|
|
|
dependencies {
|
|
compile project(':annotations')
|
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
|
compile "org.ow2.asm:asm-tree:$asm_version"
|
|
compile "org.ow2.asm:asm-util:$asm_version"
|
|
compile "org.ow2.asm:asm-commons:$asm_version"
|
|
testCompile 'junit:junit:4.12'
|
|
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
|
}
|
|
|
|
publishSettings(project, 'asmble-compiler', 'Asmble WASM Compiler', false)
|
|
}
|
|
|
|
project(':examples') {
|
|
subprojects {
|
|
dependencies {
|
|
compileOnly project(':compiler')
|
|
}
|
|
|
|
// C/C++ example helpers
|
|
|
|
task cToWasm {
|
|
doFirst {
|
|
mkdir 'build'
|
|
exec {
|
|
def cFileName = fileTree(dir: 'src', includes: ['*.c']).files.iterator().next()
|
|
commandLine 'clang', '--target=wasm32-unknown-unknown-wasm', '-O3', cFileName, '-c', '-o', 'build/lib.wasm'
|
|
}
|
|
}
|
|
}
|
|
|
|
task showCWast(type: JavaExec) {
|
|
dependsOn cToWasm
|
|
classpath configurations.compileClasspath
|
|
main = 'asmble.cli.MainKt'
|
|
doFirst {
|
|
args 'translate', 'build/lib.wasm'
|
|
}
|
|
}
|
|
|
|
task compileCWasm(type: JavaExec) {
|
|
dependsOn cToWasm
|
|
classpath configurations.compileClasspath
|
|
main = 'asmble.cli.MainKt'
|
|
doFirst {
|
|
def outFile = 'build/wasm-classes/' + wasmCompiledClassName.replace('.', '/') + '.class'
|
|
file(outFile).parentFile.mkdirs()
|
|
args 'compile', 'build/lib.wasm', wasmCompiledClassName, '-out', outFile
|
|
}
|
|
}
|
|
|
|
// Go example helpers
|
|
|
|
task goToWasm {
|
|
doFirst {
|
|
mkdir 'build'
|
|
exec {
|
|
def goFileName = fileTree(dir: '.', includes: ['*.go']).files.iterator().next()
|
|
environment 'GOOS': 'js', 'GOARCH': 'wasm'
|
|
commandLine 'go', 'build', '-o', 'build/lib.wasm', goFileName
|
|
}
|
|
}
|
|
}
|
|
|
|
task compileGoWasm(type: JavaExec) {
|
|
dependsOn goToWasm
|
|
classpath configurations.compileClasspath
|
|
main = 'asmble.cli.MainKt'
|
|
doFirst {
|
|
// args 'help', 'compile'
|
|
def outFile = 'build/wasm-classes/' + wasmCompiledClassName.replace('.', '/') + '.class'
|
|
file(outFile).parentFile.mkdirs()
|
|
args 'compile', 'build/lib.wasm', wasmCompiledClassName, '-out', outFile, '-log', 'debug'
|
|
}
|
|
}
|
|
|
|
// Rust example helpers
|
|
|
|
ext.rustBuildRelease = true
|
|
|
|
task rustToWasm(type: Exec) {
|
|
if (rustBuildRelease) {
|
|
commandLine 'cargo', 'build', '--release'
|
|
} else {
|
|
commandLine 'cargo', 'build'
|
|
}
|
|
}
|
|
|
|
ext.rustWasmFileName = { ->
|
|
def buildType = rustBuildRelease ? 'release' : 'debug'
|
|
def wasmFiles = fileTree(dir: "target/wasm32-unknown-unknown/$buildType", includes: ['*.wasm']).files
|
|
if (wasmFiles.size() != 1) throw new GradleException('Expected single WASM file, got ' + wasmFiles.size())
|
|
return wasmFiles.iterator().next()
|
|
}
|
|
|
|
task rustWasmFile() {
|
|
dependsOn rustToWasm
|
|
doFirst {
|
|
println 'File: ' + rustWasmFileName()
|
|
}
|
|
}
|
|
|
|
task showRustWast(type: JavaExec) {
|
|
dependsOn rustToWasm
|
|
classpath configurations.compileClasspath
|
|
main = 'asmble.cli.MainKt'
|
|
doFirst {
|
|
args 'translate', rustWasmFileName()
|
|
}
|
|
}
|
|
|
|
task compileRustWasm(type: JavaExec) {
|
|
dependsOn rustToWasm
|
|
classpath configurations.compileClasspath
|
|
main = 'asmble.cli.MainKt'
|
|
doFirst {
|
|
// args 'help', 'compile'
|
|
def outFile = 'build/wasm-classes/' + wasmCompiledClassName.replace('.', '/') + '.class'
|
|
file(outFile).parentFile.mkdirs()
|
|
args 'compile', rustWasmFileName(), wasmCompiledClassName, '-out', outFile
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
project(':examples:c-simple') {
|
|
apply plugin: 'application'
|
|
ext.wasmCompiledClassName = 'asmble.generated.CSimple'
|
|
dependencies {
|
|
compile files('build/wasm-classes')
|
|
}
|
|
compileJava {
|
|
dependsOn compileCWasm
|
|
}
|
|
mainClassName = 'asmble.examples.csimple.Main'
|
|
}
|
|
|
|
project(':examples:go-simple') {
|
|
apply plugin: 'application'
|
|
ext.wasmCompiledClassName = 'asmble.generated.GoSimple'
|
|
dependencies {
|
|
compile files('build/wasm-classes')
|
|
}
|
|
compileJava {
|
|
dependsOn compileGoWasm
|
|
}
|
|
mainClassName = 'asmble.examples.gosimple.Main'
|
|
}
|
|
|
|
project(':examples:rust-regex') {
|
|
apply plugin: 'application'
|
|
apply plugin: 'me.champeau.gradle.jmh'
|
|
ext.wasmCompiledClassName = 'asmble.generated.RustRegex'
|
|
dependencies {
|
|
compile files('build/wasm-classes')
|
|
testCompile 'junit:junit:4.12'
|
|
}
|
|
compileJava {
|
|
dependsOn compileRustWasm
|
|
}
|
|
mainClassName = 'asmble.examples.rustregex.Main'
|
|
test {
|
|
testLogging.showStandardStreams = true
|
|
testLogging.events 'PASSED', 'SKIPPED'
|
|
}
|
|
jmh {
|
|
iterations = 5
|
|
warmupIterations = 5
|
|
fork = 3
|
|
}
|
|
}
|
|
|
|
project(':examples:rust-simple') {
|
|
apply plugin: 'application'
|
|
ext.wasmCompiledClassName = 'asmble.generated.RustSimple'
|
|
dependencies {
|
|
compile files('build/wasm-classes')
|
|
}
|
|
compileJava {
|
|
dependsOn compileRustWasm
|
|
}
|
|
mainClassName = 'asmble.examples.rustsimple.Main'
|
|
}
|
|
|
|
project(':examples:rust-string') {
|
|
apply plugin: 'application'
|
|
ext.wasmCompiledClassName = 'asmble.generated.RustString'
|
|
dependencies {
|
|
compile files('build/wasm-classes')
|
|
}
|
|
compileJava {
|
|
dependsOn compileRustWasm
|
|
}
|
|
mainClassName = 'asmble.examples.ruststring.Main'
|
|
}
|
|
|
|
def publishSettings(project, projectName, projectDescription, includeJavadoc) {
|
|
project.with {
|
|
if (!project.hasProperty('ossrhUsername')) return
|
|
apply plugin: 'maven'
|
|
apply plugin: 'signing'
|
|
|
|
archivesBaseName = projectName
|
|
|
|
task packageSources(type: Jar) {
|
|
classifier = 'sources'
|
|
from sourceSets.main.allSource
|
|
}
|
|
|
|
if (includeJavadoc) {
|
|
task packageJavadoc(type: Jar, dependsOn: 'javadoc') {
|
|
from javadoc.destinationDir
|
|
classifier = 'javadoc'
|
|
}
|
|
} else {
|
|
task packageJavadoc(type: Jar) {
|
|
// Empty to satisfy Sonatype's javadoc.jar requirement
|
|
classifier 'javadoc'
|
|
}
|
|
}
|
|
|
|
artifacts {
|
|
archives packageSources, packageJavadoc
|
|
}
|
|
|
|
signing {
|
|
sign configurations.archives
|
|
}
|
|
|
|
uploadArchives {
|
|
repositories {
|
|
mavenDeployer {
|
|
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
|
|
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
|
|
authentication(userName: ossrhUsername, password: ossrhPassword)
|
|
}
|
|
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
|
|
authentication(userName: ossrhUsername, password: ossrhPassword)
|
|
}
|
|
pom.project {
|
|
name projectName
|
|
packaging 'jar'
|
|
description projectDescription
|
|
url 'https://github.com/cretz/asmble'
|
|
scm {
|
|
connection 'scm:git:git@github.com:cretz/asmble.git'
|
|
developerConnection 'scm:git:git@github.com:cretz/asmble.git'
|
|
url 'git@github.com:cretz/asmble.git'
|
|
}
|
|
licenses {
|
|
license {
|
|
name 'MIT License'
|
|
url 'https://opensource.org/licenses/MIT'
|
|
}
|
|
}
|
|
developers {
|
|
developer {
|
|
id 'cretz'
|
|
name 'Chad Retz'
|
|
url 'https://github.com/cretz'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |