Skip to content

Commit db001ca

Browse files
committed
feat: add MacOS/Linux cross-compiling + publishing to topheman/homebrew-tap
Relies on: - https://github.com/topheman/create-release-if-not-exist : github action that creates a release if not exist - allows to upload artefacts to a same release from multiple parallel workflows - https://github.com/topheman/update-homebrew-tap : github action that updates a homebrew tap repo based on the user's template The homebrew taps are published by the github actions above to https://github.com/topheman/homebrew-tap Now you can install the crate without needing to compile it from source with `cargo install`. Use: `brew install topheman/tap/pluginlab` Prebuilt binaries (built at the cross-compile step) for linux/macOS x86_64/macOS arm will be chosen.
1 parent b0c06c3 commit db001ca

File tree

5 files changed

+158
-6
lines changed

5 files changed

+158
-6
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# inspired by https://github.com/topheman/update-homebrew-tap-playground/blob/master/.github/workflows/cross-compile.yml
2+
name: Cross-Compile
3+
4+
on: [push]
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
BINARY_NAME: pluginlab
9+
10+
jobs:
11+
build:
12+
if: github.ref_type == 'tag'
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
17+
- name: Set up MacOS Cross Compiler
18+
uses: Timmmm/setup-osxcross@v2
19+
with:
20+
osx-version: "12.3"
21+
22+
- name: Install Rustup targets
23+
run: rustup target add x86_64-unknown-linux-gnu x86_64-apple-darwin aarch64-apple-darwin
24+
25+
- name: Check out source code
26+
uses: actions/checkout@v3
27+
28+
- name: Check
29+
run: cargo check
30+
31+
- name: Build
32+
run: cargo build -p pluginlab --release --target x86_64-unknown-linux-gnu --target x86_64-apple-darwin --target aarch64-apple-darwin
33+
34+
- name: Generate completions
35+
run: |
36+
mkdir -p ./target/x86_64-unknown-linux-gnu/release/completions/{zsh,bash,fish}
37+
./target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} generate-completions --shell zsh > ./target/x86_64-unknown-linux-gnu/release/completions/zsh/_${{ env.BINARY_NAME }}
38+
./target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} generate-completions --shell bash > ./target/x86_64-unknown-linux-gnu/release/completions/bash/${{ env.BINARY_NAME }}
39+
./target/x86_64-unknown-linux-gnu/release/${{ env.BINARY_NAME }} generate-completions --shell fish > ./target/x86_64-unknown-linux-gnu/release/completions/fish/${{ env.BINARY_NAME }}.fish
40+
41+
- name: Copy completions
42+
run: |
43+
cp -r ./target/x86_64-unknown-linux-gnu/release/completions ./target/x86_64-apple-darwin/release/completions
44+
cp -r ./target/x86_64-unknown-linux-gnu/release/completions ./target/aarch64-apple-darwin/release/completions
45+
46+
- name: Compress
47+
run: |
48+
rm -rf ./tmp
49+
mkdir ./tmp
50+
(cd target/x86_64-unknown-linux-gnu/release && tar -cvf ${{ env.BINARY_NAME }}-x86_64-unknown-linux-gnu.tar.gz ${{ env.BINARY_NAME }} completions && mv ${{ env.BINARY_NAME }}-x86_64-unknown-linux-gnu.tar.gz ../../../tmp)
51+
(cd target/x86_64-apple-darwin/release && tar -cvf ${{ env.BINARY_NAME }}-x86_64-apple-darwin.tar.gz ${{ env.BINARY_NAME }} completions && mv ${{ env.BINARY_NAME }}-x86_64-apple-darwin.tar.gz ../../../tmp)
52+
(cd target/aarch64-apple-darwin/release && tar -cvf ${{ env.BINARY_NAME }}-aarch64-apple-darwin.tar.gz ${{ env.BINARY_NAME }} completions && mv ${{ env.BINARY_NAME }}-aarch64-apple-darwin.tar.gz ../../../tmp)
53+
54+
- name: Calculate sha256
55+
run: |
56+
shasum -a 256 ./tmp/${{ env.BINARY_NAME }}-x86_64-unknown-linux-gnu.tar.gz >> ./tmp/sha256.txt
57+
shasum -a 256 ./tmp/${{ env.BINARY_NAME }}-x86_64-apple-darwin.tar.gz >> ./tmp/sha256.txt
58+
shasum -a 256 ./tmp/${{ env.BINARY_NAME }}-aarch64-apple-darwin.tar.gz >> ./tmp/sha256.txt
59+
- name: Cache
60+
if: github.ref_type == 'tag'
61+
id: cache-cross-compiled-artifacts
62+
uses: actions/cache@v4
63+
with:
64+
path: ./tmp
65+
key: ${{ runner.os }}-cross-compiled-artifacts-${{ github.sha }}
66+
67+
draft-release:
68+
if: github.ref_type == 'tag'
69+
permissions:
70+
contents: write
71+
runs-on: ubuntu-latest
72+
needs: build
73+
env:
74+
RELEASE_NAME: ${{ github.ref_name }}
75+
steps:
76+
- uses: actions/checkout@v4
77+
- name: Restore cached cross-compiled artifacts
78+
id: cache-cross-compiled-artifacts-restore
79+
uses: actions/cache/restore@v4
80+
with:
81+
path: ./tmp
82+
key: ${{ runner.os }}-cross-compiled-artifacts-${{ github.sha }}
83+
- name: Create release draft if it doesn't exist
84+
uses: topheman/create-release-if-not-exist@v1
85+
with:
86+
args: ${{ env.RELEASE_NAME }} --draft --generate-notes
87+
- name: Upload Binaries
88+
run: |
89+
gh release upload ${{ env.RELEASE_NAME }} \
90+
./tmp/${{ env.BINARY_NAME }}-x86_64-unknown-linux-gnu.tar.gz \
91+
./tmp/${{ env.BINARY_NAME }}-x86_64-apple-darwin.tar.gz \
92+
./tmp/${{ env.BINARY_NAME }}-aarch64-apple-darwin.tar.gz \
93+
./tmp/sha256.txt
94+
env:
95+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/rust-host.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,21 @@ jobs:
8080
contents: write
8181
runs-on: ubuntu-latest
8282
needs: build-and-test
83+
env:
84+
RELEASE_NAME: ${{ github.ref_name }}
8385
steps:
8486
- name: Restore cached wasm files
8587
id: cache-wasm-files-restore
8688
uses: actions/cache/restore@v4
8789
with:
8890
path: ./tmp/plugins
8991
key: ${{ runner.os }}-wasm-files-${{ github.sha }}
90-
- name: Release draft
91-
uses: softprops/action-gh-release@v2
92+
- name: Create release draft if it doesn't exist
93+
uses: topheman/create-release-if-not-exist@v1
9294
with:
93-
draft: true
94-
files: ./tmp/plugins/*.wasm
95+
args: ${{ env.RELEASE_NAME }} --draft --generate-notes
96+
- name: Upload wasm files to release draft
97+
run: |
98+
gh release upload ${{ env.RELEASE_NAME }} ./tmp/plugins/*.wasm
99+
env:
100+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Update Homebrew Tap
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
update-homebrew-tap:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: write # ✅ minimal required for pushing commits
13+
14+
steps:
15+
- name: Checkout source repo
16+
uses: actions/checkout@v4
17+
- name: Update Homebrew Formula
18+
uses: topheman/update-homebrew-tap@v1
19+
with:
20+
formula-target-repository: topheman/homebrew-tap
21+
formula-target-file: Formula/pluginlab.rb
22+
tar-files: |
23+
{
24+
"linuxIntel": "https://github.com/topheman/webassembly-component-model-experiments/releases/download/${{ github.ref_name }}/pluginlab-x86_64-unknown-linux-gnu.tar.gz",
25+
"macArm": "https://github.com/topheman/webassembly-component-model-experiments/releases/download/${{ github.ref_name }}/pluginlab-aarch64-apple-darwin.tar.gz",
26+
"macIntel": "https://github.com/topheman/webassembly-component-model-experiments/releases/download/${{ github.ref_name }}/pluginlab-x86_64-apple-darwin.tar.gz"
27+
}
28+
metadata: |
29+
{
30+
"version": "${{ github.ref_name }}",
31+
"binaryName": "pluginlab",
32+
"description": "Terminal REPL with sandboxed multi-language plugin system - unified codebase runs in CLI (Rust) and web (TypeScript)",
33+
"homepage": "https://github.com/topheman/webassembly-component-model-experiments",
34+
"license": "MIT"
35+
}
36+
github-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,20 @@ In the last seven years I've done a few projects involving rust and WebAssembly:
6565

6666
### pluginlab (rust) - REPL cli host
6767

68-
#### Install
68+
#### Install the binary
69+
70+
**Using cargo (from source)**
6971

7072
```bash
71-
# Install the pluginlab binary
7273
cargo install pluginlab
7374
```
7475

76+
**Using homebrew**
77+
78+
```bash
79+
brew install topheman/tap/pluginlab
80+
```
81+
7582
#### Run
7683

7784
```bash

crates/pluginlab/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ More details on the github repo: [topheman/webassembly-component-model-experimen
4545

4646
## Install
4747

48+
**Using cargo (from source)**
49+
4850
```bash
4951
cargo install pluginlab
5052
```
5153

54+
**Using homebrew**
55+
56+
```bash
57+
brew install topheman/tap/pluginlab
58+
```
59+
5260
## Usage
5361

5462
Run the CLI host, loading the latest versions of the plugins from the web (you can also load them from local files).

0 commit comments

Comments
 (0)