• Stars
    star
    434
  • Rank 100,274 (Top 2 %)
  • Language
    Go
  • Created about 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Somewhat hacky script to automate building of Emac.app on macOS.

build-emacs-for-macos

My personal hacked together script for building a completely self-contained Emacs.app application on macOS, from any git branch, tag, or ref. With support for native-compilation.

Use this script at your own risk.

Why?

  • To use new features available from master or branches, which have not made it into a official stable release yet.
  • Homebrew builds of Emacs are not self-contained applications, making it very difficult when doing HEAD builds and you need to rollback to a earlier version.
  • Both Homebrew HEAD builds, and nightly builds from emacsformacosx.com are built from the master branch. This script allows you to choose any branch, tag, or git ref you want.

Binary Builds

Nightly and stable binary builds produced with this build script are available from jimeh/emacs-builds.

Limitations

The build produced does have some limitations:

  • It is not a universal application. The CPU architecture of the built application will be that of the machine it was built on.
  • The minimum required macOS version of the built application will be the same as that of the machine it was built on.
  • The application is not signed automatically, but the CLI tool used to sign the nightly builds is available. Run go run ./cmd/emacs-builder package --help for details. More detailed instructions will come soon.

Requirements

  • Xcode
  • Homebrew
  • All Homebrew formula listed in the Brewfile, which can all easily be installed by running:
    brew bundle
    
  • Ruby 2.3.0 or later is needed to execute the build script itself. macOS comes with Ruby, check your version with ruby --version. If it's too old, you can install a newer version with:
    brew install ruby
    

Status

As of writing (2021-11-27) it works for me on my machine and for the nightly builds in jimeh/emacs-builds. Your luck may vary.

I have successfully built:

  • emacs-28 release branch
  • master branch (Emacs 29.x)

For reference, my machine is:

  • 13-inch MacBook Pro (2020), 10th-gen 2.3 GHz Quad-Core Intel Core i7 (4c/8t)
  • macOS Monterey 12.0.1 (21A559)
  • Xcode 13.1 (13A1030d)

Nightly builds are built with GitHub Actions on GitHub-hosted runners, using macos-10.15.

Usage

Usage: ./build-emacs-for-macos [options] <branch/tag/sha>

Branch, tag, and SHA are from the emacs-mirror/emacs/emacs Github repo,
available here: https://github.com/emacs-mirror/emacs

Options:
    -j, --parallel COUNT             Compile using COUNT parallel processes (detected: 8)
        --git-sha SHA                Override detected git SHA of specified branch allowing builds of old commits
        --[no-]xwidgets              Enable/disable XWidgets if supported (default: enabled)
        --[no-]native-comp           Enable/disable native-comp (default: enabled if supported)
        --[no-]native-march          Enable/disable -march=native CFLAG(default: disabled)
        --[no-]native-full-aot       Enable/disable NATIVE_FULL_AOT / Ahead of Time compilation (default: disabled)
        --[no-]relink-eln-files      Enable/disable re-linking shared libraries in bundled *.eln files (default: enabled)
        --[no-]rsvg                  Enable/disable SVG image support via librsvg (default: enabled)
        --no-titlebar                Apply no-titlebar patch (default: disabled)
        --posix-spawn                Apply posix-spawn patch (default: disabled)
        --no-frame-refocus           Apply no-frame-refocus patch (default: disabled)
        --[no-]github-auth           Make authenticated GitHub API requests if GITHUB_TOKEN environment variable is set.(default: enabled)
        --work-dir DIR               Specify a working directory where tarballs, sources, and builds will be stored and worked with
    -o, --output DIR                 Output directory for finished builds (default: <work-dir>/builds)
        --build-name NAME            Override generated build name
        --dist-include x,y,z         List of extra files to copy from Emacs source into build folder/archive (default: COPYING)
        --[no-]archive               Enable/disable creating *.tbz archive (default: enabled)
        --[no-]archive-keep-build-dir
                                     Enable/disable keeping source folder for archive (default: disabled)
        --plan FILE                  Follow given plan file, instead of using given git ref/sha

