Skip to content

Commit

Permalink
Merge branch 'github-actions'
Browse files Browse the repository at this point in the history
  • Loading branch information
ubolonton committed Dec 11, 2021
2 parents 8bbbfa4 + 2920738 commit 2d96a5f
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- '27.2'
runs-on: ${{ matrix.os }}
steps:
- uses: purcell/setup-emacs@v3.0
- uses: purcell/setup-emacs@b56a75706e31e22d474357c77fb25ce73be2973a
if: runner.os != 'Windows'
with:
version: ${{ matrix.emacs-version }}
Expand Down
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@ jobs:
# emacs-version: '27.2'
- os: windows-2019
emacs-version: '27.2'
- os: macos-11
emacs-version: '27.2'
# Cross build
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- name: Set up Rust
run: |
rustup install stable
rustc -Vv
cargo -V
- name: Set up Rust's cross-build target
if: matrix.target
run: |
rustup target add ${{ matrix.target }}
- uses: purcell/[email protected]
# Using a specific commit hash to fix this https://github.com/purcell/setup-emacs/issues/24.
- uses: purcell/setup-emacs@b56a75706e31e22d474357c77fb25ce73be2973a
if: runner.os != 'Windows'
with:
version: ${{ matrix.emacs-version }}
Expand All @@ -70,11 +79,13 @@ jobs:
- run: .github/script/setup-cask

- run: bin/setup
- run: bin/build
- run: bin/build -target "${{ matrix.target }}"

- run: bin/inspect-binaries
continue-on-error: true

- name: Install tree-sitter CLI
if: ${{ !matrix.target }}
run: npm install -g [email protected]
- run: bin/test
if: ${{ !matrix.target }}
32 changes: 28 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,36 @@ jobs:
fail-fast: true
matrix:
include:
# TODO: Get host platform from rustc instead of specifying it explicitly.
- os: macos-10.15
emacs-version: '27.2'
ext: dylib
host: x86_64-apple-darwin
- os: macos-11
emacs-version: '27.2'
ext: dylib
target: aarch64-apple-darwin
- os: ubuntu-18.04
emacs-version: '27.2'
ext: so
host: x86_64-unknown-linux-gnu
- os: windows-2019
emacs-version: '27.2'
ext: dll
host: x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- name: Set up Rust
run: |
rustup install stable
rustc -Vv
cargo -V
- name: Set up Rust's cross-build target
if: matrix.target
run: |
rustup target add ${{ matrix.target }}
- uses: purcell/setup-emacs@v3.0
- uses: purcell/setup-emacs@b56a75706e31e22d474357c77fb25ce73be2973a
if: runner.os != 'Windows'
with:
version: ${{ matrix.emacs-version }}
Expand All @@ -56,27 +68,39 @@ jobs:
- run: .github/script/setup-cask

- run: bin/setup
- run: bin/build
- run: bin/build -target "${{ matrix.target }}"

- run: bin/inspect-binaries
continue-on-error: true

- name: Install tree-sitter CLI
if: ${{ !matrix.target }}
run: npm install -g [email protected]
- run: bin/test
if: ${{ !matrix.target }}

- name: Rename cross-build's binary
if: matrix.target
run: |
mv core/tsc-dyn.${{ matrix.ext }} core/tsc-dyn.${{ matrix.target }}.${{ matrix.ext }}
- name: Make a target-explicit copy of native-build's binary
if: ${{ !matrix.target && matrix.host }}
shell: bash
run: |
cp core/tsc-dyn.${{ matrix.ext }} core/tsc-dyn.${{ matrix.host }}.${{ matrix.ext }}
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: tsc-dyn
path: core/tsc-dyn.${{ matrix.ext }}
path: core/tsc-dyn.*${{ matrix.ext }}
if-no-files-found: error

publish:
needs: build
runs-on: ubuntu-18.04
steps:
- uses: purcell/setup-emacs@v3.0
- uses: purcell/setup-emacs@b56a75706e31e22d474357c77fb25ce73be2973a
with:
version: '27.2'
- uses: actions/checkout@v2
Expand Down
79 changes: 67 additions & 12 deletions bin/build
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env bash
#
# bin/build [-profile {release,debug}] [-target aarch64-apple-darwin]
#
# Params:
# - profile: Defaults to release.
# - target: To specify a cross build. Defaults to empty.
#

