Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlinking on Windows needs privilege #350

Open
wolfv opened this issue Jul 21, 2021 · 10 comments
Open

Symlinking on Windows needs privilege #350

wolfv opened this issue Jul 21, 2021 · 10 comments
Labels
more-information-needed Further information is required

Comments

@wolfv
Copy link

wolfv commented Jul 21, 2021

As far as I understand, in the default configuration symlinking on Windows needs special privileges.

Here

add_custom_target(
ament_cmake_python_symlink_${package_name}
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${ARG_PACKAGE_DIR}" "${build_dir}/${package_name}"
)
if(ARG_SETUP_CFG)
add_custom_target(
ament_cmake_python_symlink_${package_name}_setup
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${ARG_SETUP_CFG}" "${build_dir}/setup.cfg"
)
list(APPEND egg_dependencies ament_cmake_python_symlink_${package_name}_setup)
endif()

the CMake tries to create some symlink which fails when building from an average user:

CUSTOMBUILD : CMake error : failed to create symbolic link 'C:/Users/robostack/miniforge3/conda-bld/ros_1626859624934/work/build/ament_cmake_python/smclib/smclib': A required privilege is not held by the client. [%SRC_DIR%\build\ament_cmake_python_symlink_smclib.vcxproj]

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238,5): error MSB8066: Custom build for '%SRC_DIR%\build\CMakeFiles\a56e20129da0512e4208cfc6816c1ca9\ament_cmake_python_symlink_smclib.rule' exited with code 1. [%SRC_DIR%\build\ament_cmake_python_symlink_smclib.vcxproj]

A "hard link" should be fine, though.

cc @ooeygui are you aware of other fixes?

Also PS: for the conda installation one doesn't need admin privileges, and it would be quite annoying to change that for symlinks :)

There is apparently a way to allow users to create symlinks: https://community.perforce.com/s/article/3472#:~:text=Create%20Symbolic%20Links%20Privilege&text=Open%20Control%20Panel%2D%3EAdministrative%20Tools,Administrators%20group%2C%20add%20the%20user.

@wolfv
Copy link
Author

wolfv commented Jul 21, 2021

I tried with create_hardlink but that also fails as it's not possible to hardlink directories 🤦

So now I'll go with copy_directory and copy. I guess that's not desirable for an "interactive" scenario where cmake would probably not re-execute the copy step. Am I getting that right?

I haven't yet dug very deeply into the functionality here.

Could this also be implemented without symlinking?

@ooeygui
Copy link

ooeygui commented Jul 21, 2021

This is a bit of a head scratcher. The Windows command line tool mklink does not require elevation to create a symbolic link within the user context. However, it seems like cmake is calling the system API directly and failing. I'll need to dig in a bit more, but a quick workaround would be to call mklink as suggested here - https://stackoverflow.com/questions/61243174/replacement-of-create-symlink-in-windows.

@wolfv
Copy link
Author

wolfv commented Jul 21, 2021

I also needed privileges for a symbolic link using mklink, unfortunately.

@wolfv
Copy link
Author

wolfv commented Jul 21, 2021

Note: hardlink doesn't need privileges (mklink /h ...) works fine

@hidmic
Copy link
Contributor

hidmic commented Jul 23, 2021

So now I'll go with copy_directory and copy. I guess that's not desirable for an "interactive" scenario where cmake would probably not re-execute the copy step. Am I getting that right?

Yeah, a copy step would defeat the purpose of a symlink install.


https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2144 suggests cmake -E create_symlink should work when Developer Mode is enabled on Windows 10. I haven't verified it myself though. If requiring Developer Mode is a no-go (although a symlink install makes sense for development only, really), why not falling back to a merged install?

@hidmic hidmic added the more-information-needed Further information is required label Jul 23, 2021
@hidmic
Copy link
Contributor

hidmic commented Jul 23, 2021

FYI @wolfv, same efforts have been made in the past: #6.

@gavanderhoorn
Copy link

gavanderhoorn commented Oct 7, 2021

I just ran into this. I'm migrating a toolchain from foxy to galactic branches.

Could it be #327 now also complicates / requires this (ie: symlinks)?

What's puzzling is that I'm asking Colcon to do a --merge-install. Is that supposed to prevent things from using symlinks or am I being too hopeful?

I'm not sure I completely understand ament_cmake_python/cmake/ament_python_install_package.cmake, but is it unconditionally trying to use symlinks?

@hidmic
Copy link
Contributor

hidmic commented Oct 7, 2021

Could it be #327 now also complicates / requires this?

Hmm, yeah, it does. It is unconditionally creating symlinks to build the egg in the build tree off of sources that are in the source tree (w/o affecting the source tree). This ensures symlink installs work, but breaks things on Windows... (I feel like a man yelling at clouds).

What's puzzling is that I'm asking Colcon to do a --merge-install. Is that supposed to prevent things from using symlinks or am I being too hopeful?

colcon can't do much if cmake starts creating symlinks here and there.


@gavanderhoorn perhaps the solution is to fallback to a copy if creating a symlink fails. Symlink installs are not possible anyways if that's the case.

@gavanderhoorn
Copy link

gavanderhoorn commented Oct 7, 2021

What would be the way forward?

This is currently completely blocking my efforts to migrate to Galactic. But I must admit I'm easily getting lost in all the ament_* packages, which prevents me from offering to patch this myself and submit a PR right now.

@hidmic
Copy link
Contributor

hidmic commented Oct 7, 2021

Let me see if I can put together something quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

No branches or pull requests

4 participants