Skip to content

Commit f9f6b10

Browse files
authored
feat: add support for pre-compiled binaries (#3)
* feat: add support for pre-compiled binaries * fix: fmt * fix: add workflow_dispatch
1 parent 2301268 commit f9f6b10

15 files changed

Lines changed: 737 additions & 56 deletions

File tree

.github/workflows/release.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: "Version to build (e.g., 0.1.0)"
11+
required: true
12+
type: string
13+
dry_run:
14+
description: "Dry run (build but don't create release)"
15+
required: false
16+
type: boolean
17+
default: true
18+
19+
env:
20+
CARGO_TERM_COLOR: always
21+
22+
jobs:
23+
build:
24+
name: Build ${{ matrix.artifact_name }}
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
include:
30+
- os: ubuntu-latest
31+
target: x86_64-unknown-linux-gnu
32+
artifact_name: linux-x86_64
33+
ffi_ext: so
34+
- os: ubuntu-24.04-arm
35+
target: aarch64-unknown-linux-gnu
36+
artifact_name: linux-aarch64
37+
ffi_ext: so
38+
- os: macos-13
39+
target: x86_64-apple-darwin
40+
artifact_name: macos-x86_64
41+
ffi_ext: dylib
42+
- os: macos-14
43+
target: aarch64-apple-darwin
44+
artifact_name: macos-aarch64
45+
ffi_ext: dylib
46+
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
51+
- name: Determine version
52+
id: version
53+
run: |
54+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
55+
echo "VERSION=v${{ inputs.version }}" >> $GITHUB_OUTPUT
56+
echo "Using manual version: v${{ inputs.version }}"
57+
else
58+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
59+
echo "Using tag version: ${GITHUB_REF#refs/tags/}"
60+
fi
61+
62+
- name: Verify version matches Cargo.toml
63+
run: |
64+
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
65+
BUILD_VERSION=${{ steps.version.outputs.VERSION }}
66+
BUILD_VERSION=${BUILD_VERSION#v} # Strip v prefix
67+
echo "Cargo.toml version: $CARGO_VERSION"
68+
echo "Build version: $BUILD_VERSION"
69+
if [ "$CARGO_VERSION" != "$BUILD_VERSION" ]; then
70+
echo "::error::Version mismatch! Cargo.toml has $CARGO_VERSION but building v$BUILD_VERSION"
71+
exit 1
72+
fi
73+
echo "Version check passed"
74+
75+
- name: Install Rust toolchain
76+
uses: dtolnay/rust-toolchain@stable
77+
with:
78+
targets: ${{ matrix.target }}
79+
80+
- name: Cache cargo
81+
uses: Swatinem/rust-cache@v2
82+
with:
83+
key: ${{ matrix.target }}
84+
85+
- name: Install dependencies (Linux)
86+
if: runner.os == 'Linux'
87+
run: |
88+
sudo apt-get update
89+
sudo apt-get install -y libluajit-5.1-dev libclang-dev pkg-config
90+
91+
- name: Install dependencies (macOS)
92+
if: runner.os == 'macOS'
93+
run: |
94+
brew install luajit pkg-config
95+
96+
- name: Build release
97+
run: cargo build --release --target ${{ matrix.target }}
98+
99+
- name: Create artifact directory
100+
run: |
101+
mkdir -p artifact/penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}
102+
103+
- name: Copy binaries to artifact directory
104+
run: |
105+
cp target/${{ matrix.target }}/release/penview artifact/penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}/
106+
cp target/${{ matrix.target }}/release/libwebsocket_ffi.${{ matrix.ffi_ext }} artifact/penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}/websocket_ffi.so
107+
echo "${{ steps.version.outputs.VERSION }}" > artifact/penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}/VERSION
108+
109+
- name: Create tarball
110+
run: |
111+
cd artifact
112+
tar -czvf penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}.tar.gz penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}
113+
114+
- name: Upload artifact
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}
118+
path: artifact/penview-${{ steps.version.outputs.VERSION }}-${{ matrix.artifact_name }}.tar.gz
119+
120+
release:
121+
name: Create Release
122+
needs: build
123+
runs-on: ubuntu-latest
124+
if: ${{ github.event_name == 'push' || !inputs.dry_run }}
125+
permissions:
126+
contents: write
127+
128+
steps:
129+
- name: Checkout
130+
uses: actions/checkout@v4
131+
132+
- name: Determine version
133+
id: version
134+
run: |
135+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
136+
echo "VERSION=v${{ inputs.version }}" >> $GITHUB_OUTPUT
137+
else
138+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
139+
fi
140+
141+
- name: Download all artifacts
142+
uses: actions/download-artifact@v4
143+
with:
144+
path: artifacts
145+
146+
- name: Collect tarballs
147+
run: |
148+
mkdir -p release
149+
find artifacts -name "*.tar.gz" -exec cp {} release/ \;
150+
ls -la release/
151+
152+
- name: Generate checksums
153+
run: |
154+
cd release
155+
sha256sum *.tar.gz > SHA256SUMS.txt
156+
cat SHA256SUMS.txt
157+
158+
- name: Create GitHub Release
159+
uses: softprops/action-gh-release@v2
160+
with:
161+
name: penview ${{ steps.version.outputs.VERSION }}
162+
draft: false
163+
prerelease: false
164+
generate_release_notes: true
165+
files: |
166+
release/*.tar.gz
167+
release/SHA256SUMS.txt

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
2+
/bin
23
rust/websocket-ffi/lua/

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,42 @@ members = [
44
"rust/penview",
55
"rust/websocket-ffi",
66
]
7+
8+
[workspace.package]
9+
version = "0.1.0"
10+
edition = "2024"
11+
authors = ["Rahul Garg <rg@vihu.dev>"]
12+
readme = "README.md"
13+
license = "MIT"
14+
repository = "https://github.com/vihu/penview.nvim"
15+
homepage = "https://github.com/vihu/penview.nvim"
16+
17+
[workspace.dependencies]
18+
anyhow = "1"
19+
askama = "0.14"
20+
axum = { version = "0.8", features = ["ws"] }
21+
base64 = "0.22.0"
22+
clap = { version = "4", features = ["derive"] }
23+
futures-channel = "0.3"
24+
futures-util = "0.3"
25+
inquire = "0.9"
26+
mime_guess = "2"
27+
lazy_static = "1.4.0"
28+
log = "0.4"
29+
log4rs = { version = "1.4", features = ["file_appender"] }
30+
log-panics = "2"
31+
notify = "8"
32+
mlua = "0.9.7"
33+
nvim-oxi = { version = "0.4.2", features = ["neovim-0-9", "libuv", "mlua"] }
34+
open = "5"
35+
parking_lot = "0.12"
36+
pulldown-cmark = "0.13"
37+
resolve-path = "0.1.0"
38+
serde = { version = "1", features = ["derive"] }
39+
serde_json = "1"
40+
tokio = { version = "1", features = ["full"] }
41+
tokio-tungstenite = { version = "0.21.0", features = [] }
42+
tracing = "0.1"
43+
tracing-subscriber = "0.3"
44+
url = "2"
45+
uuid = { version = "1", features = [ "v4", "fast-rng", "macro-diagnostics" ] }

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ Real-time Markdown preview for Neovim with GitHub Flavored Markdown styling.
1616
## Requirements
1717

1818
- Neovim 0.9+
19-
- Rust toolchain (for building)
19+
- curl (for downloading pre-compiled binaries)
20+
- Rust toolchain (only if building from source)
2021

2122
## Installation
2223

23-
### lazy.nvim
24+
### lazy.nvim (recommended)
25+
26+
Pre-compiled binaries are automatically downloaded for Linux and macOS (x86_64 and aarch64):
2427

2528
```lua
2629
{
2730
"vihu/penview.nvim",
28-
build = "make build",
31+
build = function()
32+
require("penview.build").install()
33+
end,
2934
ft = "markdown",
3035
config = function()
3136
require("penview").setup({
@@ -43,6 +48,51 @@ Real-time Markdown preview for Neovim with GitHub Flavored Markdown styling.
4348
}
4449
```
4550

51+
### packer.nvim
52+
53+
```lua
54+
use {
55+
"vihu/penview.nvim",
56+
run = function()
57+
require("penview.build").install()
58+
end,
59+
config = function()
60+
require("penview").setup({
61+
browser = "firefox",
62+
})
63+
end,
64+
}
65+
```
66+
67+
### vim-plug
68+
69+
```vim
70+
Plug 'vihu/penview.nvim', { 'do': ':lua require("penview.build").install()' }
71+
72+
" In your init.vim or after/plugin:
73+
lua require("penview").setup({ browser = "firefox" })
74+
```
75+
76+
### Building from source
77+
78+
If pre-compiled binaries are unavailable for your platform, or you prefer to build from source:
79+
80+
```lua
81+
-- lazy.nvim
82+
{
83+
"vihu/penview.nvim",
84+
build = "make build", -- Requires Rust toolchain
85+
-- ...
86+
}
87+
```
88+
89+
Build dependencies:
90+
91+
- Rust toolchain (stable)
92+
- libluajit (libluajit-5.1-dev on Debian/Ubuntu)
93+
- libclang-dev
94+
- pkg-config
95+
4696
## Usage
4797

4898
1. Open a markdown file

0 commit comments

Comments
 (0)