Add 'inhibit-native-compilation'
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 3 Oct 2022 13:26:04 +0000 (15:26 +0200)
committerSean Whitton <spwhitton@spwhitton.name>
Mon, 24 Feb 2025 07:37:43 +0000 (15:37 +0800)
The following upstream patch has been backported:

  Add new variable 'inhibit-native-compilation'

  * lisp/startup.el (normal-top-level): Set
  inhibit-native-compilation from environment variable.

  * lisp/emacs-lisp/comp.el (comp-trampoline-compile): Don't write
  trampolines to disk.

  * lisp/progmodes/elisp-mode.el
  (emacs-lisp-native-compile-and-load): Adjust.

  * src/comp.c (syms_of_comp): New variable
  inhibit-native-compilation.
  (maybe_defer_native_compilation): Use it.

Origin: upstream, commit: 5fec9182dbeffa88cef6651d8c798ef9665d6681
Forwarded: not-needed

lisp/emacs-lisp/comp.el
lisp/startup.el
src/comp.c

index e2abd6dbc5ba4922477ce771dbc6559a0809977d..d1182b35cfe1697ce97f1229da2dc32e42aa0b27 100644 (file)
@@ -3357,28 +3357,31 @@ Prepare every function for final compilation and drive the C back-end."
 
 (defun comp--trampoline-abs-filename (subr-name)
   "Return the absolute filename for a trampoline for SUBR-NAME."
-  (cl-loop
-   with dirs = (if (stringp native-comp-enable-subr-trampolines)
-                   (list (expand-file-name native-comp-enable-subr-trampolines
-                                           invocation-directory))
-                 (if native-compile-target-directory
-                     (list (expand-file-name comp-native-version-dir
-                                             native-compile-target-directory))
-                   (comp-eln-load-path-eff)))
-   with rel-filename = (comp-trampoline-filename subr-name)
-   for dir in dirs
-   for abs-filename = (expand-file-name rel-filename dir)
-   unless (file-exists-p dir)
-     do (ignore-errors
-          (make-directory dir t)
-          (cl-return abs-filename))
-   when (file-writable-p abs-filename)
-     do (cl-return abs-filename)
-   ;; Default to some temporary directory if no better option was
-   ;; found.
-   finally (cl-return
-            (make-temp-file (file-name-sans-extension rel-filename) nil ".eln"
-                            nil))))
+  ;; If we've disabled nativecomp, don't write the trampolines to
+  ;; the eln cache (but create them).
+  (and (not inhibit-native-compilation)
+       (cl-loop
+       with dirs = (if (stringp native-comp-enable-subr-trampolines)
+                       (list (expand-file-name native-comp-enable-subr-trampolines
+                                               invocation-directory))
+                      (if native-compile-target-directory
+                         (list (expand-file-name comp-native-version-dir
+                                                 native-compile-target-directory))
+                       (comp-eln-load-path-eff)))
+       with rel-filename = (comp-trampoline-filename subr-name)
+       for dir in dirs
+       for abs-filename = (expand-file-name rel-filename dir)
+       unless (file-exists-p dir)
+       do (ignore-errors
+             (make-directory dir t)
+             (cl-return abs-filename))
+       when (file-writable-p abs-filename)
+       do (cl-return abs-filename)
+       ;; Default to some temporary directory if no better option was
+       ;; found.
+       finally (cl-return
+                (make-temp-file (file-name-sans-extension rel-filename) nil ".eln"
+                                nil)))))
 
 ;; Called from comp-run.el
 ;;;###autoload
index e07e6515991cd4f0f6abfdf98813fdc03d4152ac..e5d6bd87cacba9d3680388b0c3d21a1855bd6028 100644 (file)
@@ -528,7 +528,7 @@ DIRS are relative."
      (t emacs-d-dir))))
 
 (defvar native-comp-eln-load-path)
-(defvar native-comp-jit-compilation)
+(defvar inhibit-native-compilation)
 (defvar native-comp-enable-subr-trampolines)
 
 (defvar startup--original-eln-load-path nil
@@ -589,6 +589,9 @@ It is the default value of the variable `top-level'."
     (funcall 'android-enumerate-fonts)
     (setq android-fonts-enumerated t))
 
+  ;; Allow disabling automatic .elc->.eln processing.
+  (setq inhibit-native-compilation (getenv "EMACS_INHIBIT_NATIVE_COMPILATION"))
+
   (if command-line-processed
       (message internal--top-level-message)
     (setq command-line-processed t)
@@ -607,7 +610,7 @@ It is the default value of the variable `top-level'."
         ;; in this session.  This is necessary if libgccjit is not
         ;; available on MS-Windows, but Emacs was built with
         ;; native-compilation support.
-        (setq native-comp-jit-compilation nil
+        (setq inhibit-native-compilation t
               native-comp-enable-subr-trampolines nil))
 
       ;; Form `native-comp-eln-load-path'.
index e24f1afb9022598d5c6e4749c6712a619d8a1f5e..ffbc2be106bf72b2e37a958cce5b0abd1131426f 100644 (file)
@@ -5201,6 +5201,7 @@ maybe_defer_native_compilation (Lisp_Object function_name,
     return;
 
   if (!native_comp_jit_compilation
+      || !NILP (Vinhibit_native_compilation)
       || noninteractive
       || !NILP (Vpurify_flag)
       || !CLOSUREP (definition)
@@ -5688,6 +5689,12 @@ void
 syms_of_comp (void)
 {
 #ifdef HAVE_NATIVE_COMP
+  DEFVAR_LISP ("inhibit-native-compilation", Vinhibit_native_compilation,
+              doc: /* If non-nil, inhibit automatic native compilation of loaded .elc files.
+
+After compilation, each function definition is updated to the native
+compiled one.  */);
+  Vinhibit_native_compilation = Qnil;
   DEFVAR_BOOL ("native-comp-jit-compilation", native_comp_jit_compilation,
     doc: /* If non-nil, compile loaded .elc files asynchronously.