Resulting applications are saved to the builds directory in a bzip2 compressed tarball.

If you don't want the build process to eat all your CPU cores, pass in a -j value of how many CPU cores you want it to use.

Re-building the same Git SHA again can yield weird results unless you first trash the corresponding directory from the sources directory.

Examples

To download a tarball of the master branch (Emacs 28.x with native-compilation as of writing) and build Emacs.app from it:

./build-emacs-for-macos

To build the stable emacs-27.1 release git tag run:

./build-emacs-for-macos emacs-27.1

All sources as downloaded as tarballs from the emacs-mirror GitHub repository. Hence to get a list of tags/branches available to install, simply check said repository.

Use Emacs.app as emacs CLI Tool

Builds come with a custom emacs shell script launcher for use from the command line, located next to emacsclient in Emacs.app/Contents/MacOS/bin.

The custom emacs script makes sure to use the main Emacs.app/Contents/MacOS/Emacs executable from the correct path, ensuring it finds all the relevant dependencies within the Emacs.app bundle, regardless of it it's exposed via PATH or symlinked to from elsewhere.

To use it, simply add Emacs.app/Contents/MacOS/bin to your PATH. For example, if you place Emacs.app in /Applications:

if [ -d "/Applications/Emacs.app/Contents/MacOS/bin" ]; then
  export PATH="/Applications/Emacs.app/Contents/MacOS/bin:$PATH"
  alias emacs="emacs -nw" # Always launch "emacs" in terminal mode.
fi

If you want emacs in your terminal to launch a GUI instance of Emacs, don't use the alias from the above example.

Native-Comp

Note: On 2021-04-25 the feature/native-comp branch was merged into master.

The build script will automatically detect if the source tree being built supports native-compilation, and enable it if available. You can override the auto-detection logic to force enable or force disable native-compilation by passing --native-comp or --no-native-comp respectfully.

By default NATIVE_FULL_AOT is disabled which ensures a fast build by native compiling as few elisp source files as possible to build Emacs itself. Any remaining elisp files will be dynamically compiled in the background the first time they are used.

To enable native full Ahead-of-Time compilation, pass in the --native-full-aot option, which will native-compile all of Emacs' elisp at built-time. On my machine it takes around 10 minutes to build Emacs.app with NATIVE_FULL_AOT disabled, and around 20-25 minutes with it enabled.

Configuration

Native-Lisp Cache Directory

By default natively compiled *.eln files will be cached in ~/.emacs.d/eln-cache/. If you want to customize that, simply set a new path as the first element of the native-comp-eln-load-path variable. The path string must end with a /.

Below is an example which stores all compiled *.eln files in cache/eln-cache within your Emacs configuration directory:

