Skip to content

Commit

Permalink
Merge branch 'snapshot' into core22
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Murray <murray.alex@gmail.com>
  • Loading branch information
alexmurray committed May 2, 2023
2 parents c0cb218 + 1b08835 commit c3fbb8e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: build-snap

on:
pull_request:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: snapcore/action-build@v1
14 changes: 14 additions & 0 deletions native-comp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/usr/share/emacs/@@VERSION@@/lisp/emacs-lisp/comp.el b/usr/share/emacs/@@VERSION@@/lisp/emacs-lisp/comp.el
index e97832455b9..b04cfa00c33 100644
--- a/usr/share/emacs/@@VERSION@@/lisp/emacs-lisp/comp.el
+++ b/usr/share/emacs/@@VERSION@@/lisp/emacs-lisp/comp.el
@@ -188,7 +188,8 @@ and above."

(defcustom native-comp-driver-options
(cond ((eq system-type 'darwin) '("-Wl,-w"))
- ((eq system-type 'cygwin) '("-Wl,-dynamicbase")))
+ ((eq system-type 'cygwin) '("-Wl,-dynamicbase"))
+ ((getenv "SNAP") (list (concat "--sysroot=" (file-name-as-directory (getenv "SNAP"))) (concat "-B" (file-name-as-directory (getenv "SNAP")) "usr/lib/gcc/"))))
"Options passed verbatim to the native compiler's back-end driver.
Note that not all options are meaningful; typically only the options
affecting the assembler and linker are likely to be useful.
10 changes: 6 additions & 4 deletions site-lisp/site-start.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"FONTCONFIG_FILE"))
(setenv env))

;; ensure the correct native-comp-driver-options are set - use
;; /snap/emacs/current if $SNAP is not set for some reason - we also patch
;; keep a proxy to the SNAP env so that our patched comp.el and treesit.el can
;; use it - use /snap/emacs/current if $SNAP is not set for some reason
(setenv "EMACS_SNAP_DIR" (or (getenv "SNAP") "/snap/emacs/current"))

;; ensure the correct native-comp-driver-options are set -- we also patch
;; comp.el in when building the emacs snap but do it here too to try and
;; ensure this is always set no matter what
(when (require 'comp nil t)
(let ((sysroot (file-name-as-directory (or (getenv "SNAP")
"/snap/emacs/current"))))
(let ((sysroot (file-name-as-directory (getenv "EMACS_SNAP_DIR"))))
(dolist (opt (list (concat "--sysroot=" sysroot)
(concat "-B" sysroot "usr/lib/gcc/")))
(add-to-list 'native-comp-driver-options opt t))))
Expand Down
22 changes: 18 additions & 4 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ parts:
plugin: autotools
build-attributes:
- enable-patchelf
source: https://github.com/emacs-mirror/emacs.git
source-type: git
source: git://git.savannah.gnu.org/emacs.git
source-depth: 1
autotools-configure-parameters:
[
Expand All @@ -66,7 +65,9 @@ parts:
"--with-modules",
"--with-cairo",
"--with-native-compilation",
"--with-xinput2"
"--with-xinput2",
"--with-tree-sitter",
"--with-json"
]
organize:
snap/emacs/current/usr: usr
Expand All @@ -78,6 +79,7 @@ parts:
- debhelper
- dpkg-dev
- gcc-12
- g++-12
- libacl1-dev
- libasound2-dev
- libdbus-1-dev
Expand Down Expand Up @@ -113,6 +115,8 @@ parts:
stage-packages:
- bash
- gsettings-desktop-schemas
- gcc-12 # for tree-sitter
- g++-12 # for tree-sitter
- gvfs
- libasound2
- libaspell15
Expand Down Expand Up @@ -144,6 +148,7 @@ parts:
- libfreetype6
- libgbm1
- libgccjit0
- libgccjit-10-dev
- libgcc-s1
- libgdk-pixbuf2.0-0
- libgif7
Expand Down Expand Up @@ -231,12 +236,19 @@ parts:
- -usr/share/emacs/site-lisp
build-environment:
- CC: "gcc-12"
- CXX: "g++-10"
- CFLAGS: "-O2"
- NATIVE_FULL_AOT: "1"
- LD_LIBRARY_PATH: "$SNAPCRAFT_STAGE/usr/lib"
override-pull: |
craftctl default
craftctl set version=$(grep AC_INIT configure.ac | grep -o '[0-9.]\+' | head -n1)-$(git branch --show-current | sed 's|/|-|')-$(git log -n 1 --format=%h)
override-build: |
# ensure we hard-code our copy of gcc-10 and g++10 for tree-sitter
# otherwise it will use the system installed ones which will have a
# different libc version and we will fail to load them
patch -p1 < $SNAPCRAFT_PROJECT_DIR/treesit.patch
craftctl default
override-prime: |
set -eu
craftctl default
Expand All @@ -252,7 +264,9 @@ parts:
# snap
rm -f usr/share/emacs/*/lisp/emacs-lisp/comp.elc
gunzip -f usr/share/emacs/*/lisp/emacs-lisp/comp.el.gz
sed -i -e 's|defcustom native-comp-driver-options nil|defcustom native-comp-driver-options (when (getenv "SNAP") (list (concat "--sysroot=" (file-name-as-directory (getenv "SNAP"))) (concat "-B" (file-name-as-directory (getenv "SNAP")) "usr/lib/gcc/")))|' usr/share/emacs/*/lisp/emacs-lisp/comp.el
# ensure we use the right path in the patch file
VERSION=$(echo usr/share/emacs/*/lisp/emacs-lisp/comp.el | cut -d / -f 4)
sed s/@@VERSION@@/$VERSION/g $SNAPCRAFT_PROJECT_DIR/native-comp.patch | patch -p1
../parts/emacs/build/src/emacs -batch -f batch-byte-compile usr/share/emacs/*/lisp/emacs-lisp/comp.el
gzip usr/share/emacs/*/lisp/emacs-lisp/comp.el
site-lisp:
Expand Down
18 changes: 18 additions & 0 deletions treesit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/lisp/treesit.el b/lisp/treesit.el
index e718ea1a23a..3a313c613ee 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2932,11 +2932,11 @@ function signals an error."
(default-directory (make-temp-file "treesit-workdir" t))
(workdir (expand-file-name "repo"))
(source-dir (expand-file-name (or source-dir "src") workdir))
- (cc (or cc (seq-find #'executable-find '("cc" "gcc" "c99"))
+ (cc (or cc (concat (file-name-as-directory (getenv "EMACS_SNAP_DIR")) "usr/bin/gcc-10")
;; If no C compiler found, just use cc and let
;; `call-process' signal the error.
"cc"))
- (c++ (or c++ (seq-find #'executable-find '("c++" "g++"))
+ (c++ (or c++ (concat (file-name-as-directory (getenv "EMACS_SNAP_DIR")) "usr/bin/g++-10")
"c++"))
(soext (or (car dynamic-library-suffixes)
(signal 'treesit-error '("Emacs cannot figure out the file extension for dynamic libraries for this system, because `dynamic-library-suffixes' is nil"))))

0 comments on commit c3fbb8e

Please sign in to comment.