Skip to content

Commit

Permalink
feat(toolchains): add version to registration process
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Aug 2, 2024
1 parent 4040755 commit 348518c
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 56 deletions.
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exports_files([
"LICENSE",
"MODULE.bazel",
"extensions.bzl",
"biome.json",
])

#ifdef _BZLPARTY_RELEASE_PRIVATE_
Expand Down
4 changes: 2 additions & 2 deletions cmd/templ/tools.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

var ToolsTemplate = `"Tools"
var ToolsTemplate = `"Tools Assets"
{{range .}}
load("//toolchains/{{.}}:assets.bzl", {{. | ToUpper}}_ASSETS = "ASSETS")
{{end}}
TOOLS = {
TOOLS_ASSETS = {
{{range .}}
"{{.}}": {{. | ToUpper}}_ASSETS,
{{end}}
Expand Down
6 changes: 3 additions & 3 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"bzlparty tools extensions"

load("//lib:extensions.bzl", "tools_ext")
load("//toolchains:tools.bzl", "TOOLS")
load("//toolchains:tools_assets.bzl", "TOOLS_ASSETS")

TAG_CLASSES = {
t: tag_class(attrs = {"name": attr.string(default = t)})
for t in TOOLS.keys()
for t in TOOLS_ASSETS.keys()
}

tools = module_extension(
tools_ext.impl(TOOLS),
tools_ext.impl(TOOLS_ASSETS),
tag_classes = TAG_CLASSES,
)
1 change: 1 addition & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bzl_library(
srcs = ["extensions.bzl"],
deps = [
"//lib/private/toolchains:repositories",
"//toolchains:tools",
"//vendor/aspect_bazel_lib:extension_utils",
],
)
Expand Down
3 changes: 2 additions & 1 deletion lib/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ load(
"//lib/private/toolchains:repositories.bzl",
"register_platform_toolchains",
)
load("//toolchains:tools.bzl", "VERSIONS")
load("//vendor/aspect_bazel_lib:extension_utils.bzl", "extension_utils")

def _impl(ctx, tools):
for name, assets in tools.items():
extension_utils.toolchain_repos_bfs(
mctx = ctx,
get_version_fn = lambda _: "0.0.0",
get_version_fn = lambda _: VERSIONS.get(name),
get_tag_fn = lambda tags: getattr(tags, name),
toolchain_name = name,
toolchain_repos_fn = lambda name, version: register_platform_toolchains(name = name, assets = assets, toolchain_type = "@bzlparty_tools//toolchains:%s_toolchain_type" % name),
Expand Down
20 changes: 7 additions & 13 deletions toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//toolchains/private:defs.bzl", "create_bzl_file")
load(":toolchains.bzl", "bzlparty_toolchains")
load(":tools.bzl", "TOOLS")

package(default_visibility = ["//visibility:public"])

bzlparty_toolchains()

#ifdef _BZLPARTY_RELEASE_PRIVATE_
TOOLS = [
"biome",
"fd",
"goawk",
"ripgrep",
"sha",
"shellcheck",
"shellspec",
"templ",
"typos",
]

create_bzl_file(
name = "tools_bzl",
out = "tools.bzl",
out = "tools_assets.bzl",
template = "tools",
tools = TOOLS,
)
Expand All @@ -39,6 +28,11 @@ bzl_library(
srcs = ["external.bzl"],
)

bzl_library(
name = "tools",
srcs = ["tools.bzl"],
)

bzl_library(
name = "toolchains",
srcs = ["toolchains.bzl"],
Expand Down
3 changes: 1 addition & 2 deletions toolchains/biome/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "1.8.3"
load("//toolchains:tools.bzl", VERSION = "BIOME_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand Down
3 changes: 1 addition & 2 deletions toolchains/fd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "10.1.0"
load("//toolchains:tools.bzl", VERSION = "FD_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand Down
7 changes: 3 additions & 4 deletions toolchains/goawk/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "v1.27.0"
load("//toolchains:tools.bzl", VERSION = "GOAWK_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand All @@ -10,10 +9,10 @@ SUPPORTED_PLATFORMS = [
"windows_amd64",
]

GITHUB_URL = "https://github.com/benhoyt/goawk/releases/download/%s" % VERSION
GITHUB_URL = "https://github.com/benhoyt/goawk/releases/download/v%s" % VERSION

multi_platform_assets(
name = "goawk",
platforms = SUPPORTED_PLATFORMS,
url = "%s/goawk_%s_{platform}.{ext}" % (GITHUB_URL, VERSION),
url = "%s/goawk_v%s_{platform}.{ext}" % (GITHUB_URL, VERSION),
)
3 changes: 1 addition & 2 deletions toolchains/ripgrep/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "14.1.0"
load("//toolchains:tools.bzl", VERSION = "RIPGREP_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand Down
3 changes: 1 addition & 2 deletions toolchains/shellcheck/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "0.10.0"
load("//toolchains:tools.bzl", VERSION = "SHELLCHECK_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand Down
3 changes: 1 addition & 2 deletions toolchains/shellspec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "0.28.1"
load("//toolchains:tools.bzl", VERSION = "SHELLSPEC_VERSION")

GITHUB_URL = "https://github.com/shellspec/shellspec/releases/download/%s/shellspec-dist.tar.gz" % VERSION

Expand Down
40 changes: 20 additions & 20 deletions toolchains/tools.bzl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"Tools"
"Tools metadata"

load("//toolchains/biome:assets.bzl", BIOME_ASSETS = "ASSETS")
load("//toolchains/fd:assets.bzl", FD_ASSETS = "ASSETS")
load("//toolchains/goawk:assets.bzl", GOAWK_ASSETS = "ASSETS")
load("//toolchains/ripgrep:assets.bzl", RIPGREP_ASSETS = "ASSETS")
load("//toolchains/sha:assets.bzl", SHA_ASSETS = "ASSETS")
load("//toolchains/shellcheck:assets.bzl", SHELLCHECK_ASSETS = "ASSETS")
load("//toolchains/shellspec:assets.bzl", SHELLSPEC_ASSETS = "ASSETS")
load("//toolchains/templ:assets.bzl", TEMPL_ASSETS = "ASSETS")
load("//toolchains/typos:assets.bzl", TYPOS_ASSETS = "ASSETS")
BIOME_VERSION = "1.8.3"
FD_VERSION = "10.1.0"
GOAWK_VERSION = "1.27.0"
RIPGREP_VERSION = "14.1.0"
SHELLCHECK_VERSION = "0.10.0"
SHELLSPEC_VERSION = "0.28.1"
TYPOS_VERSION = "1.23.2"

TOOLS = {
"biome": BIOME_ASSETS,
"fd": FD_ASSETS,
"goawk": GOAWK_ASSETS,
"ripgrep": RIPGREP_ASSETS,
"sha": SHA_ASSETS,
"shellcheck": SHELLCHECK_ASSETS,
"shellspec": SHELLSPEC_ASSETS,
"templ": TEMPL_ASSETS,
"typos": TYPOS_ASSETS,
VERSIONS = {
"biome": BIOME_VERSION,
"fd": FD_VERSION,
"goawk": GOAWK_VERSION,
"ripgrep": RIPGREP_VERSION,
"sha": "host",
"shellcheck": SHELLCHECK_VERSION,
"shellspec": SHELLSPEC_VERSION,
"templ": "host",
"typos": TYPOS_VERSION,
}

TOOLS = VERSIONS.keys()
23 changes: 23 additions & 0 deletions toolchains/tools_assets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"Tools Assets"

load("//toolchains/biome:assets.bzl", BIOME_ASSETS = "ASSETS")
load("//toolchains/fd:assets.bzl", FD_ASSETS = "ASSETS")
load("//toolchains/goawk:assets.bzl", GOAWK_ASSETS = "ASSETS")
load("//toolchains/ripgrep:assets.bzl", RIPGREP_ASSETS = "ASSETS")
load("//toolchains/sha:assets.bzl", SHA_ASSETS = "ASSETS")
load("//toolchains/shellcheck:assets.bzl", SHELLCHECK_ASSETS = "ASSETS")
load("//toolchains/shellspec:assets.bzl", SHELLSPEC_ASSETS = "ASSETS")
load("//toolchains/templ:assets.bzl", TEMPL_ASSETS = "ASSETS")
load("//toolchains/typos:assets.bzl", TYPOS_ASSETS = "ASSETS")

TOOLS_ASSETS = {
"biome": BIOME_ASSETS,
"fd": FD_ASSETS,
"goawk": GOAWK_ASSETS,
"ripgrep": RIPGREP_ASSETS,
"sha": SHA_ASSETS,
"shellcheck": SHELLCHECK_ASSETS,
"shellspec": SHELLSPEC_ASSETS,
"templ": TEMPL_ASSETS,
"typos": TYPOS_ASSETS,
}
3 changes: 1 addition & 2 deletions toolchains/typos/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//lib:defs.bzl", "multi_platform_assets")

VERSION = "1.23.2"
load("//toolchains:tools.bzl", VERSION = "TYPOS_VERSION")

SUPPORTED_PLATFORMS = [
"darwin_amd64",
Expand Down

0 comments on commit 348518c

Please sign in to comment.