1 - Bazel aspects

1.1 - al_print_deps

al_print_deps

load("@com-alwaldend-git-src//bzl/aspects:al_print_deps.bzl", "al_print_deps")

al_print_deps()

ASPECT ATTRIBUTES

Name Type
deps String

ATTRIBUTES

1.2 - al_toml_validate

al_toml_validate

load("@com-alwaldend-git-src//bzl/aspects:al_toml_validate.bzl", "al_toml_validate")

al_toml_validate()

Aspect adding linters for toml files

ASPECT ATTRIBUTES

Name Type
deps String

ATTRIBUTES

2 - Bazel configs

3 - Bazel macros

3.1 - al_alias_map

al_alias_map

load("@com-alwaldend-git-src//bzl/macros:al_alias_map.bzl", "al_alias_map")

al_alias_map(aliases, visibility)

Generate aliases from an alias map

PARAMETERS

Name Description Default Value
aliases alias map, keys are names, values are alias arguments none
visibility default visibility ["//visibility:public"]

3.2 - al_apply_patches

al_apply_patches

load("@com-alwaldend-git-src//bzl/macros:al_apply_patches.bzl", "al_apply_patches")

al_apply_patches(name, src, patches, visibility, **kwargs)

Create a genrule applying patches

PARAMETERS

Name Description Default Value
name genrule name none
src source archive label none
patches patches label none
visibility visibility ["//visibility:public"]
kwargs other genrule kwargs none

3.3 - al_bzl_library_map

al_bzl_library_map

load("@com-alwaldend-git-src//bzl/macros:al_bzl_library_map.bzl", "al_bzl_library_map")

al_bzl_library_map(name, visibility, libs, deps, **kwargs)

Create bzl_library targets from a map

PARAMETERS

Name Description Default Value
name combined bzl_library target name none
visibility

-

none
libs bzl_library names {}
deps other al_bzl_library_map targets []
kwargs bzl_library kwargs none

3.4 - al_combine_files

al_combine_files

load("@com-alwaldend-git-src//bzl/macros:al_combine_files.bzl", "al_combine_files")

al_combine_files(name, srcs, **kwargs)

Create a genrule combining several files into one

PARAMETERS

Name Description Default Value
name genrule target none
srcs list of labels to combine none
kwargs other genrule kwargs none

3.5 - al_compile_pip_requirements_combined

al_compile_pip_requirements_combined

load("@com-alwaldend-git-src//bzl/macros:al_compile_pip_requirements_combined.bzl", "al_compile_pip_requirements_combined")

al_compile_pip_requirements_combined(name, srcs, **kwargs)

Create compile_pip_requirements target for several requirement files

PARAMETERS

Name Description Default Value
name compile_pip_requirements name none
srcs list of labels of requirement files to combine none
kwargs kwargs for compile_pip_requirements none

3.6 - al_drawio_run_binary

al_drawio_run_binary

load("@com-alwaldend-git-src//bzl/macros:al_drawio_run_binary.bzl", "al_drawio_run_binary")

al_drawio_run_binary(**kwargs)

Wrapper around al_drawio_run_binary rule

PARAMETERS

Name Description Default Value
kwargs kwargs for al_drawio_run_binary none

3.7 - al_genquery_write_to_source_file

al_genquery_write_to_source_file

load("@com-alwaldend-git-src//bzl/macros:al_genquery_write_to_source_file.bzl", "al_genquery_write_to_source_file")

al_genquery_write_to_source_file(name, expression, scope, var_name, out_file)

Write genquery result to a bzl file

Example:

    al_genquery_write_to_source_file(
        name = "al_bzl_libs",
        expression = """
            filter(
                "^//",
                attr(
                    "srcs",
                    ".{3,}",
                    kind(
                        "bzl_library",
                        deps("//bzl")
                    )
                )
            )
        """,
        out_file = "al_bzl_libs.bzl",
        scope = ["//bzl"],
        var_name = "AL_BZL_LIBS",
    )

PARAMETERS

Name Description Default Value
name name prefix none
expression genquery expression none
scope genquery scope none
var_name variable name in the generated .bzl file none
out_file output bzl file none

3.8 - al_genrule

al_genrule

load("@com-alwaldend-git-src//bzl/macros:al_genrule.bzl", "al_genrule")

al_genrule(test, executable, **kwargs)

Generate al_genrule target

PARAMETERS

Name Description Default Value
test If set, use al_genrule_test False
executable if set, use al_genrule_executable False
kwargs kwargs for the rule none

3.9 - al_genrule_src

al_genrule_src

load("@com-alwaldend-git-src//bzl/macros:al_genrule_src.bzl", "al_genrule_src")

al_genrule_src(name, srcs, visibility)

Create a filegroup and a genrule generating a tar archive

PARAMETERS

Name Description Default Value
name genrule name none
srcs source labels []
visibility

-

["//visibility:public"]

3.10 - al_genrule_with_wheels

al_genrule_with_wheels

load("@com-alwaldend-git-src//bzl/macros:al_genrule_with_wheels.bzl", "al_genrule_with_wheels")

al_genrule_with_wheels(name, wheels, srcs, cmd, **kwargs)

Regular genrule with wheels added to ${PYTHONPATH}

PARAMETERS

Name Description Default Value
name genrule name none
wheels list of wheel labels none
srcs srcs for the genrule []
cmd genrule cmd []
kwargs other genrule kwargs none

3.11 - al_go_checkers

3.12 - al_install_file

al_install_file

load("@com-alwaldend-git-src//bzl/macros:al_install_file.bzl", "al_install_file")

al_install_file(name, args, install_file_label, visibility, **py_binary_kwargs)

Create py_binary target to install file

PARAMETERS

Name Description Default Value
name target name none
args install-file args []
install_file_label

-

"//py/install-file:lib"
visibility

-

["//visibility:public"]
py_binary_kwargs

-

none

3.13 - al_lua_library

al_lua_library

load("@com-alwaldend-git-src//bzl/macros:al_lua_library.bzl", "al_lua_library")

al_lua_library(name, srcs, check, stylua_config_label, stylua_label, pkg_tar_kwargs, visibility)

Generate targets for a lua library

Targets:

  • ${name}: pkg_tar
  • ${name}-stylua-fix: al_run_tool executable
  • ${name}-stylua-test: al_run_tool test

PARAMETERS

Name Description Default Value
name library name none
srcs library sources none
check if set, only these files will be checked []
stylua_config_label

-

"//lua:stylua-config"
stylua_label

-

"@com-alwaldend-src-cargo//:stylua__stylua"
pkg_tar_kwargs kwargs for pkg_tar {}
visibility visibility ["//visibility:public"]

3.14 - al_md_data

al_md_data

load("@com-alwaldend-git-src//bzl/macros:al_md_data.bzl", "al_md_data")

al_md_data(name, srcs, deps, **kwargs)

Markdown data backed by a filegroup

Targets:

  • ${name}: filegroup

PARAMETERS

Name Description Default Value
name filegroup name none
srcs markdown files none
deps deps []
kwargs filegroup kwargs none

3.15 - al_pkg_tar_combined

al_pkg_tar_combined

load("@com-alwaldend-git-src//bzl/macros:al_pkg_tar_combined.bzl", "al_pkg_tar_combined")

al_pkg_tar_combined(name, srcs, strip_components, **kwargs)

Create a genrule combining several tars into one

PARAMETERS

Name Description Default Value
name genrule name none
srcs dicts tar archives ({“label”: “tar label”, “dir”: “target dir”}) []
strip_components value of –stip-components 2
kwargs other genrule kwargs none

3.16 - al_py_binary_shell

al_py_binary_shell

load("@com-alwaldend-git-src//bzl/macros:al_py_binary_shell.bzl", "al_py_binary_shell")

al_py_binary_shell(name, deps, srcs, shell_type, shell_label, **kwargs)

Create a py_binary target that allows you to run commands in proper python environment

PARAMETERS

Name Description Default Value
name target name none
deps py_binary deps []
srcs py_binary srcs []
shell_type ${BAZEL_PYTHON_SHELL_TYPE} "python"
shell_label

-

"//py/bazel-python-shell:library"
kwargs other py_binary kwargs none

3.17 - al_py_checker

al_py_checker

load("@com-alwaldend-git-src//bzl/macros:al_py_checker.bzl", "al_py_checker")

al_py_checker(name, tool, args_bin, args_test, test_size, disable_fix, **kwargs)

Create -fix and -test targets for a python checker

PARAMETERS

Name Description Default Value
name Name prefix None
tool Tool label None
args_bin Args for the binary target None
args_test Args for the test None
test_size

-

"small"
disable_fix If set, do not create fix target False
kwargs Kwargs for both targets none

3.18 - al_py_checkers

al_py_checkers

load("@com-alwaldend-git-src//bzl/macros:al_py_checkers.bzl", "al_py_checkers")

al_py_checkers(srcs, isort_label, black_label, mypy_label, flake8_label, pyproject_label)

Generate -fix and -test targets for python checkers

PARAMETERS

Name Description Default Value
srcs list of source file labels none
isort_label

-

"//py:isort"
black_label

-

"//py:black"
mypy_label

-

"//py:mypy"
flake8_label

-

"//py:flake8"
pyproject_label

-

"//:pyproject"

3.19 - al_readme

al_readme

load("@com-alwaldend-git-src//bzl/macros:al_readme.bzl", "al_readme")

al_readme(name, srcs, subpackages, **kwargs)

Create readme targets

Targets:

  • ${name}: al_md_data target
  • ${name}-children: pkg_tar containing ${name}-children from subpackages

PARAMETERS

Name Description Default Value
name target name none
srcs

-

[":README.md"]
subpackages override list of subpackages []
kwargs al_md_data kwargs none

3.20 - al_run_tool

al_run_tool

load("@com-alwaldend-git-src//bzl/macros:al_run_tool.bzl", "al_run_tool")

al_run_tool(name, tool, executable, test, **kwargs)

Generate either native_test, native_binary, or run_binary target

PARAMETERS

Name Description Default Value
name Target name (required) none
tool Tool label to run (required) none
executable If True, generate native_binary False
test If True, generate native_test False
kwargs kwargs for rules none

3.21 - al_sh_library

al_sh_library

load("@com-alwaldend-git-src//bzl/macros:al_sh_library.bzl", "al_sh_library")

al_sh_library(name, shfmt_src, editorconfig_src, shellcheck_src, run_args_src, visibility,
              **common_kwargs)

Create targets for a shell library

Targets:

  • ${name}-shfmt-fix: executable to run shfmt
  • ${name}-shfmt-test: test whether the script is formatted
  • ${name}-shellcheck-test: shellcheck test

PARAMETERS

Name Description Default Value
name target name none
shfmt_src

-

"@cc_mvdan_sh_v3//cmd/shfmt:shfmt"
editorconfig_src

-

"//:editorconfig"
shellcheck_src

-

"@com-github-koalaman-shellcheck-linux-x86_64//:bin"
run_args_src

-

"//sh/scripts:run-args-lib"
visibility

-

["//visibility:public"]
common_kwargs kwargs for both targets none

3.22 - al_template_files

al_template_files

load("@com-alwaldend-git-src//bzl/macros:al_template_files.bzl", "al_template_files")

al_template_files(**kwargs)

Macros around al_template_files rule

PARAMETERS

Name Description Default Value
kwargs kwargs for al_template_files none

3.23 - al_txt_data

al_txt_data

load("@com-alwaldend-git-src//bzl/macros:al_txt_data.bzl", "al_txt_data")

al_txt_data(name, srcs, **kwargs)

Text data

PARAMETERS

Name Description Default Value
name target name none
srcs sources none
kwargs filegroup kwargs none

4 - Bazel providers

4.1 - al_hugo_site_info

AlHugoSiteInfo

load("@com-alwaldend-git-src//bzl/providers:al_hugo_site_info.bzl", "AlHugoSiteInfo")

AlHugoSiteInfo(content, data, themes, layouts, config, env, env_script)

Information about a hugo site

FIELDS

Name Description
content Content dir
data Data dir
themes Themes dir
layouts Layouts dir
config Config file
env Environment variables
env_script Shell script to export env variables

4.2 - al_toml_info

AlTomlInfo

load("@com-alwaldend-git-src//bzl/providers:al_toml_info.bzl", "AlTomlInfo")

AlTomlInfo(srcs, deps)

Provide toml data info

FIELDS

Name Description
srcs Toml files
deps Toml data targets

4.3 - al_transitive_sources

AlTransitiveSources

load("@com-alwaldend-git-src//bzl/providers:al_transitive_sources.bzl", "AlTransitiveSources")

AlTransitiveSources(transitive_sources)

Provide transitive sources

FIELDS

Name Description
transitive_sources -

al_transitive_sources

load("@com-alwaldend-git-src//bzl/providers:al_transitive_sources.bzl", "al_transitive_sources")

al_transitive_sources(srcs, deps)

Obtain the source files for a target and its transitive dependencies.

PARAMETERS

Name Description Default Value
srcs a list of source files none
deps a list of targets that are direct dependencies none

RETURNS

a collection of the transitive sources

5 - Bazel registry

Docs: https://bazel.build/external/registry

6 - Bazel rules

6.1 - al_drawio_run_binary

al_drawio_run_binary

load("@com-alwaldend-git-src//bzl/rules:al_drawio_run_binary.bzl", "al_drawio_run_binary")

al_drawio_run_binary(name, srcs, out, arguments, cmd_timeout)

Run drawio a a build action

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Sources List of labels optional []
out Output Label; nonconfigurable required
arguments Arguments, location statements are expanded List of strings required
cmd_timeout Drawio command timeout String optional "1m"

6.2 - al_genrule

al_genrule_executable

load("@com-alwaldend-git-src//bzl/rules:al_genrule.bzl", "al_genrule_executable")

al_genrule_executable(name, srcs, data, outs, cmd, set_flags, shell, tools, worker)

Build executable using shell worker

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Sources, will not be added to runfiles List of labels optional []
data Data, will be added to runfiles List of labels optional []
outs Outputs List of labels; nonconfigurable required
cmd Script to execute String required
set_flags set flags List of strings optional ["-eux"]
shell shell to use String optional "/bin/sh"
tools Tools, will be added to runfiles List of labels optional []
worker Worker binary Label optional "@com-alwaldend-git-src//go/bazel-shell-worker"

al_genrule_regular

load("@com-alwaldend-git-src//bzl/rules:al_genrule.bzl", "al_genrule_regular")

al_genrule_regular(name, srcs, data, outs, cmd, set_flags, shell, tools, worker)

Build shell worker rule

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Sources, will not be added to runfiles List of labels optional []
data Data, will be added to runfiles List of labels optional []
outs Outputs List of labels; nonconfigurable required
cmd Script to execute String required
set_flags set flags List of strings optional ["-eux"]
shell shell to use String optional "/bin/sh"
tools Tools, will be added to runfiles List of labels optional []
worker Worker binary Label optional "@com-alwaldend-git-src//go/bazel-shell-worker"

al_genrule_test

load("@com-alwaldend-git-src//bzl/rules:al_genrule.bzl", "al_genrule_test")

al_genrule_test(name, srcs, data, outs, cmd, set_flags, shell, tools, worker)

Test using shell worker

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Sources, will not be added to runfiles List of labels optional []
data Data, will be added to runfiles List of labels optional []
outs Outputs List of labels; nonconfigurable required
cmd Script to execute String required
set_flags set flags List of strings optional ["-eux"]
shell shell to use String optional "/bin/sh"
tools Tools, will be added to runfiles List of labels optional []
worker Worker binary Label optional "@com-alwaldend-git-src//go/bazel-shell-worker"

6.3 - al_hugo_binary

al_hugo_binary

load("@com-alwaldend-git-src//bzl/rules:al_hugo_binary.bzl", "al_hugo_binary")

al_hugo_binary(name, arguments, site)

Run a hugo command

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
arguments Hugo arguments List of strings required
site Hugo site Label required

6.4 - al_hugo_run_binary

al_hugo_run_binary

load("@com-alwaldend-git-src//bzl/rules:al_hugo_run_binary.bzl", "al_hugo_run_binary")

al_hugo_run_binary(name, arguments, site)

Run hugo binary as a build action

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
arguments Hugo arguments List of strings required
site Hugo site Label required

6.5 - al_hugo_site

al_hugo_site

load("@com-alwaldend-git-src//bzl/rules:al_hugo_site.bzl", "al_hugo_site")

al_hugo_site(name, configs, content, env, hugo_data, hugo_layouts, postcss, themes, tools)

Define a hugo site

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
configs Hugo configs List of labels required
content Hugo content Label required
env Hugo environment variables (support location statements, support make variables, support shell commands) Dictionary: String -> String optional {}
hugo_data Hugo data Label required
hugo_layouts Hugo layouts Label required
postcss Postcss target Label required
themes Hugo themes Label required
tools Tools that should be available for the build List of labels optional []

6.6 - al_remove_directories

al_remove_directories

load("@com-alwaldend-git-src//bzl/rules:al_remove_directories.bzl", "al_remove_directories")

al_remove_directories(name, srcs)

Remove directory files from DefaultInfo

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Sources to remove directories from List of labels optional []

6.7 - al_template_files

al_template_files

load("@com-alwaldend-git-src//bzl/rules:al_template_files.bzl", "al_template_files")

al_template_files(name, srcs, data, outs, templater)

Load data files, then template the template and write the output

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs Template files List of labels required
data Data files List of labels required
outs Output files List of labels; nonconfigurable required
templater Templater to use Label optional "@com-alwaldend-git-src//go/template-files"

6.8 - al_toml_data

al_toml_data

load("@com-alwaldend-git-src//bzl/rules:al_toml_data.bzl", "al_toml_data")

al_toml_data(name, deps, srcs, tomlv)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps Toml data targets List of labels optional []
srcs Toml files List of labels optional []
tomlv Tomlv target to use for validation Label optional "@com-alwaldend-git-src//tools:tomlv"

6.9 - al_unpack_archives

al_unpack_archives

load("@com-alwaldend-git-src//bzl/rules:al_unpack_archives.bzl", "al_unpack_archives")

al_unpack_archives(name, srcs, out)

Unpack several archives using tar into a directory

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
srcs - List of labels required
out - String optional ""

6.10 - al_write_script

al_write_script

load("@com-alwaldend-git-src//bzl/rules:al_write_script.bzl", "al_write_script")

al_write_script(name, out, content, make_vars, set_flags, shebang)

Write a script and make it executable

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
out Output file Label; nonconfigurable required
content Script content String required
make_vars Additional make vars Dictionary: String -> String optional {}
set_flags Flags to pass to set List of strings optional ["-eu"]
shebang Sheband to use String optional "#!/usr/bin/env sh"

7 - Bazel rules

Qt setup

  • Install qt: aqt install-qt -O /opt/qt linux desktop 6.9.0
  • Register toolchain: register_toolchains("//bazel/qt:preinstalled-qt-toolchain")

7.1 - al_drawio_toolchain

al_drawio_toolchain

load("@com-alwaldend-git-src//bzl/toolchains:al_drawio_toolchain.bzl", "al_drawio_toolchain")

al_drawio_toolchain(name, drawio)

Drawio toolchain

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
drawio Drawio binary Label required

7.2 - al_hugo_toolchain

al_hugo_toolchain

load("@com-alwaldend-git-src//bzl/toolchains:al_hugo_toolchain.bzl", "al_hugo_toolchain")

al_hugo_toolchain(name, hugo)

Hugo toolchain

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
hugo Hugo binary Label required

7.3 - al_qt_local_toolchain

al_qt_local_toolchain

load("@com-alwaldend-git-src//bzl/toolchains:al_qt_local_toolchain.bzl", "al_qt_local_toolchain")

al_qt_local_toolchain(name, dir, platform, version)

Local qt toolchain

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
dir Root qt directory String required
platform Qt platform String required
version Qt version String required

7.4 - al_qt_resolved_toolchain

al_qt_resolved_toolchain

load("@com-alwaldend-git-src//bzl/toolchains:al_qt_resolved_toolchain.bzl", "al_qt_resolved_toolchain")

al_qt_resolved_toolchain(name)

Resolved qt toolchain

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required

7.5 - al_shellcheck_toolchain

al_shellcheck_toolchain

load("@com-alwaldend-git-src//bzl/toolchains:al_shellcheck_toolchain.bzl", "al_shellcheck_toolchain")

al_shellcheck_toolchain(name, shellcheck)

Shellcheck toolchain

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
shellcheck Shellcheck binary Label required

8 - BUILD.bazel files

9 - Module extensions

9.1 - al_repo_map

al_repo_map

al_repo_map = use_extension("@com-alwaldend-git-src//bzl/extensions:al_repo_map.bzl", "al_repo_map")
al_repo_map.download(name, build_file_content, download_type, executable, repos, strip_prefix)

Extension to create several repos from a map

TAG CLASSES

download

Attributes

Name Description Type Mandatory Default
name Name Name required
build_file_content Build file content String optional ""
download_type Download type String required
executable Field executable for http_file Boolean optional False
repos Map of repos Dictionary: String -> List of strings required
strip_prefix Strip prefix String optional ""

10 - Static bazel variables

11 - Toolchain types