diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index fe94d80..8ab46d1 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,4 +4,8 @@ plugins { repositories { jcenter() } - \ No newline at end of file + +dependencies { + // Needed by the script 'canteen.gradle' + implementation("com.google.guava:guava:27.0.1-jre") +} \ No newline at end of file diff --git a/canteen.gradle b/canteen.gradle new file mode 100644 index 0000000..b92cc53 --- /dev/null +++ b/canteen.gradle @@ -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 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") + } +} diff --git a/kroto-plus-coroutines/build.gradle b/kroto-plus-coroutines/build.gradle index 4ad3e8b..afb898c 100644 --- a/kroto-plus-coroutines/build.gradle +++ b/kroto-plus-coroutines/build.gradle @@ -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 } diff --git a/protoc-gen-grpc-coroutines/build.gradle b/protoc-gen-grpc-coroutines/build.gradle index 570437e..eed30d8 100644 --- a/protoc-gen-grpc-coroutines/build.gradle +++ b/protoc-gen-grpc-coroutines/build.gradle @@ -31,6 +31,8 @@ bootJar { } } +apply from: "${rootProject.projectDir}/canteen.gradle" + jar.enabled = true artifacts { diff --git a/protoc-gen-kroto-plus/build.gradle b/protoc-gen-kroto-plus/build.gradle index 4fdd5c8..667aa6b 100644 --- a/protoc-gen-kroto-plus/build.gradle +++ b/protoc-gen-kroto-plus/build.gradle @@ -83,6 +83,8 @@ bootJar { } } +apply from: "${rootProject.projectDir}/canteen.gradle" + jar.enabled = true artifacts {