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
Systematically handle Windows MAX_PATH issues #1120
I feel like I run into Windows MAX_PATH issues more often in rules_rust than I do for other rules. I'm wondering if there's a way to address this in a systematic way using the process_wrapper or something. But it'd be nice to not need to worry about this since there's apparently solutions (\\?\ prefixes) that might be able to help.
So if I understand right - the issue is that rules_rust produce paths that are too long on Windows. We have multiple solutions:
decreasing the chance of this being a problem by using shorter names (for example by using crate_universe_examples instead of rules_rust_examples_crate_universe)
implementing support for \\?\ in the process wrapper
implementing support for \\?\ in starlark implementation of rules
Let's use this issue to collect more data first. Which paths are problematic? Tools? Files?
#1434 shortened a target name for the same reason too.
So far, whenever I've ran into this issue, the culprit turned out to be MSVC, especially the linker, and I don't believe we can do anything reasonable about that (maybe in process_wrapper we could copy all the files to a temporary location and copy the output file to the desired location afterwards, but that would be expensive). Bazel's best practices suggest using a short output_user_root but we already do that on CI and are still close to the limit even for some toolchain files.
I believe one of the reasons we are hitting this issue sooner than other rulesets are the temporary files that rustc produces, eg
will create a proc_macro_has_native_dep-1976543513.proc_macro_using_native_dep.26a1bb4a-cgu.1.rcgu.o file. I don't think there is a way to instruct rustc to shorten this filename.
Last time I talked to Bazel's Windows expert @meteorcloudy I got the impression that there is not much we can do about MSVC, but tagging them to confirm/contradict me.
@scentini You're right, we cannot do anything about it other than try to use a shorter path. The MSVC compiler/link doesn't work with the \\?\ solution.
I've run into this issue several times when updating rules_rust recently on our project. I've worked around this by using a patch to rules_rust that truncates the auto-generated workspace names so that a workspace name like:
(It's just taking the first character of each _ separated component.) Although this is horribly ugly, it has reliably solved the problem for us and we've not had any more path issues on any of the crates we're compiling. The patch is not invasive - there are only two places where this truncation is required.
Given that this problem appears unlikely to be solvable without MSVC supporting long paths, would a PR for such a truncation scheme (enabled only on Windows) be useful? I appreciate it's not pretty, but I don't see many other options without MSVC supporting long paths. The only other option would seem to be copying files into a short temporary location, but I expect this would be expensive.
Given that this problem appears unlikely to be solvable without MSVC supporting long paths, would a PR for such a truncation scheme (enabled only on Windows) be useful? I appreciate it's not pretty, but I don't see many other options without MSVC supporting long paths. The only other option would seem to be copying files into a short temporary location, but I expect this would be expensive.
Shortening repository names to short ugly paths is what we've been doing to solve this in other places so yeah, if there is a way to enable that for windows then that sounds good to me! Just recently I was wondering if such a thing were possible. Perhaps the verbose repository name could still be created but it only contains aliases to the ugly one so for building short paths get used by folks can still refer to the verbose one? Not sure if that's that valuable though. Working builds definitely are though 😄
Activity
hlopko commentedon Feb 4, 2022
So if I understand right - the issue is that rules_rust produce paths that are too long on Windows. We have multiple solutions:
crate_universe_examplesinstead ofrules_rust_examples_crate_universe)\\?\in the process wrapper\\?\in starlark implementation of rulesLet's use this issue to collect more data first. Which paths are problematic? Tools? Files?
UebelAndre commentedon Feb 4, 2022
#1006 was another example of this issue
[-]Systematically handle MAX_PATH issues[/-][+]Systematically handle Windows MAX_PATH issues[/+]UebelAndre commentedon Mar 31, 2022
#423 is also an example of this issue.
Create .bazelrc.windows for Windows users
UebelAndre commentedon Jul 11, 2022
#1420 (comment) shows another example of this issue.
scentini commentedon Jul 13, 2022
#1434 shortened a target name for the same reason too.
So far, whenever I've ran into this issue, the culprit turned out to be
MSVC, especially the linker, and I don't believe we can do anything reasonable about that (maybe in process_wrapper we could copy all the files to a temporary location and copy the output file to the desired location afterwards, but that would be expensive). Bazel's best practices suggest using a shortoutput_user_rootbut we already do that on CI and are still close to the limit even for some toolchain files.I believe one of the reasons we are hitting this issue sooner than other rulesets are the temporary files that
rustcproduces, egwill create a
proc_macro_has_native_dep-1976543513.proc_macro_using_native_dep.26a1bb4a-cgu.1.rcgu.ofile. I don't think there is a way to instructrustcto shorten this filename.Last time I talked to Bazel's Windows expert @meteorcloudy I got the impression that there is not much we can do about MSVC, but tagging them to confirm/contradict me.
meteorcloudy commentedon Jul 13, 2022
@scentini You're right, we cannot do anything about it other than try to use a shorter path. The MSVC compiler/link doesn't work with the
\\?\solution.This issue is reported back to Microsoft a long time ago: https://developercommunity.visualstudio.com/t/allow-building-running-and-debugging-a-net-applica/351628
UebelAndre commentedon Sep 20, 2022
#1556 seems to be another case of this issue.
tomgr commentedon Nov 1, 2023
I've run into this issue several times when updating rules_rust recently on our project. I've worked around this by using a patch to rules_rust that truncates the auto-generated workspace names so that a workspace name like:
becomes
(It's just taking the first character of each _ separated component.) Although this is horribly ugly, it has reliably solved the problem for us and we've not had any more path issues on any of the crates we're compiling. The patch is not invasive - there are only two places where this truncation is required.
Given that this problem appears unlikely to be solvable without MSVC supporting long paths, would a PR for such a truncation scheme (enabled only on Windows) be useful? I appreciate it's not pretty, but I don't see many other options without MSVC supporting long paths. The only other option would seem to be copying files into a short temporary location, but I expect this would be expensive.
UebelAndre commentedon Nov 1, 2023
Shortening repository names to short ugly paths is what we've been doing to solve this in other places so yeah, if there is a way to enable that for windows then that sounds good to me! Just recently I was wondering if such a thing were possible. Perhaps the verbose repository name could still be created but it only contains aliases to the ugly one so for building short paths get used by folks can still refer to the verbose one? Not sure if that's that valuable though. Working builds definitely are though 😄
peakschris commentedon Jun 26, 2024
@tomgr (or anyone else who has it) - could you share your horrible hack? I'm running into this issue. Thank you!