You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
runfiles, Windows: $RUNFILES should point to the actual runfiles directory #4280
P3We're not considering working on this, but happy to review a PR. (No assignee)area-WindowsWindows-specific issues and feature requestsplatform: windowsteam-OSSIssues for the Bazel OSS team: installation, release processBazel packaging, websitetype: feature request
the PWD dir sh_binary executed in should be RUNFILES. Currently
PWD: /c/cygwin64/tmp/_bazel_wyan/zgiahg30/execroot/__main__/bazel-out/x64_windows-fastbuild/bin/shell_wrapper.exe.runfiles # Has '.exe' in last segment of path, Exist in filesystem.
RUNFILES: C:\cygwin64\tmp\_bazel_wyan\zgiahg30\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\shell_wrapper.runfiles # Not exist in filesystem
I agree, $RUNFILES should point to the actual runfiles directory (with .exe in the name).
Since the RUNFILES we're talking about is constructed by RUNFILES=${BASH_SOURCE[0]}.runfiles, I don't think it should contain .exe.
Because the first argument a shell script receives will always be itself, which will never end with .exe.
As an alternative, we can use RUNFILES_MANIFEST_FILE environment variable. It is set by the Windows native launcher, in this case, shell_wrapper.exe.
It points to the manifest file under runfiles directory, like
Being consistent across platforms is important. My BUILD rule need be run on both Windows and Linux. RUNFILES_MANIFEST_FILE is not available on LInux. If you don't like ".exe" in the path please make the directory the execute 'bazel run' under without .exe.
Better documentation, such as the explanation of symlink to files and why runfile dir has MANIFEST only on Windows, is definitely needed. But the discrepancy on two "RUNFILES" and confusions from it sound avoidable to me.
@wyan-nestlabs : we're working on adding libraries that'll unify runfiles handling on all platforms. In shell for example, on Linux you'll have to source this library from $RUNFILES, and on Windows it'll be automatically sourced, and once it is sourced you can use the rlocation function to retrieve runfile paths platform-independently, e.g. rlocation path/to/runfile.
I'm planning to complete that work in Q1-2018, at least for sh_* rules. (What language we implement it for next, we haven't decided yet.) See #3865.
Personally, it'd be a lot more convenient and language-independent to simply set environment variables in a consistent way across all platforms. In my case, I use python scripts to provide platform independence. Do you plan to make a python library (and a library for each language) that provides the rlocation function? Doesn't it seem easier to just make the RUNFILES env var consistent and let each language figure out what to do with it?
I've attempted to write such an rlocation function in python and found that if there was a consistent environment, writing that function would be a lot easier. My goal is to actually always use the manifest file on every platform to resolve paths to their original locations so that rlocation works consistently everywhere. Another very useful env var would be something equivalent to TEST_SRCDIR but under the run context.
I've attempted to write such an rlocation function in python and found that if there was a consistent environment, writing that function would be a lot easier.
I don't see how it would be a lot easier, because on Linux rlocation is simply echo $RUNFILES/$1 (in case of Bash scripts, for example). Do you mean something else?
My goal is to actually always use the manifest file on every platform to resolve paths to their original locations so that rlocation works consistently everywhere.
I like that idea. I'm not aware of any reason why a symlink tree would be better than using a manifest file, if one already has to use rlocation because of Windows. Migrating existing binaries and tests would be practical / economical if they all used rlocation already because we could then change the implementation of rlocation and simultaneously stop generating the symlink tree.
Another very useful env var would be something equivalent to TEST_SRCDIR but under the run context.
Thanks! Yes, we're aware of it. We decided not to use that because (a) it's opt-in and requires one-time registry editing and possibly Admin approval, and (b) it's only available in the very latest Win10 update, and Bazel supports Win7 and up. That said ideally Bazel would detect whether it can create symlinks and fall back to copying, but we didn't think it's high priority for now.
P3We're not considering working on this, but happy to review a PR. (No assignee)area-WindowsWindows-specific issues and feature requestsplatform: windowsteam-OSSIssues for the Bazel OSS team: installation, release processBazel packaging, websitetype: feature request
Activity
meteorcloudy commentedon Dec 12, 2017
@laszlocsomor @wyan-nestlabs
Continue discussion in #4261
Since the
RUNFILESwe're talking about is constructed byRUNFILES=${BASH_SOURCE[0]}.runfiles, I don't think it should contain.exe.Because the first argument a shell script receives will always be itself, which will never end with
.exe.As an alternative, we can use
RUNFILES_MANIFEST_FILEenvironment variable. It is set by the Windows native launcher, in this case,shell_wrapper.exe.It points to the manifest file under runfiles directory, like
This is only the useful thing under runfiles directory on Windows.
And you can get
RUNFILESdirectory by$(dirname ${RUNFILES_MANIFEST_FILE})But I do agree that we really should have a better documentation for these unique Windows behaviors.
wyan-nestlabs commentedon Dec 12, 2017
Being consistent across platforms is important. My BUILD rule need be run on both Windows and Linux. RUNFILES_MANIFEST_FILE is not available on LInux. If you don't like ".exe" in the path please make the directory the execute 'bazel run' under without .exe.
Better documentation, such as the explanation of symlink to files and why runfile dir has MANIFEST only on Windows, is definitely needed. But the discrepancy on two "RUNFILES" and confusions from it sound avoidable to me.
laszlocsomor commentedon Dec 14, 2017
@wyan-nestlabs : we're working on adding libraries that'll unify runfiles handling on all platforms. In shell for example, on Linux you'll have to source this library from $RUNFILES, and on Windows it'll be automatically sourced, and once it is sourced you can use the
rlocationfunction to retrieve runfile paths platform-independently, e.g.rlocation path/to/runfile.I'm planning to complete that work in Q1-2018, at least for
sh_*rules. (What language we implement it for next, we haven't decided yet.) See #3865.flaub commentedon Dec 24, 2017
Personally, it'd be a lot more convenient and language-independent to simply set environment variables in a consistent way across all platforms. In my case, I use python scripts to provide platform independence. Do you plan to make a python library (and a library for each language) that provides the
rlocationfunction? Doesn't it seem easier to just make theRUNFILESenv var consistent and let each language figure out what to do with it?laszlocsomor commentedon Jan 2, 2018
@flaub --
The user would still have to deal with the difference that Bazel generates a symlink tree on Linux, and a manifest file on Windows.
Yes, for Python, Bash, Java, and C++.
As I said, Bazel's behavior is different on Linux and Windows. I see no point in setting this envvar on Windows. WDYT?
flaub commentedon Jan 2, 2018
I've attempted to write such an
rlocationfunction in python and found that if there was a consistent environment, writing that function would be a lot easier. My goal is to actually always use the manifest file on every platform to resolve paths to their original locations so thatrlocationworks consistently everywhere. Another very useful env var would be something equivalent toTEST_SRCDIRbut under the run context.Something else you might want to consider, as of Windows 10 Creators Update, symlinks no longer require admin privileges when using "Developer Mode". More details here: https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/
laszlocsomor commentedon Jan 2, 2018
I don't see how it would be a lot easier, because on Linux
rlocationis simplyecho $RUNFILES/$1(in case of Bash scripts, for example). Do you mean something else?I like that idea. I'm not aware of any reason why a symlink tree would be better than using a manifest file, if one already has to use
rlocationbecause of Windows. Migrating existing binaries and tests would be practical / economical if they all usedrlocationalready because we could then change the implementation ofrlocationand simultaneously stop generating the symlink tree.What do you mean? Can you give an example?
Thanks! Yes, we're aware of it. We decided not to use that because (a) it's opt-in and requires one-time registry editing and possibly Admin approval, and (b) it's only available in the very latest Win10 update, and Bazel supports Win7 and up. That said ideally Bazel would detect whether it can create symlinks and fall back to copying, but we didn't think it's high priority for now.
laszlocsomor commentedon Jan 2, 2018
I meant one-time enabling in some settings menu (or maybe it is indeed registry editing; I didn't check).
meteorcloudy commentedon Dec 22, 2021
I don't see any complain about the
$RUNFILESfor a long time, closing this now. Feel free to reopen if the issue still exists.