mirror of
https://github.com/anomalyco/opentui.git
synced 2026-09-19 01:26:03 +08:00
add a release workflow for the dylib; create install.sh; move the C header to go/ for now, cgo doesnt support looking in parent dirs (#105)
It needs proper packaging like brew and stuff, but we can at least have an install.sh script for now
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
name: Build and Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-zig:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: x86_64-linux
|
||||||
|
- os: macos-13
|
||||||
|
target: x86_64-macos
|
||||||
|
- os: macos-latest
|
||||||
|
target: aarch64-macos
|
||||||
|
- os: windows-latest
|
||||||
|
target: x86_64-windows
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Zig
|
||||||
|
uses: goto-bus-stop/setup-zig@v2
|
||||||
|
with:
|
||||||
|
version: 0.14.1
|
||||||
|
|
||||||
|
- name: Build Zig library
|
||||||
|
run: |
|
||||||
|
cd packages/core/src/zig
|
||||||
|
zig build -Doptimize=ReleaseFast
|
||||||
|
|
||||||
|
- name: Upload library artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: library-${{ matrix.target }}
|
||||||
|
path: packages/core/src/zig/lib/
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: build-zig
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Prepare release assets
|
||||||
|
run: |
|
||||||
|
mkdir -p release-assets
|
||||||
|
|
||||||
|
# Copy header file and install script
|
||||||
|
cp packages/go/opentui.h release-assets/
|
||||||
|
cp install.sh release-assets/
|
||||||
|
cp opentui.pc.in release-assets/
|
||||||
|
|
||||||
|
# Copy libraries with proper naming
|
||||||
|
for target in x86_64-linux x86_64-macos aarch64-macos x86_64-windows; do
|
||||||
|
if [ -d "artifacts/library-$target" ]; then
|
||||||
|
case $target in
|
||||||
|
*-linux)
|
||||||
|
find artifacts/library-$target -name "*.so" -exec cp {} release-assets/libopentui-$target.so \;
|
||||||
|
;;
|
||||||
|
*-macos)
|
||||||
|
find artifacts/library-$target -name "*.dylib" -exec cp {} release-assets/libopentui-$target.dylib \;
|
||||||
|
;;
|
||||||
|
*-windows)
|
||||||
|
find artifacts/library-$target -name "*.dll" -exec cp {} release-assets/opentui-$target.dll \;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
ls -la release-assets/
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: release-assets/*
|
||||||
|
generate_release_notes: true
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -28,6 +28,14 @@ bun install @opentui/core
|
|||||||
|
|
||||||
### Go
|
### Go
|
||||||
|
|
||||||
|
First install OpenTUI system-wide:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -L https://github.com/sst/opentui/releases/latest/download/install.sh | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Then use in your Go projects:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/sst/opentui/packages/go
|
go get github.com/sst/opentui/packages/go
|
||||||
```
|
```
|
||||||
|
|||||||
Executable
+150
@@ -0,0 +1,150 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# OpenTUI System Installation Script
|
||||||
|
# Installs OpenTUI headers and libraries system-wide
|
||||||
|
|
||||||
|
REPO="sst/opentui"
|
||||||
|
RELEASE_URL="https://github.com/$REPO/releases/latest/download"
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${GREEN}OpenTUI System Installer${NC}"
|
||||||
|
echo "Installing OpenTUI headers and libraries..."
|
||||||
|
|
||||||
|
# Detect platform
|
||||||
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
case "$ARCH" in
|
||||||
|
x86_64|amd64) ARCH="x86_64" ;;
|
||||||
|
arm64|aarch64) ARCH="aarch64" ;;
|
||||||
|
*) echo -e "${RED}Error: Unsupported architecture: $ARCH${NC}"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$OS" in
|
||||||
|
darwin) OS="macos" ;;
|
||||||
|
linux) OS="linux" ;;
|
||||||
|
mingw*|cygwin*|msys*) OS="windows" ;;
|
||||||
|
*) echo -e "${RED}Error: Unsupported OS: $OS${NC}"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
PLATFORM="${ARCH}-${OS}"
|
||||||
|
echo "Detected platform: $PLATFORM"
|
||||||
|
|
||||||
|
# Determine installation paths
|
||||||
|
if [[ "$OS" == "macos" ]]; then
|
||||||
|
INCLUDE_DIR="/opt/homebrew/include"
|
||||||
|
LIB_DIR="/opt/homebrew/lib"
|
||||||
|
if [[ ! -d "$INCLUDE_DIR" ]]; then
|
||||||
|
INCLUDE_DIR="/usr/local/include"
|
||||||
|
LIB_DIR="/usr/local/lib"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
INCLUDE_DIR="/usr/local/include"
|
||||||
|
LIB_DIR="/usr/local/lib"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installation paths:"
|
||||||
|
echo " Headers: $INCLUDE_DIR"
|
||||||
|
echo " Libraries: $LIB_DIR"
|
||||||
|
|
||||||
|
# Check for sudo if needed
|
||||||
|
if [[ ! -w "$INCLUDE_DIR" ]] || [[ ! -w "$LIB_DIR" ]]; then
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo -e "${YELLOW}Administrator privileges required for system installation${NC}"
|
||||||
|
echo "Please run with sudo or as administrator"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create temporary directory
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
trap "rm -rf $TEMP_DIR" EXIT
|
||||||
|
|
||||||
|
echo "Downloading assets..."
|
||||||
|
|
||||||
|
# Download header file
|
||||||
|
echo " - opentui.h"
|
||||||
|
curl -L -o "$TEMP_DIR/opentui.h" "$RELEASE_URL/opentui.h" || {
|
||||||
|
echo -e "${RED}Error: Failed to download header file${NC}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download library for current platform
|
||||||
|
case "$OS" in
|
||||||
|
macos)
|
||||||
|
LIB_FILE="libopentui.dylib"
|
||||||
|
ASSET_NAME="libopentui-$PLATFORM.dylib"
|
||||||
|
;;
|
||||||
|
linux)
|
||||||
|
LIB_FILE="libopentui.so"
|
||||||
|
ASSET_NAME="libopentui-$PLATFORM.so"
|
||||||
|
;;
|
||||||
|
windows)
|
||||||
|
LIB_FILE="opentui.dll"
|
||||||
|
ASSET_NAME="opentui-$PLATFORM.dll"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo " - $ASSET_NAME"
|
||||||
|
curl -L -o "$TEMP_DIR/$LIB_FILE" "$RELEASE_URL/$ASSET_NAME" || {
|
||||||
|
echo -e "${RED}Error: Failed to download library for $PLATFORM${NC}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install files
|
||||||
|
echo "Installing files..."
|
||||||
|
|
||||||
|
echo " - Installing header to $INCLUDE_DIR/opentui.h"
|
||||||
|
cp "$TEMP_DIR/opentui.h" "$INCLUDE_DIR/opentui.h" || {
|
||||||
|
echo -e "${RED}Error: Failed to install header file${NC}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
echo " - Installing library to $LIB_DIR/$LIB_FILE"
|
||||||
|
cp "$TEMP_DIR/$LIB_FILE" "$LIB_DIR/$LIB_FILE" || {
|
||||||
|
echo -e "${RED}Error: Failed to install library file${NC}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set permissions
|
||||||
|
chmod 644 "$INCLUDE_DIR/opentui.h"
|
||||||
|
chmod 755 "$LIB_DIR/$LIB_FILE"
|
||||||
|
|
||||||
|
# Install pkg-config file
|
||||||
|
PKG_CONFIG_DIR="/usr/local/lib/pkgconfig"
|
||||||
|
if [[ "$OS" == "macos" ]] && [[ -d "/opt/homebrew/lib/pkgconfig" ]]; then
|
||||||
|
PKG_CONFIG_DIR="/opt/homebrew/lib/pkgconfig"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " - Installing pkg-config file to $PKG_CONFIG_DIR/opentui.pc"
|
||||||
|
mkdir -p "$PKG_CONFIG_DIR"
|
||||||
|
|
||||||
|
# Download and install pkg-config template
|
||||||
|
curl -L -o "$TEMP_DIR/opentui.pc.in" "$RELEASE_URL/opentui.pc.in" || {
|
||||||
|
echo -e "${YELLOW}Warning: Could not download pkg-config template${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -f "$TEMP_DIR/opentui.pc.in" ]]; then
|
||||||
|
sed "s|@PREFIX@|${INCLUDE_DIR%/include}|g; s|@VERSION@|latest|g" "$TEMP_DIR/opentui.pc.in" > "$PKG_CONFIG_DIR/opentui.pc"
|
||||||
|
chmod 644 "$PKG_CONFIG_DIR/opentui.pc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update library cache on Linux
|
||||||
|
if [[ "$OS" == "linux" ]]; then
|
||||||
|
echo "Updating library cache..."
|
||||||
|
ldconfig 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ OpenTUI installed successfully!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "You can now use OpenTUI in your Go projects:"
|
||||||
|
echo " go get github.com/dnakov/opentui/packages/go"
|
||||||
|
echo ""
|
||||||
|
echo "To uninstall:"
|
||||||
|
echo " sudo rm $INCLUDE_DIR/opentui.h $LIB_DIR/$LIB_FILE"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
prefix=@PREFIX@
|
||||||
|
libdir=${prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: OpenTUI
|
||||||
|
Description: High-performance terminal user interface library
|
||||||
|
Version: @VERSION@
|
||||||
|
Libs: -L${libdir} -lopentui -Wl,-rpath,${libdir}
|
||||||
|
Cflags: -I${includedir}
|
||||||
+20
-3
@@ -12,6 +12,20 @@ Go bindings for [OpenTUI](https://github.com/sst/opentui), a high-performance te
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
### 1. Install OpenTUI System Dependencies
|
||||||
|
|
||||||
|
First, install OpenTUI headers and libraries system-wide:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -L https://github.com/sst/opentui/releases/latest/download/install.sh | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This downloads the latest compiled libraries and headers for your platform and installs them to standard system locations.
|
||||||
|
|
||||||
|
### 2. Install Go Package
|
||||||
|
|
||||||
|
Then use in your Go projects:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/sst/opentui/packages/go
|
go get github.com/sst/opentui/packages/go
|
||||||
```
|
```
|
||||||
@@ -20,7 +34,7 @@ go get github.com/sst/opentui/packages/go
|
|||||||
|
|
||||||
- Go 1.21 or later
|
- Go 1.21 or later
|
||||||
- CGO enabled
|
- CGO enabled
|
||||||
- C compiler (gcc, clang, or MSVC)
|
- pkg-config (usually pre-installed on most systems)
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
@@ -222,8 +236,11 @@ To build with a custom OpenTUI library:
|
|||||||
cd ../../core/src/zig
|
cd ../../core/src/zig
|
||||||
zig build -Doptimize=ReleaseFast
|
zig build -Doptimize=ReleaseFast
|
||||||
|
|
||||||
# Copy library to appropriate system location or set CGO_LDFLAGS
|
# Install locally instead of using releases
|
||||||
# Then test Go bindings
|
sudo cp lib/$(uname -m)-$(uname -s | tr '[:upper:]' '[:lower:]')/libopentui.* /usr/local/lib/
|
||||||
|
sudo cp ../../go/opentui.h /usr/local/include/
|
||||||
|
|
||||||
|
# Test Go bindings
|
||||||
cd ../../go
|
cd ../../go
|
||||||
go test
|
go test
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
package opentui
|
package opentui
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -I${SRCDIR}/../core/src/zig
|
#cgo pkg-config: opentui
|
||||||
#cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/aarch64-macos -lopentui -Wl,-rpath,${SRCDIR}/../core/src/zig/lib/aarch64-macos
|
#include <opentui.h>
|
||||||
#cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/x86_64-macos -lopentui -Wl,-rpath,${SRCDIR}/../core/src/zig/lib/x86_64-macos
|
|
||||||
#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/x86_64-linux -lopentui -Wl,-rpath,${SRCDIR}/../core/src/zig/lib/x86_64-linux
|
|
||||||
#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/aarch64-linux -lopentui -Wl,-rpath,${SRCDIR}/../core/src/zig/lib/aarch64-linux
|
|
||||||
#cgo windows,amd64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/x86_64-windows -lopentui
|
|
||||||
#cgo windows,arm64 LDFLAGS: -L${SRCDIR}/../core/src/zig/lib/aarch64-windows -lopentui
|
|
||||||
|
|
||||||
#include "opentui.h"
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|||||||
Reference in New Issue
Block a user