A minimal Next.js + Rust CLI template for Vercel deployment with ping functionality.
- Next.js Frontend: Clean, minimal React interface with Tailwind CSS
- Rust CLI Binary: Processes JSON input and returns structured responses
- Ping Functionality: Built-in ping/pong testing between frontend and Rust binary
- Docker Support: Local compilation using Docker for cross-platform builds
- Vercel Ready: Configured for seamless Vercel deployment
- Automated Build & Deploy: Single script for complete build and deployment pipeline
- Node.js: Version 22.x (as specified in package.json engines)
- Package Manager: Choose one:
- npm: Comes with Node.js (default)
- yarn: Alternative package manager (recommended for faster installs)
- Git: For version control and Vercel CLI authentication
Option A: Local Rust Toolchain (Recommended for Development)
- Rust: Latest stable version via rustup
- Cross-compilation tools (choose one):
- cargo-zigbuild + Zig: For macOS/Linux cross-compilation
- cross: Alternative cross-compilation tool
Option B: Docker (No Local Rust Required)
- Docker: For containerized builds
- Docker BuildKit: Enabled for optimized builds
- Vercel CLI: For deployment automation
- Vercel Account: With project linked
- Environment Variables: Any required secrets/API keys
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Node.js (via Homebrew)
brew install node@22
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
# Install cross-compilation tools (choose one)
# Option 1: cargo-zigbuild + Zig (recommended)
cargo install cargo-zigbuild
brew install zig
# Option 2: cross
cargo install cross --git https://github.com/cross-rs/cross
# Install Docker (if using Docker option)
brew install --cask docker
# Install Vercel CLI
npm install -g vercel
# or with yarn
yarn global add vercel# Update package manager
sudo apt update
# Install Node.js 22.x
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
# Install cross-compilation tools (choose one)
# Option 1: cargo-zigbuild + Zig
cargo install cargo-zigbuild
sudo apt install zig
# Option 2: cross
cargo install cross --git https://github.com/cross-rs/cross
# Install Docker (if using Docker option)
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
# Install Vercel CLI
sudo npm install -g vercel
# or with yarn
sudo yarn global add vercelThis project supports both npm and yarn package managers. Choose based on your preference:
- Pros: Comes with Node.js, widely supported, stable
- Cons: Slower installs, larger lock files
- Usage:
npm install,npm run <script>
- Pros: Faster installs, better dependency resolution, smaller lock files
- Cons: Additional installation step
- Usage:
yarn install,yarn <script>
# Install yarn globally
npm install -g yarn
# or via Homebrew (macOS)
brew install yarn
# or via apt (Linux)
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarnUsing npm:
# Single command for complete build and deployment
npm run build:deployUsing yarn:
# Single command for complete build and deployment
yarn run build:deployDirect script execution:
# Make the script executable (first time only)
chmod +x scripts/build-and-deploy.sh
# Run complete build and deployment
./scripts/build-and-deploy.sh-
Install dependencies:
# Using npm npm install # Using yarn yarn install
-
Build the Rust CLI locally (requires Rust toolchain):
# Using npm npm run build:cli # Using yarn yarn run build:cli
-
Or build using Docker (no local Rust required):
# Using npm npm run build:cli:docker # Using yarn yarn run build:cli:docker
-
Start development server:
# Using npm npm run dev # Using yarn yarn dev
-
Build for production:
# Using npm npm run build # Using yarn yarn build
-
Deploy to Vercel:
vercel --prod
- Click "Ping Rust Binary" to test the connection
- Sends a structured ping message with timestamp
- Rust binary responds with pong confirmation
- Enter a custom message in the text area
- Click "Send Custom Message" to process it
- Message is sent to Rust CLI binary via
/api/proxyendpoint - Rust binary processes input and returns JSON response
- Frontend: Next.js with React hooks for state management
- API:
/api/proxy.jsspawns Rust binary and handles I/O - Rust CLI: Processes JSON input, handles ping/pong, echoes messages
- Deployment: Vercel functions with binary included in deployment
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install cargo-zigbuild (recommended)
cargo install cargo-zigbuild
brew install zig # macOS
# Build CLI
# Using npm
npm run build:cli
# Using yarn
yarn run build:cli# Just need Docker running
# Using npm
npm run build:cli:docker
# Using yarn
yarn run build:cli:docker-
Build the CLI binary:
# Using npm npm run build:cli:docker # Using yarn yarn run build:cli:docker
-
Deploy to Vercel:
vercel --prod
The binary will be automatically included in the Vercel function deployment.
The yarn run build:deploy command is a comprehensive automation script that handles the entire build and deployment pipeline. Here's everything you need to know:
- Validates Prerequisites: Checks for Node.js, yarn, Git, Rust toolchain, Docker, and Vercel CLI
- Installs Dependencies: Runs
yarn installto install all Node.js dependencies - Builds Rust CLI: Compiles the Rust binary using the best available method
- Builds Next.js App: Compiles the frontend for production
- Validates Build: Ensures all components are properly built
- Deploys to Vercel: Pushes the complete application to production
Before running yarn run build:deploy, ensure you have:
- Node.js 22.x:
node --version - yarn:
yarn --version - Git:
git --version - Rust toolchain (for local builds):
rustc --version - Docker (for Docker builds):
docker --version - Vercel CLI:
vercel --version - Vercel Authentication:
vercel whoami
Basic deployment:
yarn run build:deployVerbose output (recommended for debugging):
yarn run build:deploy:verboseStep-by-step process:
# 1. Install dependencies
yarn install
# 2. Build Rust CLI (choose one)
yarn run build:cli # Local Rust toolchain
yarn run build:cli:docker # Docker build
# 3. Build Next.js app
yarn build
# 4. Deploy to Vercel
vercel --prodCommon Issues:
-
yarn not found:
# Install yarn globally npm install -g yarn -
Vercel not authenticated:
vercel login vercel whoami # Verify authentication -
Rust toolchain missing:
# Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env
-
Docker not running:
# Start Docker service brew services start docker # macOS sudo systemctl start docker # Linux
-
Permission issues:
# Fix script permissions chmod +x scripts/build-and-deploy.sh
The script automatically handles:
- Node.js environment detection
- Rust toolchain detection
- Docker availability
- Vercel authentication status
The script provides:
- β Success indicators for each step
- β Error messages with troubleshooting hints
- π Build statistics and timing
- π Deployment URL upon completion
The scripts/build-and-deploy.sh script provides a complete automation pipeline that:
- β Node.js: Checks for Node.js 22.x installation
- β npm: Validates npm availability
- β Git: Ensures Git is installed for Vercel authentication
- β Rust Toolchain: Validates Rust installation and toolchain
- β Cross-compilation: Checks for cargo-zigbuild or cross
- β Docker: Validates Docker installation (if using Docker build)
- β Vercel CLI: Ensures Vercel CLI is installed and authenticated
- Dependency Installation: Runs
npm installto install Node.js dependencies - Rust CLI Compilation: Builds the Rust binary using the best available method:
- Prefers local Rust toolchain with cargo-zigbuild
- Falls back to Docker build if local Rust unavailable
- Next.js Build: Compiles the Next.js application for production
- Binary Validation: Ensures the compiled binary is executable and properly placed
- Vercel Authentication: Validates Vercel CLI authentication
- Production Deployment: Deploys to Vercel with
--prodflag - Deployment Verification: Confirms successful deployment
Direct Script Execution:
# Make the script executable (first time only)
chmod +x scripts/build-and-deploy.sh
# Run complete build and deployment
./scripts/build-and-deploy.sh
# Or run with verbose output
./scripts/build-and-deploy.sh --verbosePackage Manager Scripts (Alternative):
# Using npm
npm run build:deploy
npm run build:deploy:verbose
# Using yarn
yarn run build:deploy
yarn run build:deploy:verbose- macOS (OSX): Primary target with Homebrew package manager
- Linux: Ubuntu/Debian support with apt package manager
- Auto-detection: Automatically detects OS and adjusts commands accordingly
βββ pages/
β βββ index.js # Main React component with ping/message UI
β βββ _app.js # Next.js app wrapper
βββ api/
β βββ proxy.js # Vercel function that spawns Rust binary
β βββ bin/ # Compiled Rust CLI binary (generated)
βββ rust-cli/
β βββ Cargo.toml # Rust dependencies
β βββ src/main.rs # Rust CLI with ping/pong logic
βββ scripts/
β βββ build-cli.sh # Local build script
β βββ build-cli-docker.sh # Docker build script
β βββ build-and-deploy.sh # Complete build & deploy automation
βββ docker/
β βββ cli.Dockerfile # Docker build for Rust binary
βββ package.json # Node.js dependencies and scripts
βββ vercel.json # Vercel configuration
βββ README.md # This file
Missing Cross-Compilation Tools
# Install cargo-zigbuild (recommended)
cargo install cargo-zigbuild
brew install zig # macOS
sudo apt install zig # LinuxDocker Not Running
# Start Docker service
brew services start docker # macOS
sudo systemctl start docker # LinuxVercel Authentication Issues
# Login to Vercel
vercel login
# Check authentication status
vercel whoamiNode.js Version Mismatch
# Check current version
node --version
# Install Node.js 22.x if needed
brew install node@22 # macOS
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs # LinuxBinary Not Executable
# Fix permissions
chmod +x api/bin/cliEnable Verbose Output
./scripts/build-and-deploy.sh --verbose
# or
npm run build:deploy:verbose
# or
yarn run build:deploy:verboseCheck Individual Components
# Test Rust CLI build only
npm run build:cli
# or
yarn run build:cli
# Test Docker build only
npm run build:cli:docker
# or
yarn run build:cli:docker
# Test Next.js build only
npm run build
# or
yarn build- Frontend: Modify
pages/index.jsfor UI changes - Rust Logic: Update
rust-cli/src/main.rsfor custom processing - API: Modify
api/proxy.jsfor different binary interaction patterns - Styling: Update
styles/globals.cssfor custom Tailwind styles