This document provides a high-level overview of the KCL (Kubernetes Configuration Language) compiler system, its architecture, and core capabilities. KCL is a constraint-based record and functional programming language designed for writing and managing complex configurations, particularly in cloud-native environments.
This overview introduces the major system components, execution flow, and workspace organization. For detailed information about specific subsystems, refer to:
Sources: README.md22-24 README.md42-57
KCL is an open-source, constraint-based configuration language implemented primarily in Rust. It combines features from high-level languages like Python and Golang with functional programming principles to provide a type-safe, declarative approach to configuration management.
Key Characteristics:
Aspect | Description |
---|---|
Language Paradigm | Constraint-based record and functional language |
Primary Use Case | Cloud-native configuration, especially Kubernetes |
Type System | Static typing with inference, constraints, and validation rules |
Execution Models | AST interpretation (FastRunner) and LLVM native compilation |
Implementation | Rust with C/LLVM for high-performance runtime |
Output Formats | JSON, YAML, or programmatic API results |
Sources: README.md24 README.md44-51
The KCL system follows a layered architecture with clear separation between external interfaces, service orchestration, compilation pipeline, and execution backends.
Sources: kclvm/Cargo.toml38-63 Diagram 1 from high-level architecture
The KCL compiler is organized as a Rust Cargo workspace with 20+ specialized crates. The workspace root is defined in kclvm/Cargo.toml38-63
Primary Crates:
Crate | Purpose | Location |
---|---|---|
kclvm-api | Service API implementation and protobuf interfaces | kclvm/api |
kclvm-cmd | Command-line interface entry points | kclvm/cmd |
kclvm-parser | Lexer and parser producing AST | kclvm/parser |
kclvm-ast | Abstract Syntax Tree definitions | kclvm/ast |
kclvm-sema | Semantic analysis, type checking, symbol resolution | kclvm/sema |
kclvm-compiler | LLVM code generation | kclvm/compiler |
kclvm-runner | Execution orchestration | kclvm/runner |
kclvm-evaluator | AST interpretation engine | kclvm/evaluator |
kclvm-runtime | Runtime library and built-in functions | kclvm/runtime |
kclvm-driver | Workspace discovery and build coordination | kclvm/driver |
kclvm-error | Error reporting and diagnostics | kclvm/error |
kclvm-tools | Formatting, linting, testing, documentation | kclvm/tools |
kcl-language-server | LSP implementation for IDE support | kclvm/tools/src/LSP |
Sources: kclvm/Cargo.toml1-72 kclvm/api/Cargo.toml kclvm/parser/Cargo.toml kclvm/sema/Cargo.toml kclvm/runner/Cargo.toml kclvm/tools/src/LSP/Cargo.toml
Sources: Diagram 2 from high-level architecture, kclvm/driver kclvm/parser kclvm/sema kclvm/runner
KCL supports two execution backends, selectable via feature flags in kclvm/Cargo.toml65-71:
kclvm-evaluator
kclvm-compiler
--features llvm
Both backends share the same kclvm-runtime
library for built-in functions and FFI support.
Sources: kclvm/Cargo.toml65-71 kclvm/runner/Cargo.toml50-51 kclvm/api/Cargo.toml50-51 Diagram 1 from high-level architecture
Key Integration Components:
cdylib
and staticlib
outputs named kclvm_cli_cdylib
KclvmServiceImpl
in kclvm-api
provides unified interface for all operationsSources: kclvm/Cargo.toml8-11 kclvm/api/Cargo.toml README.md55-56 Diagram 4 from high-level architecture
The kcl-language-server
crate (kclvm/tools/src/LSP) provides IDE features:
Sources: kclvm/tools/src/LSP/Cargo.toml README.md53 Diagram 3 from high-level architecture
The kclvm-tools
crate provides:
Sources: kclvm/tools/Cargo.toml README.md53 Diagram 7 from high-level architecture
KCL supports multiple platforms through CI/CD workflows:
Platform | Architecture | Build Environment |
---|---|---|
macOS | AMD64, ARM64 | Native |
Windows | AMD64 | MSVC, MinGW |
Linux | AMD64, ARM64 | Ubuntu native |
Linux | AMD64 | CentOS7 (Docker) |
Linux | AMD64 (musl) | Alpine (Docker) |
WebAssembly | WASM32 | WASI target |
The default target is configured at build time in kclvm/runner/build.rs6-10
Sources: kclvm/runner/build.rs1-12 Diagram 6 from high-level architecture, .devcontainer/devcontainer.json
A basic KCL program (samples/fib.k):
A Kubernetes deployment (samples/kubernetes.k):
Sources: samples/fib.k1-15 samples/kubernetes.k1-19
Key external libraries and their purposes:
Category | Dependencies | Purpose |
---|---|---|
Parsing | rustc_lexer , petgraph | Lexical analysis, dependency graphs |
Serialization | serde , serde_json , serde_yaml_ng | JSON/YAML output |
Compilation | LLVM libraries (optional) | Native code generation |
LSP | lsp-server , lsp-types | IDE integration |
Error Reporting | compiler_base_error , annotate-snippets | Diagnostics |
Concurrency | tokio , crossbeam , parking_lot | Async runtime, thread safety |
Sources: kclvm/Cargo.lock1-300 kclvm/parser/Cargo.toml8-36 kclvm/tools/src/LSP/Cargo.toml35-43 kclvm/runtime/Cargo.toml6-37
The project follows standard Rust conventions:
kclvm/
directory containing all cratesdocs/
directory with development guidessamples/
directory with example .k
filescargo build
in target/
.devcontainer/
for GitHub Codespaces supportFor contribution guidelines, see docs/dev_guide/1.about_this_guide.md
Sources: docs/dev_guide/1.about_this_guide.md1-21 .devcontainer/devcontainer.json1-14 README.md75-78
This overview has introduced the KCL system architecture and major components. For deeper dives into specific subsystems:
Sources: Table of contents provided in prompt
Refresh this wiki
This wiki was recently refreshed. Please wait 2 days to refresh again.