From 58a850f0afbbac721c2c1eb42cc99bbb6dcebb15 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Sat, 23 Mar 2024 09:34:17 -0700 Subject: [PATCH] Create Debian packages --- MODULE.bazel | 1 + WORKSPACE | 12 +++++++++++ deb/BUILD | 52 +++++++++++++++++++++++++++++++++++++++++++++ deb/description.txt | 6 ++++++ 4 files changed, 71 insertions(+) create mode 100644 deb/BUILD create mode 100644 deb/description.txt diff --git a/MODULE.bazel b/MODULE.bazel index 6cf861b..1dc1751 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,6 +5,7 @@ bazel_dep(name = "gazelle", version = "0.32.0", repo_name = "bazel_gazelle") bazel_dep(name = "platforms", version = "0.0.7") bazel_dep(name = "rules_nodejs", version = "5.5.3", repo_name = "build_bazel_rules_nodejs") bazel_dep(name = "rules_go", version = "0.41.0", repo_name = "io_bazel_rules_go") +bazel_dep(name = "rules_pkg", version = "0.10.1") # -- bazel_dep definitions -- # go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") diff --git a/WORKSPACE b/WORKSPACE index bdcca7f..bbd07c8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -92,3 +92,15 @@ http_archive( "https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz", ], ) + +http_archive( + name = "rules_pkg", + urls = [ + "https://github.com/bazelbuild/rules_pkg/releases/download/0.10.1/rules_pkg-0.10.1.tar.gz", + ], + sha256 = "d250924a2ecc5176808fc4c25d5cf5e9e79e6346d79d5ab1c493e289e722d1d0", +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() diff --git a/deb/BUILD b/deb/BUILD new file mode 100644 index 0000000..a74f52b --- /dev/null +++ b/deb/BUILD @@ -0,0 +1,52 @@ +load("@rules_pkg//pkg:deb.bzl", "pkg_deb") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +config_setting( + name = "stamp_detect", + values = {"stamp": "1"}, +) + +genrule( + name = "parse_version", + outs = ["version.txt"], + cmd_bash = select({ + ":stamp_detect": "sed -ne 's#^STABLE_VERSION v##p' bazel-out/stable-status.txt > $@", + "//conditions:default": "echo 0.0.0 > $@", + }), + cmd_bat = "echo 0.0.0 >> $@", + stamp = True, +) + +ARCHES = ["amd64", "arm64"] + +[ + pkg_tar( + name = "bazelisk-{}_tar".format(arch), + out = "bazelisk-{}.tar".format(arch), + srcs = ["//:bazelisk-linux-{}".format(arch)], + remap_paths = {"bazelisk-linux_{}".format(arch): "bazelisk"}, + package_dir = "/usr/bin", + stamp = -1, + symlinks = {"bazel": "bazelisk"}, + ) + for arch in ARCHES +] + +[ + pkg_deb( + name = "bazelisk-{}_deb".format(arch), + architecture = arch, + conflicts = ["bazel"], + data = ":bazelisk-{}_tar".format(arch), + description_file = ":description.txt", + homepage = "https://github.com/bazelbuild/bazelisk", + license = "Apache-2.0", + maintainer = "The Bazel Authors ", + out = "bazelisk-{}.deb".format(arch), + package = "bazelisk", + section = "contrib/devel", + version_file = ":version.txt", + visibility = ["//visibility:public"], + ) + for arch in ARCHES +] diff --git a/deb/description.txt b/deb/description.txt new file mode 100644 index 0000000..db7080d --- /dev/null +++ b/deb/description.txt @@ -0,0 +1,6 @@ +A user-friendly launcher for Bazel + Bazelisk is a wrapper for Bazel written in Go. It automatically picks a good + version of Bazel given your current working directory, downloads it from the + official server (if required) and then transparently passes through all + command-line arguments to the real Bazel binary. You can call it just like you + would call Bazel.