1{ lib, vscode-utils
2, fetchurl, writeScript, runtimeShell
3, jq, clang-tools
4, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise.
5, autoPatchelfHook, makeWrapper, stdenv, lttng-ust, libkrb5, zlib
6}:
7
8/*
9 Note that this version of the extension still has some nix specific issues
10 which could not be fixed merely by patching (inside a C# dll).
11
12 In particular, the debugger requires either gnome-terminal or xterm. However
13 instead of looking for the terminal executable in `PATH`, for any linux platform
14 the dll uses an hardcoded path to one of these.
15
16 So, in order for debugging to work properly, you merely need to create symlinks
17 to one of these terminals at the appropriate location.
18
19 The good news is the the utility library is open source and with some effort
20 we could build a patched version ourselves. See:
21
22 <https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156>
23
24 Also, the extension should eventually no longer require an external terminal. See:
25
26 <https://github.com/Microsoft/vscode-cpptools/issues/35>
27
28 Once the symbolic link temporary solution taken, everything shoud run smootly.
29*/
30
31let
32 gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb";
33in
34vscode-utils.buildVscodeMarketplaceExtension {
35 mktplcRef = {
36 name = "cpptools";
37 publisher = "ms-vscode";
38 version = "1.17.3";
39 sha256 = "sha256-4mKCBqUCOndKEfsJqTIsfwEt+0CZI8QAhBj3Y4+wKlg=";
40 arch = "linux-x64";
41 };
42
43 nativeBuildInputs = [
44 autoPatchelfHook
45 makeWrapper
46 ];
47
48 buildInputs = [
49 jq
50 lttng-ust
51 libkrb5
52 zlib
53 stdenv.cc.cc.lib
54 ];
55
56 postPatch = ''
57 mv ./package.json ./package_orig.json
58
59 # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime.
60 # 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`.
61 cat ./package_orig.json | \
62 jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \
63 jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \
64 ./package.json
65
66 # Prevent download/install of extensions
67 touch "./install.lock"
68
69 # Clang-format from nix package.
70 mv ./LLVM/ ./LLVM_orig
71 mkdir "./LLVM/"
72 find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM"
73
74 # Patching binaries
75 chmod +x bin/cpptools bin/cpptools-srv bin/cpptools-wordexp debugAdapters/bin/OpenDebugAD7
76 patchelf --replace-needed liblttng-ust.so.0 liblttng-ust.so.1 ./debugAdapters/bin/libcoreclrtraceptprovider.so
77 '';
78
79 postFixup = lib.optionalString gdbUseFixed ''
80 wrapProgram $out/share/vscode/extensions/ms-vscode.cpptools/debugAdapters/bin/OpenDebugAD7 --prefix PATH : ${lib.makeBinPath [ gdb ]}
81 '';
82
83 meta = {
84 description = "The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging.";
85 homepage = "https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools";
86 license = lib.licenses.unfree;
87 maintainers = [ lib.maintainers.jraygauthier lib.maintainers.stargate01 ];
88 platforms = [ "x86_64-linux" ];
89 };
90}