Skip to content

Provide a build.zig utility that helps people make a build step for g…#14

Merged
milogreg merged 2 commits into
newfrom
utility-generate-graph
Jul 9, 2025
Merged

Provide a build.zig utility that helps people make a build step for g…#14
milogreg merged 2 commits into
newfrom
utility-generate-graph

Conversation

@sdzx-1
Copy link
Copy Markdown
Collaborator

@sdzx-1 sdzx-1 commented Jul 9, 2025

…enerating state graph

demo: sdzx-1/polystate-examples@fd4fe89

@sdzx-1 sdzx-1 requested a review from milogreg July 9, 2025 08:12
@sdzx-1
Copy link
Copy Markdown
Collaborator Author

sdzx-1 commented Jul 9, 2025

This will produce the following output

➜  zig-out git:(demo) ls
atm.dot  bin  cont.dot	counter.dot  todo.dot

Comment thread build.zig
.target = target,
.imports = &.{
.{ .name = "polystate", .module = polystate.module("root") },
.{ .name = b.allocator.dupe(u8, module_name) catch @panic("OOM"), .module = module },
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dupe wasted my half day

Copy link
Copy Markdown
Collaborator

@milogreg milogreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the core functionality looks good.

However, I think that we should actually have the function just return the install_dot_file, rather than adding it as a dependency to the install step. This gives the caller the freedom to add it to whichever step they choose (like if they just want to generate the graph when running zig build graph). It may also make sense to rename the function to addGraphFile, which reflects the new behavior better.

Also, if you wanted to be even more consistent with the std.Build API, you could split the generation of dot_file into another public function, giving you addGraphFile which generates dot_file and addInstallGraphFile which generates install_dot_file. This would give the user two options to choose depending on how much control they want.

@sdzx-1
Copy link
Copy Markdown
Collaborator Author

sdzx-1 commented Jul 9, 2025

new demo: sdzx-1/polystate-examples@24c4e65

➜  zig-out git:(demo) tree .
.
├── bin
│   ├── atm
│   ├── cont
│   ├── counter
│   ├── data
│   │   └── FiraMono.ttf
│   └── todo
└── graphs
    ├── atm.dot
    ├── cont.dot
    ├── counter.dot
    └── todo.dot

4 directories, 9 files
polystate-examples git:(demo) zig build --summary all
Build Summary: 57/57 steps succeeded
install cached
├─ install data/FiraMono.ttf to bin/data/FiraMono.ttf cached
├─ install generated to counter.dot cached
│  └─ run exe _generate_graph_for_counter cached
│     └─ compile exe _generate_graph_for_counter Debug native cached 30ms MaxRSS:77M
│        ├─ options cached
│        ├─ WriteFile  cached
│        ├─ compile lib glfw Debug native cached 27ms MaxRSS:77M
│        ├─ WriteFile cached
│        ├─ compile lib imgui Debug native cached 31ms MaxRSS:77M
│        ├─ WriteFile raylib.h cached
│        ├─ compile lib raylib Debug native cached 22ms MaxRSS:77M
│        │  ├─ run wayland-scanner (wayland-client-protocol.h) cached
│        │  ├─ run wayland-scanner (wayland-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (xdg-shell-client-protocol.h) cached
│        │  ├─ run wayland-scanner (xdg-shell-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (xdg-decoration-unstable-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (xdg-decoration-unstable-v1-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (viewporter-client-protocol.h) cached
│        │  ├─ run wayland-scanner (viewporter-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (relative-pointer-unstable-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (relative-pointer-unstable-v1-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (pointer-constraints-unstable-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (pointer-constraints-unstable-v1-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (fractional-scale-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (fractional-scale-v1-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (xdg-activation-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (xdg-activation-v1-client-protocol-code.h) cached
│        │  ├─ run wayland-scanner (idle-inhibit-unstable-v1-client-protocol.h) cached
│        │  ├─ run wayland-scanner (idle-inhibit-unstable-v1-client-protocol-code.h) cached
│        │  ├─ WriteFile raygui.c cached
│        │  ├─ run wayland-scanner (wayland-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (wayland-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (xdg-shell-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (xdg-shell-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (xdg-decoration-unstable-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (xdg-decoration-unstable-v1-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (viewporter-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (viewporter-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (relative-pointer-unstable-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (relative-pointer-unstable-v1-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (pointer-constraints-unstable-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (pointer-constraints-unstable-v1-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (fractional-scale-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (fractional-scale-v1-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (xdg-activation-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (xdg-activation-v1-client-protocol-code.h) (reused)
│        │  ├─ run wayland-scanner (idle-inhibit-unstable-v1-client-protocol.h) (reused)
│        │  ├─ run wayland-scanner (idle-inhibit-unstable-v1-client-protocol-code.h) (reused)
│        │  └─ WriteFile raygui.c (reused)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ options cached
│        ├─ options cached
│        └─ options cached
├─ install counter cached
│  └─ compile exe counter Debug native cached 31ms MaxRSS:77M
│     ├─ WriteFile  (reused)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ WriteFile (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ WriteFile raylib.h (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ options (reused)
│     ├─ options (reused)
│     └─ options (reused)
├─ install generated to atm.dot cached
│  └─ run exe _generate_graph_for_atm cached
│     └─ compile exe _generate_graph_for_atm Debug native cached 31ms MaxRSS:73M
│        ├─ options cached
│        ├─ WriteFile  (reused)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ WriteFile (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ WriteFile raylib.h (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ options cached
│        ├─ options (reused)
│        └─ options (reused)
├─ install atm cached
│  └─ compile exe atm Debug native cached 25ms MaxRSS:77M
│     ├─ WriteFile  (reused)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ WriteFile (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ WriteFile raylib.h (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ options (reused)
│     ├─ options (reused)
│     └─ options (reused)
├─ install generated to cont.dot cached
│  └─ run exe _generate_graph_for_cont cached
│     └─ compile exe _generate_graph_for_cont Debug native cached 29ms MaxRSS:73M
│        ├─ options cached
│        ├─ WriteFile  (reused)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ WriteFile (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ WriteFile raylib.h (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ options cached
│        ├─ options (reused)
│        └─ options (reused)
├─ install cont cached
│  └─ compile exe cont Debug native cached 21ms MaxRSS:77M
│     ├─ WriteFile  (reused)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ WriteFile (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ WriteFile raylib.h (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ compile lib glfw Debug native (reused)
│     ├─ compile lib imgui Debug native (reused)
│     ├─ compile lib raylib Debug native (+38 more reused dependencies)
│     ├─ options (reused)
│     ├─ options (reused)
│     └─ options (reused)
├─ install generated to todo.dot cached
│  └─ run exe _generate_graph_for_todo cached
│     └─ compile exe _generate_graph_for_todo Debug native cached 31ms MaxRSS:77M
│        ├─ options cached
│        ├─ WriteFile  (reused)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ WriteFile (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ WriteFile raylib.h (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ compile lib glfw Debug native (reused)
│        ├─ compile lib imgui Debug native (reused)
│        ├─ compile lib raylib Debug native (+38 more reused dependencies)
│        ├─ options cached
│        ├─ options (reused)
│        └─ options (reused)
└─ install todo cached
   └─ compile exe todo Debug native cached 26ms MaxRSS:74M
      ├─ WriteFile  (reused)
      ├─ compile lib glfw Debug native (reused)
      ├─ WriteFile (reused)
      ├─ compile lib imgui Debug native (reused)
      ├─ WriteFile raylib.h (reused)
      ├─ compile lib raylib Debug native (+38 more reused dependencies)
      ├─ compile lib glfw Debug native (reused)
      ├─ compile lib imgui Debug native (reused)
      ├─ compile lib raylib Debug native (+38 more reused dependencies)
      ├─ options (reused)
      ├─ options (reused)
      └─ options (reused)

@sdzx-1 sdzx-1 requested a review from milogreg July 9, 2025 11:00
@milogreg milogreg merged commit b361417 into new Jul 9, 2025
@sdzx-1 sdzx-1 deleted the utility-generate-graph branch July 9, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants