rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

"Failed to create symlink" on windows

Open baszalmstra opened this issue 2 years ago • 3 comments

When trying out this project I immediately ran into an issue on Windows:

ERROR: An error occurred during the fetch of repository 'crate_index':
   Traceback (most recent call last):
        File "C:/users/bas/_bazel_bas/2verhtmo/external/rules_rust/crate_universe/private/crates_repository.bzl", line 59, column 50, in _crates_repository_impl
                metadata_path = splice_workspace_manifest(
        File "C:/users/bas/_bazel_bas/2verhtmo/external/rules_rust/crate_universe/private/splicing_utils.bzl", line 180, column 12, in splice_workspace_manifest
                execute(
        File "C:/users/bas/_bazel_bas/2verhtmo/external/rules_rust/crate_universe/private/common_utils.bzl", line 48, column 13, in execute
                fail(_EXECUTE_ERROR_MESSAGE.format(
Error in fail: Command [C:/users/bas/_bazel_bas/2verhtmo/external/crate_index/cargo-bazel.exe, "splice", "--output-dir", C:/users/bas/_bazel_bas/2verhtmo/external/crate_index/splicing-output, "--splicing-manifest", C:/users/bas/_bazel_bas/2verhtmo/external/crate_index/splicing_manifest.json, "--config", C:/users/bas/_bazel_bas/2verhtmo/external/crate_index/cargo-bazel.json, "--cargo", C:/users/bas/_bazel_bas/2verhtmo/external/rust_windows_x86_64__x86_64-pc-windows-msvc__stable_tools/bin/cargo.exe, "--rustc", C:/users/bas/_bazel_bas/2verhtmo/external/rust_windows_x86_64__x86_64-pc-windows-msvc__stable_tools/bin/rustc.exe, "--cargo-lockfile", C:/users/bas/developer/prefix.dev/Cargo.lock] failed with exit code 1.
STDOUT ------------------------------------------------------------------------

STDERR ------------------------------------------------------------------------
Error: Failed to create symlink: C:/users/bas/developer/prefix.dev\.cargo -> C:\Users\bas\AppData\Local\Temp\.tmpFaPzlG\.cargo

Caused by:
    A required privilege is not held by the client. (os error 1314)

Looks like cargo-bazel tries to create a symlink which is only allowed in rare circumstances on Windows. Hard-links would usually work though?

baszalmstra avatar Jun 18 '23 14:06 baszalmstra

I think you can enable the "Developer Mode" on Windows and then you don't need a privilege to create symlinks.

https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging

wolfv avatar Jun 18 '23 14:06 wolfv

I just ran into the same problem (or at least similar, bazel fails to extract the rules_rust tarball due to contained symlinks). On my company-managed laptop, I would need admin privileges to enable "Developer Mode", but I don't have admin privileges. So the workaround doesn't work for me.

csarn avatar Mar 20 '24 10:03 csarn

This could probably be solved by updating @rules_rust//crate_universe/src/utils/symlink.rs to create junctions instead of symlinking on Windows. I'm unfortunately not very familiar with windows so would need the help of the community to drive such a change 😅

Happy to review a pull-request though!

Relates to https://github.com/bazelbuild/rules_rust/issues/1156

UebelAndre avatar Sep 14 '24 15:09 UebelAndre