Created
May 17, 2023 09:59
-
-
Save Siedlerchr/0fd9e463f6ffa2ea3c4b5e5ae3e5889e to your computer and use it in GitHub Desktop.
Download and extract protoc-gen.js and configure it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.protobuf.gradle.id | |
import de.undercouch.gradle.tasks.download.Download | |
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | |
plugins { | |
id("java") | |
id("idea") | |
id("net.linguica.maven-settings") version "0.5" | |
`maven-publish` | |
id("com.google.protobuf") version "0.9.3" | |
id("de.undercouch.download") version "5.4.0" | |
} | |
val protocGenJsVersion = "3.21.2" | |
val protocjsDir = "${projectDir}/protocjs" | |
val downloadAndUnzipFile = tasks.register<Copy>("downloadAndUnzipFile") { | |
dependsOn(downloadZip) | |
from(zipTree(downloadZip.get().dest)) | |
into(protocjsDir) | |
fileMode = "755".toInt(radix = 8) // kotlin does not support oktals | |
} | |
val downloadZip = tasks.register<Download>("downloadZipFile") { | |
val os = DefaultNativePlatform.getCurrentOperatingSystem() | |
val arch = DefaultNativePlatform.getCurrentArchitecture(); | |
var downloadOsName = "linux" | |
if (os.isWindows) { | |
downloadOsName = "win64" | |
} | |
if (os.isMacOsX) { | |
downloadOsName = "osx" | |
if (arch.isArm) { | |
downloadOsName += "-aarch_64" | |
} | |
} | |
if (os.isLinux) { | |
downloadOsName = "linux" | |
if (arch.isAmd64) { | |
downloadOsName += "-x86_64" | |
} | |
if (arch.isArm) { | |
downloadOsName += "-aarch64" | |
} | |
} | |
print("downloadOsName $downloadOsName") | |
val downloadSrc = | |
"https://github.com/protocolbuffers/protobuf-javascript/releases/download/v${protocGenJsVersion}/protobuf-javascript-${protocGenJsVersion}-${downloadOsName}.zip" | |
src(downloadSrc) | |
dest(File(protocjsDir, "protobuf-javascript-${protocGenJsVersion}-${downloadOsName}.zip")) | |
} | |
// Configure the protoc executable | |
protoc { | |
// Download from repositories | |
artifact = "com.google.protobuf:protoc:3.23.0" | |
} | |
plugins { | |
id("grpc") { | |
artifact = "io.grpc:protoc-gen-grpc-java:1.55.1" | |
// or | |
// path = 'tools/protoc-gen-grpc-java' | |
} | |
id("js") { | |
path = "$protocjsDir/bin/protoc-gen-js" | |
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows) { | |
path += ".exe" | |
} | |
} | |
} | |
generateProtoTasks { | |
ofSourceSet("main").forEach { | |
all().configureEach { | |
dependsOn(downloadAndUnzipFile) | |
} | |
it.plugins { | |
// Apply the "grpc" plugin whose spec is defined above, without | |
// options. Note the braces cannot be omitted, otherwise the | |
// plugin will not be added. This is because of the implicit way | |
// NamedDomainObjectContainer binds the methods. | |
id("grpc") { } | |
id("js") { | |
option("import_style=closure") | |
option("binary") | |
option("library=fxl_proto_library") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment