carla-sys
This crate provides Rust FFI bindings for CARLA simulator. It links to
pre-built libcarla_client libraries and generates FFI bindings using
autocxx. Additional C++ code in
csrc directory replaces some classes and functions that cannot
be correctly handled by autocxx.
Supported CARLA Versions: 0.9.14, 0.9.16 (default: 0.9.16)
It is part of carla crate and normally you don't have to include this package in your project.
Version Selection
Use the CARLA_VERSION environment variable to select which CARLA version to build against:
# Use CARLA 0.9.16 (default)
# Use CARLA 0.9.14
CARLA_VERSION=0.9.14
The version selection affects:
- Which prebuilt library is downloaded (when available)
- Which vendored headers are used for binding generation
- Which boost version is linked (1.80.0 for 0.9.14, 1.84.0 for 0.9.16)
Building Prebuilt libcarla_client Libraries
This section documents how to build prebuilt libcarla_client libraries for distribution. These prebuilt libraries allow users to build carla-sys without requiring the full CARLA source code.
Prerequisites
LLVM/clang compatibility: Building requires LLVM versions 11-13. LLVM 14+ is not supported due to autocxx compatibility issues.
# Install compatible LLVM version (Ubuntu/Debian)
# Or use LLVM 12 or 11
The build script automatically detects compatible LLVM versions (preference order: 13, 12, 11). To manually override:
Building from CARLA Source
Option 1: Automated Script (Recommended)
Use the provided build script with your CARLA directory path:
# Or use CARLA_DIR environment variable
The script will:
- Validate the CARLA installation
- Check LLVM/clang compatibility
- Build with the
build-prebuiltfeature - Display generated artifacts and next steps
Option 2: Manual Build
- Clone and prepare CARLA repository (version 0.9.14):
- Set CARLA_DIR and build with the build-prebuilt feature:
The build-prebuilt feature:
- Compiles
libcarla_clientfrom CARLA source (requires CARLA_DIR) - Saves compiled library as tarball in
generated/directory - Saves generated FFI bindings to
generated/bindings.rs
- Locate the generated artifacts:
After a successful build, the following artifacts are created in carla-sys/generated/:
carla-sys/generated/
├── libcarla_client.{VERSION}-{TARGET}.tar.zstd # Prebuilt library tarball
└── bindings.rs # Generated FFI bindings
Example: libcarla_client.0.9.14-x86_64-unknown-linux-gnu.tar.zstd
Using Prebuilt Libraries
The prebuilt tarballs can be distributed via:
- GitHub Releases: Upload the tarball to a release
- Update index.json5: Add an entry mapping the target to the download URL
{
"0.9.14-x86_64-unknown-linux-gnu": "https://github.com/user/repo/releases/download/tag/libcarla_client.0.9.14-x86_64-unknown-linux-gnu.tar.zstd"
}
The build script automatically downloads and uses prebuilt libraries from the index when the build-prebuilt feature is not enabled.
Building for Multiple Targets
To create prebuilt libraries for different platforms, repeat the build process on each target platform (e.g., Linux x86_64, Windows, macOS).
Use Custom CARLA Source Code
To use a custom CARLA repository without creating prebuilt libraries:
# Set CARLA_DIR to your custom CARLA installation
# Build without the build-prebuilt feature
This uses the existing prebuilt library from your CARLA installation without creating a distributable tarball.
License
It is distributed under MIT license. Please see LICENSE.txt file for full license text.