Skip to content

Instantly share code, notes, and snippets.

@o-nix
Created November 28, 2025 20:51
Show Gist options
  • Select an option

  • Save o-nix/573517935ad4c1751224964543471a24 to your computer and use it in GitHub Desktop.

Select an option

Save o-nix/573517935ad4c1751224964543471a24 to your computer and use it in GitHub Desktop.
Simplest buf installation
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