Skip to content

Commit

Permalink
build and publish native artifacts #6
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoferrer committed Nov 15, 2019
1 parent b978f5f commit 9a190ae
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
6 changes: 5 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ plugins {
repositories {
jcenter()
}


dependencies {
// Needed by the script 'canteen.gradle'
implementation("com.google.guava:guava:27.0.1-jre")
}
81 changes: 81 additions & 0 deletions canteen.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// The following dependency needs to exist on the 'buildscript' classpath
// 'com.google.guava:guava:27.0.1-jre'
// It is currently added via the buildSrc project
import com.google.common.io.ByteStreams

// Native artifact generation based off of
// https://github.com/salesforce/grpc-java-contrib/tree/master/canteen

def platforms = ["osx-x86_64", "linux-x86_64", "windows-x86_64"]

Task bootJarTask = tasks.getByName("bootJar")
File bootJarFile = bootJarTask.archiveFile.get().asFile

platforms.each { platform ->

// Resolve the canteen bootstrap artifact
Configuration config = project.configurations.create("canteenBootstrapLocator_$platform") {
visible = false
transitive = false
extendsFrom = []
}
Map<String, String> notation = [
group: "com.salesforce.servicelibs",
name: "canteen-bootstrap",
version: "1.0.0",
classifier: platform,
ext: "exe",
]
Dependency dep = project.dependencies.add(config.name, notation)
File bootstrapFile = config.fileCollection(dep).singleFile
File destinationArtifactFile = new File(bootJarTask.destinationDirectory.get().asFile,
bootJarFile.name.replace("jvm8.jar", platform + ".exe"))

// Create task to copy the original jar and embed the
// canteen bootstrap executable for the target platform
Task canteenTask = task("canteenArtifact_$platform"){
group = "canteen"
dependsOn("bootJar")
// Add files for UP-TO-DATE checks
inputs.files(bootJarFile)
outputs.files(destinationArtifactFile)
doLast {
// Build the bootstrap file
OutputStream targetStream = new FileOutputStream(destinationArtifactFile)
InputStream bootstrapStream = new FileInputStream(bootstrapFile)
ByteStreams.copy(bootstrapStream, targetStream);
InputStream sourceStream = new FileInputStream(bootJarFile)
ByteStreams.copy(sourceStream, targetStream);
targetStream.flush()
targetStream.close()
sourceStream.close()
bootstrapStream.close()
destinationArtifactFile.setExecutable(true);
}
}

artifacts {
archives(destinationArtifactFile) {
builtBy canteenTask
classifier platform
}
}

publishing {
publications {
mavenPublication(MavenPublication) {
artifact(destinationArtifactFile.absolutePath) {
builtBy canteenTask
classifier platform
}
}
}
}
}

task buildCanteenArtifacts{
group = "canteen"
platforms.each { platform ->
dependsOn("canteenArtifact_$platform")
}
}
5 changes: 2 additions & 3 deletions kroto-plus-coroutines/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ protobuf {
//noinspection GroovyAssignabilityCheck
plugins {
coroutines {
path = "${rootProject.projectDir}/protoc-gen-grpc-coroutines/build/libs/protoc-gen-grpc-coroutines-${project.version}-jvm8.jar"
path = "${rootProject.projectDir}/protoc-gen-grpc-coroutines/build/libs/protoc-gen-grpc-coroutines-${project.version}-${osdetector.classifier}.exe"
}
}

generateProtoTasks {

all().each{ task ->
task.dependsOn ':protoc-gen-grpc-coroutines:bootJar'
task.dependsOn ':protoc-gen-grpc-coroutines:buildCanteenArtifacts'
task.builtins {
remove java
}
Expand Down
2 changes: 2 additions & 0 deletions protoc-gen-grpc-coroutines/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ bootJar {
}
}

apply from: "${rootProject.projectDir}/canteen.gradle"

jar.enabled = true

artifacts {
Expand Down
2 changes: 2 additions & 0 deletions protoc-gen-kroto-plus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ bootJar {
}
}

apply from: "${rootProject.projectDir}/canteen.gradle"

jar.enabled = true

artifacts {
Expand Down

0 comments on commit 9a190ae

Please sign in to comment.