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

Linux: Add support for snaps of CMake #838

Open
Zingam opened this issue Oct 19, 2019 · 24 comments
Open

Linux: Add support for snaps of CMake #838

Zingam opened this issue Oct 19, 2019 · 24 comments
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Milestone

Comments

@Zingam
Copy link
Contributor

Zingam commented Oct 19, 2019

I have just installed Ubuntu 19.10 and used the Software installer application to install Visual Studio Code and CMake 3.15. I cloned my repository from GitHub and whenever I try to call CMake configure in Visual Studio code I get an error message: Bad CMake executable /snap/bin/cmake. CMake seems to run fine in a terminal.

VS Code/CMake extension used to run just fine out-of-the-box in previous version of Ubuntu.

When I try to enter the path manually I get error messages like these:

[rollbar] Unhandled exception: Unhandled Promise rejection: configure TypeError: Cannot read property 'on' of undefined {}
[rollbar] Unhandled exception: Error during CMake upgrade TypeError: Cannot read property 'on' of undefined {"version":"3.13.2","linuxURL":"https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2-Linux-x86_64.sh","windowsURL":"https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2-win64-x64.msi"}

Actually /snap/bin/cmake is not an executable but a link if I recall correctly.

@bobbrow
Copy link
Member

bobbrow commented Oct 21, 2019

A link should be ok. In your case the extension is running /snap/bin/cmake --version and inspecting the output to check if the executable is ok. Can you run that command and let me know what it prints out in your terminal?

The "unhandled exception" error is unrelated to this and should be gone in 1.2.0 (unreleased).

@Zingam
Copy link
Contributor Author

Zingam commented Oct 21, 2019

Ubuntu Terminal:

~$ /snap/bin/cmake --version
cmake version 3.15.4

CMake` suite maintained and supported by Kitware (kitware.com/cmake).

VSCode Terminal:

~/Projects/GitHub/GunBox/GunBox$ ~$ /snap/bin/cmake --version
~$: command not found
~/Projects/GitHub/GunBox/GunBox$ cmake version 3.15.4
CMake Error: The source directory "/home/hristo/Projects/GitHub/GunBox/GunBox/3.15.4" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
/Projects/GitHub/GunBox/GunBox$
~/Projects/GitHub/GunBox/GunBox$ CMake suite maintained and supported by Kitware (kitware.com/cmake).
bash: syntax error near unexpected token `('
~/Projects/GitHub/GunBox/GunBox$

I removed the PC name

@Zingam
Copy link
Contributor Author

Zingam commented Oct 23, 2019

This command also appears to execute properly: /snap/bin/cmake -E server --experimental

@Zingam
Copy link
Contributor Author

Zingam commented Oct 23, 2019

@bobbrow Will version 1.2 be released soon?

@bobbrow
Copy link
Member

bobbrow commented Oct 25, 2019

Yes. Should be early next week. We're doing some final testing.

@Zingam
Copy link
Contributor Author

Zingam commented Oct 28, 2019

OK. Thanks! I'll wait to see how version 1.2 will behave as the currently released doesn't work for me neither on latest Ubuntu nor Windows with the latest MSVC, CMake, GCC, etc. All of which worked before.

@hheld
Copy link

hheld commented Nov 1, 2019

It works when you use /snap/cmake/current/bin/cmake as CMake Path. All snap executables seem to be just symbolic links to /usr/bin/snap, and that seems to work fine when called from a terminal but apparently not from the CMake extension in VSCode ...

@Zingam
Copy link
Contributor Author

Zingam commented Nov 1, 2019

@hheld Thank you for the advice. I'll try that. I tried setting this manually before but maybe I didn't set the proper path.

@Zingam
Copy link
Contributor Author

Zingam commented Nov 1, 2019

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path
Name/path of the CMake executable to use
cmake
Cmake: Ctest Path
Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null)
Cmake: Cmake Path
The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job!

Screenshot from 2019-11-01 13-12-05
Thank you!

