Skip to content

Commit

Permalink
build scripts and github actions work
Browse files Browse the repository at this point in the history
  • Loading branch information
railwaycat committed Aug 8, 2023
1 parent 7d6ceeb commit af9a270
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 35 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/emacs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: set env variables
run: |
echo "EMACS_VER=29.1" >> $GITHUB_ENV
echo "MACPORT_VER=29.1-mac-10.0" >> $GITHUB_ENV
echo "COMMIT_HASH=65c6c96f27afa446df6f9d8eff63f9cc012cc738" >> $GITHUB_ENV
echo "OUTPUT_DIR=build_out" >> $GITHUB_ENV
- name: get current time
run: echo "REL_DATE=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
- name: get OS version
run: echo "OS_VER=$(sw_vers -productVersion)" >> $GITHUB_ENV

- name: prepare
run: ./build-scripts/prepare_homebrew.sh
run: pushd build-scripts; ./prepare_homebrew.sh; popd

- name: build and pack
run: |
pushd build-scripts
./fetch-emacs-mac-port.sh "28.2-mac-9.1"
./build-emacs.sh emacs-source "28.2"
pushd emacs-source; ../copylib.rb $(brew --prefix); popd
./make-zipball.sh emacs-source/tmproot "28.2-mac-9.1"
ls -d $PWD/emacs-source/tmproot/*.zip
./fetch-emacs-mac-port.sh "${{ env.MACPORT_VER }}" "${{ env.COMMIT_HASH }}" "${{ env.OUTPUT_DIR }}"
./build-emacs.sh "${{ env.OUTPUT_DIR }}" "${{ env.EMACS_VER }}"
./install_libs.sh $(pwd) "${{ env.OUTPUT_DIR }}"
./make-zipball.sh "${{ env.OUTPUT_DIR }}/tmproot" "${{ env.MACPORT_VER }}"
ls -d ${{ env.OUTPUT_DIR }}/tmproot/*.zip
popd
- name: publish
Expand All @@ -34,7 +40,7 @@ jobs:
name: ${{ matrix.os }}-${{ env.REL_DATE }}
draft: true
files: |
build-scripts/emacs-source/tmproot/emacs-28.2-mac-9.1-${{ env.OS_VER }}.zip
build-scripts/emacs-source/tmproot/emacs-28.2-mac-9.1-${{ env.OS_VER }}-spacemacs-icon.zip
build-scripts/${{ env.OUTPUT_DIR }}/tmproot/emacs-${{ env.MACPORT_VER }}-${{ env.OS_VER }}.zip
build-scripts/${{ env.OUTPUT_DIR }}/tmproot/emacs-${{ env.MACPORT_VER }}-${{ env.OS_VER }}-spacemacs-icon.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions build-scripts/Brewfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tap "homebrew/bundle"
tap "homebrew/core"
brew "autoconf"
brew "automake"
brew "gnutls"
# brew "gnutls"
brew "pkg-config"
brew "texinfo"
brew "jansson"
brew "libxml2"
brew "libyaml"
brew "tree-sitter"
25 changes: 18 additions & 7 deletions build-scripts/build-emacs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ source_dir=$1
installprefix=`pwd`/$source_dir/tmproot
emacs_version=$2

# texinfo usually a keg-only package
export PATH="/opt/homebrew/opt/texinfo/bin:/usr/local/opt/texinfo/bin:$PATH"

# only use when on a separated homebrew
# BREW_DIR="$HOME/homebrew"
# eval "$($BREW_DIR/bin/brew shellenv)"

set -e
cd $source_dir
./autogen.sh
./configure --with-mac \
--enable-locallisppath=/usr/local/share/emacs/site-lisp:/opt/homebrew/share/emacs/site-lisp \
--enable-mac-app=$installprefix \
--prefix=$installprefix \
--enable-mac-self-contained \
--with-modules \
--with-xwidgets
# use `--without-xx` here to prevent pollution from CI image
# preinstalled libs.
./configure \
--with-mac \
--enable-locallisppath=/usr/local/share/emacs/site-lisp:/opt/homebrew/share/emacs/site-lisp \
--enable-mac-app=$installprefix \
--prefix=$installprefix \
--enable-mac-self-contained \
--with-modules \
--with-xwidgets \
--with-tree-sitter \
--without-lcms2 \
--without-webp
make
make install
set +e
20 changes: 20 additions & 0 deletions build-scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

EMACS_VER="29.1"
MACPORT_VER="$EMACS_VER-mac-10.0"
COMMIT_HASH="65c6c96f27afa446df6f9d8eff63f9cc012cc738"
OUTPUT_DIR="build_out"

./prepare_homebrew.sh

./fetch-emacs-mac-port.sh "$MACPORT_VER" "$COMMIT_HASH" "$OUTPUT_DIR"

./build-emacs.sh "$OUTPUT_DIR" "$EMACS_VER"

./install_libs.sh $(pwd) "$OUTPUT_DIR"

./make-zipball.sh "$OUTPUT_DIR/tmproot" "$MACPORT_VER"

ls -d $OUTPUT_DIR/tmproot/*.zip
4 changes: 2 additions & 2 deletions build-scripts/copylib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Vsh.verbose = true

def copy_lib(exe, brew_dir, dest, options={})
options[:rel_path_to_dest] ||= "@executable_path/" + Pathname.new(dest).relative_path_from(Pathname.new(exe).dirname).to_s
options[:rel_path_to_dest] ||= "@executable_path/" + Pathname.new(dest).relative_path_from(Pathname.new(exe).dirname).to_s
`otool -L #{exe}`.split("\n").each do |line| # ex: /Volumes/sensitive/src/build-emacs/brew/opt/gnutls/lib/libgnutls.30.dylib (compatibility version 37.0.0, current version 37.6.0)
(m,orig,brew_path,lib)=line.match(%r,^\s+(#{brew_dir}(/[^ ]+)/(lib[^/ ]+))\s,).to_a
if m
Expand All @@ -32,7 +32,7 @@ def copy_lib(exe, brew_dir, dest, options={})
Vsh.system(*%W"install_name_tool -change #{orig} #{options[:rel_path_to_dest]}/#{lib} #{exe}") # Point the libs to the newly embedded lib directory
end
}
unless lib == File.basename(exe) || File.exists?(File.join(dest, lib))
unless lib == File.basename(exe) || File.exist?(File.join(dest, lib))
Vsh.mkdir_p(dest)
Vsh.cp(File.join(brew_dir, brew_path, lib), dest)
copy_lib(File.join(dest, lib), brew_dir, dest, options) # Copy lib's deps, too
Expand Down
18 changes: 11 additions & 7 deletions build-scripts/fetch-emacs-mac-port.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

set -e

MACPORT_VAR="$1"
COMMIT_HASH="$2"
OUTPUT_DIR="$3"

echo "fetch tarball"
if [ "$1" = "head" ]; then
git clone --depth=1 --branch=work https://bitbucket.org/mituharu/emacs-mac.git emacs-source
git clone --depth=1 --branch=work https://bitbucket.org/mituharu/emacs-mac.git "$OUTPUT_DIR"
else
curl -O -L https://bitbucket.org/mituharu/emacs-mac/get/emacs-$1.tar.gz
mkdir emacs-source
tar xf emacs-$1.tar.gz -C ./emacs-source --strip-components=1
curl -L "https://bitbucket.org/mituharu/emacs-mac/get/$COMMIT_HASH.tar.gz" -o "emacs-$MACPORT_VAR.tar.gz"
mkdir "$OUTPUT_DIR"
tar xf "emacs-$MACPORT_VAR.tar.gz" -C "./$OUTPUT_DIR" --strip-components=1
fi

echo "apply patch: --with-natural-title-bar"
patch -d emacs-source -p1 < ../patches/emacs-mac-title-bar-9.0.patch
patch -d "$OUTPUT_DIR" -p1 < ../patches/emacs-mac-title-bar-9.1.patch

echo "apply patch: multi-tty-27"
patch -d emacs-source -p1 < ../patches/multi-tty-27.diff
patch -d "$OUTPUT_DIR" -p1 < ../patches/emacs-mac-29-multi-tty.diff

echo "apply patch: bundle structure signature hack"
# this is a hack to let pdump be installed under Contents/MacOS and libexec
# under Contents/MacOS/libexec. To avoid an error on bundle structure when
# signing.
patch -d emacs-source -p1 < ../patches/bundle-signature-hack-9.0.diff
patch -d "$OUTPUT_DIR" -p1 < ../patches/bundle-signature-hack-9.0.diff
14 changes: 14 additions & 0 deletions build-scripts/install_libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

SCRIPT_DIR=$1
OUTPUT_DIR=$2

# only use when on a separated homebrew
# BREW_DIR="$HOME/homebrew"
# eval "$($BREW_DIR/bin/brew shellenv)"

pushd "$OUTPUT_DIR"
"$SCRIPT_DIR/copylib.rb" $(brew --prefix)
popd
4 changes: 2 additions & 2 deletions build-scripts/make-zipball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

work_dir=$1
emacs_version=$2
version="$emacs_version-$(sw_vers -productVersion)"
version="$emacs_version-$(uname -m)-$(sw_vers -productVersion)"
echo "make tarball for version $version"

# default icon
Expand All @@ -18,4 +18,4 @@ rm $icon_dir
curl -L "https://github.com/nashamri/spacemacs-logo/blob/master/spacemacs.icns?raw=true" -o $icon_dir
ditto -c -k --sequesterRsrc --keepParent Emacs.app "emacs-$version-spacemacs-icon.zip"
shasum -a 256 emacs-*.zip
echo "done with emacs-$version-spacemacs-icon.zip"
echo "done with emacs-$version-spacemacs-icon.zip"
28 changes: 22 additions & 6 deletions build-scripts/prepare_homebrew.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#!/bin/sh

# Use a fresh homebrew under $HOME. May not needed in most of the
# cases
new_homebrew () {
BREW_DIR="$HOME/homebrew"

mkdir "$BREW_DIR" && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C "$BREW_DIR"

eval "$($BREW_DIR/bin/brew shellenv)"
}

# disable all the automation to prevent unexpected time spending
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1

OS_VER=$(sw_vers -productVersion)

brew update
# remove all installed formula and reinstall from Brewfile, prevent waste time
# on upgrade all
set -e

brew update --force --quiet

# brew update remove all installed formula and reinstall from
# Brewfile, prevent waste time on upgrade all
# brew remove --force $(brew list --formula)
brew bundle --file $(pwd)/build-scripts/Brewfile
brew bundle --force cleanup --file ./Brewfile
brew bundle --file ./Brewfile
# build gnutls from source code, to ensure the absolute path for
# linked libs
brew install --build-from-source gnutls

# output the version of gnutls
brew info gnutls
brew list

0 comments on commit af9a270

Please sign in to comment.