Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05-pre 99 lines 3.7 kB view raw
1{ lib, vscode-utils 2, fetchurl, mono, 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}: 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 30let 31 gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb"; 32 33 34 openDebugAD7Script = writeScript "OpenDebugAD7" '' 35 #!${runtimeShell} 36 BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)" 37 ${if gdbUseFixed 38 then '' 39 export PATH=''${PATH}''${PATH:+:}${gdb}/bin 40 '' 41 else ""} 42 ${mono}/bin/mono $BIN_DIR/bin/OpenDebugAD7.exe $* 43 ''; 44in 45 46vscode-utils.buildVscodeMarketplaceExtension rec { 47 mktplcRef = { 48 name = "cpptools"; 49 publisher = "ms-vscode"; 50 version = "1.7.1"; 51 }; 52 53 vsix = fetchurl { 54 name = "${mktplcRef.publisher}-${mktplcRef.name}.zip"; 55 url = "https://github.com/microsoft/vscode-cpptools/releases/download/${mktplcRef.version}/cpptools-linux.vsix"; 56 sha256 = "sha256-LqndG/vv8LgVPEX6dGkikDB6M6ISneo2UJ78izXVFbk="; 57 }; 58 59 buildInputs = [ 60 jq 61 ]; 62 63 postPatch = '' 64 mv ./package.json ./package_orig.json 65 66 # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime. 67 # 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`. 68 cat ./package_orig.json | \ 69 jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \ 70 jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \ 71 ./package.json 72 73 # Prevent download/install of extensions 74 touch "./install.lock" 75 76 # Mono runtimes from nix package (used by generated `OpenDebugAD7`). 77 mv ./debugAdapters/bin/OpenDebugAD7 ./debugAdapters/bin/OpenDebugAD7_orig 78 cp -p "${openDebugAD7Script}" "./debugAdapters/bin/OpenDebugAD7" 79 80 # Clang-format from nix package. 81 mv ./LLVM/ ./LLVM_orig 82 mkdir "./LLVM/" 83 find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM" 84 85 # Patching cpptools and cpptools-srv 86 elfInterpreter="$(cat $NIX_CC/nix-support/dynamic-linker)" 87 patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools 88 patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools-srv 89 chmod a+x ./bin/cpptools{-srv,} 90 ''; 91 92 meta = with lib; { 93 license = licenses.unfree; 94 maintainers = [ maintainers.jraygauthier ]; 95 # A 32 bit linux would also be possible with some effort (specific download of binaries + 96 # patching of the elf files with 32 bit interpreter). 97 platforms = [ "x86_64-linux" ]; 98 }; 99}