diff --git a/.github/workflows/kcl.yml b/.github/workflows/kcl.yml new file mode 100644 index 000000000..4223f636d --- /dev/null +++ b/.github/workflows/kcl.yml @@ -0,0 +1,11 @@ +name: KCL +on: ["push", "pull_request"] +jobs: + build: + # Ref: https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v2 + with: + submodules: 'true' diff --git a/README-zh.md b/README-zh.md new file mode 100644 index 000000000..6e4059c9c --- /dev/null +++ b/README-zh.md @@ -0,0 +1,94 @@ +

KCL: Constraint-based Record & Functional Language

+ +

+English | 简体中文 +

+

+介绍 | 特性 | 场景 | 安装 | 快速开始 | 文档 | 贡献 | 路线规划 +

+ +

+ + + + + +

+ +## 介绍 + +Kusion 配置语言(KCL)是一个开源的基于约束的记录及函数语言。KCL 通过成熟的编程语言技术和实践来改进对大量繁杂配置的编写,致力于构建围绕配置的更好的模块化、扩展性和稳定性,更简单的逻辑编写,以及更快的自动化集成和良好的生态延展性。 + +## 特性 + ++ **简单易用**:源于 Python、Golang 等高级语言,采纳函数式编程语言特性,低副作用 ++ **设计良好**:独立的 Spec 驱动的语法、语义、运行时和系统库设计 ++ **快速建模**:以 [Schema](https://kusionstack.io/docs/reference/lang/lang/tour#schema) 为中心的配置类型及模块化抽象 ++ **功能完备**:基于 [Config](https://kusionstack.io/docs/reference/lang/lang/codelab/simple)、[Schema](https://kusionstack.io/docs/reference/lang/lang/tour/#schema)、[Lambda](https://kusionstack.io/docs/reference/lang/lang/tour/#%E5%87%BD%E6%95%B0)、[Rule](https://kusionstack.io/docs/reference/lang/lang/tour/#rule) 的配置及其模型、逻辑和策略编写 ++ **可靠稳定**:依赖[静态类型系统](https://kusionstack.io/docs/reference/lang/lang/tour#%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F)、约束和[自定义规则](https://kusionstack.io/docs/reference/lang/lang/tour#rule)的配置稳定性 ++ **强可扩展**:通过独立配置块[自动合并机制](https://kusionstack.io/docs/reference/lang/lang/tour#%E9%85%8D%E7%BD%AE%E6%93%8D%E4%BD%9C)保证配置编写的高可扩展性 ++ **易自动化**:[CRUD APIs](https://kusionstack.io/docs/reference/lang/lang/tour#kcl-%E5%8F%98%E9%87%8F%E4%BF%AE%E6%94%B9),[多语言 SDK](https://kusionstack.io/docs/reference/lang/xlang-api/overview),[语言插件](https://github.com/KusionStack/kcl-plugin) 构成的梯度自动化方案 ++ **极致性能**:使用 Rust & C,[LLVM](https://llvm.org/) 实现,支持编译到本地代码和 [WASM](https://webassembly.org/) 的高性能编译时和运行时 ++ **API 亲和**:原生支持 [OpenAPI](https://github.com/KusionStack/kcl-openapi)、 Kubernetes CRD, Kubernetes YAML 等 API 生态规范 ++ **开发友好**:[语言工具](https://kusionstack.io/docs/reference/cli/kcl/) (Format,Lint,Test,Vet,Doc 等)、 [IDE 插件](https://github.com/KusionStack/vscode-kcl) 构建良好的研发体验 ++ **安全可控**:面向领域,不原生提供线程、IO 等系统级功能,低噪音,低安全风险,易维护,易治理 + +## 场景 + +您可以将 KCL 用于 + ++ 生成静态配置数据如 JSON, YAML 等 ++ 使用 schema 对配置数据进行建模并减少配置数据中的样板文件 ++ 为配置数据定义带有规则约束的 schema 并对数据进行自动验证 ++ 无副作用地组织、简化、统一和管理庞大的配置 ++ 通过分块编写配置数据可扩展地管理庞大的配置 ++ 与 [Kusion Stack](https://kusionstack.io) 一起,用作平台工程语言来交付现代应用程序 + +## 安装 + +从 Github releases 页面[下载](https://github.com/KusionStack/KCLVM/releases),并且将 `{install-location}/kclvm/bin` 添加到您的环境变量中 + +## 快速开始 + +`./samples/fib.k` 是一个计算斐波那契数列的例子 + +```kcl +schema Fib: + n1 = n - 1 + n2 = n1 - 1 + n: int + value: int + + if n <= 1: + value = 1 + elif n == 2: + value = 1 + else: + value = Fib {n = n1}.value + Fib {n = n2}.value + +fib8 = Fib {n = 8}.value +``` + +我们可以通过执行如下命令得到 YAML 输出 + +``` +kcl ./samples/fib.k +``` + +YAML 输出 + +```yaml +fib8: 21 +``` + +## 文档 + +更多文档请访问[语言手册](https://kusionstack.io/docs/reference/lang/lang/tour) + +## 贡献 + +参考[开发手册](./docs/dev_guide/1.about_this_guide.md). + +## 路线规划 + +参考[KCLVM 路线规划](https://kusionstack.io/docs/governance/intro/roadmap#kclvm-%E8%B7%AF%E7%BA%BF%E8%A7%84%E5%88%92) diff --git a/README.md b/README.md index 14e3de166..8a7aa70cc 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,61 @@ -# KCL +

KCL: Constraint-based Record & Functional Language

-![license](https://img.shields.io/badge/license-Apache--2.0-green.svg) -[![Continuous Integration](https://github.com/KusionStack/KCLVM/actions/workflows/github-actions.yaml/badge.svg)](https://github.com/KusionStack/KCLVM/actions?query=branch%3Amain) +

+English | 简体中文 +

+

+Introduction | Features | What is it for | Installation | Showcase | Documentation | Contributing | Roadmap +

-[中文](./README_ZH.md) +

+ + + + + +

-Kusion Configuration Language (KCL) is an open source configuration language mainly used in [Kusion Stack](https://kusionstack.io). KCL is a statically typed language for configuration and policy scenarios, based on concepts such as declarative and Object-Oriented Programming (OOP) paradigms. +## Introduction -## Core Features +Kusion Configuration Language (KCL) is an open source constraint-based record and functional language. KCL improves the writing of a large number of complex configurations through mature programming language technology and practice, and is committed to building better modularity, scalability and stability around configuration, simpler logic writing, fast automation and good ecological extensionality. -+ **Simple** - + Originated from Python and Golang, incorporating functional language features. - + Absorbs integrated language elements such as statements, expressions, conditions, loops, etc. - + Type and data separation, schema declaration configuration definition. -+ **Stable** - + Strong immutable constraint. - + Compile-time type deduction, type checking. - + Rule policy definition: attribute-centric constraint expressions, query results based on constraints. - + Testable: assert, print, and test tools. -+ **Scalable** - + Configuration unification: compile-time configuration dependency graph substitution. - + Configuration attribute operators: meet the needs of configuration override, merge, add and delete, etc. - + Configuration reuse: rich built-in data structures and syntax semantics, easily to expand one configuration of different scenarios. -+ **Engineering** - + Schema single inheritance and declarative model reuse and assembly. - + Tool & API granular configuration automation. - + Rich built-in functions and system libraries. - + Top-level dynamic data input. - + Code organization: modules and packages. - + [Plug-in system](https://github.com/KusionStack/kcl-plugin): reuse common programming language ecology. - + [OpenAPI model support](https://github.com/KusionStack/kcl-openapi): Swagger and KCL schema bidirectional conversion, Kubernetes CRD conversion to KCL schema. -+ **High Performance** - + Works with the LLVM optimizer, supports compilation to native code and formats like WASM and executes efficiently. +## Features -## Installing & Documentation ++ **Easy-to-use**: Originated from high-level languages ​​such as Python and Golang, incorporating functional language features with low side effects. ++ **Well-designed**: Independent Spec-driven syntax, semantics, runtime and system modules design. ++ **Quick modeling**: [Schema](https://kusionstack.io/docs/reference/lang/lang/tour#schema)-centric configuration types and modular abstraction. ++ **Rich capabilities**: Configuration with type, logic and policy based on [Config](https://kusionstack.io/docs/reference/lang/lang/codelab/simple), [Schema](https://kusionstack.io/docs/reference/lang/lang/tour/#schema), [Lambda](https://kusionstack.io/docs/reference/lang/lang/tour/#%E5%87%BD%E6%95%B0), [Rule](https://kusionstack.io/docs/reference/lang/lang/tour/#rule). ++ **Stability**: Configuration stability built on [static type system](https://kusionstack.io/docs/reference/lang/lang/tour/#%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F), constraints, and [rules](https://kusionstack.io/docs/reference/lang/lang/tour#rule). ++ **Scalability**: High scalability through [automatic merge mechanism](https://kusionstack.io/docs/reference/lang/lang/tour#%E9%85%8D%E7%BD%AE%E6%93%8D%E4%BD%9C) of isolated config blocks. ++ **Fast automation**: Gradient automation scheme of [CRUD APIs](https://kusionstack.io/docs/reference/lang/lang/tour#kcl-%E5%8F%98%E9%87%8F%E4%BF%AE%E6%94%B9), [multilingual SDKs](https://kusionstack.io/docs/reference/lang/xlang-api/overview), [language plugin](https://github.com/KusionStack/kcl-plugin) ++ **High performance**: High compile time and runtime performance using Rust & C and [LLVM](https://llvm.org/), and support compilation to native code and [WASM](https://webassembly.org/). ++ **API affinity**: Native support API ecological specifications such as [OpenAPI](https://github.com/KusionStack/kcl-openapi), Kubernetes CRD, Kubernetes YAML spec. ++ **Development friendly**: Friendly development experiences with rich [language tools](https://kusionstack.io/docs/reference/cli/kcl/) (Format, Lint, Test, Vet, Doc, etc.) and [IDE plugins](https://github.com/KusionStack/vscode-kcl). ++ **Safety & maintainable**: Domain-oriented, no system-level functions such as native threads and IO, low noise and security risk, easy maintenance and governance. -### How to install +## What is it for? -[Download](https://github.com/KusionStack/KCLVM/releases) the latest release from GitHub and add `{install-location}/kclvm/bin` to environment PATH. +You can use KCL to -### Quick Showcase ++ Generate low-level static configuration data like JSON, YAML, etc. ++ Reduce boilerplate in configuration data with the schema modeling. ++ Define schemas with rule constraints for configuration data and validate them automatically. ++ Organize, simplify, unify and manage large configurations without side effects. ++ Manage large configurations scalably with isolated configuration blocks. ++ Used as a platform engineering lang to deliver modern app with [Kusion Stack](https://kusionstack.io). + +## Installation + +[Download](https://github.com/KusionStack/KCLVM/releases) the latest release from GitHub and add `{install-location}/kclvm/bin` to the environment `PATH`. + +## Showcase `./samples/fib.k` is an example of calculating the Fibonacci sequence. ```kcl schema Fib: - n1: int = n - 1 - n2: int = n1 - 1 + n1 = n - 1 + n2 = n1 - 1 n: int value: int @@ -55,9 +64,9 @@ schema Fib: elif n == 2: value = 1 else: - value = Fib {n: n1}.value + Fib {n: n2}.value + value = Fib {n = n1}.value + Fib {n = n2}.value -fib8 = Fib {n: 8}.value +fib8 = Fib {n = 8}.value ``` We can execute the following command to get a YAML output. @@ -72,20 +81,14 @@ YAML output fib8: 21 ``` -### Documentation +## Documentation -Detailed documentation is available at https://kusionstack.io +Detailed documentation is available at [KCL tour](https://kusionstack.io/docs/reference/lang/lang/tour) -## Developing & Contributing - -### Developing +## Contributing See [Developing Guide](./docs/dev_guide/1.about_this_guide.md). -### Roadmap - -See [KCLVM Roadmap](https://kusionstack.io/docs/governance/intro/roadmap#kclvm-%E8%B7%AF%E7%BA%BF%E8%A7%84%E5%88%92) - -## License +## Roadmap -Apache License Version 2.0 +See [KCLVM Roadmap](https://kusionstack.io/docs/governance/intro/roadmap#kclvm-%E8%B7%AF%E7%BA%BF%E8%A7%84%E5%88%92). diff --git a/README_ZH.md b/README_ZH.md deleted file mode 100644 index 948d10b8d..000000000 --- a/README_ZH.md +++ /dev/null @@ -1,91 +0,0 @@ -# KCL - -![license](https://img.shields.io/badge/license-Apache--2.0-green.svg) -[![Continuous Integration](https://github.com/KusionStack/KCLVM/actions/workflows/github-actions.yaml/badge.svg)](https://github.com/KusionStack/KCLVM/actions?query=branch%3Amain) - -[English](./README.md) - -Kusion 配置语言(KCL)是一种开源配置语言,主要用于 [Kusion Stack](https://kusionstack.io) 开放协同技术栈。并且 KCL 是一种基于声明性和面向对象编程 (OOP) 范式等概念,用于配置和策略场景的静态类型语言。 - -## 核心特性 - -+ **简单** - + 源于 Python、Golang,融入函数语言特性 - + 吸收语句、表达式、条件、循环等语言元素 - + 类型和数据分离,Schema 声明配置定义 -+ **稳定** - + 强不可变约束 - + 编译时类型推导、类型检查 - + Rule 策略定义:以属性为中心的约束表达式、根据约束查询结果 - + 可测试:语言内置 assert 断言、print 打印和测试工具 -+ **可扩展** - + 配置合并:编译时配置依赖图代换 - + 配置属性运算符:满足配置覆盖、合并、添加和删除等需求 - + 配置复用:丰富的内置数据结构和语法语义,轻松扩展同一份配置到不同场景 -+ **工程化** - + Schema 单一继承和声明性模型复用和组装 - + 工具和API 粒度的配置自动化“增删改查” - + 丰富的内置函数和系统库 - + 顶层数据动态导入 - + 代码组织:模块和包 - + [插件系统](https://github.com/KusionStack/kcl-plugin):复用通用编程语言生态。 - + [OpenAPI 模型支持](https://github.com/KusionStack/kcl-openapi):Swagger 与 Schema 双向转换,Kubernetes CRD 转换为 Schema -+ **高性能** - + 配合 LLVM 优化器、支持编译到本地代码和 WASM 等格式并高效执行 - -## 安装 & 文档 - -### 如何安装 - -从 Github releases 页面[下载](https://github.com/KusionStack/KCLVM/releases),并且将 `{install-location}/kclvm/bin` 添加到您的环境变量中 - -### 快速开始 - -`./samples/fib.k` 是一个计算斐波那契数列的例子 - -```kcl -schema Fib: - n1: int = n - 1 - n2: int = n1 - 1 - n: int - value: int - - if n <= 1: - value = 1 - elif n == 2: - value = 1 - else: - value = Fib {n: n1}.value + Fib {n: n2}.value - -fib8 = Fib {n: 8}.value -``` - -我们可以通过执行如下命令得到 YAML 输出 - -``` -kcl ./samples/fib.k -``` - -YAML 输出 - -```yaml -fib8: 21 -``` - -### 文档 - -更多文档请访问 https://kusionstack.io - -## 开发 & 贡献 - -### 开发 - -参考[开发手册](./docs/dev_guide/1.about_this_guide.md). - -### 路线规划 - -参考[KCLVM 路线规划](https://kusionstack.io/docs/governance/intro/roadmap#kclvm-%E8%B7%AF%E7%BA%BF%E8%A7%84%E5%88%92) - -## 许可 - -Apache License Version 2.0 diff --git a/samples/fib.k b/samples/fib.k index fcb164f58..96926c055 100644 --- a/samples/fib.k +++ b/samples/fib.k @@ -1,6 +1,6 @@ schema Fib: - n1: int = n - 1 - n2: int = n1 - 1 + n1 = n - 1 + n2 = n1 - 1 n: int value: int @@ -9,6 +9,6 @@ schema Fib: elif n == 2: value = 1 else: - value = Fib {n: n1}.value + Fib {n: n2}.value + value = Fib {n = n1}.value + Fib {n = n2}.value -fib8 = Fib {n: 8}.value +fib8 = Fib {n = 8}.value