kern-project/kern

GitHub: kern-project/kern

Stars: 45 | Forks: 6

Kern
A systems programming language for kernels, firmware, and freestanding software.

English | 简体中文

Install | Quick Start | Examples | Documentation

Kern is designed for low-level software that still wants modern language structure: explicit modules, generics, algebraic data types, traits, exhaustive pattern matching, and a package/build tool that understands freestanding targets. There is no garbage collector, no exceptions, no implicit allocation, and no hidden runtime policy. The standard library is optional layering over `base`, `rt`, and hosted internals, not a compiler requirement. ## Install Linux and macOS: curl -sSf https://raw.githubusercontent.com/kern-project/kern/main/install.sh | bash Windows PowerShell: powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression (Invoke-WebRequest -Uri https://raw.githubusercontent.com/kern-project/kern/main/install.ps1 -UseBasicParsing).Content" The installer bootstraps `kernup`, which installs the SDK under `~/.kern` on Unix and `%USERPROFILE%\.kern` on Windows, then verifies that `kernc`, `craft`, and `kern-lsp` start successfully. If you are using NixOS or otherwise manage your toolchain through Nix, see [docs/nix.md](./docs/nix.md) instead of the shell installer flow. For offline installs, source builds, local SDK archives, and reproducibility details, see [Installing Kern](docs/install.md). ## Quick Start Create a package: mkdir hello cd hello craft init `craft init` creates a minimal package with `Craft.toml` and `src/main.kn`. Edit `src/main.kn`: use std.io; fn main() i32 { "hello, {}!" .fmt(.{"kern"}) .println(); return 0; } Then run it again: craft run Common commands: craft check craft build craft run craft test craft clean Select a package, binary, example, or release profile: craft build -p path/to/package craft run -b my-tool craft run --example smoke craft build --profile release `craft init` starts as a single-package project. Multi-package repositories use a `[workspace]` root that names members, centralizes shared metadata with `[workspace.package]`, and exports selected member packages through `[workspace.exports]`. See [docs/craft.md](docs/craft.md) for the full Craft model. ## Single File For direct compiler use, call `kernc` with explicit runtime and library choices: kernc --runtime-entry rt --library-bundle std examples/hello_world.kn -o hello ./hello Compile only: kernc -c --runtime-entry rt --library-bundle std examples/hello_world.kn -o hello.o Inspect LLVM IR: kernc --emit-llvm --runtime-entry rt --library-bundle std examples/hello_world.kn For full compiler-driver usage, see [docs/kernc.md](docs/kernc.md). ## A Small Taste use std.io; enum ParseResult { Number: i32, Missing, }; fn describe(result: ParseResult) void { match (result) { .{ Number: value } => "number = {}".fmt(.{value}).println(), .Missing => "missing".println(), } } fn main() i32 { describe(.{ Number: 42 }); return 0; } Kern syntax keeps ownership of effects visible: - `let mut value` makes storage mutable. - `&T`, `&mut T`, `^T`, and `^mut T` are explicit pointer values. - `?T` and `T!E` are built-in enum forms, not implicit nullable references or exceptions. - `match` is exhaustive. - Return values cannot be silently ignored. ## Examples The repository carries runnable examples for both hosted and freestanding programs: - [examples](examples): Craft-managed first-learn examples. Build all of them with `craft build --project-path examples --examples`, or run one with `craft run --project-path examples --example hello_world`. - [examples/limine-smoke](examples/limine-smoke): freestanding kernel example that builds a bootable Limine ISO through `craft`. - [examples/limine-mkiso](examples/limine-mkiso): hosted build tool used by the Limine example. Run an example package from the repository root: craft build -p examples/limine-smoke craft run -p examples/limine-mkiso -- --help ## Toolchain Kern ships these tools: - `kernc`: compiler, analysis, object emission, and linking driver. - `craft`: package manager, automatic lockfile synchronizer, and build orchestrator. - `kern-lsp`: language server for editor integration. - `kernlib`: the official library workspace, containing `base`, `rt`, and `std`. Use `craft` when you want package discovery, dependency resolution, build scripts, generated files, or test/example selection. Use `kernc` when you want to drive a specific compile or link action directly. ## Editors The first-party VS Code extension lives in [editors/vscode](editors/vscode). It provides Kern language support, language icons, semantic tokens, completion, hover, diagnostics, rename, code actions, code lenses, document links, folding ranges, selection ranges, inlay hints, and workspace symbols. ## Build From Source For local compiler development: git clone https://github.com/kern-project/kern.git cd kern cargo build --release cargo test This builds `kernc`, `craft`, and `kern-lsp` under `target/release/`. The official library workspace is checked in under `library/`. You can still set `KERNLIB_PATH` to an external compatible library workspace when testing an alternate library snapshot. Repository maintenance commands are moving to Rust host tools. For grouped compiler integration tests, prefer: cargo run -p kernworker -- ci kernc-tests --mode smoke Windows source builds require a full LLVM 21 development prefix, not only the installed end-user SDK. `kernup` installs SDK archives; it does not build Kern from source or add the LLVM development libraries required by `cargo build`. If `cargo build` reports missing LLVM libraries such as `libxml2.lib` or `libxml2s.lib`, follow the Windows source-build setup in [Windows Distribution](docs/windows-distribution.md#local-development-build). For installed SDK layout, local archives, offline installs, and the Rust `kernup` entry point, see [Installing Kern](docs/install.md). ## Documentation - [Documentation Map](docs/documentation-map.md): where each kind of documentation lives. - [Installing Kern](docs/install.md): SDK installation, offline installs, source builds, local archive packaging, and reproducibility checks. - [Kern Tutorial](docs/tutorial/README.md): introductory guided tour through tools, language basics, core semantics, libraries, and freestanding entry points. Also available in [Simplified Chinese](docs/tutorial/zh/README.md). - [Kern Language Design](docs/design.md): current language semantics and syntax. - [Source Style Guide](docs/style.md): repository-level Kern code style. - [The `kernc` Compiler Guide](docs/kernc.md): CLI, linking, LLVM output, and integration details. - [`craft` Package And Build Guide](docs/craft.md): packages, lockfiles, build scripts, generated files, resources, and command behavior. - [Runtime And Library Architecture](docs/runtime-architecture.md): the `base`/`rt`/`std` split and freestanding model. - [Unix Distribution](docs/unix-distribution.md) and [Windows Distribution](docs/windows-distribution.md): platform-specific release packaging policy and host baseline notes. ## License Kern uses a split licensing model. The core toolchain is licensed under GPL-3.0-or-later, while the libraries, installer, shared helper crates, examples, editor extension, and documentation remain MIT. See [Licensing Policy](docs/licensing.md).
标签:通知系统