# 使用 Homebrew, Nix 安装 cargo-component

查看 cargo-component 的安装路径、可执行文件、元数据以及面向 AI 代理工作流的安全说明。

## 安装

```sh
sudo av install brew:cargo-component
```

其他安装命令:

### macOS

- Homebrew (100%):

```sh
brew install cargo-component
```

  证据: local Homebrew formula metadata

### Linux

- Nix (92%):

```sh
nix profile install nixpkgs#cargo-component
```

  证据: nixpkgs package indexes: pkgs/by-name/ca/cargo-component/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1

## 软件包事实

- **软件包键:** brew:cargo-component
- **软件包管理器:** Homebrew
- **版本:** 0.21.1
- **来源摘要:** Create WebAssembly components based on the component model proposal
- **主页:** <https://github.com/bytecodealliance/cargo-component>
- **仓库:** <https://github.com/bytecodealliance/cargo-component>
- **已生成:** 2026-08-03T19:37:03+00:00

## 可执行文件

- cargo-component (别名)

## 安装行为

- Bottle: 不可用

## 版本和新鲜度

- 页面生成时间: 2026-08-03
- 管理器版本: 0.21.1
## 项目历史与用法

cargo-component is a Bytecode Alliance Cargo subcommand for creating WebAssembly components from Rust projects. It exists to bridge Cargo workflows with the WebAssembly component model, WIT interfaces, generated bindings, and component dependencies.

### 项目历史

The repository was created in 2022 under the Bytecode Alliance. Its README describes cargo-component as an experimental attempt to imagine what first-class Rust support for WebAssembly components might look like before Cargo itself has native component-model support.

The project grew alongside Bytecode Alliance work on the WebAssembly component model, wit-bindgen, Wasmtime, and WASI Preview 2. It uses Cargo.toml metadata and generates Rust bindings so component interfaces can be used in a Cargo-like development loop.

### 采用历史

Adoption has followed the WebAssembly component-model community rather than general Rust CLI usage. crates.io metadata shows hundreds of thousands of downloads by June 2026, and Homebrew and Nix packaging make it easier to install for component-model experiments and CI builds.

The README notes that Rust's upstream wasm32-wasip2 target now produces components for some WASI use cases, leaving cargo-component most relevant where projects need non-WASI WIT interfaces, component dependencies, or features not yet covered by plain Cargo.

### 使用方式

The documented flow starts with `cargo component new --lib <name>` or a command component, creates a `wit/world.wit` interface, implements generated bindings in Rust, and builds with `cargo component build`.

The tool can also add and update component interface dependencies through Cargo.toml, and it supports adapter configuration in `[package.metadata.component]` for WASI Preview 1 to Preview 2 adaptation.

### 为什么软件包爱好者会关心

cargo-component is significant because it treats WebAssembly components as packageable dependencies inside Cargo projects. For package ecosystem watchers, it is a live example of how Rust's package manager might evolve when language packages and portable component interfaces meet.

It also marks a transitional period: component-model tooling is moving quickly, and the README explicitly frames cargo-component as useful until more support lands in the Rust compiler and Cargo.

### 时间线

- 2021: crates.io records an initial cargo-component publication.
- 2022: GitHub repository created under bytecodealliance/cargo-component.
- 2024: README references Rust 1.82 adding the upstream wasm32-wasip2 target.
- 2025: GitHub releases show the 0.21.x series.

### Related projects

- The WebAssembly component model defines the component format cargo-component targets.
- wit-bindgen generates bindings for WIT interfaces and is closely related to cargo-component's generated Rust bindings.
- Wasmtime supplies WASI adapter work referenced by the README.
- Rust's wasm32-wasip2 target is an upstream alternative for some WASI-only component builds.

### 来源

- <https://api.github.com/repos/bytecodealliance/cargo-component>
- <https://crates.io/api/v1/crates/cargo-component>
- <https://github.com/bytecodealliance/cargo-component#readme>


## 安全说明

narrow executable package without higher-risk signals.

- **Geiger 风险:** 绿色 / 低
- narrow executable package without higher-risk signals


## Configuration and credential file locations

These source-backed paths show where this package keeps local settings or durable credentials. Automic Vault can use them as review targets for secret scanning, migration, and command approval.


## Configuration files

- Unix: Cargo.toml, .vscode/settings.json
## 其他软件包管理器记录

- Nix - cargo-component: normalized package name match | nixpkgs package indexes: pkgs/by-name/ca/cargo-component/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1


## 相关链接

- [cargo-component](https://pkg.so/zh-hans/pkg/cargo/cargo-component/) - Same normalized package name exists in another local package ecosystem.

## Combined YAML source

View the package source record on GitHub. [combined/cargo-component.yml](https://github.com/mxcl/pkgdb/blob/main/combined/cargo-component.yml)


## 来源

- pkg.so package database
- Geiger risk classifier
- curated configuration and credential file locations
- curated package history
- pkgdb category and tag curation
- external package-manager database matches
- cross-ecosystem install command graph