I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

@Zingam
Copy link
Contributor Author

Zingam commented Nov 1, 2019

@bobbrow Maybe this issue's title should be changed and filed as a bug: "CMake Tools" don't work with symbolic links on Linux?

@hheld
Copy link

hheld commented Nov 1, 2019

I don't think this issue has anything to do with symbolic links. I don't really know the mechanics of how snap apps work, but I guess something must transform a call to /snap/bin/cmake to something like snap run cmake -- and I guess this doesn't happen when called from the VSCode extension. The link simply points to /usr/bin/snap and this isn't cmake.

@bobbrow bobbrow added the enhancement an enhancement to the product that is either not present or an improvement to an existing feature label Nov 1, 2019
@bobbrow bobbrow changed the title Bad CMake executable - VS Code on Ubuntu 19.10 Linux: Add support for snaps of CMake Nov 1, 2019
@Zingam
Copy link
Contributor Author

Zingam commented Nov 22, 2019

In regard to this: #685 (comment)

I'm also experiencing this issue on Ubuntu:

I installed vscode/cmake from snap packages

$ cmake --version
cmake version 3.16.0-rc4
CMake suite maintained and supported by Kitware (kitware.com/cmake).

But I got this error from the vscode extension:

Bad CMake executable "/snap/bin/cmake". Is it installed or settings contain the correct path (cmake.cmakePath)?

I checked my path

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

I checked my cmake

$ which cmake
/snap/bin/cmake

The story so far...

The snap/bin/cmake links points to the snap application.

/snap/bin$ ls -l
total 0
lrwxrwxrwx 1 root root 12 ное  1 13:02 ccmake -> cmake.ccmake
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.ccmake -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.cmake-gui -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.cpack -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 cmake.ctest -> /usr/bin/snap
lrwxrwxrwx 1 root root 15 ное  1 13:02 cmake-gui -> cmake.cmake-gui
lrwxrwxrwx 1 root root 13 ное 17 08:34 code -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 17 08:34 code.url-handler -> /usr/bin/snap
lrwxrwxrwx 1 root root 11 ное  1 13:02 cpack -> cmake.cpack
lrwxrwxrwx 1 root root 11 ное  1 13:02 ctest -> cmake.ctest
lrwxrwxrwx 1 root root 13 ное  1 13:15 gimp -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное  1 13:02 gnome-calculator -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 17 08:34 gnome-characters -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 окт 19 09:45 gnome-logs -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.npm -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.npx -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.yarn -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 ное 22 09:04 node.yarnpkg -> /usr/bin/snap
lrwxrwxrwx 1 root root  8 ное 22 09:04 npm -> node.npm
lrwxrwxrwx 1 root root  8 ное 22 09:04 npx -> node.npx
lrwxrwxrwx 1 root root  9 ное 22 09:04 yarn -> node.yarn
lrwxrwxrwx 1 root root 12 ное 22 09:04 yarnpkg -> node.yarnpkg

snap list can be used to check for an installed cmake package.

/snap/bin$ snap list
Name                Version                     Rev   Tracking  Publisher     Notes
cmake               3.15.5                      148   stable    crascit✓      classic
code                8795a988                    20    stable    vscode✓       classic
core                16-2.42.1                   8039  stable    canonical✓    core
core18              20191030                    1265  stable    canonical✓    base
gimp                2.10.12                     227   stable    snapcrafters  -
gnome-3-28-1804     3.28.0-16-g27c9498.27c9498  110   stable/…  canonical✓    -
gnome-calculator    3.34.1+git1.d34dc842        544   stable/…  canonical✓    -
gnome-characters    v3.32.1+git2.3367201        367   stable/…  canonical✓    -
gnome-logs          3.34.0                      81    stable/…  canonical✓    -
gtk-common-themes   0.1-25-gcc83164             1353  stable/…  canonical✓    -
gtk2-common-themes  0.1                         5     stable    canonical✓    -
node                13.2.0                      2559  13        nodesource✓   classic

snap run cmake to execute the snap package.

/snap/bin$ snap run cmake
Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>
  cmake [options] -S <path-to-source> -B <path-to-build>

Specify a source directory to (re-)generate a build system for it in the
current working directory.  Specify an existing build directory to
re-generate its build system.

Run 'cmake --help' for more information.

cmake.cmakePath

Cmake: Cmake Path
Name/path of the CMake executable to use.
/snap/cmake/current/bin/cmake
"cmake.cmakePath": "/snap/cmake/current/bin/cmake"

Cmake: Cmake Path
The path to CMake generator executable
"cmake.cmakePath": "/snap/cmake/current/bin/cmake"

I wonder how did the extension decide to use the path /snap/bin/cmake as a cmake.cmakePath setting?

@pietromezzadri
Copy link

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path
Name/path of the CMake executable to use
cmake
Cmake: Ctest Path
Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null)
Cmake: Cmake Path
The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job!

Screenshot from 2019-11-01 13-12-05
Thank you!

I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

@cemlyn007
Copy link

There are two entries related to CMake Path. Which one is the correct one:

Cmake: Cmake Path
Name/path of the CMake executable to use
cmake
Cmake: Ctest Path
Path to CTest executable. If null, will be inference from cmake.cmakePath (recommended to leave null)
Cmake: Cmake Path
The path to CMake generator executable

@hheld Setting /snap/cmake/current/bin/cmake did the job!
Screenshot from 2019-11-01 13-12-05
Thank you!
I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

This also worked for me. Thank you much!

@mosdav
Copy link

mosdav commented Dec 15, 2020

I don't think this issue has anything to do with symbolic links. I don't really know the mechanics of how snap apps work, but I guess something must transform a call to /snap/bin/cmake to something like snap run cmake -- and I guess this doesn't happen when called from the VSCode extension. The link simply points to /usr/bin/snap and this isn't cmake.

@hheld snap uses argv[0] for transforming the call to the "real" cmake.
My best educated guess is some code in the VS plugin fully resolves the symlink and invoke it, so argv[0] is lost in this process

@TianyiShi2001
Copy link

@hheld Setting /snap/cmake/current/bin/cmake did the job!
Thank you!
I also have the twxs's extension (which I hope will be absorbed into CMake Tools) but I don't think that it is causing that duplication.

This fixed for me

This also worked for me. Thank you much!

This also works for me. Many thanks!

But it would be nice if this issue can really be fixed (i.e. /snap/bin/cmake should ideally be fine).

@Zingam
Copy link
Contributor Author

Zingam commented Feb 9, 2021

@TianyiShi2001 Yesterday I setup a new Linux development environment and it is still The Way. I had the intention to fix this but Microsoft stopped reviewing and merging new PRs for nearly a year and I also stopped using VSCode, so I lost the motivation. Now I am back to using it but I doubt that I'll have the time.
I think implementing this functionality would be relatively easy. Typescript is easy. It will require some refactoring how CMake is detected though. Why not try to do it yourself? That would be a fun little project.

Unfortunately even the simplest features require a lot of iterations and thus a lot of time.

@mumin16
Copy link

mumin16 commented Apr 25, 2021

same problem

@Dimon4eg
Copy link

Dimon4eg commented Apr 30, 2021

The same on Ubuntu 20.04.

$ which cmake
/snap/bin/cmake

The /snap/bin/cmake is link:

$ readlink -f /snap/bin/cmake
/usr/bin/snap

CMake works by that link:

$ /snap/bin/cmake --version
cmake version 3.20.2

but VS Code doesn't support it.

Solution is to use /snap/cmake/current/bin/cmake as @hheld suggested above 👍

@H-G-Hristov
Copy link

Another solution:

$ sudo ln -s /snap/cmake/current/bin/cmake /user/bin/cmake

@github-project-automation github-project-automation bot moved this to Triage Needed in CMake Tools Nov 29, 2023
@gcampbell-msft gcampbell-msft moved this from Triage Needed to Pending Prioritization in CMake Tools Nov 29, 2023
@hwhsu1231
Copy link

hwhsu1231 commented Dec 29, 2023

It seems that @H-G-Hristov 's solution is more suitable for me.

$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake

First of all, my laptop has a dual-boot setup with both Windows and Kubuntu installed. Moreover, the vscode installations on both systems share a settings.json configuration file stored in the cloud.

If I adopt solution 1, by setting "cmake.cmakePath" to /snap/cmake/current/bin/cmake, I would need to manually adjust "cmake.cmakePath" every time I switch between the Windows and Kubuntu systems. This is because cmake-tools on Windows cannot locate the file /snap/cmake/current/bin/cmake.

On the other hand, if I adopt solution 2, by creating a new symbolic link /usr/bin/cmake to /snap/cmake/current/bin/cmake using ln -s, then I wouldn't need to make any additional modifications to "cmake.cmakePath" on Kubuntu. I would just let cmake-tools find cmake within the existing PATH environment variable. Since the priority of /usr/bin is higher than that of /snap/bin, it will preferentially find the symbolic link at /usr/bin/cmake, rather than /snap/bin/cmake.

Click to expand demo logs for solution 2
hwhsu1231@vb-kubuntu:~$ /snap/cmake/current/bin/cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake
[sudo] password for hwhsu1231: 
hwhsu1231@vb-kubuntu:~$ which -a cmake
/usr/bin/cmake
/bin/cmake
/snap/bin/cmake
hwhsu1231@vb-kubuntu:~$ which cmake
/usr/bin/cmake
hwhsu1231@vb-kubuntu:~$ cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ echo $PATH
/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts

@Neels99
Copy link

Neels99 commented Mar 20, 2024

Fix for me
change cmakePath
from: cmake
to: /snap/cmake/1366/bin

@chanmaoganda
Copy link

It seems that @H-G-Hristov 's solution is more suitable for me.

$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake

First of all, my laptop has a dual-boot setup with both Windows and Kubuntu installed. Moreover, the vscode installations on both systems share a settings.json configuration file stored in the cloud.

If I adopt solution 1, by setting "cmake.cmakePath" to /snap/cmake/current/bin/cmake, I would need to manually adjust "cmake.cmakePath" every time I switch between the Windows and Kubuntu systems. This is because cmake-tools on Windows cannot locate the file /snap/cmake/current/bin/cmake.

On the other hand, if I adopt solution 2, by creating a new symbolic link /usr/bin/cmake to /snap/cmake/current/bin/cmake using ln -s, then I wouldn't need to make any additional modifications to "cmake.cmakePath" on Kubuntu. I would just let cmake-tools find cmake within the existing PATH environment variable. Since the priority of /usr/bin is higher than that of /snap/bin, it will preferentially find the symbolic link at /usr/bin/cmake, rather than /snap/bin/cmake.

Click to expand demo logs for solution 2

hwhsu1231@vb-kubuntu:~$ /snap/cmake/current/bin/cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ sudo ln -s /snap/cmake/current/bin/cmake /usr/bin/cmake
[sudo] password for hwhsu1231: 
hwhsu1231@vb-kubuntu:~$ which -a cmake
/usr/bin/cmake
/bin/cmake
/snap/bin/cmake
hwhsu1231@vb-kubuntu:~$ which cmake
/usr/bin/cmake
hwhsu1231@vb-kubuntu:~$ cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).
hwhsu1231@vb-kubuntu:~$ echo $PATH
/home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts

wsl and windows use different settings.json

I use wsl and i can apply diff settings.json in wsl and windows
I wonder if windows and kubuntu can hold diff settings.json like wsl and windows do.
I have little knowledge about kubuntu, please forgive my misunderstandings

@Master811129
Copy link

The original post is from 2019 and the issue is still here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Projects
Status: Pending Prioritization
Development

No branches or pull requests