Subject: Re: bug#75812: 29.2.50; Support native-compiling package-install from batch Emacs

From: Eli Zaretskii <[email-masked]>
Date: Fri, 25 Apr 2025 10:12:27 +0300

> From: Spencer Baugh <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked],
>    [email-masked],  [email-masked]
> Date: Thu, 24 Apr 2025 17:25:47 -0400
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > I don't understand why you need all that complexity.  Why not loop
> > calling comp--async-runnings as long as it returns non-nil, each time
> > sleeping for, say, 0.5 sec?
> 
> Sleeping for 0.5 sec means that building a package will take an extra
> .25 seconds on average, which adds up over hundreds of packages.
> Sleeping for 0.0001 sec wastes CPU, which also adds up over hundreds of
> packages.

So make it 0.02 sec instead.  0.5 sec was just an example; no need to
take a suggestion "ad absurdum", you know.

> > Or why not install a native-comp-async-all-done-hook that will notice
> > when compilations are done and allow the batch job to exit?  All you
> > need is a means to wait until all the async compilations are finished,
> > no?
> 
> How do you propose to do that?  I guess I could call kill-emacs from the
> hook, but I have more code I want to run after the native compilation is
> finished, and I can't move it all into the hook.

Then don't call kill-emacs from the hook; instead, use 'throw', or run
the rest of the code from the hook directly.

> >> There's another related issue for the packaging use case I mentioned in
> >> my original email: The .eln files are placed in ~/.emacs.d/eln-cache/ by
> >> default when doing this native compilation.  That complicates building
> >> and installing these packages independently.  Is there a way to put the
> >> .eln files for a package in that individual package directory instead?
> >
> > You need to tweak native-comp-eln-load-path, e.g. prepend to the
> > default-value list the directory where you want the *.eln files to be
> > written.  But you are well advised to leave the other directories in
> > the list alone.
> 
> Makes sense.
> 
> Does that mean that, if I want the .eln files to be loaded from the
> individual package directory, I have to put every single package
> directory on native-comp-eln-load-path at runtime?  That seems annoying,
> and probably slow.

I'm confused.  It was you who asked how to avoid placing the *.eln
files in ~/.emacs.d/eln-cache/, but now you say it causes problems?
"If it hurts, don't do that."  I don't understand why the default
location is problematic in the first place, and you haven't provided
any reasons.

And why are you talking about a separate directory for each package?
One could envision using a single directory for the *.eln files of all
the packages, for example.  Whether that is reasonable again depends
on your goals and specific cases, which you haven't described.

> Is there a way to get an .eln file to be loaded from the directory the
> .elc file was found in?

No, and it doesn't make sense to do that, because the *.eln files are
not in the directories mentioned in native-comp-eln-load-path, they
are in versioned subdirectories of those directories, and those
subdirectories must be verified by computing the hashes of the
corresponding *.el files, to make sure we are not by chance loading
incompatible machine code.