(when (boundp 'native-comp-eln-load-path)
  (setcar native-comp-eln-load-path
          (expand-file-name "cache/eln-cache/" user-emacs-directory)))

Compilation Warnings

By default any warnings encountered during async native compilation will pop up a warnings buffer. As this tends to happen rather frequently with a lot of packages, it can get annoying. You can disable showing these warnings by setting native-comp-async-report-warnings-errors to nil:

(setq native-comp-async-report-warnings-errors nil)

Issues

Please see all issues with the native-comp label. It's a good idea if you read through them so you're familiar with the types of issues and or behavior you can expect.

Known Good Commits/Builds

A list of known "good" commits which produce working builds is tracked in: #6 Known good commits for native-comp

Credits

Internals

The script downloads the source code as a gzipped tar archive from the GitHub mirror repository, as it makes it very easy to get a tarball of any given git reference.

It then runs ./configure with a various options, including copying various dynamic libraries into the application itself. So the built application should in theory run on a macOS install that does not have Homebrew, or does not have the relevant Homebrew formulas installed.

Code quality of the script itself, is well, non-existent. The build script started life a super-quick hack back in 2013, and now it's even more of a dirty hack. I might clean it up and add unit tests if I end up relying on this script for a prolonged period of time. For now I plan to use it at least until native-comp lands in a stable Emacs release for macOS.

License

CC0 1.0 Universal

More Repositories

1

git-aware-prompt

Display current Git branch name in your terminal prompt when in a Git working directory.
Shell
2,139
star
2

tmux-themepack

A pack of various Tmux themes.
Go
1,564
star
3

tmuxifier

Tmuxify your Tmux. Powerful session, window & pane management for Tmux.
Shell
1,018
star
4

emacs-builds

Self-contained Emacs.app builds for macOS, with native-compilation support.
Go
333
star
5

manservant

Browse man pages in style with your personal manservant.
Perl
164
star
6

redistat

A Redis-backed statistics storage and querying library written in Ruby.
Ruby
155
star
7

docker-znc

Run the ZNC IRC Bouncer in a Docker container.
Shell
134
star
8

zsh-peco-history

Search shell history with peco when pressing ctrl+r.
Shell
122
star
9

PastryKit

A little-known and unreleased iPhone web-app Javascript framework developed by Apple.
JavaScript
104
star
10

.emacs.d

My personal Emacs config with any quirks, oddities, bugs, and man-eating errors I live with on a daily basis.
Emacs Lisp
98
star
11

twilight-bright-theme.el

A Emacs port of the TextMate theme by the same name with some minor tweaks and additions.
Emacs Lisp
63
star
12

stub.sh

Helpers for bash script testing to stub/fake binaries and functions. Includes support for validating number of stub calls, and/or if stub has been called with specific arguments.
Shell
53
star
13

php-rack

An implementation of the middleware execution stack from Ruby's Rack library, for PHP.
PHP
52
star
14

common-flow

An attempt to gather a sensible selection of the most common usage patterns of git into a single and concise specification.
41
star
15

dotfiles

My personals dotfiles with any quirks, oddities, bugs, and man-eating errors I live with on a daily basis.
Shell
40
star
16

twilight-anti-bright-theme

A light-on-dark Emacs and TextMate theme inspired by the dark-on-light Twilight Bright TextMate theme.
Emacs Lisp
40
star
17

birds-of-paradise-plus-theme.el

A Emacs port of Joseph Bergantine's light-on-dark theme by the same name.
Emacs Lisp
38
star
18

node-base58

Base58 encoding and decoding for Node.js
JavaScript
33
star
19

rubocopfmt.el

Emacs minor-mode to format Ruby code with RuboCop on save.
Emacs Lisp
16
star
20

go-midjourney

Go
15
star
21

760-grid-system

Use the same principals of the 960 grid system within Facebook's 760 pixel wide frame for Facebook Applications.
Ruby
15
star
22

jimeh.me-v3.0

Jekyll project of a old version my personal website and blog.
CSS
13
star
23

tomorrow-night-paradise-theme.el

A light-on-dark Emacs theme which is essentially a tweaked version of Chris Kempson's Tomorrow Night Bright theme.
Emacs Lisp
11
star
24

litemysql

Very light-weight and simple ORM-like MySQL library for PHP. Kind of like ActiveRecord's little brother.
PHP
11
star
25

amqp-failover

Add multi-server support with failover and fallback to the amqp gem.
Ruby
10
star
26

jimeh.github.io

This is the source-code for my personal website.
SCSS
9
star
27

homebrew-emacs-builds

Ruby
8
star
28

suggest_results

Easily customizable search suggestion plugin for jQuery, which suggests results directly, rather than search terms.
JavaScript
7
star
29

yank-indent

Emacs minor-mode that ensures pasted (yanked) text has the correct indentation level.
Emacs Lisp
7
star
30

collecta_ruby

A light Ruby library / Rails plugin for querying the Collecta API.
Ruby
7
star
31

ansible-adguardhome

Ansible role to install and run AdGuard Home, with support for non-root operation.
Python
7
star
32

mta-sts-on-github-pages

Template repository for hosting MTA-STS (.well-known/mta-sts.txt) on GitHub Pages.
6
star
33

go-golden

Yet another Go package for working with *.golden test files, with a focus on simplicity.
Go
6
star
34

airbrake-statsd

Extends the Airbrake gem to also report exceptions to Esty's StatsD statistics aggregator.
Ruby
6
star
35

greek_easter

Never wonder again when easter is in Greece.
Ruby
6
star
36

facebooker_plus

A Ruby on Rails plugin fixing, extending and adding features to Facebooker, possibly beyond the originally intended scope of Facebooker itself.
Ruby
5
star
37

fancy_input

Easily customizable search suggestion plugin for jQuery, which suggests results directly, rather than search terms. (Formally known as suggest_results)
JavaScript
5
star
38

casecmp

Case-insensitive string comparison, as an API. Because Β―\_(ツ)_/Β―
Go
5
star
39

docker-flexget

Simple Docker container for running Flexget
Shell
4
star
40

zynapse

Rails-like MVC framework for PHP5. Currently abandoned and published for educational reasons.
JavaScript
4
star
41

twhois

Whois-like command-line tool and Ruby Gem for Twitter users
Ruby
3
star
42

undent

Go package which removes leading indentation/white-space from strings.
Go
3
star
43

tab-bar-notch

Adjust tab-bar height for MacBook Pro notch
Emacs Lisp
3
star
44

Dockerfiles

Small collection of Docker and Docker Compose files I use to run stuff on my personal laptop
Shell
3
star
45

time_ext

Extends the abilities of Ruby's built-in Time class by building on top of ActiveSupport.
Ruby
3
star
46

standardfmt.el

Emacs minor-mode to format JavaScript with standard / semistandard on save.
Emacs Lisp
3
star
47

960-grid-system-plus

A clone/enhancement of the excellent 960 Grid System by Nathan Smith to fit my personal likes and dislikes.
3
star
48

skyline

Ruby-based interactive shell tools to send terminal commands to instances in Amazon EC2 AutoScaling groups
Ruby
2
star
49

fastmail-rules

Go
2
star
50

kotaku-uk-rss

Small experimental web-scraper to provide a RSS feed of kotaku.co.uk for my own personal use.
Go
2
star
51

skyhook

A customized set of scripts and config files to deploy projects and control services on Amazon EC2.
Ruby
2
star
52

rubocopfmt

DEPRECATED! Easy formatting of Ruby code using rubocop. Analogous to gofmt.
Ruby
2
star
53

terraform-cloudflare-email

Terraform module to configure various email related DNS records on Cloudflare.
HCL
2
star
54

envctl

Go package providing test helper functions to temporarily change and restore environment variables.
Go
1
star
55

git-basics

A basic intro to git
1
star
56

cloudflare-dyndns

Go
1
star
57

chef-btsync

A simple and quickly hacked together chef cookbook for installing and configuring BTSync on Ubuntu for my own personal needs.
Ruby
1
star
58

rands

Go package providing a suite of functions that use crypto/rand to generate cryptographically secure random strings in various formats.
Go
1
star
59

tmux-themepack-previews

This holds nothing interesting. Go check out the Tmux Themepack project instead.
Shell
1
star
60

blank_gem

A blank/empty Ruby gem that does nothing.
Ruby
1
star
61

modern_bubbling

An Adium message style.
JavaScript
1
star
62

seedsafe

An attempt to learn about AES encryption.
Go
1
star
63

heartb.it

Ruby
1
star
64

mje

Go
1
star
65

pylight

Quick hack to create an HTTP API for accessing Pygments, and to start teaching myself Python.
Python
1
star
66

bah.io

Static landing page for bah.io
HTML
1
star
67

jimeh.me-api

Experimental project to rewrite my site and blog to run off of an EventMachine-based API. Cause it's fun ^_^
Ruby
1
star
68

update-tags-action

Easily create/update one or more Git tags in a GitHub repository.
JavaScript
1
star
69

play-store-notifier

Small shitty script I originally used to notify myself via email of when the Nexus 4 came back in stock. Now using it to find out when the Nexus 5 becomes available on the Play Store.
Ruby
1
star
70

rbheap

A tool to help with tracking down memory leaks in Ruby.
Go
1
star
71

ps4-20th-tool

A small tool built for educational purposes that attempts to pick apart Sony's 20 Years Of Character's website to find the secret URL.
Go
1
star