Skip to content

Including a genfile at compile time is not possible #79

@SirVer

Description

@SirVer

Minimal repro case with a potential (but ugly) fix:

https://github.com/bazelbuild/rules_rust/compare/master...SirVer:00_include_genfiles?expand=1

The linked branch does the following changes:

  1. Add a genrule call that trivially creates a file containing a string.
  2. The goal is to include_str! this file in hello_world.rs. Code for this is here. For this to ever work, the genfile is made a data dependency of the rust_binary.
  3. I could not pull this off without exposing bazel's ctx.bin_dir and ctx.genfiles_dir as environment variables. This is still ugly, since it includes "external", so the file needs to have the context that it is embedded as an external workspace.

Ideally, I would just want to include_str!("message.string"); or include_str!("../message.string");, but both do not currently work. Is there a better way or solution to this issue? Should my repro case become a patch?

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