crate_universe: declare a crate's identity and license as package metadata (#4455)

This change makes `generate_rules_license_metadata` declare every
generated crate through the `package_metadata` module: a
`package_metadata` target with the crate's `purl`,
`pkg:cargo/<name>@<version>`, which the package's
`default_package_metadata` attaches to every target of the crate, and a
`license` attribute with the SPDX kind of the crate's license and its
license text when the crate ships one. The module records one license
per package and has no model for a choice of licenses yet, so a crate
offered under several is recorded under the first of them the module has
a kind for. Each hub subpackage aliases both targets, so
`@crates//serde:license` and `@crates//serde:package_metadata` name
serde's. Generated BUILD files load the rules through
`@rules_rust//crate_universe/private:package_metadata.bzl`, like
everything else they load. The purl is a literal: a crate name needs no
encoding and of a version only the `+` before build metadata does, which
is written `%2B` as the module's builder would. rules_rust depends on
`package_metadata` in place of rules_license, whose rules it rendered
before.

A kind must exist as a target, and the module does not export the BUILD
file declaring them, so the `spdx_license_kinds` repository of the
development extension reads it and records the names in `kinds.json`.
`spdx_license_kinds_diff_test` keeps
`src/rendering/spdx_license_kinds.json` in step with it and
`spdx_license_kinds.install` updates the table, replacing the generated
table's subcommand.

The setting stays off by default: the lockfile digest covers the render
settings, so turning it on for everyone would repin every workspace on
upgrade.
32 files changed
tree: 7b9ab635e63757cd7436b41912723118569f67af
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cargo/
  5. crate_universe/
  6. docs/
  7. examples/
  8. extensions/
  9. ffi/
  10. nix/
  11. rust/
  12. test/
  13. tools/
  14. util/
  15. .bazelignore
  16. .bazelrc
  17. .clang-format
  18. .clippy.toml
  19. .envrc
  20. .gitattributes
  21. .gitignore
  22. .pre-commit-config.yaml
  23. .prettierrc.toml
  24. .rustfmt.toml
  25. .typos.toml
  26. ARCHITECTURE.md
  27. AUTHORS
  28. BUILD.bazel
  29. CODEOWNERS
  30. COMPATIBILITY.md
  31. CONTRIBUTING.md
  32. CONTRIBUTORS
  33. LICENSE.txt
  34. MODULE.bazel
  35. README.md
  36. version.bzl
  37. WORKSPACE.bazel
README.md

Rust Rules

  • Postsubmit Build status

Overview

This repository provides rules for building Rust projects with Bazel.

Starter repo

The fastest way to try this in an empty project is to click the green “Use this template” button on https://github.com/bazel-starters/rust.

Community

General discussions and announcements take place in the GitHub Discussions, but there are additional places where community members gather to discuss rules_rust.

Documentation

Please refer to the full documentation.