Infer Deployment and Usage Guide
A comprehensive guide for installing, configuring, and deploying Facebook's Infer static analyzer for Java, C, C++, and Objective-C.
1. Prerequisites
System Requirements
- Operating System: Linux (64-bit), macOS (10.14+), or Windows (via WSL2)
- Memory: Minimum 4GB RAM (8GB+ recommended for large codebases)
- Disk Space: 2GB+ free space for installation and analysis artifacts
Required Dependencies
Core Build Tools (for source installation):
# Ubuntu/Debian
sudo apt-get install -y \
autoconf automake libtool cmake pkg-config \
libsqlite3-dev python3 python3-distutils \
openjdk-11-jdk clang libmpfr-dev libgmp-dev
# macOS (with Homebrew)
brew install autoconf automake libtool cmake pkg-config \
sqlite python openjdk@11 mpfr gmp
OCaml Toolchain (required for building from source):
- OCaml 4.14.0 or later
- opam 2.1.0 or later
- Python 3.6+ (for build scripts)
Language-Specific Requirements:
- Java Analysis: JDK 8 or 11 (JDK 11 recommended)
- C/C++/Objective-C: Clang/LLVM 11+ or GCC 9+
- Android: Android SDK and NDK (for Android projects)
2. Installation
Option A: Pre-built Binaries (Recommended)
Download the latest release for your platform:
# Linux
VERSION=1.1.0
curl -sSL "https://github.com/facebook/infer/releases/download/v${VERSION}/infer-linux64-v${VERSION}.tar.xz" \
| tar -C /opt -xJ
ln -s "/opt/infer-linux64-v${VERSION}/bin/infer" /usr/local/bin/infer
# macOS
brew install infer
Verify installation:
infer --version
Option B: Build from Source
- Clone the repository:
git clone https://github.com/facebook/infer.git
cd infer
git checkout v1.1.0 # Check out specific version tag
- Initialize opam (if not already done):
opam init --disable-sandboxing --bare
opam switch create 4.14.0+flambda
eval $(opam env)
- Install OCaml dependencies:
opam install -y . --deps-only
- Build Infer:
./build-infer.sh
- Install to system:
sudo make install
# Or install to custom location:
# make install PREFIX=$HOME/.local
3. Configuration
Environment Variables
Add to your shell profile (~/.bashrc, ~/.zshrc, etc.):
# Infer installation path (if not installed system-wide)
export PATH="$HOME/.local/bin:$PATH"
# Java configuration (required for Java analysis)
export JAVA_HOME=$(/usr/libexec/java_home -v 11) # macOS
# export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 # Linux
# Optional: Increase memory for large codebases
export INFER_ARGS="--jobs 4"
Project Configuration
Create infer.conf in your project root for persistent options:
--jobs 4
--report-console-limit 100
--no-filtering
--annotation-reachability
4. Build & Run
Basic Usage
Analyze a Java project (Maven):
cd my-java-project
infer run -- mvn clean compile
Analyze a Java project (Gradle):
infer run -- ./gradlew build
Analyze C/C++ project:
infer run -- make clean
infer run -- make
Analyze Objective-C (iOS):
infer run -- xcodebuild -target MyApp -configuration Debug -sdk iphonesimulator
Advanced Analysis Modes
Incremental analysis (capture once, analyze multiple times):
# Capture phase
infer capture -- make
# Analysis phase
infer analyze
# Generate report
infer report
Differential analysis (compare two revisions):
infer run --reactive -- make
Output formats:
infer run -- make # Default: generates infer-out/ directory
infer run -o reports -- make # Custom output directory
infer report --from-json-report infer-out/report.json --html # Generate HTML report
Integration with Build Systems
Buck:
infer capture --buck-targets //src:main
infer analyze
CMake:
cd build
infer capture -- cmake ..
infer capture -- make
infer analyze
5. Deployment
Docker Deployment
Use the official Docker image for CI/CD pipelines:
FROM infer/infer:1.1.0
WORKDIR /app
COPY . .
RUN infer run -- make
Run locally:
docker run -v $(pwd):/app -w /app infer/infer:1.1.0 infer run -- make
CI/CD Integration
GitHub Actions:
name: Infer Analysis
on: [push, pull_request]
jobs:
infer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Infer
run: |
curl -sSL "https://github.com/facebook/infer/releases/download/v1.1.0/infer-linux64-v1.1.0.tar.xz" | tar -xJ
sudo mv infer-linux64-v1.1.0 /opt/infer
echo "/opt/infer/bin" >> $GITHUB_PATH
- name: Run Infer
run: infer run -- make
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: infer-report
path: infer-out/
GitLab CI:
infer:
image: infer/infer:1.1.0
script:
- infer run -- make
artifacts:
paths:
- infer-out/
expire_in: 1 week
Pre-commit Hook
.pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: infer
name: Infer Static Analysis
entry: infer run --
language: system
pass_filenames: false
always_run: true
6. Troubleshooting
Build Issues
Error: opam: command not found
# Install opam
sh <(curl -sL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh)
Error: No available switch
opam switch create 4.14.0
eval $(opam env)
Error: sqlite3.h: No such file
# Ubuntu/Debian
sudo apt-get install libsqlite3-dev
# macOS
brew install sqlite
Runtime Issues
Out of memory during analysis:
# Reduce parallelism
infer run --jobs 2 -- make
# Or increase JVM heap for Java analysis
export JAVA_OPTS="-Xmx4g"
Java version mismatch:
# Verify Java version
java -version
# Set correct JAVA_HOME
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
Missing clang for C/C++ analysis:
# Ubuntu
sudo apt-get install clang
# macOS
xcode-select --install
Analysis Issues
Empty report generated:
- Ensure build completes successfully before analysis
- Check that source files are actually compiled (Infer only analyzes compiled code)
- Verify file extensions are recognized (.c, .cpp, .java, .m, .mm)
False positives:
Add to .inferconfig in project root:
{
"suppress-errors": [
"NULL_DEREFERENCE",
"RESOURCE_LEAK"
]
}
Getting Help
- Documentation: http://fbinfer.com/docs/
- Issues: https://github.com/facebook/infer/issues
- Build from source details: See
INSTALL.mdin repository root - Contributing: See
CONTRIBUTING.mdfor development setup