Created
November 28, 2025 20:51
-
-
Save o-nix/573517935ad4c1751224964543471a24 to your computer and use it in GitHub Desktop.
Simplest buf installation
This file contains hidden or 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 org.jetbrains.kotlin.de.undercouch.gradle.tasks.download.Download | |
| tasks.register<Download>("downloadBuf") { | |
| val os = System.getProperty("os.name").lowercase() | |
| val osPart = | |
| when { | |
| os.startsWith("linux") -> "Linux" | |
| os.startsWith("mac") -> "Darwin" | |
| else -> error("unsupported os: $os") | |
| } | |
| val archPart = | |
| when (val arch = System.getProperty("os.arch").lowercase()) { | |
| in setOf("x86_64", "amd64") -> "x86_64" | |
| in setOf("arm64", "aarch64") -> if (osPart == "Darwin") "arm64" else "aarch64" | |
| else -> error("unsupported architecture for buf: $arch") | |
| } | |
| src("https://github.com/bufbuild/buf/releases/download/v$bufVersion/buf-$osPart-$archPart") | |
| dest("${layout.buildDirectory.get()}/buf") | |
| onlyIfModified(true) | |
| overwrite(false) | |
| doLast { | |
| exec { | |
| commandLine("chmod", "+x", "${layout.buildDirectory.get()}/buf") | |
| } | |
| } | |
| } | |
| tasks.register<Exec>("bufGenerate") { | |
| dependsOn(tasks.getByName("downloadBuf")) | |
| val bufPath = "${layout.buildDirectory.get()}/buf" | |
| commandLine(bufPath, "generate") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment