diff --git a/MODULE.bazel b/MODULE.bazel index a40db6c3..ef526a9e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -17,6 +17,9 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2") bazel_dep(name = "rules_python", version = "0.29.0") bazel_dep(name = "platforms", version = "0.0.7") +bazel_lib = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains") +bazel_lib.expand_template() + # Custom python version for testing only python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True) python.toolchain( diff --git a/WORKSPACE b/WORKSPACE index af575f13..e1a407ac 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -42,10 +42,12 @@ py_repositories() ############################################ # Aspect bazel-lib -load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains") +load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains", "register_expand_template_toolchains") register_coreutils_toolchains() +register_expand_template_toolchains() + load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains") load_musl_toolchains(extra_target_compatible_with = ["@//tools/linkers:musl"]) diff --git a/examples/py_binary/BUILD.bazel b/examples/py_binary/BUILD.bazel index 43e61a7e..23fd4bac 100644 --- a/examples/py_binary/BUILD.bazel +++ b/examples/py_binary/BUILD.bazel @@ -1,8 +1,17 @@ +load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template") load("//py:defs.bzl", "py_binary") +expand_template( + name = "stamped", + stamp_substitutions = { + "": "{{BUILD_TIMESTAMP}}", + }, + template = "say.py", +) + py_binary( name = "py_binary", - srcs = ["say.py"], + srcs = [":stamped"], deps = [ "@pypi_cowsay//:pkg", ], diff --git a/examples/py_binary/say.py b/examples/py_binary/say.py index 69f2299f..b580ac6d 100644 --- a/examples/py_binary/say.py +++ b/examples/py_binary/say.py @@ -1,3 +1,3 @@ import cowsay -cowsay.cow('hello py_binary!') \ No newline at end of file +cowsay.cow('hello py_binary! (built at )') \ No newline at end of file