From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.devel Subject: Re: Emacs + bear + compile_commands.json + clangd Date: Tue, 11 Oct 2022 10:37:38 -0700 Message-ID: <87k056w9b1.fsf@rfc20.org> References: <87pmezvw4p.fsf@rfc20.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35010"; mail-complaints-to="usenet@ciao.gmane.io" Cc: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= , emacs-devel To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 11 19:41:40 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiJG8-0008ts-BN for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Oct 2022 19:41:40 +0200 Original-Received: from localhost ([::1]:58216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiJG6-0001BV-P1 for ged-emacs-devel@m.gmane-mx.org; Tue, 11 Oct 2022 13:41:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiJCP-0007RP-Ia for emacs-devel@gnu.org; Tue, 11 Oct 2022 13:37:49 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:36367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiJCM-0005mf-Iv for emacs-devel@gnu.org; Tue, 11 Oct 2022 13:37:49 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id 2D80F1C0007; Tue, 11 Oct 2022 17:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1665509862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FWQ0WjyJL65FAB7GGCj/H+Ly+yqXajyfWkAo6lurH3A=; b=D/tHIrecz06Y04MLG2WpKqDuP4z9qyD2JGm9EBWJxmTPBuwsEsXw+yPv0oqGJzXSypm98/ ZZHqunvxW8YaUOKIOdG/8dGDInIsKLwlbweoh16U2bopWkoTPSO2nT9AlQgRnLs9DR6238 dGqmAQ3hNEj6oToQYmjJ8Hz9/2fjlVzp8JROaPAMy7IRK30Aq6qRuqfFzhbq0Z2rmBkdl+ 8Pu2UqIdNNGQ62MCmkairzhO7s9b8A8h4ojv1ye4CiYaZoy2acT9BCovFOt2rgIhS9EfwU cc5UkPDKT1deIGwFRwm7WcRwaiithHNbTcPIsy2rmdYhJT+bhiCvIdQg89M/3A== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1oiJCE-009Yof-0Z; Tue, 11 Oct 2022 10:37:38 -0700 In-Reply-To: Received-SPF: pass client-ip=217.70.183.197; envelope-from=matt@rfc20.org; helo=relay5-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297512 Archived-At: Gerd M=C3=B6llmann writes: > Matt Armstrong writes: > >> Hey Jo=C3=A3o, I had issues with Emacs source and clangd, especially with >> header files. The issue is that many of Emacs' C header files are not >> "self contained" so they can't be compiled alone. Also, `bear` will >> only generate compile commands for .c files, and clangd uses >> heuristics to guess a compile command for nearby .h files. It does a >> reasonable job in some projects, but not Emacs due to the "self >> contained" issue. Biggest issue: when editing an .h file clangd won't >> include for you. > > I'm wondering how you use clangd. Is this lsp-mode or eglot? I'm using > lsp-mode ATM, just because I tried it first, and it worked for me. I use eglot because I tried it first and it worked for me. ;-) I tried eglot first because I like the general design philosophy of integration with core Emacs packages and a more conservative approach to the UI. You barely know when eglot is running! >> I now do this: >> >> ./configure >> bear --force-wrapper -- make -j$CPUS >> emacs-fixup-compile-commands.py >> >> where emacs-fixup-compile-commands.py is attached. Bonus to anyone >> rewrites it in elisp. ;-) > > I've never had to use --force-wrapper or alter compile_commands.json. Regarding compile_commands.json, if I use the compile_commands.json generated by bear, with eglot, with clangd version "Debian clangd version 14.0.6-2", it works well for .c files but not .h files. E.g. I open src/buffer.h and I get these errors in flymake (this is a small subset): 26 9 error e-f-b clang [unknown_typename]: In included file: unk= nown type name 'INLINE_HEADER_BEGIN' 1 0 error e-f-b clang [fatal_too_many_errors]: Too many errors = emitted, stopping now 283 4 error e-f-b clang [unknown_typename]: Unknown type name 'IN= TERVAL' 722 9 warning e-f-b clang [-Wimplicit-function-declaration]: Implic= it declaration of function 'PSEUDOVECTORP' is invalid in C99 877 5 warning e-f-b clang [-Wimplicit-function-declaration]: Implic= it declaration of function 'NILP' is invalid in C99 1079 26 error e-f-b clang [expr_not_ice]: Expression is not an inte= ger constant expression 1256 7 error e-f-b clang [unknown_typename]: Unknown type name 'IN= TERVAL' 1573 14 warning e-f-b clang [-Wint-conversion]: Incompatible integer = to pointer conversion initializing 'Lisp_Object' (aka 'struct Lisp_X *') wi= th an expression of type 'int' 1573 21 warning e-f-b clang [-Wimplicit-function-declaration]: Implic= it declaration of function 'CHAR_TABLE_REF' is invalid in C99 I always assumed that this was becuase clangd didn't know how to compile src/buffer.h and is unable to figure it out: $ grep -F buffer.h compile_commands.json After I run my emacs-fixup-compile-commands.py I have this in compile_commands.json: { "arguments": [ "/usr/bin/gcc", [...blah blah blah you get the point...] "-Wno-unused-macros", "-Wno-unused-function", "-include", "config.h", "buffer.h" ], "directory": "/home/matt/git/emacs-noverlay/src", "file": "/home/matt/git/emacs-noverlay/src/buffer.h" }, and clangd works fine. Given all this I have no idea how your experience with clangd could different, but I'm not a clangd expert =F0=9F=A4=94. > My current version is bear 3.0.20, on macOS 12.6. What's your system? bear 3.0.20 on Debian/Bullseye (testing) My issue may have been related to building with Address Sanitizer, which I think also (might) play games with LD_PRELOAD. I tried --force-wrapper and it worked for me. ;-) > P.S. > > WRT to seamless, I have to add, for macOS: This was true for me with > Xcode 13, and is no longer with Xcode 14. Both clangd and lldb crash > pretty frequently :-(. Maybe using the clangd from homebrew would work better for you?