1

please take a look at the bin-win target in my repository here: https://github.com/thinlizzy/bazelexample/blob/master/demo/BUILD#L28

it seems to be properly packing the executable inside a file named bin-win.tar.gz, but I still have some questions:

1- in my machine, the file is being generated at this directory:

C:\Users\John\AppData\Local\Temp_bazel_John\aS4O8v3V\execroot__main__\bazel-out\x64_windows-fastbuild\bin\demo

which makes finding the tar.gz file a cumbersome task. The question is how can I make my bin-win target to move the file from there to a "better location"? (perhaps defined by an environment variable or a cmd line parameter/flag)

2- how can I include more files with my executable? My actual use case is I want to supply data files and some DLLs together with the executable. Should I use a filegroup() rule and refer its name in the "srcs" attribute as well?

2a- for the DLLs, is there a way to make a filegroup() rule to interpret environment variables? (e.g: the directories of the DLLs)

Thanks!

1 Answer 1

0
  1. Look for the bazel-bin and bazel-genfiles directories in your workspace. These are actually junctions (directory symlinks) that Bazel updates after every build. If you bazel build //:demo, you can access its output as bazel-bin\demo.

    (a) You can also set TMP and TEMP in your environment to point to e.g. c:\tmp. Bazel will pick those up instead of C:\Users\John\AppData\Local\Temp, so the full path for the output directory (that bazel-bin points to) will be c:\tmp\aS4O8v3V\execroot\__main__\bazel-out\x64_windows-fastbuild\bin.

    (b) Or you can pass the --output_user_root startup flag, e.g. bazel--output_user_root=c:\tmp build //:demo. That will have the same effect as (a).

    There's currently no way to get rid of the _bazel_John\aS4O8v3V\execroot part of the path.

  2. Yes, I think you need to put those files in pkg_tar.srcs. Whether you use a filegroup() rule is irrelevant; filegroup just lets you group files together, so you can refer to the group by name, which is useful when you need to refer to the same files in multiple rules.

    2.a. I don't think so.

5
  • I am not sure whether the bazel-bin and bazel-genfiles symlinks will also work on Windows.
    – thinlizzy
    Commented Feb 6, 2018 at 22:16
  • (a) and (b) seem to be good options to define an output dir, but I still have the problem of discovering the "aS4O8v3V" hashed directory (or I can just set the output_user_root to some unique dir and then just "jump" six levels there)
    – thinlizzy
    Commented Feb 6, 2018 at 22:19
  • @thinlizzy: The bazel-{bin,genfiles} symlinks do work on Windows. Bazel can create directory symlinks ("junctions" in Windows' lingo) on all Windows versions it supports, starting from Win7. Bazel-on-Windows currently cannot create file symlinks though.
    – László
    Commented Feb 7, 2018 at 7:35
  • @thinlizzy: You can ask Bazel about the output directory: bazel info output_root. Run bazel info to see the list of all values info can retrieve.
    – László
    Commented Feb 7, 2018 at 7:38
  • is this file symlink issue the reason that I can't normally open files in my data dependencies when I do a bazel run in Windows ? (the same files open fine when I do bazel run in Linux)
    – thinlizzy
    Commented Feb 18, 2018 at 16:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.