> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# Compile, Run and Test StarRocks on macOS ARM64

> How to compile, run, debug, and test StarRocks on macOS ARM64 (Apple Silicon).

This document provides detailed instructions on how to compile, run, debug, and test StarRocks on the macOS ARM64 platform (Apple Silicon), making it easier for developers to work on Mac.

## Prerequisites

### Software Requirements

* macOS 15.0 or higher
* Xcode Command Line Tools
* Homebrew package manager

### Install Basic Tools

1. Install Xcode Command Line Tools:

```bash theme={null}
xcode-select --install
```

2. Install Homebrew (if not already installed):

```bash theme={null}
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

3. No separate macOS environment script is required. The third-party build step below installs the required Homebrew formulas.

## Mac Compilation

## Compile Third-party Libraries

Before compiling BE on macOS, compile third-party dependencies from the repository root:

```bash theme={null}
./thirdparty/build-thirdparty.sh
```

## Compile FE

### Compilation Steps

```bash theme={null}
./build.sh --fe
```

### Compilation Output

After compilation, FE artifacts are located in:

```
output/fe/
├── bin/              # FE startup scripts
├── conf/             # Configuration files
├── lib/              # JAR packages and dependencies
└── meta/             # Metadata storage directory
```

## Compile BE

Use the root build script to compile BE on macOS.

### First-time Compilation

```bash theme={null}
./build.sh --be
```

The first-time compilation will automatically complete the following steps:

1. Check and configure environment variables
2. Validate third-party dependencies (protobuf, thrift, brpc, etc.)
3. Generate script-based sources and let CMake materialize BE Thrift/Protobuf outputs
4. Compile BE code
5. Install to `output/be/` directory

### Compilation Output

After compilation, BE artifacts are located in:

```
output/be/
├── bin/              # Startup scripts
├── conf/             # Configuration files
├── lib/              # starrocks_be binary file
│   └── starrocks_be  # BE main program
└── storage/          # Data storage directory
```

## Configure and Run FE

### Configure FE

For local single-node development, edit `output/fe/conf/fe.conf` and set required defaults such as `priority_networks`, `default_replication_num`, and `bdbje_reset_election_group`.

### Start FE

```bash theme={null}
cd output/fe
./bin/start_fe.sh --daemon
```

### View FE Logs

```bash theme={null}
tail -f output/fe/log/fe.log
```

## Configure and Run BE

### Configure BE

For local single-node development, edit `output/be/conf/be.conf` and set required defaults such as `priority_networks`, `datacache_enable`, `enable_system_metrics`, and `sys_log_verbose_modules`.

### Start BE

```bash theme={null}
cd output/be
./bin/start_be.sh --daemon
```

### View BE Logs

```bash theme={null}
tail -f output/be/log/be.INFO
```

### Stop BE

```bash theme={null}
ps aux | grep starrocks_be

kill -9 <PID>
```

### Add BE to Cluster

After starting BE, you need to register it to FE via MySQL client:

```sql theme={null}
-- Connect to FE
mysql -h 127.0.0.1 -P 9030 -u root

-- Add BE (replace with your actual IP address)
ALTER SYSTEM ADD BACKEND "127.0.0.1:9050";

-- Check BE status
SHOW BACKENDS\G
```

Confirm that the `Alive` field is `true`, indicating BE is running properly.

## Connect and Test

### Connect Using MySQL Client

```bash theme={null}
# Use MySQL client installed via Homebrew
/opt/homebrew/Cellar/mysql-client/9.4.0/bin/mysql -h 127.0.0.1 -P 9030 -u root

# Or use system path (if configured)
mysql -h 127.0.0.1 -P 9030 -u root
```

### Basic Testing

```sql theme={null}
-- Create database
CREATE DATABASE test_db;
USE test_db;

-- Create table
CREATE TABLE test_table (
    id INT,
    name VARCHAR(100)
) DISTRIBUTED BY HASH(id) BUCKETS 1;

-- Insert data
INSERT INTO test_table VALUES (1, 'Alice'), (2, 'Bob');

-- Query data
SELECT * FROM test_table;
```

## Debug BE

### Using LLDB for Debugging

macOS uses LLDB as the debugger (replacement for GDB).

#### Attach to Running BE Process

```bash theme={null}
# Find BE process ID
ps aux | grep starrocks_be

# Attach to process using LLDB (replace <PID> with actual process ID)
sudo lldb -p <PID>
```

#### Common LLDB Commands

```lldb theme={null}
# View all threads
thread list

# View current thread's stack
bt

# View all threads' stacks
thread backtrace all

# Continue execution
continue

# Step execution
step

# Set breakpoint
breakpoint set --name function_name

# Exit LLDB
quit
```

#### Export All Thread Stacks to File

```bash theme={null}
# Export stack information for problem analysis
lldb -p <PID> --batch -o "thread backtrace all" > starrocks_bt.txt
```

## SQL Testing

StarRocks provides a complete SQL testing framework that can run on macOS.

### Prepare Test Environment

```bash theme={null}
# Navigate to test directory
cd test

