Support system ripgrep on Android (Termux)

Open
#76 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
android, javascript, node.js

Research direction

Start in lib/postinstall.js, especially main() and getTarget(), and review how the existing postinstall download path handles platforms. Test npm install in Android Termux with system ripgrep installed and absent. Done means Android avoids the unknown-platform failure, links the available rg binary, and preserves the fallback behavior when it is unavailable.

Written by the indexing model from the issue text.

Description

Problem

On Android (Termux), the postinstall script fails when trying to download prebuilt ripgrep binaries due to:

  • Platform compatibility issues with prebuilt binaries
  • The getTarget() function throws "Unknown platform: android"
  • Network restrictions and architecture support limitations in Android environments

Current Behavior

When running npm install on Android, the postinstall script fails with:

Error: Unknown platform: android
    at getTarget (/path/to/lib/postinstall.js:49:24)

Proposed Solution

Add Android platform detection to use system-installed ripgrep via symlink before falling back to downloads. This leverages the well-maintained ripgrep package available in Termux.

Code Implementation

Add this logic to the main() function in lib/postinstall.js:

// Handle Android specially - try to use system ripgrep if available
if (os.platform() === 'android') {
    console.log('Android detected, checking for system ripgrep...');
    try {
        const result = await exec('which rg');
        const systemRgPath = result.stdout.trim();
        if (systemRgPath) {
            console.log(`Found system ripgrep at ${systemRgPath}`);
            const targetRgPath = path.join(BIN_PATH, 'rg');

            // Remove existing symlink/file if it exists
            try {
                await util.promisify(fs.unlink)(targetRgPath);
            } catch (err) {
                // Ignore error if file doesn't exist
            }

            // Create symlink to system ripgrep
            await util.promisify(fs.symlink)(systemRgPath, targetRgPath);
            console.log(`Created symlink from ${targetRgPath} to ${systemRgPath}`);
            return;
        }
    } catch (err) {
        console.log('System ripgrep not found, falling back to download...');
    }
}

Benefits of This Approach

  • Reliability: Uses Termux's well-tested ripgrep package that works across Android devices
  • Performance: Native builds optimized for the specific Android environment
  • Compatibility: Avoids architecture and library compatibility issues with prebuilt binaries
  • Maintenance: Leverages Termux package management for updates and security patches
  • Graceful fallback: Still attempts download if system ripgrep unavailable

Testing

Tested on Android (Termux) with system ripgrep available:

  • ✅ Detects Android platform correctly
  • ✅ Finds system ripgrep at /data/data/com.termux/files/usr/bin/rg
  • ✅ Creates symlink successfully
  • ✅ Symlinked ripgrep works correctly (rg --version shows expected output)
  • ✅ Handles existing symlinks by removing them first

Installation Instructions for Users

On Android/Termux, users should install ripgrep first:

pkg install ripgrep

Then install vscode-ripgrep normally:

npm install vscode-ripgrep

The postinstall script will automatically detect and use the system ripgrep.

Dominant language
JavaScript
Stars
203
Forks
66
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode-ripgrep

All issues in microsoft/vscode-ripgrep

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.