How to get bzlmod version info embedded at build time?

39 views
Skip to first unread message

Jelle Schuhmacher

unread,
Mar 27, 2025, 7:41:11 AM3/27/25
to bazel-discuss
Hi folks,

I'm trying to embed some version information of third party modules into a generated file, "Version.cpp.inc", and so far without success.

I have a .bazelrc with --workspace_status_command "utils/workspace_status.sh" that outputs the required STABLE_XXX lines to the stable-status.txt file, and a corresponding genrule that embeds those into the required include file. 

This setup works fine until I try to add module version information into the mix. When I add:
bazel mod --output=json --depth=1 path "my_top_level_module" | jq ...<snip>... 
into the workspace_status_command script, the build hangs. It turns out bazel mod cannot be used inside a workspace status command, it hangs with:
Another command (pid=68387) is running. Waiting for it to complete on the server (server_pid=61337)...

Are there better ways to get to the module version information so that it can be embedded in the generated file? Would it perhaps somehow be accessible with a genquery instead? 

Cheers,
Jelle

For info, I'm trying to get to this field somehow:
{
  "key": "onnx...@20250219.1035",
  "name": "onnx-mlir",
  "version": "20250219.1035",
  "apparentName": "onnx-mlir",
  ... <snip> ...

Xudong Yang

unread,
Mar 27, 2025, 3:21:03 PM3/27/25
to Jelle Schuhmacher, bazel-discuss
in a .bzl file loaded from a BUILD file, you can use `native.module_version()` (https://bazel.build/rules/lib/toplevel/native#module_version) to get the version of the module the BUILD file is in.

"  YÁNG Xùdōng (杨旭东)
#  SURNAME Givenname
=  Software Engineer
@  Google New York


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bazel-discuss/f866603e-3327-4196-827b-0a6a4bc0fcd2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages