> For the complete documentation index, see [llms.txt](https://zenofchain.gitbook.io/sway-bian-cheng-yu-yan-geng-xin-zhong-the-sway-programming-languageupdatin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zenofchain.gitbook.io/sway-bian-cheng-yu-yan-geng-xin-zhong-the-sway-programming-languageupdatin/11.-forc-yin-yong-forc-reference/11.3-yi-lai-dependencies.md).

# 11.3 依赖(Dependencies)

Forc has a dependency management system which can pull packages using git. This allows users to build and share Forc libraries.

Forc 有一个依赖管理系统，可以使用 git 拉取包。这允许用户构建和共享 Forc 库。

### 添加依赖 (Adding a dependency)

If your `Forc.toml` doesn't already have a `[dependencies]` table, add one. Below, list the package name alongside its source. Currently, `forc` supports both `git` and `path` sources.

如果您的`Forc.toml`还没有`[依赖]`表，那就请添加一个。下面列出了包名称及其来源。目前，`forc`支持`git`和`path`源。

If a `git` source is specified, `forc` will fetch the git repository at the given URL and then search for a `Forc.toml` for a package with the given name anywhere inside the git repository.

如果指定了 `git` 源，`forc`将在给定 URL 处获取 git 存储库，然后在 git 存储库中的任意位置搜索具有给定名称的包的`Forc.toml`。

The following example adds a library dependency named `custom_lib`. For git dependencies you may optionally specify a `branch`, `tag`, or `rev` (i.e. commit hash) reference.

以下示例添加名为`custom_lib`的库依赖项。对于 `git` 依赖项，您可以选择指定`branch`、`tag`或`rev`（即提交哈希）引用。

```
[dependencies]
custom_lib = { git = "https://github.com/FuelLabs/custom_lib", branch = "master" }
# custom_lib = { git = "https://github.com/FuelLabs/custom_lib", tag = "v0.0.1" }
# custom_lib = { git = "https://github.com/FuelLabs/custom_lib", rev = "87f80bdf323e2d64e213895d0a639ad468f4deff" }

```

Depending on a local library using `path`:

取决于使用`path`的本地库：

```
[dependencies]
custom_lib = { path = "../custom_lib" }

```

Once the package is added, running `forc build` will automatically download added dependencies.

添加包后，运行`forc build`将自动下载添加的依赖。

### 更新依赖 (Updating dependencies)

To update dependencies in your Forc directory you can run `forc update`. For `path` dependencies this will have no effect. For `git` dependencies with a `branch` reference, this will update the project to use the latest commit for the given branch.

要更新  `Forc` 目录中的依赖，您可以运行“`forc update` 。对于 `路径` 依赖项，这不会产生任何影响。对于具有 `branch` 引用的 `git` 依赖项，这将更新项目，进而使用给定分支的最新提交。
