at master 144 lines 5.2 kB view raw
1{ 2 lib, 3 vscode-utils, 4 jq, 5 clang-tools, 6 gdbUseFixed ? true, 7 gdb, # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise. 8 autoPatchelfHook, 9 makeWrapper, 10 stdenv, 11 lttng-ust, 12 libkrb5, 13 zlib, 14}: 15 16/* 17 Note that this version of the extension still has some nix specific issues 18 which could not be fixed merely by patching (inside a C# dll). 19 20 In particular, the debugger requires either gnome-terminal or xterm. However 21 instead of looking for the terminal executable in `PATH`, for any linux platform 22 the dll uses an hardcoded path to one of these. 23 24 So, in order for debugging to work properly, you merely need to create symlinks 25 to one of these terminals at the appropriate location. 26 27 The good news is the the utility library is open source and with some effort 28 we could build a patched version ourselves. See: 29 30 <https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156> 31 32 Also, the extension should eventually no longer require an external terminal. See: 33 34 <https://github.com/Microsoft/vscode-cpptools/issues/35> 35 36 Once the symbolic link temporary solution taken, everything should run smootly. 37*/ 38 39let 40 gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb"; 41 isx86Linux = stdenv.hostPlatform.system == "x86_64-linux"; 42 isDarwin = stdenv.hostPlatform.isDarwin; 43 supported = { 44 x86_64-linux = { 45 hash = "sha256-JES5esVW6cRlrmFAQO1yLYEZbLdQu4ILW0rjDBp5Ek4="; 46 arch = "linux-x64"; 47 }; 48 aarch64-linux = { 49 hash = "sha256-fZzYzR2wHbCCllhyu4fI2ekPu3fMngUmeJawhkYdWyA="; 50 arch = "linux-arm64"; 51 }; 52 aarch64-darwin = { 53 hash = "sha256-fPtCIOYvbO/S06io9lFAXxkB/6g00GO5+RXt5aewPME="; 54 arch = "darwin-arm64"; 55 }; 56 }; 57 58 base = 59 supported.${stdenv.hostPlatform.system} 60 or (throw "unsupported platform ${stdenv.hostPlatform.system}"); 61in 62vscode-utils.buildVscodeMarketplaceExtension { 63 mktplcRef = base // { 64 name = "cpptools"; 65 publisher = "ms-vscode"; 66 version = "1.26.3"; 67 }; 68 69 nativeBuildInputs = [ 70 autoPatchelfHook 71 makeWrapper 72 ]; 73 74 buildInputs = [ 75 jq 76 libkrb5 77 zlib 78 (lib.getLib stdenv.cc.cc) 79 ] 80 ++ lib.optionals stdenv.hostPlatform.isLinux [ lttng-ust ]; 81 82 dontAutoPatchelf = isx86Linux || isDarwin; 83 84 postPatch = '' 85 mv ./package.json ./package_orig.json 86 87 # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime. 88 # 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`. 89 cat ./package_orig.json | \ 90 jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \ 91 jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \ 92 ./package.json 93 94 # Prevent download/install of extensions 95 touch "./install.lock" 96 97 # Clang-format from nix package. 98 rm -rf ./LLVM 99 mkdir "./LLVM/" 100 find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM" 101 102 # Patching binaries 103 chmod +x bin/cpptools bin/cpptools-srv bin/cpptools-wordexp debugAdapters/bin/OpenDebugAD7 104 '' 105 + lib.optionalString stdenv.hostPlatform.isLinux '' 106 patchelf --replace-needed liblttng-ust.so.0 liblttng-ust.so.1 ./debugAdapters/bin/libcoreclrtraceptprovider.so 107 '' 108 + lib.optionalString isx86Linux '' 109 chmod +x bin/libc.so 110 '' 111 + lib.optionalString isDarwin '' 112 chmod +x debugAdapters/lldb-mi/bin/lldb-mi 113 ''; 114 115 # On aarch64 the binaries are statically linked 116 # but on x86 they are not. 117 postFixup = 118 lib.optionalString isx86Linux '' 119 autoPatchelf $out/share/vscode/extensions/ms-vscode.cpptools/debugAdapters 120 # cpptools* are distributed by the extension and need to be run through the distributed musl interpretter 121 patchelf --set-interpreter $out/share/vscode/extensions/ms-vscode.cpptools/bin/libc.so $out/share/vscode/extensions/ms-vscode.cpptools/bin/cpptools 122 patchelf --set-interpreter $out/share/vscode/extensions/ms-vscode.cpptools/bin/libc.so $out/share/vscode/extensions/ms-vscode.cpptools/bin/cpptools-srv 123 patchelf --set-interpreter $out/share/vscode/extensions/ms-vscode.cpptools/bin/libc.so $out/share/vscode/extensions/ms-vscode.cpptools/bin/cpptools-wordexp 124 '' 125 + lib.optionalString gdbUseFixed '' 126 wrapProgram $out/share/vscode/extensions/ms-vscode.cpptools/debugAdapters/bin/OpenDebugAD7 --prefix PATH : ${lib.makeBinPath [ gdb ]} 127 ''; 128 129 meta = { 130 description = "C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging"; 131 homepage = "https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools"; 132 license = lib.licenses.unfree; 133 maintainers = with lib.maintainers; [ 134 jraygauthier 135 stargate01 136 ]; 137 platforms = [ 138 "x86_64-linux" 139 "aarch64-linux" 140 "aarch64-darwin" 141 ]; 142 sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; 143 }; 144}