# Create Python virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate

# Install test dependencies
python3 -m pip install -r requirements.txt
```

### Mark macOS Compatible Test Cases

Since the macOS version has some features disabled, you need to mark which test cases can run on Mac:

```bash theme={null}
# Mark tests in test_scan directory (preview mode, no actual modification)
python3 tag_mac_tests.py -d ./sql/test_scan --dry-run

# Actually mark tests
python3 tag_mac_tests.py -d ./sql/test_scan

# Mark tests in test_agg directory
python3 tag_mac_tests.py -d ./sql/test_agg
```

### Run SQL Tests

```bash theme={null}
# Run tests with @mac tag
pytest sql/test_scan -m mac

# Run specific test file
pytest sql/test_scan/test_basic_scan.py -m mac

# Verbose output
pytest sql/test_agg -m mac -v
```

### Test Configuration

The test framework will automatically connect to the local StarRocks instance:

* Host: `127.0.0.1`
* Port: `9030`
* User: `root`
* Password: empty

## Development Tools Configuration

### Git Pre-commit Hook (Code Formatting)

To maintain consistent code style, it's recommended to configure a pre-commit hook to automatically format C++ code.

Create the file `.git/hooks/pre-commit`:

```bash theme={null}
#!/bin/bash

echo "Running clang-format on modified files..."

STYLE=$(git config --get hooks.clangformat.style)
if [ -n "${STYLE}" ] ; then
  STYLEARG="-style=${STYLE}"
else
  STYLEARG=""
fi

format_file() {
  file="${1}"
  if [ -f $file ]; then
    /opt/homebrew/Cellar/clang-format@11/11.1.0/bin/clang-format-11 -i ${STYLEARG} ${1}
    git add ${1}
  fi
}

case "${1}" in
  --about )
    echo "Runs clang-format on source files"
    ;;
  * )
    for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cc|h|hpp)$' ` ; do
      format_file "${file}"
    done
    ;;
esac
```

Add execute permissions:

```bash theme={null}
chmod +x .git/hooks/pre-commit
```

## Limitations and Known Issues

### Features Disabled in macOS Version

Due to platform compatibility limitations, the following features are disabled in the macOS version:

#### Storage and Data Sources

* **HDFS Support**: No HDFS client library available
* **ORC Format**: Complete ORC module disabled
* **Avro Format**: avro-c library compatibility issues
* **JDBC Data Source**: JNI/Java dependencies
* **MySQL Scanner**: Missing MariaDB development headers

#### Cloud Service Integration

* **AWS S3**: Poco HTTP client compatibility issues
* **Azure Storage**: Azure SDK compatibility issues
* **Apache Pulsar**: librdkafka++ compatibility issues

#### Performance and Monitoring Tools

* **Google Breakpad**: Crash reporting (minidump)
* **OpenTelemetry**: Distributed tracing

#### Other Features

* **GEO Module**: Missing generated parser files
* **JIT Compilation**: Requires complete LLVM development environment
* **Starcache**: Cache acceleration feature
* **CLucene**: Inverted index functionality
* **LZO Compression**: Use alternative compression algorithms

### Design Principles

The macOS compilation implementation follows these principles:

1. **Do Not Affect Linux Compilation**: All modifications are isolated through conditional compilation
2. **Minimize Code Changes**: Prefer disabling features through configuration
3. **Centralized Management**: Build entrypoints remain at the repository root, macOS build helpers live in `build-support/`, and Darwin third-party logic lives in `thirdparty/`
4. **Use Standard Tools**: Rely on Homebrew and LLVM toolchain
5. **Compile Key Dependencies from Source**: Ensure ABI compatibility (protobuf, thrift, brpc)

## FAQ

**Q: Getting "protobuf version mismatch" error during compilation**

A: Make sure the BE CMake build is using `thirdparty/installed/bin/protoc` (version 3.16.1) instead of system or Homebrew's protobuf:

```bash theme={null}
# Check protobuf version
/Users/kks/git/starrocks/thirdparty/installed/bin/protoc --version

# Should output: libprotoc 3.16.1
```

**Q: Out of memory during compilation**

A: Reduce the number of parallel compilation tasks:

```bash theme={null}
./build.sh --be -j 4
```

**Q: FE cannot connect to BE**

A: Ensure that the `priority_networks` configuration in FE and BE is consistent and includes your local IP address.

**Q: Some test cases fail**

A: Check if they are tests related to disabled features (such as HDFS, S3, ORC, etc.), as these tests cannot pass on macOS.

## Contribution Guidelines

If you find issues or have improvement suggestions on macOS:

1. Check the relevant root build scripts, macOS helpers in `build-support/`, and Darwin third-party scripts in `thirdparty/`
2. Follow the principle of "do not affect Linux compilation"
3. Use `#ifdef __APPLE__` for platform-specific code modifications
4. Submit a Pull Request with detailed description of changes

Contributions are welcome in the following areas:

* Support compiling more disabled features on Mac
* Continuously improve the @mac tag for SQL tests

***

Happy coding on macOS!


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.