Skip to content

Commit

Permalink
vscode-extensions.vadimcn.vscode-lldb: fix on Darwin
Browse files Browse the repository at this point in the history
Summary:

  vscode-lldb has been broken on Darwin due to a build-time issue:

    * on Darwin, the vscode-lldb build scripts expect $HOME to exist and be
      writable, NixOS#202507

  and several runtime-issues:

    * codelldb can't find its dynamic libraries (NixOS#160874)

    * lldb-server from nixpkgs doesn't work due to missing the

        "com.apple.security.cs.debugger"

      macOS codesigning entitlement, (NixOS#38624), also with the symptom that
      tccd, the macOS "Transparency, Consent, and Control" daemon, denies
      requests it receives from vscode/codium with log messages like:

	  "AUTHREQ_CTX: msgID=..., function=<private>, service=kTCCServiceDeveloperTool, preflight=yes, query=1,"
          "Service kTCCServiceDeveloperTool does not allow prompting; returning denied."
          "AUTHREQ_RESULT: msgID=..., authValue=0, authReason=5, authVersion=1, error=(null),", etc.

    * lldb-server from nixpkgs may also provide a different CLI interface than
      codelldb expects on macOS.

    * vscode-lldb directs lldb to load rust pretty-printing scripts which need
      to be preserved through the build process in nixpkgs

Solution:

  * The build problem can be fixed by setting HOME="$(pwd)/home", as suggested
    in NixOS#202507.

  * The dynamic libraries issue can be fixed by setting LD_LIBRARY_PATH while
    wrapping codelldb

  * The permissions issue and CLI interface issue can both be fixed by using
    Xcode's debugserver,

      /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver

    on macOS, since it has the required entitlement and the expected interface.

  * Finally, the script-loading issue can be fixed by copying the required
    scripts to the location that vscode-lldb expects to find them in.

Fixes:

  * NixOS#148946: Error failed to get reply to handshake packet on x86_64-darwin
    with vscode-extensions.vadimcn.vscode-lldb

  * NixOS#160874: codelldb inside of vscode-lldb extension doesn't work

  * NixOS#202507: vscode-extensions.vadimcn.vscode-lldb fails to build on aarch64-darwin

(cherry picked from commit fa70e7499b08524a4a02e7ce9e39847b9d3c95df)
  • Loading branch information
mstone authored and qrlex committed Oct 9, 2023
1 parent af89d3a commit 0c110aa
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ let
dontNpmInstall = true;
}));

# debugservers on macOS require the 'com.apple.security.cs.debugger'
# entitlement which nixpkgs' lldb-server does not yet provide; see
# <https://github.com/NixOS/nixpkgs/pull/38624> for details
lldbServer = if stdenv.isDarwin then
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver"
else
"${lldb.out}/bin/lldb-server";

in stdenv.mkDerivation {
pname = "vscode-extension-${publisher}-${pname}";
inherit src version vscodeExtUniqueId vscodeExtPublisher vscodeExtName;
Expand All @@ -64,6 +72,9 @@ in stdenv.mkDerivation {

postConfigure = ''
cp -r ${nodeDeps}/lib/{node_modules,package-lock.json} .
'' + lib.optionalString stdenv.isDarwin ''
mkdir -p "$(pwd)/home"
export HOME="$(pwd)/home"
'';

cmakeFlags = [
Expand All @@ -81,8 +92,10 @@ in stdenv.mkDerivation {
mkdir -p $ext/{adapter,formatters}
mv -t $ext vsix-extracted/extension/*
cp -t $ext/adapter ${adapter}/{bin,lib}/* ../adapter/*.py
cp -r -t $ext/adapter ../adapter/scripts
wrapProgram $ext/adapter/codelldb \
--set-default LLDB_DEBUGSERVER_PATH "${lldb.out}/bin/lldb-server"
--prefix LD_LIBRARY_PATH : "$ext/lldb/lib" \
--set-default LLDB_DEBUGSERVER_PATH "${lldbServer}"
cp -t $ext/formatters ../formatters/*.py
ln -s ${lldb.lib} $ext/lldb
# Mark that all components are installed.
Expand Down

0 comments on commit 0c110aa

Please sign in to comment.