Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
cc Rust Bindings
Rust bindings for the cc virtualization library, providing a safe Rust interface to cc's virtualization primitives.
Build Requirements
IMPORTANT: Building this crate requires Go 1.21+ to compile the native libcc library.
| Requirement | Version | Notes |
|---|---|---|
| Rust | 1.70+ | Stable toolchain |
| Go | 1.21+ | Required to build libcc |
The build.rs script will automatically compile libcc using Go if LIBCC_PATH is not set.
Installation
From crates.io
[]
= "0.1"
Ensure Go is installed and available in your PATH:
# macOS
# Ubuntu/Debian
# Verify installation
From Source
-
Build the
libccshared library: -
Set the library path (or copy
libcc.dylib/libcc.soto a standard location): -
Add to Cargo.toml:
[] = { = "/path/to/cc/bindings/rust" }
Quick Start
use ;
API Reference
Module Functions
cc::init()- Initialize the library (required before any other call)cc::shutdown()- Shutdown and release resourcescc::api_version()- Get API version stringcc::api_version_compatible(major, minor)- Check version compatibilitycc::supports_hypervisor()- Check if hypervisor is availablecc::query_capabilities()- Get system capabilitiescc::guest_protocol_version()- Get guest protocol version
Structs
OciClient
OCI image client for pulling and managing container images.
let client = new?;
let client = with_cache_dir?;
let source = client.pull?;
let source = client.load_tar?;
let source = client.load_dir?;
client.export_dir?;
Instance
A running VM instance with filesystem, command, and network access.
let inst = new?;
// Properties
inst.id; // Instance ID
inst.is_running; // Check if running
// Lifecycle
inst.wait?; // Wait for termination
inst.close?; // Close and cleanup
// Filesystem
inst.read_file?;
inst.write_file?;
inst.stat?;
inst.mkdir?;
inst.remove?;
inst.read_dir?;
// File handles (implement std::io::Read/Write/Seek)
let mut f = inst.open?;
let mut f = inst.create?;
// Commands
let output = inst.command?.output?;
let exit_code = inst.command?.run?;
// Networking
let listener = inst.listen?;
// Snapshots
let snapshot = inst.snapshot?;
Cmd
Command builder for execution in instances.
let cmd = inst.command?;
let cmd = cmd.dir?;
let cmd = cmd.env?;
// Synchronous execution
let exit_code = cmd.run?;
// Capture output
let output = cmd.output?;
let combined = cmd.combined_output?;
// Async execution
let mut cmd = inst.command?;
cmd.start?;
// ... do other work ...
let exit_code = cmd.wait?;
File
File handle for read/write operations. Implements std::io::Read, Write, and Seek.
use ;
let mut f = inst.open?;
let mut contents = Stringnew;
f.read_to_string?;
let mut f = inst.create?;
f.write_all?;
f.seek?;
Types
InstanceOptions- VM configuration (memory_mb, cpus, timeout_seconds, user, mounts)PullOptions- Image pull options (platform, auth, policy)PullPolicy- Pull policy enum (IfNotPresent, Always, Never)FileInfo- File metadata (name, size, mode, is_dir, is_symlink)DirEntry- Directory entry (name, is_dir, mode)ImageConfig- OCI image configurationCapabilities- System capabilitiesSeekWhence- Seek origin (Set, Current, End)CommandOutput- Command output with stdout and exit_code
File Open Flags
use *;
O_RDONLY // Read only
O_WRONLY // Write only
O_RDWR // Read and write
O_APPEND // Append mode
O_CREATE // Create if not exists
O_TRUNC // Truncate to zero
O_EXCL // Exclusive create (fail if exists)
Error Handling
All operations return cc::Result<T>, which is Result<T, cc::Error>.
use Error;
match result
Code Signing
Your Rust binary does NOT need code signing.
The libcc shared library handles virtualization through cc-helper, which is already signed with the necessary entitlements. Your application simply links against libcc and does not require any special entitlements or code signing.
Running Tests
# Build libcc first
# Set library path
# or .so on Linux
# Run tests (non-VM tests only)
# Run all tests including VM tests (requires hypervisor)
CC_RUN_VM_TESTS=1
Running Examples
# Set library path
# Run basic example
Thread Safety
All types in this crate implement Send and Sync, allowing them to be used across threads. However, operations on a single instance should be synchronized externally if accessed from multiple threads simultaneously.
License
MIT