set -euo pipefail

Expand All @@ -7,25 +14,73 @@ source "$here/env.bash"

core_root="$PROJECT_ROOT/core"

(
cd "$core_root"

target=${1:-release}
case $target in
(release)
cargo build --all --release
# Parse named parameters.
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
(-profile)
profile_="$2"
shift
shift
;;
(debug)
cargo build --all
(-target)
target="$2"
shift
shift
;;
(*)
echo "Unknown target $target"
exit 1
POSITIONAL+=("$1")
shift
;;
esac
done
profile_=${profile_:-release}
target=${target:-''}

# Construct arguments to cargo.
extra_args=()
target_dir=target
case $profile_ in
(release)
extra_args+=(--release)
;;
(debug)
;;
(*)
echo "!! Unknown profile $profile_"
exit 1
esac
case $target in
(aarch64-apple-darwin)
extra_args+=(--target "$target")
target_dir="target/$target"
;;
('')
;;
(*)
echo "!! Unsupport cross-build target $target"
exit 1
;;
esac

echo "!! Building the dynamic module"
(
cd "$core_root"
cargo build --all "${extra_args[@]}"

cp -f target/"$target/$MODULE_ORIGINAL" "$MODULE_RENAMED"
cp -f "$target_dir/$profile_/$MODULE_ORIGINAL" "$MODULE_RENAMED"
version=$(cargo pkgid | cut -d'#' -f2 | cut -d: -f2)
echo "$version".1 | tr -d $'\n' > DYN-VERSION
)

echo "!! Building Lisp code"
if [[ $target != '' ]]; then
echo "!! Will skip building Lisp since this is a cross build"
exit 0
fi
(
cd "$core_root"
cask build
)
(
Expand Down
21 changes: 12 additions & 9 deletions bin/build.ps1
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
param (
[string]$profile = "release"
)

$here = $PSScriptRoot
$project_root = (Get-Item $here).Parent.FullName
$module_name = "tsc_dyn"
$module_renamed = $module_name.replace("_", "-")
$core_root = "$project_root\core"

$target = $args[0]

echo "!! Building the dynamic module"
Push-Location $core_root
try {
if ($target -eq "debug") {
cargo build --all
} else {
$target = "release"
cargo build --all --release
switch ($profile) {
'debug' { cargo build --all }
'release' { cargo build --all --release }
default { throw "Unknown profile $profile" }
}

Copy-Item "target\$target\${module_name}.dll" "${module_renamed}.dll"
Copy-Item "target\$profile\${module_name}.dll" "${module_renamed}.dll"
$version = ((cargo pkgid) | Out-String).Trim().Split('#')[-1].Split(':')[-1]
Set-Content -Path "DYN-VERSION" -Value "${version}.1" -NoNewLine -Force
Set-Content -Path "DYN-VERSION" -Value "${version}" -NoNewLine -Force
cask build
} finally {
Pop-Location
}

echo "!! Building Lisp code"
Push-Location $project_root
try {
cask build
Expand Down
12 changes: 10 additions & 2 deletions bin/inspect-binaries
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ PROJECT_ROOT=$(cd "$here/.."; pwd)

case $system in
(Linux)
echo ┌─────────────────────────────────────────────────────────────────────
echo └ Dynamic module:
file core/tsc-dyn.so
ldd core/tsc-dyn.so
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ┌─────────────────────────────────────────────────────────────────────
echo └ Emacs:
ldd "$(which emacs)"
;;
(Darwin)
echo ┌─────────────────────────────────────────────────────────────────────
echo └ Dynamic module:
file core/tsc-dyn.dylib
otool -L core/tsc-dyn.dylib
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ┌─────────────────────────────────────────────────────────────────────
echo └ Emacs:
otool -L "$(which emacs)"
;;
(*)
Expand Down

0 comments on commit 2d96a5f

Please sign in to comment.