From 1f4555f4437921012653f62b72d240c9f77e0d9e Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia-Ripoll Date: Sun, 27 Dec 2020 19:08:03 +0100 Subject: [PATCH] Enable standalone builds without preexisting MSYS/MIGNW64 environments. --- README.md | 91 ++++++++++++++++------------------------- emacs-build.cmd | 3 ++ scripts/msys2.cmd | 8 ++++ scripts/setup-msys2.ps1 | 42 +++++++++++++++++++ 4 files changed, 89 insertions(+), 55 deletions(-) create mode 100644 emacs-build.cmd create mode 100644 scripts/msys2.cmd create mode 100644 scripts/setup-msys2.ps1 diff --git a/README.md b/README.md index 9bc4ac2..d29accd 100644 --- a/README.md +++ b/README.md @@ -7,40 +7,35 @@ Scripts to build a distribution of Emacs from sources, using MSYS2 and Mingw64(3 I wanted a script to build Emacs from sources, package it and install it on different computers, with the following conditions -- I should be able to build any branch or release from Emacs. This includes - the last release branch (right now emacs-27), as well as the master branch - for development. Always using pristine sources from Savannah. -- I want to build emacs with different options from the default, which is to - use all features available. For instance, I do not care for SVG support. -- The script needs to track all packages that are required by the Emacs build - even if I change the build options. -- The installation should take as little space as possible, removing useless - directories or files that come from the dependencies. For instance, headers - from libraries used by emacs, spurious documentation files, etc. -- The script should be able to build other components I regularly use, such as - mu, mu4e or pdf-tools, in a way that is not affected by updates to the mingw - or msys environments. +- I should be able to build any branch or release from Emacs. This includes the last release branch (right now emacs-27), as well as the master branch for development. Always using pristine sources from Savannah. +- I want to build emacs with different options from the default, which is to use all features available. For instance, I do not care for SVG support. +- The script needs to track all packages that are required by the Emacs build even if I change the build options. +- The installation should take as little space as possible, removing useless directories or files that come from the dependencies. For instance, headers from libraries used by emacs, spurious documentation files, etc. +- The script should be able to build other components I regularly use, such as mu, mu4e or pdf-tools, in a way that is not affected by updates to the mingw or msys environments. ## Usage -### Before running +The script supports two way of being invoked: -1. Install MSYS/Mingw64 as explained [here](https://www.msys2.org/). -2. Open a Mingw64 terminal. -3. Install Git using `pacman -S git`. -4. Upgrade your system if this is not a fresh install. -5. Clone this repository somewhere in your home directory. -6. Enter the repository and use the command line tool as explained below. +- The `emacs-build.cmd` assumes nothing about your system, except for an existing installation of PowerShell. It will download and install a minimal MSYS/MINGW64 environment and build Emacs and all other requested components. This allows for a more deterministic build, without perturbing your computer. +- The `emacs-build.sh` is meant to be ran from an existing MSYS/MINGW64 environment, which will be modified to allow building Emacs and all tools. Use this version at your own risk. -### General instructions +### Steps + +1. Download or clone the script from GitHub +2. Open a Windows terminal and move to the folder for this script +3. Issue whatever commands you need, such as `.\emacs-build.cmd --clone --deps --build --pack-emacs` +4. Inspect the `zips` folder for the products of the script + +### General options ```` Usage: - ./emacs-build.sh [--branch b] - [--clone] [--build] [--deps] [--pack-emacs] [--pack-all] - [--without-X] [--with-X] - [--pdf-tools] [--hunspell] [--mu] [--isync] + ./emacs-build.cmd [--branch b] + [--clone] [--build] [--deps] [--pack-emacs] [--pack-all] + [--without-X] [--with-X] + [--pdf-tools] [--hunspell] [--mu] [--isync] Actions: @@ -79,17 +74,19 @@ Extensions: Assume you invoke this script as follows ```` -./emacs-build.sh --slim --clone --build --pdf-tools --hunspell --mu --isync --pack-all +./emacs-build.cmd --slim --clone --build --pdf-tools --hunspell --mu --isync --pack-all ```` It will take care of the following tasks -1. Clone the latest emacs repository on the branch emacs-27 -2. Ensure that all required packages Mingw64 are installed, or install them. -3. Configure and build Emacs using those packages -4. Pack all the dependencies into a ZIP file. -5. Download and build pdf-tools, hunspell, mu and isync (plus xapian and gmime3). In the process, ensure that the required packages are also installed. -6. Create a ZIP file with Emacs, all the dependencies and all the extensions. +1. Download the latest release of MSYS +2. Download a minimal set of MSYS and MINGW programs needed to build Emacs and the extensions +3. Clone the latest emacs repository on the branch emacs-27 +4. Ensure that all required packages Mingw64 are installed, or install them. +5. Configure and build Emacs using those packages +6. Pack all the dependencies into a ZIP file. +7. Download and build pdf-tools, hunspell, mu and isync (plus xapian and gmime3). In the process, ensure that the required packages are also installed. +8. Create a ZIP file with Emacs, all the dependencies and all the extensions. The script, just like its creator, is a bit opinionated. It performs takes some extra steps to reduce the size of the distribution @@ -101,12 +98,6 @@ The script, just like its creator, is a bit opinionated. It performs takes some ### Considerations -Regarding versions: - -- Upgrade your MSYS/Mingw installation with `pacman -Su` before running this script. -- After every upgrade, it is recommended to do a full clean (`--clean-all`) and - rebuild. Otherwise different packages may be in an inconsistent state. - There are implicit dependencies in the various actions: - `--clone` is required to get the sources @@ -114,26 +105,16 @@ There are implicit dependencies in the various actions: The tool produces zip files that are stored in `./zips` and can be uncompressed wherever you want: -- `emacs-xx-xxxx-deps.zips` is the file with optional libraries (png, jpeg, - etc) used by Emacs. -- `emacs-xx-xxxx-nodeps.zip` is a bare Emacs installation. It runs even if the - 'deps' file is not used -- `emacs-xx-xxxx-full.zip` is a complete Emacs installation, with the optional - libraries and all extensions (pdf-tools, mu, etc) you mentioned in the - command line. -- `pdf-tools-xxxx.zip` and others are the Zip files for the extensions. They - can be unpacked inside an Emacs installation, but may assume that 'deps' have - also been unpacked. +- `emacs-xx-xxxx-deps.zips` is the file with optional libraries (png, jpeg, etc) used by Emacs. +- `emacs-xx-xxxx-nodeps.zip` is a bare Emacs installation. It runs even if the 'deps' file is not used +- `emacs-xx-xxxx-full.zip` is a complete Emacs installation, with the optional libraries and all extensions (pdf-tools, mu, etc) you mentioned in the command line. +- `pdf-tools-xxxx.zip` and others are the Zip files for the extensions. They can be unpacked inside an Emacs installation, but may assume that 'deps' have also been unpacked. Regarding the extensions to Emacs and third-party utilities: - They can be built separately from Emacs. -- If `c:\emacs` is where you unpacked the full installation, some extensions - will reside in `c:\emacs\bin` (e.g. pdftools) and some others in - `c:\emacs\usr\bin` (e.g. mu and mbsync). -- Even though elisp files are provided, it is highly recommended that you - install pdf-tools and mu4e from Melpa or other repositories, to properly take - care of dependencies from other elisp libraries. +- If `c:\emacs` is where you unpacked the full installation, some extensions will reside in `c:\emacs\bin` (e.g. pdftools) and some others in `c:\emacs\usr\bin` (e.g. mu and mbsync). +- Even though elisp files are provided, it is highly recommended that you install pdf-tools and mu4e from Melpa or other repositories, to properly take care of dependencies from other elisp libraries. ## TO-DO @@ -143,4 +124,4 @@ Regarding the extensions to Emacs and third-party utilities: - Setting up an MSYS/MINGW system https://github.com/marketplace/actions/setup-msys2 - MINGW packages recipes https://github.com/msys2/MINGW-packages/blob/master/.github/workflows/main.yml - Uploading artifacts https://github.com/actions/upload-artifact - - https://github.com/actions/create-release + - https://github.com/actions/create-release diff --git a/emacs-build.cmd b/emacs-build.cmd new file mode 100644 index 0000000..b91040d --- /dev/null +++ b/emacs-build.cmd @@ -0,0 +1,3 @@ +@echo off +powershell -c scripts\setup-msys2.ps1 +.\scripts\msys2.cmd -c "./emacs-build.sh %*" diff --git a/scripts/msys2.cmd b/scripts/msys2.cmd new file mode 100644 index 0000000..0ae814b --- /dev/null +++ b/scripts/msys2.cmd @@ -0,0 +1,8 @@ +@echo off +setlocal +set MSYSTEM=MINGW64 +set CHERE_INVOKING=1 +set emacs_build_dir=%~dp0 +set emacs_build_dir=%emacs_build_dir:~0,-9% +set msys2_dir=%emacs_build_dir%\msys64 +%msys2_dir%\usr\bin\bash.exe -leo pipefail %* diff --git a/scripts/setup-msys2.ps1 b/scripts/setup-msys2.ps1 new file mode 100644 index 0000000..a4e3f4c --- /dev/null +++ b/scripts/setup-msys2.ps1 @@ -0,0 +1,42 @@ +# Ensure a minimal MSYS2/MINGW64 environment. We follow the recipes +# from the GitHub Action setup-msys2, found at +# https://github.com/msys2/setup-msys2/blob/master/main.js + +$emacs_build_dir = $PSScriptRoot + '\..' +$msys2_dir = $emacs_build_dir + '\msys64' +$inst_url = 'https://github.com/msys2/msys2-installer/releases/download/2020-11-09/msys2-base-x86_64-20201109.sfx.exe' +$installer_checksum = 'f8a05b9353c42735521f393497dbbd0ce4db1a9de79ee1f6ef224bc9fae144b7' +$installer = ${msys2_dir} + '\msys2-base.exe' + +if ( !(Test-Path ${msys2_dir}) ) { + echo "Creating MSYS2 directory ${msys2_dir}" + mkdir ${msys2_dir} +} +if ( !(Test-Path ${msys2_dir}\msys2_shell.cmd) ) { + if ( !(Test-Path ${installer}) ) { + echo "Downloading MSYS2 installer to ${installer}" + Invoke-WebRequest -Uri $inst_url -OutFile ${installer} + } + $checksum = (Get-FileHash ${installer} -Algorithm SHA256)[0].Hash + if ( $checksum -ne $installer_checksum ) { + echo "Downloaded file $installer has checksum $checksum" + echo "which differs from $installer_checksum" + } + echo "Emacs build root: $emacs_build_dir" + cd "${emacs_build_dir}" + & ${installer} -y + + # Reduce time required to install packages by disabling pacman's disk space checking + .\scripts\msys2.cmd -c 'sed -i "s/^CheckSpace/#CheckSpace/g" /etc/pacman.conf' + # Force update packages + .\scripts\msys2.cmd -c 'pacman --noprogressbar --noconfirm -Syuu --overwrite "\\*"' + # We have changed /etc/pacman.conf above which means on a pacman upgrade + # pacman.conf will be installed as pacman.conf.pacnew + .\scripts\msys2.cmd -c 'mv -f /etc/pacman.conf.pacnew /etc/pacman.conf' + # Kill remaining tasks + taskkill /f /fi 'modules eq msys-2.0.dll' + # Final upgrade + .\scripts\msys2.cmd -c 'pacman --noprogressbar --noconfirm -Syuu --overwrite "\\*"' + # Install packages required by emacs-build + .\scripts\msys2.cmd -c 'pacman --noprogressbar --noconfirm -S git zip base-devel mingw-w64-x86_64-toolchain' +}