diff --git a/pkgs/misc/vscode-extensions/cpptools/default.nix b/pkgs/misc/vscode-extensions/cpptools/default.nix index c537aa8a1f92..c29611c0c662 100644 --- a/pkgs/misc/vscode-extensions/cpptools/default.nix +++ b/pkgs/misc/vscode-extensions/cpptools/default.nix @@ -1,5 +1,5 @@ -{ stdenv, lib, fetchurl, vscode-utils, unzip, dos2unix, mono46, clang-tools, writeScript -, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise. +{ stdenv, lib, fetchurl, fetchzip, vscode-utils, jq, mono46, clang-tools, writeScript +, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise. }: assert gdbUseFixed -> null != gdb; @@ -33,13 +33,11 @@ let langComponentBinaries = stdenv.mkDerivation { name = "cpptools-language-component-binaries"; - src = fetchurl { - url = https://download.visualstudio.microsoft.com/download/pr/11151953/d3cc8b654bffb8a2f3896d101f3c3155/Bin_Linux.zip; - sha256 = "12qbxsrdc73cqjb84xdck1xafzhfkcyn6bqbpcy1bxxr3b7hxbii"; + src = fetchzip { + url = https://download.visualstudio.microsoft.com/download/pr/11991016/8a81aa8f89aac452956b0e4c68e6620b/Bin_Linux.zip; + sha256 = "0ma59fxfldbgh6ijlvfbs3hnl4g0cnw5gs6286zdrp065n763sv4"; }; - buildInputs = [ unzip ]; - patchPhase = '' elfInterpreter="${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2" patchelf --set-interpreter "$elfInterpreter" ./Microsoft.VSCode.CPP.Extension.linux @@ -53,13 +51,6 @@ let ''; }; - cpptoolsJsonFile = fetchurl { - url = https://download.visualstudio.microsoft.com/download/pr/11070848/7b97d6724d52cae8377c61bb4601c989/cpptools.json; - sha256 = "124f091aic92rzbg2vg831y22zr5wi056c1kh775djqs3qv31ja6"; - }; - - - openDebugAD7Script = writeScript "OpenDebugAD7" '' #!${stdenv.shell} BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)" @@ -76,23 +67,24 @@ vscode-utils.buildVscodeMarketplaceExtension { mktplcRef = { name = "cpptools"; publisher = "ms-vscode"; - version = "0.12.3"; - sha256 = "1dcqy54n1w29xhbvxscd41hdrbdwar6g12zx02f6kh2f1kw34z5z"; + version = "0.16.1"; + sha256 = "0m4cam8sf3zwp8ss1dii908g7rc8b9l6pry0dglg0rmf45pkiaj3"; }; buildInputs = [ - dos2unix - ]; - - prePatch = '' - dos2unix package.json - ''; - - patches = [ - ./vscode-cpptools-0-12-3-package-json.patch + jq ]; postPatch = '' + mv ./package.json ./package_ori.json + + # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime. + # 2. Patch `packages.json` so that nix's *gdb* is used as default value for `miDebuggerPath`. + cat ./package_ori.json | \ + jq --slurpfile actEvts ${./package-activation-events-0-16-1.json} '(.activationEvents) = $actEvts[0]' | \ + jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \ + ./package.json + # Patch `packages.json` so that nix's *gdb* is used as default value for `miDebuggerPath`. substituteInPlace "./package.json" \ --replace "\"default\": \"/usr/bin/gdb\"" "\"default\": \"${gdbDefaultsTo}\"" @@ -103,9 +95,6 @@ vscode-utils.buildVscodeMarketplaceExtension { # Move unused files out of the way. mv ./debugAdapters/bin/OpenDebugAD7.exe.config ./debugAdapters/bin/OpenDebugAD7.exe.config.unused - # Bring the `cpptools.json` file at the root of the package, same as the extension would do. - cp -p "${cpptoolsJsonFile}" "./cpptools.json" - # Combining the language component binaries as part of our package. find "${langComponentBinaries}/bin" -mindepth 1 -maxdepth 1 | xargs cp -p -t "./bin" @@ -121,7 +110,7 @@ vscode-utils.buildVscodeMarketplaceExtension { meta = with stdenv.lib; { license = licenses.unfree; maintainers = [ maintainers.jraygauthier ]; - # A 32 bit linux would also be possible with some effort (specific download of binaries + + # A 32 bit linux would also be possible with some effort (specific download of binaries + # patching of the elf files with 32 bit interpreter). platforms = [ "x86_64-linux" ]; }; diff --git a/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh b/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh new file mode 100755 index 000000000000..f5eb08d78a5d --- /dev/null +++ b/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env nix-shell +#! nix-shell -p coreutils -i bash + +scriptDir=$(cd "`dirname "$0"`"; pwd) +echo "scriptDir='$scriptDir'" + +function get_pkg_out() { + local pkg="$1" + local suffix="${2:-}" + local nixExp="with (import {}); ${pkg}" + echo "$(nix-build -E "$nixExp" --no-out-link)${suffix}" +} + +interpreter="$(get_pkg_out "stdenv.glibc" "/lib/ld-linux-x86-64.so.2")" +echo "interpreter='$interpreter'" + +# For clangformat dep on 'libtinfo.so.5'. +ncursesLibDir="$(get_pkg_out "ncurses5.out" "/lib")" +echo "ncursesLibDir='$ncursesLibDir'" + +# For clanformat dep on 'libstdc++.so.6'. +stdcppLibDir="$(get_pkg_out "stdenv.cc.cc.lib" "/lib")" +echo "stdcppLibDir='$stdcppLibDir'" + +# For clangformat dep on 'libz.so.1'. +zlibLibDir="$(get_pkg_out "zlib.out" "/lib")" +echo "zlibLibDir='$zlibLibDir'" + +function patchelf_mono() { + local exe="$1" + patchelf --set-interpreter "$interpreter" "$exe" +} + +function patchelf_clangformat() { + local exe="$1" + patchelf --set-interpreter "$interpreter" "$exe" + local rpath="$ncursesLibDir:$stdcppLibDir:$zlibLibDir" + patchelf --set-rpath "$rpath" "$exe" +} + +function print_nix_version_clangtools() { + nixClangToolsBin="$(get_pkg_out "clang-tools" "/bin")" + echo "nixClangToolsBin='$nixClangToolsBin'" + $nixClangToolsBin/clang-format --version +} + +function print_nix_version_mono() { + nixMonoBin="$(get_pkg_out "mono" "/bin")" + echo "nixMonoBin='$nixMonoBin'" + $nixMonoBin/mono --version +} + diff --git a/pkgs/misc/vscode-extensions/cpptools/package-activation-events-0-16-1.json b/pkgs/misc/vscode-extensions/cpptools/package-activation-events-0-16-1.json new file mode 100644 index 000000000000..3a12a8bc0474 --- /dev/null +++ b/pkgs/misc/vscode-extensions/cpptools/package-activation-events-0-16-1.json @@ -0,0 +1,22 @@ +[ +"onLanguage:cpp", +"onLanguage:c", +"onCommand:extension.pickNativeProcess", +"onCommand:extension.pickRemoteNativeProcess", +"onCommand:C_Cpp.ConfigurationEdit", +"onCommand:C_Cpp.ConfigurationSelect", +"onCommand:C_Cpp.SwitchHeaderSource", +"onCommand:C_Cpp.Navigate", +"onCommand:C_Cpp.GoToDeclaration", +"onCommand:C_Cpp.PeekDeclaration", +"onCommand:C_Cpp.ToggleErrorSquiggles", +"onCommand:C_Cpp.ToggleIncludeFallback", +"onCommand:C_Cpp.ToggleDimInactiveRegions", +"onCommand:C_Cpp.ShowReleaseNotes", +"onCommand:C_Cpp.ResetDatabase", +"onCommand:C_Cpp.PauseParsing", +"onCommand:C_Cpp.ResumeParsing", +"onCommand:C_Cpp.ShowParsingCommands", +"onCommand:C_Cpp.TakeSurvey", +"onDebug" +] \ No newline at end of file diff --git a/pkgs/misc/vscode-extensions/cpptools/update_helper.sh b/pkgs/misc/vscode-extensions/cpptools/update_helper.sh new file mode 100755 index 000000000000..00ef77553242 --- /dev/null +++ b/pkgs/misc/vscode-extensions/cpptools/update_helper.sh @@ -0,0 +1,168 @@ +#!/usr/bin/env nix-shell +#! nix-shell -p coreutils -p jq -p unzip -i bash +set -euo pipefail + +# +# A little script to help maintaining this package. It will: +# +# - download the specified version of the extension to the store and print its url, packed store path and hash +# - unpack the extension, bring it to the store and print its store path and hash +# - fetch its runtimes dependencies from the 'package.json' file using the 'jq' utility, unpack those to the store +# and print its url store path and hash +# - patch elf of the binaries that got a nix replacement +# - bring the patched version to the store +# - run their '--version' and call 'ldd' +# - print the version of the runtime deps nix replacements. +# +# TODO: Print to a properly formated nix file all the required information to fetch everything (extension + runtime deps). +# TODO: Print x86 and maybe darwin runtime dependencies. +# + +scriptDir=$(cd "`dirname "$0"`"; pwd) +echo "scriptDir='$scriptDir'" + +extPublisher="vscode" +extName="cpptools" +defaultExtVersion="0.16.1" +extVersion="${1:-$defaultExtVersion}" + +echo +echo "------------- Downloading extension ---------------" + +extZipStoreName="${extPublisher}-${extName}.zip" +extUrl="https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/cpptools/${extVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" +echo "extUrl='$extUrl'" +storePathWithSha=$(nix-prefetch-url --name "$extZipStoreName" --print-path "$extUrl" 2> /dev/null) + +cpptoolsZipStorePath="$(echo "$storePathWithSha" | tail -n1)" +cpptoolsZipSha256="$(echo "$storePathWithSha" | head -n1)" +echo "cpptoolsZipStorePath='$cpptoolsZipStorePath'" +echo "cpptoolsZipSha256='$cpptoolsZipSha256'" + + +extStoreName="${extPublisher}-${extName}" + + +function rm_tmpdir() { + #echo "Removing \`tmpDir='$tmpDir'\`" + rm -rf -- "$tmpDir" + unset tmpDir + trap - INT TERM HUP EXIT +} +function make_trapped_tmpdir() { + tmpDir=$(mktemp -d) + trap rm_tmpdir INT TERM HUP EXIT +} + +echo +echo "------------- Unpacked extension ---------------" + +make_trapped_tmpdir +unzip -q -d "$tmpDir" "$cpptoolsZipStorePath" + +cpptoolsStorePath="$(nix add-to-store -n "$extStoreName" "$tmpDir")" +cpptoolsSha256="$(nix hash-path --base32 --type sha512 "$cpptoolsStorePath")" +echo "cpptoolsStorePath='$cpptoolsStorePath'" +echo "cpptoolsSha256='$cpptoolsSha256'" + +rm_tmpdir + +storePathWithSha=$(nix-prefetch-url --print-path "file://${cpptoolsStorePath}/extension/package.json" 2> /dev/null) + +extPackageJSONStorePath="$(echo "$storePathWithSha" | tail -n1)" +extPackageJSONSha256="$(echo "$storePathWithSha" | head -n1)" +echo "extPackageJSONStorePath='$extPackageJSONStorePath'" +echo "extPackageJSONSha256='$extPackageJSONSha256'" + +print_runtime_dep() { + + local outName="$1" + local extPackageJSONStorePath="$2" + local depDesc="$3" + + local urlRaw=$(cat "$extPackageJSONStorePath" | jq -r --arg desc "$depDesc" '.runtimeDependencies[] | select(.description == $desc) | .url') + local url=$(echo $urlRaw | xargs curl -Ls -o /dev/null -w %{url_effective}) + + local urlRawVarStr="${outName}_urlRaw='$urlRaw'" + local urlVarStr="${outName}_url='$url'" + echo "$urlRawVarStr" + echo "$urlVarStr" + + local storePathWithSha="$(nix-prefetch-url --unpack --print-path "$url" 2> /dev/null)" + + local storePath="$(echo "$storePathWithSha" | tail -n1)" + local sha256="$(echo "$storePathWithSha" | head -n1)" + + local sha256VarStr="${outName}_sha256='$sha256'" + local storePathVarStr="${outName}_storePath='$storePath'" + echo "$sha256VarStr" + echo "$storePathVarStr" + + eval "$urlRawVarStr" + eval "$urlVarStr" + eval "$sha256VarStr" + eval "$storePathVarStr" +} + +echo +echo "------------- Runtime dependencies ---------------" + +print_runtime_dep "langComponentBinaries" "$extPackageJSONStorePath" "C/C++ language components (Linux / x86_64)" +print_runtime_dep "monoRuntimeBinaries" "$extPackageJSONStorePath" "Mono Runtime (Linux / x86_64)" +print_runtime_dep "clanFormatBinaries" "$extPackageJSONStorePath" "ClangFormat (Linux / x86_64)" + + +echo +echo "------------- Runtime deps missing elf deps ---------------" + +source "$scriptDir/missing_elf_deps.sh" + +echo +echo "------------- Runtime dep mono ---------------" + +make_trapped_tmpdir +find "$monoRuntimeBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir" +chmod -R a+rwx "$tmpDir" + +ls -la "$tmpDir/debugAdapters" + +patchelf_mono "$tmpDir/debugAdapters/mono.linux-x86_64" + +chmod a+x "$tmpDir/debugAdapters/mono.linux-x86_64" +ldd "$tmpDir/debugAdapters/mono.linux-x86_64" +"$tmpDir/debugAdapters/mono.linux-x86_64" --version + +monoRuntimeBinariesPatched_storePath="$(nix add-to-store -n "monoRuntimeBinariesPatched" "$tmpDir")" +echo "monoRuntimeBinariesPatched_storePath='$monoRuntimeBinariesPatched_storePath'" + +rm_tmpdir + + +echo +echo "------------- Runtime dep clang ---------------" +make_trapped_tmpdir +find "$clanFormatBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir" +chmod -R a+rwx "$tmpDir" + +ls -la "$tmpDir/bin" + +patchelf_clangformat "$tmpDir/bin/clang-format" + +chmod a+x "$tmpDir/bin/clang-format" +ldd "$tmpDir/bin/clang-format" +"$tmpDir/bin/clang-format" --version + + +clanFormatBinariesPatched_storePath="$(nix add-to-store -n "clanFormatBinariesPatched" "$tmpDir")" +echo "clanFormatBinariesPatched_storePath='$clanFormatBinariesPatched_storePath'" + +rm_tmpdir + +echo +echo "------------- Nix mono ---------------" +print_nix_version_clangtools + +echo +echo "------------- Nix mono ---------------" +print_nix_version_mono + diff --git a/pkgs/misc/vscode-extensions/cpptools/vscode-cpptools-0-12-3-package-json.patch b/pkgs/misc/vscode-extensions/cpptools/vscode-cpptools-0-12-3-package-json.patch deleted file mode 100644 index 1873963f460d..000000000000 --- a/pkgs/misc/vscode-extensions/cpptools/vscode-cpptools-0-12-3-package-json.patch +++ /dev/null @@ -1,82 +0,0 @@ -diff --git a/package.json b/package.json -index 518e839..1c17c35 100644 ---- a/package.json -+++ b/package.json -@@ -37,7 +37,26 @@ - "Linters" - ], - "activationEvents": [ -- "*" -+ "onLanguage:cpp", -+ "onLanguage:c", -+ "onCommand:extension.pickNativeProcess", -+ "onCommand:extension.pickRemoteNativeProcess", -+ "onCommand:extension.provideInitialConfigurations_cppvsdbg", -+ "onCommand:extension.provideInitialConfigurations_cppdbg", -+ "onCommand:C_Cpp.ConfigurationEdit", -+ "onCommand:C_Cpp.ConfigurationSelect", -+ "onCommand:C_Cpp.SwitchHeaderSource", -+ "onCommand:C_Cpp.UnloadLanguageServer", -+ "onCommand:C_Cpp.Navigate", -+ "onCommand:C_Cpp.GoToDeclaration", -+ "onCommand:C_Cpp.PeekDeclaration", -+ "onCommand:C_Cpp.ToggleErrorSquiggles", -+ "onCommand:C_Cpp.ToggleIncludeFallback", -+ "onCommand:C_Cpp.ShowReleaseNotes", -+ "onCommand:C_Cpp.ResetDatabase", -+ "workspaceContains:.vscode/c_cpp_properties.json", -+ "onDebug:cppdbg", -+ "onDebug:cppvsdbg" - ], - "main": "./out/src/main", - "contributes": { -@@ -281,8 +300,7 @@ - "cpp" - ] - }, -- "runtime": "node", -- "program": "./out/src/Debugger/Proxy/debugProxy.js", -+ "program": "./debugAdapters/OpenDebugAD7", - "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", - "variables": { - "pickProcess": "extension.pickNativeProcess", -@@ -722,7 +740,29 @@ - } - } - } -- } -+ }, -+ "configurationSnippets": [ -+ { -+ "label": "C/C++: (gdb) Launch", -+ "description": "Launch with gdb.", -+ "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}" -+ }, -+ { -+ "label": "C/C++: (gdb) Attach", -+ "description": "Attach with gdb.", -+ "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}" -+ }, -+ { -+ "label": "C/C++: (gdb) Pipe Launch", -+ "description": "Pipe Launch with gdb.", -+ "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}" -+ }, -+ { -+ "label": "C/C++: (gdb) Pipe Attach", -+ "description": "Pipe Attach with gdb.", -+ "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}" -+ } -+ ] - }, - { - "type": "cppvsdbg", -@@ -741,7 +781,7 @@ - "variables": { - "pickProcess": "extension.pickNativeProcess" - }, -- "initialConfigurations": "extension.provideInitialConfigurations_cppvsdbg", -+ "initialConfigurations": "", - "configurationAttributes": { - "launch": { - "required": [