#tarball #compliance #macro #const #repo #git #agpl

include-repo

此crate实现了'include_repo!'宏,以便轻松实现AGPL合规性!在您的代码中将tarball作为const包含!

2个版本 (1个稳定版)

1.0.0 2021年4月25日
0.1.0 2018年8月30日

过程宏中排名第589

每月下载量22

AGPL-3.0-only

18KB
69

include-repo

include_repo rust crate提供了一个宏,可以将项目git仓库中的所有文件嵌入到最终的可执行文件中。它不嵌入git历史或元数据,而是包含一个tarball,就像git archive生成的tarball一样。

为什么您可能需要这个?我想到的主要用例(实际上这是我创建它的原因)是提供一个AGPL合规性端点。

如果源代码已经内置到二进制文件中,提供软件的源代码是非常简单的。

用法

此crate易于使用。只需在您的代码中的某个位置包含以下内容

use include:repo::include_repo;

const SOURCE_CODE: &[u8] = include_repo!();
// Expands to:
// const SOURCE_CODE: &[u8] = [128, 80, ...];
// The bag of bytes is a tarball, so serve it with a .tar extension please!

如果您不想包含所有的文件,这也是可能的。例如,如果您不想包含'img'和'third_party'文件夹中的内容,可以这样操作

use include:repo::include_repo;

const SOURCE_CODE: &[u8] = include_repo!(".", ":!/img/", ":!/third_party");
// Any valid pathspec (see
// https://git-scm.cn/docs/gitglossary#gitglossary-aiddefpathspecapathspec) may
// be used. Pathspecs *must* be string literals. Any number may be provided to
// the macro.
// The "." portion is optional on newer versions of git, but for backwards
// compatibility it's best to add it if all other pathspecs are exclusions.

如果您想对tarball进行gzip压缩,请使用include_repo_gz!宏。如果您在二进制文件中还没有包含gzip解压缩,当请求源代码时,通过tar -xzv -f -更容易,或者向用户提供.tar.gz文件。

假设

以下假设必须成立,此crate才能正确工作

  • 您使用git进行版本控制,并在您的PATH中有一个现代版本的git
  • 您希望以tarball(可选gzip压缩)的形式提供源代码,而不是zip或其他格式
  • 您希望将代码作为巨型const嵌入到二进制文件中(例如,不是磁盘上的静态文件)
  • 您不介意构建过程中运行'git'的proc宏

许可协议

此代码在AGPL协议下方便地可用。

依赖项

~2MB
~42K SLoC