Skip to content

Best way to define a pure Runnable from a command line? #665

@cbarrete

Description

@cbarrete

Is there a recommended way of creating a target from something like a cmd_args or a string, that only has a RunInfo, using the standard prelude?

I've tried using genrule for this like so:

genrule(
    name = "run_os",
    executable = True,
    out = "dummy",
    cmd = "touch dummy && $(exe :qemu) -cdrom $(location :os_image) -monitor stdio",
)

But this has a couple of major downsides:

  • It requires a dummy output (Should this be relaxed when executable = True? It might not make sense for a gen rule to not generate any output though.)
  • It has a DefaultInfo, which makes it get picked up by any buck2 build commands with a pattern that matches this target

I've considered using a sh_binary instead, but I like the conciseness of defining everything in a single rule invocation, and I have other concerns mentioned in #664.

For now I'm going to write something like a runnable rule that will do what I want, but I was wondering if there was a better way that I missed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions