git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #28782 from jraygauthier/jrg/vscode_cpptools_init
efc46c2Jörg Thalheim
pkgs/misc/vscode-extensions/cpptools/default.nixnew file+128
@@ -0,0 +1,128 @@
1+{ stdenv, lib, fetchurl, vscode-utils, unzip, dos2unix, mono46, clang-tools, writeScript
2+, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise.
3+}:
4+
5+assert gdbUseFixed -> null != gdb;
6+
7+/*
8+ Note that this version of the extension still has some nix specific issues
9+ which could not be fixed merely by patching (inside a C# dll).
10+
11+ In particular, the debugger requires either gnome-terminal or xterm. However
12+ instead of looking for the terminal executable in `PATH`, for any linux platform
13+ the dll uses an hardcoded path to one of these.
14+
15+ So, in order for debugging to work properly, you merely need to create symlinks
16+ to one of these terminals at the appropriate location.
17+
18+ The good news is the the utility library is open source and with some effort
19+ we could build a patched version ourselves. See:
20+
21+ <https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156>
22+
23+ Also, the extension should eventually no longer require an external terminal. See:
24+
25+ <https://github.com/Microsoft/vscode-cpptools/issues/35>
26+
27+ Once the symbolic link temporary solution taken, everything shoud run smootly.
28+*/
29+
30+let
31+ gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb";
32+
33+ langComponentBinaries = stdenv.mkDerivation {
34+ name = "cpptools-language-component-binaries";
35+
36+ src = fetchurl {
37+ url = https://download.visualstudio.microsoft.com/download/pr/11151953/d3cc8b654bffb8a2f3896d101f3c3155/Bin_Linux.zip;
38+ sha256 = "12qbxsrdc73cqjb84xdck1xafzhfkcyn6bqbpcy1bxxr3b7hxbii";
39+ };
40+
41+ buildInputs = [ unzip ];
42+
43+ patchPhase = ''
44+ elfInterpreter="${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2"
45+ patchelf --set-interpreter "$elfInterpreter" ./Microsoft.VSCode.CPP.Extension.linux
46+ patchelf --set-interpreter "$elfInterpreter" ./Microsoft.VSCode.CPP.IntelliSense.Msvc.linux
47+ chmod a+x ./Microsoft.VSCode.CPP.Extension.linux ./Microsoft.VSCode.CPP.IntelliSense.Msvc.linux
48+ '';
49+
50+ installPhase = ''
51+ mkdir -p "$out/bin"
52+ find . -mindepth 1 -maxdepth 1 | xargs cp -a -t "$out/bin"
53+ '';
54+ };
55+
56+ cpptoolsJsonFile = fetchurl {
57+ url = https://download.visualstudio.microsoft.com/download/pr/11070848/7b97d6724d52cae8377c61bb4601c989/cpptools.json;
58+ sha256 = "124f091aic92rzbg2vg831y22zr5wi056c1kh775djqs3qv31ja6";
59+ };
60+
61+
62+
63+ openDebugAD7Script = writeScript "OpenDebugAD7" ''
64+ #!${stdenv.shell}
65+ BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)"
66+ ${if gdbUseFixed
67+ then ''
68+ export PATH=''${PATH}''${PATH:+:}${gdb}/bin
69+ ''
70+ else ""}
71+ ${mono46}/bin/mono $BIN_DIR/bin/OpenDebugAD7.exe $*
72+ '';
73+in
74+
75+vscode-utils.buildVscodeMarketplaceExtension {
76+ mktplcRef = {
77+ name = "cpptools";
78+ publisher = "ms-vscode";
79+ version = "0.12.3";
80+ sha256 = "1dcqy54n1w29xhbvxscd41hdrbdwar6g12zx02f6kh2f1kw34z5z";
81+ };
82+
83+ buildInputs = [
84+ dos2unix
85+ ];
86+
87+ prePatch = ''
88+ dos2unix package.json
89+ '';
90+
91+ patches = [
92+ ./vscode-cpptools-0-12-3-package-json.patch
93+ ];
94+
95+ postPatch = ''
96+ # Patch `packages.json` so that nix's *gdb* is used as default value for `miDebuggerPath`.
97+ substituteInPlace "./package.json" \
98+ --replace "\"default\": \"/usr/bin/gdb\"" "\"default\": \"${gdbDefaultsTo}\""
99+
100+ # Prevent download/install of extensions
101+ touch "./install.lock"
102+
103+ # Move unused files out of the way.
104+ mv ./debugAdapters/bin/OpenDebugAD7.exe.config ./debugAdapters/bin/OpenDebugAD7.exe.config.unused
105+
106+ # Bring the `cpptools.json` file at the root of the package, same as the extension would do.
107+ cp -p "${cpptoolsJsonFile}" "./cpptools.json"
108+
109+ # Combining the language component binaries as part of our package.
110+ find "${langComponentBinaries}/bin" -mindepth 1 -maxdepth 1 | xargs cp -p -t "./bin"
111+
112+ # Mono runtimes from nix package (used by generated `OpenDebugAD7`).
113+ rm "./debugAdapters/OpenDebugAD7"
114+ cp -p "${openDebugAD7Script}" "./debugAdapters/OpenDebugAD7"
115+
116+ # Clang-format from nix package.
117+ mkdir -p "./LLVM"
118+ find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM"
119+ '';
120+
121+ meta = with stdenv.lib; {
122+ license = licenses.unfree;
123+ maintainer = [ maintainers.jraygauthier ];
124+ # A 32 bit linux would also be possible with some effort (specific download of binaries +
125+ # patching of the elf files with 32 bit interpreter).
126+ platforms = [ "x86_64-linux" ];
127+ };
128+}
pkgs/misc/vscode-extensions/cpptools/vscode-cpptools-0-12-3-package-json.patchnew file+82
@@ -0,0 +1,82 @@
1+diff --git a/package.json b/package.json
2+index 518e839..1c17c35 100644
3+--- a/package.json
4++++ b/package.json
5+@@ -37,7 +37,26 @@
6+ "Linters"
7+ ],
8+ "activationEvents": [
9+- "*"
10++ "onLanguage:cpp",
11++ "onLanguage:c",
12++ "onCommand:extension.pickNativeProcess",
13++ "onCommand:extension.pickRemoteNativeProcess",
14++ "onCommand:extension.provideInitialConfigurations_cppvsdbg",
15++ "onCommand:extension.provideInitialConfigurations_cppdbg",
16++ "onCommand:C_Cpp.ConfigurationEdit",
17++ "onCommand:C_Cpp.ConfigurationSelect",
18++ "onCommand:C_Cpp.SwitchHeaderSource",
19++ "onCommand:C_Cpp.UnloadLanguageServer",
20++ "onCommand:C_Cpp.Navigate",
21++ "onCommand:C_Cpp.GoToDeclaration",
22++ "onCommand:C_Cpp.PeekDeclaration",
23++ "onCommand:C_Cpp.ToggleErrorSquiggles",
24++ "onCommand:C_Cpp.ToggleIncludeFallback",
25++ "onCommand:C_Cpp.ShowReleaseNotes",
26++ "onCommand:C_Cpp.ResetDatabase",
27++ "workspaceContains:.vscode/c_cpp_properties.json",
28++ "onDebug:cppdbg",
29++ "onDebug:cppvsdbg"
30+ ],
31+ "main": "./out/src/main",
32+ "contributes": {
33+@@ -281,8 +300,7 @@
34+ "cpp"
35+ ]
36+ },
37+- "runtime": "node",
38+- "program": "./out/src/Debugger/Proxy/debugProxy.js",
39++ "program": "./debugAdapters/OpenDebugAD7",
40+ "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
41+ "variables": {
42+ "pickProcess": "extension.pickNativeProcess",
43+@@ -722,7 +740,29 @@
44+ }
45+ }
46+ }
47+- }
48++ },
49++ "configurationSnippets": [
50++ {
51++ "label": "C/C++: (gdb) Launch",
52++ "description": "Launch with gdb.",
53++ "bodyText": "{\n\t\"name\": \"(gdb) Launch\",\n\t\"type\": \"cppdbg\",\n\t\"request\": \"launch\",\n\t\"program\": \"enter program name, for example \\${workspaceRoot}/a.out\",\n\t\"args\": [],\n\t\"stopAtEntry\": false,\n\t\"cwd\": \"\\${workspaceRoot}\",\n\t\"environment\": [],\n\t\"externalConsole\": true,\n\t\"MIMode\": \"gdb\",\n\t\"setupCommands\": [\n\t {\n\t \"description\": \"Enable pretty-printing for gdb\",\n\t \"text\": \"-enable-pretty-printing\",\n\t \"ignoreFailures\": true\n\t }\n\t]\n}"
54++ },
55++ {
56++ "label": "C/C++: (gdb) Attach",
57++ "description": "Attach with gdb.",
58++ "bodyText": "{ \n\t\"name\": \"(gdb) Attach\",\n\t\"type\": \"cppdbg\",\n\t\"request\": \"attach\",\n\t\"program\": \"enter program name, for example \\${workspaceRoot}/a.out\",\n\t\"processId\": \"\\${command:pickProcess}\",\n\t\"MIMode\": \"gdb\"\n}"
59++ },
60++ {
61++ "label": "C/C++: (gdb) Pipe Launch",
62++ "description": "Pipe Launch with gdb.",
63++ "bodyText": "{\n\t\"name\": \"(gdb) Pipe Launch\",\n\t\"type\": \"cppdbg\",\n\t\"request\": \"launch\",\n\t\"program\": \"enter program name, for example \\${workspaceRoot}/a.out\",\n\t\"args\": [],\n\t\"stopAtEntry\": false,\n\t\"cwd\": \"\\${workspaceRoot}\",\n\t\"environment\": [],\n\t\"externalConsole\": true,\n\t\"pipeTransport\": {\n\t\t\"debuggerPath\": \"/usr/bin/gdb\",\n\t\t\"pipeProgram\": \"/usr/bin/ssh\",\n\t\t\"pipeArgs\": [],\n\t\t\"pipeCwd\": \"\"\n\t},\n\t\"MIMode\": \"gdb\",\n\t\"setupCommands\": [\n\t {\n\t \"description\": \"Enable pretty-printing for gdb\",\n\t \"text\": \"-enable-pretty-printing\",\n\t \"ignoreFailures\": true\n\t }\n\t]\n}"
64++ },
65++ {
66++ "label": "C/C++: (gdb) Pipe Attach",
67++ "description": "Pipe Attach with gdb.",
68++ "bodyText": "{\n\t\"name\": \"(gdb) Pipe Attach\",\n\t\"type\": \"cppdbg\",\n\t\"request\": \"attach\",\n\t\"program\": \"enter program name, for example \\${workspaceRoot}/a.out\",\n\t\"processId\": \"\\${command:pickRemoteProcess}\",\n\t\"pipeTransport\": {\n\t\t\"debuggerPath\": \"/usr/bin/gdb\",\n\t\t\"pipeProgram\": \"/usr/bin/ssh\",\n\t\t\"pipeArgs\": [],\n\t\t\"pipeCwd\": \"\"\n\t},\n\t\"MIMode\": \"gdb\"\n}"
69++ }
70++ ]
71+ },
72+ {
73+ "type": "cppvsdbg",
74+@@ -741,7 +781,7 @@
75+ "variables": {
76+ "pickProcess": "extension.pickNativeProcess"
77+ },
78+- "initialConfigurations": "extension.provideInitialConfigurations_cppvsdbg",
79++ "initialConfigurations": "",
80+ "configurationAttributes": {
81+ "launch": {
82+ "required": [
pkgs/misc/vscode-extensions/default.nix+3−1
@@ -1,4 +1,4 @@
1−{ stdenv, lib, fetchurl, vscode-utils }:
1+{ stdenv, lib, fetchurl, callPackage, vscode-utils }:
2
2
3let
3let
4 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
4 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
@@ -22,4 +22,6 @@ rec {
22 license = licenses.mit;
22 license = licenses.mit;
23 };
23 };
24 };
24 };
25+
26+ ms-vscode.cpptools = callPackage ./cpptools {};
25}
27}