docs/en/developers/mac-compile-run-test.md
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.
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
cd build-mac
./env_macos.sh
Before compiling BE on macOS, you need to compile third-party dependencies first. Navigate to the build-mac directory and run:
cd build-mac
./build_thirdparty.sh
./build.sh --fe
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
The BE compilation script for macOS is located in the build-mac directory.
cd build-mac
./build_be.sh
The first-time compilation will automatically complete the following steps:
be/output/ directoryAfter compilation, BE artifacts are located in:
be/output/
├── bin/ # Startup scripts
├── conf/ # Configuration files
├── lib/ # starrocks_be binary file
│ └── starrocks_be # BE main program
└── storage/ # Data storage directory
Edit the output/fe/conf/fe.conf file:
# Network configuration - Specify the network range for FE to listen on
# Adjust according to your local network configuration
priority_networks = 10.10.10.0/24;192.168.0.0/16
# Set default replica count to 1 (for single-machine development environment)
default_replication_num = 1
# Reset election group (IP changes during compilation affect FE leader election)
bdbje_reset_election_group = true
cd output/fe
./bin/start_fe.sh --daemon
tail -f output/fe/log/fe.log
Edit the be/output/conf/be.conf file:
# Network configuration - Must match FE configuration
priority_networks = 10.10.10.0/24;192.168.0.0/16
# Disable datacache (not supported on macOS)
datacache_enable = false
# Disable system metrics collection (some features not supported on macOS)
enable_system_metrics = false
enable_table_metrics = false
enable_collect_table_metrics = false
# Verbose logging mode (for debugging)
sys_log_verbose_modules = *
On macOS, starting BE requires setting some environment variables:
cd be/output
# Set environment variables and start BE
export ASAN_OPTIONS=detect_container_overflow=0
export STARROCKS_HOME=/Users/kks/git/starrocks/be/output
export PID_DIR=/Users/kks/git/starrocks/be/output/bin
export UDF_RUNTIME_DIR=/Users/kks/git/starrocks/be/output/lib
# Start BE in background
./lib/starrocks_be &
Note: Replace the path
/Users/kks/git/starrockswith your actual StarRocks code path.
tail -f be/output/log/be.INFO
ps aux | grep starrocks_be
kill -9 <PID>
After starting BE, you need to register it to FE via MySQL client:
-- 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.
# 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
-- 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;
macOS uses LLDB as the debugger (replacement for GDB).
# Find BE process ID
ps aux | grep starrocks_be
# Attach to process using LLDB (replace <PID> with actual process ID)
sudo lldb -p <PID>
# 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 stack information for problem analysis
lldb -p <PID> --batch -o "thread backtrace all" > starrocks_bt.txt
StarRocks provides a complete SQL testing framework that can run on macOS.
# 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
Since the macOS version has some features disabled, you need to mark which test cases can run on Mac:
# 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 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
The test framework will automatically connect to the local StarRocks instance:
127.0.0.19030rootTo 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:
#!/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:
chmod +x .git/hooks/pre-commit
Due to platform compatibility limitations, the following features are disabled in the macOS version:
The macOS compilation implementation follows these principles:
build-mac/ directoryQ: Getting "protobuf version mismatch" error during compilation
A: Make sure to use thirdparty/installed/bin/protoc (version 3.14.0) instead of system or Homebrew's protobuf:
# Check protobuf version
/Users/kks/git/starrocks/thirdparty/installed/bin/protoc --version
# Should output: libprotoc 3.14.0
Q: Out of memory during compilation
A: Reduce the number of parallel compilation tasks:
./build_be.sh --parallel 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.
If you find issues or have improvement suggestions on macOS:
build-mac/ directory#ifdef __APPLE__ for platform-specific code modificationsContributions are welcome in the following areas:
Happy coding on macOS!