Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build native executable artifacts #87

Merged
merged 5 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:/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")
}
}
2 changes: 1 addition & 1 deletion example-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protobuf {
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${versions.grpc}" }
kroto {
artifact = "com.github.marcoferrer.krotoplus:protoc-gen-kroto-plus:${versions.krotoplus}:jvm8@jar"
path = "${rootDir}/../protoc-gen-kroto-plus/build/libs/protoc-gen-kroto-plus-${versions.krotoplus}-${osdetector.classifier}.exe"
marcoferrer marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
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
4 changes: 2 additions & 2 deletions protoc-gen-kroto-plus/generator-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protobuf {
//noinspection GroovyAssignabilityCheck
plugins {
kroto {
path = "${rootProject.projectDir}/protoc-gen-kroto-plus/build/libs/protoc-gen-kroto-plus-${project.version}-jvm8.jar"
path = "${rootProject.projectDir}/protoc-gen-kroto-plus/build/libs/protoc-gen-kroto-plus-${project.version}-${osdetector.classifier}.exe"
}
}

Expand All @@ -51,7 +51,7 @@ protobuf {

all().each{ task ->
task.inputs.files krotoConfig
task.dependsOn ':protoc-gen-kroto-plus:bootJar'
task.dependsOn ':protoc-gen-kroto-plus:buildCanteenArtifacts'

task.plugins {
kroto {
Expand Down