Skip to content

Commit

Permalink
feat(deps): add support for Nix package manager
Browse files Browse the repository at this point in the history
This serves as an alternative to Homebrew. It should be much more stable
and cause less headaches over time for automated builds.

There should be no change to the end user experience of using the build
script, as it should still work with and use Homebrew by default.

Additionally, Nix provides older Apple SDKs, allowing us to run against
macOS 11.x SDKs. This allows the resulting Emacs.app builds to be
compatible with macOS 11.x and later versions.

In testing, this seems to be the case on macOS 11.x (x86_64) and macOS
12.x (arm64).
  • Loading branch information
jimeh committed Nov 25, 2024
1 parent 2758cc9 commit 8e61835
Show file tree
Hide file tree
Showing 17 changed files with 827 additions and 184 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.55
version: v1.61
env:
VERBOSE: "true"

Expand All @@ -23,9 +23,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
- name: Check if mods are tidy
run: make check-tidy

Expand All @@ -34,9 +34,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
- name: Run tests
run: make test
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DS_Store
.envrc
Formula/*
Gemfile.lock
bin
builds
sources
Expand Down
9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ linters-settings:
gocyclo:
min-complexity: 20
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
Expand All @@ -23,9 +22,9 @@ linters:
disable-all: true
enable:
- bodyclose
- copyloopvar
- dupl
- errcheck
- exportloopref
- funlen
- gochecknoinits
- goconst
Expand Down Expand Up @@ -72,12 +71,12 @@ issues:
- source: "`yaml:"
linters:
- lll

run:
skip-dirs:
exclude-dirs:
- builds
- sources
- tarballs

run:
timeout: 2m
allow-parallel-runners: true
modules-download-mode: readonly
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ source 'http://rubygems.org/'
gem 'ruby-macho'

group :development do
gem 'byebug'
gem 'rubocop'
gem 'rubocop-daemon'
gem 'solargraph', '~> 0.39.17'
end
40 changes: 40 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
GEM
remote: http://rubygems.org/
specs:
ast (2.4.2)
json (2.8.2)
language_server-protocol (3.17.0.3)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.9.2)
rubocop (1.68.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
parser (>= 3.3.1.0)
ruby-macho (4.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.6.0)

PLATFORMS
arm64-darwin
ruby
x86_64-darwin

DEPENDENCIES
rubocop
ruby-macho

BUNDLED WITH
2.5.23
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ SHELL := env \
bootstrap: bootstrap-brew bootstrap-ruby

bootstrap-ruby:
bundle install
env BUNDLE_WITHOUT=development bundle install

bootstrap-brew:
ifndef IN_NIX_SHELL
brew bundle --verbose
endif

bootstrap-pip:
$(PIP) install -r requirements-ci.txt
Expand All @@ -69,7 +71,7 @@ $(TOOLDIR)/$(1): Makefile
endef

$(eval $(call tool,gofumpt,mvdan.cc/gofumpt@latest))
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55))
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61))
$(eval $(call tool,gomod,github.com/Helcaraxan/gomod@latest))

.PHONY: tools
Expand Down Expand Up @@ -132,6 +134,21 @@ format: $(TOOLDIR)/gofumpt
gen:
go generate $$(go list ./... | grep -v 'sources/' | grep -v 'builds/')

.PHONY: nix-flake-update
nix-flake-update:
nix flake update \
&& $(MAKE) flake-package-versions.txt

.SILENT: flake-package-versions
flake-package-versions:
nix develop --command -- bash -c \
'nix derivation show \
$$(echo $$PATH | tr ":" "\n" | grep "/nix/store" | sort -u) \
| jq -r ".[].name" | sort -u'

flake-package-versions.txt: flake.nix flake.lock
$(MAKE) flake-package-versions > flake-package-versions.txt

#
# Dependencies
#
Expand Down
65 changes: 54 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,40 @@ The build produced does have some limitations:

## Requirements

Required with both Nix and Homebrew approaches:

- [Xcode](https://apps.apple.com/gb/app/xcode/id497799835?mt=12)
- [Homebrew](https://brew.sh/)
- 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
```
- All dependencies can all easily be installed by running:
```
make bootstrap
```

### Nix

The [Nix](https://nixos.org/) package manager is the preferred and most reliable
way to install all dependencies required to build Emacs, by way of a Nix flake
included in the project root.

To install all required dependencies within the nix shell, run:

```
nix develop --command make bootstrap
```

### Homebrew

If you do not have Nix installed, then the alternative way to manage and install
build-time dependencies is via [Homebrew](https://brew.sh/).

Ruby 3.3.x or later is also needed to execute the build script. Earlier versions
may work, but are untested. Simplest way to install a recent Ruby version is via
Homebrew:

```
brew install ruby
```

And finally, to install all built-time dependencies, run:

```
make bootstrap
```

## Status

Expand All @@ -71,15 +93,36 @@ Nightly builds are built with GitHub Actions on GitHub-hosted runners, using

## Usage

### Nix

Ensure [Flakes](https://nixos.wiki/wiki/Flakes) are enabled, and enter the flake
development environment with `nix develop`. Within this environment, you can
execute the `./build-emacs-for-macos --help` to get started.

Or you can run the build script via `nix develop`:

```
nix develop --command ./build-emacs-for-macos --help
```

### Homebrew

Run `make boostrap` to ensure all Ruby and Homebrew dependencies are installed.

### Build Script

```
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:
--info Print environment info and detected library paths, then exit
--preview Print preview details about build and exit.
-j, --parallel COUNT Compile using COUNT parallel processes (detected: 16)
--git-sha SHA Override detected git SHA of specified branch allowing builds of old commits
--[no-]use-nix Use Nix instead of Homebrew to find dependencies (default: enabled if IN_NIX_SHELL is set)
--[no-]xwidgets Enable/disable XWidgets if supported (default: enabled)
--[no-]tree-sitter Enable/disable tree-sitter if supported (default: enabled)
--[no-]native-comp Enable/disable native-comp (default: enabled if supported)
Expand Down
Loading

0 comments on commit 8e61835

Please sign in to comment.