Subject: Re: bug#58318: 28.2; Emacs installed from package won't work with MinGW

From: Corwin Brust <[email-masked]>
Date: Thu, 6 Oct 2022 08:09:16 -0500

On Thu, Oct 6, 2022 at 12:44 AM Eli Zaretskii <[email-masked]> wrote:
>
> > From: Bartosz Bubak <[email-masked]>
> > Date: Wed, 5 Oct 2022 18:01:00 +0200
> >
> > When installing Emacs using the installer (emacs-28.2-installer.exe),
> > by default it adds the compiler and libraries (gcc and libgccjit)
> > to the ./bin directory without prompting the user for his opinion.

I'm confused.  With one exception, I do not think that we provide GCC
with Emacs binaries for windows.

We *do* provide libgcc_s_seh-1.dll but we do not provide, e.g.
gcc.exe, as.exe, etc.

> >
> > The problem appears when another compiler is already installed in the
> > system, eg. from MinGW. Emacs then tries to use the libraries from PATH
> > instead of those installed in its subdirectories:
> >
> > Warning (comp): c: /tools/emacs/share/emacs/28.2/lisp/org/org-entities.el:
> > Error: Internal native compiler error failed to compile
> > Warning (comp): C: \\ ProgramData \\ chocolatey \\ lib \\ mingw \\ tools \\
> > install \\ mingw64 \\ bin \\ libgccjit-0.dll: error: error invoking gcc
> > driver

It does make sense to me that having two different versions of GCC
both findable on the Windows path could be problematic (although I
don't see how the Emacs installer could be responsible for installing
any of them).

> >
> > When I tried to find a solution to the problem, I found something like
> > this:
> >
> > M-: (executable-find "gcc") RET
> > "c:/ProgramData/chocolatey/bin/gcc.exe
> > M-: (executable-find "as") RET
> > "c:/ProgramData/chocolatey/bin/as.exe"
> > etc, etc
> >
> > But  should be:
> > C:\Program Files\Emacs\emacs-28.2\bin\gcc.exe
> > C:\Program Files\Emacs\emacs-28.2\bin\as.exe

That's very odd -- looking at the "install" folder created when I
built and packaged the emacs-28 binaries I can't find either of those
files:

  corwi@Avalon MINGW64 /d/emacs-build/install/emacs-28.2
  $ (cd /d/emacs-build/install/emacs-28.2; ls -Rl | grep 'as.exe')

  corwi@Avalon MINGW64 /d/emacs-build/install/emacs-28.2
  $ (cd /d/emacs-build/install/emacs-28.2; ls -Rl | grep 'gcc')
  -rwxr-xr-x 1 corwi corwi   84147 Feb 20  2022 libgcc_s_seh-1.dll
  -rw-r--r-- 1 corwi corwi  10282 Sep  6 16:31 gcc.el
  -rw-r--r-- 1 corwi corwi   4680 Sep  6 18:05 gcc.elc

> >
> > The only solution I have found so far is to uninstall the "global"
> > MinGW, then emacs uses the embedded libraries and everything is fine.
> >
> > In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
> >  of 2022-09-13 built on AVALON
> > Windowing system distributor 'Microsoft Corp.', version 10.0.22000
> > System Description: Microsoft Windows 10 Pro (v10.0.2009.22000.978)
> >
> > Configured using:
> >  'configure --with-modules --without-dbus --with-native-compilation
> >  --without-compress-install CFLAGS=-O2'
> >
> > Configured features:
> > ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
> > NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
> > XPM ZLIB
> >
> > (NATIVE_COMP present but libgccjit not available)

It looks from this that Emacs doesn't find (a complete) GCC kit for
use with GCC, so your Emacs should be loading ELN files shipped with
the release but not trying to compile any new ones, I think?

Unfortunately, that just makes the "Error: Internal native compiler
error failed to compile" even more of a mystery:

Eli,
If, per the configuration reported when generating this bug report,
Emacs can see libgccjit is not available, then should Emacs still be
trying to native compile org-entitles in this case?

> >
> > Important settings:
> >   value of $LANG: PLK
> >   locale-coding-system: cp1250
>
> Corwin, are you reading this?

Yes, I am now.  Thank you.

>
> I admit I don't have a clear idea of why the problem happens.  Is the
> libgccjit and/or GCC and/or Binutils distributed by chocolatey somehow
> incompatible with the ones you include in the installer?  Because if
> they are compatible, just removing the GCC/Binutils stuff bundled with
> the Emacs installer should have solved the issue (and then providing
> an option in the installer not to install the bundled GCC would be a
> way towards solving this).  And yet the OP seems to say (AFAIU) that
> this didn't help, and only uninstalling the chocolatey GCC/Binutils
> did.  We cannot possibly ask users to uninstall their existing
> development environment when installing Emacs.

I'm not aware of any incompatibilities but I'm not a chocolatey user.
I'll need to do some experimentation.

I'd be happy to add/adjust installer options.  Would we (probably most
simply?) add an option where we can "uncheck" installing all of the
deps?  If not, what else would the new option suppress installing
(beside libgcc_s_seh-1.dll)?

>
> I think someone should try installing the chocolatey distribution and
> see whether the binaries from the GNU FTP site can work with its
> libgccjit.  Because I'm not sure I understand what happens in this
> case, even though I asked several times.  If indeed there's
> incompatibility, I'd be interested to know why (I have no idea how
> chocolatey builds its GCC).  If that is not solvable, we should
> probably say that people with chocolatey installation should not
> install Emacs binaries with native-compilation enabled.

I'll get the machine I'm using to test release binaries going on this
today after work and report back with any success I have
reproducing/researching. Others' findings would be most welcome if
anyone else is experimenting with this too.