adding-packages-cargo.adoc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. === Infrastructure for Cargo-based packages
  4. Cargo is the package manager for the Rust programming language. It allows the
  5. user to build programs or libraries written in Rust, but it also downloads and
  6. manages their dependencies, to ensure repeatable builds. Cargo packages are
  7. called "crates".
  8. [[cargo-package-tutorial]]
  9. ==== +cargo-package+ tutorial
  10. The +Config.in+ file of Cargo-based package 'foo' should contain:
  11. ---------------------------
  12. 01: config BR2_PACKAGE_FOO
  13. 02: bool "foo"
  14. 03: depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
  15. 04: select BR2_PACKAGE_HOST_RUSTC
  16. 05: help
  17. 06: This is a comment that explains what foo is.
  18. 07:
  19. 08: http://foosoftware.org/foo/
  20. ---------------------------
  21. And the +.mk+ file for this package should contain:
  22. ------------------------------
  23. 01: ################################################################################
  24. 02: #
  25. 03: # foo
  26. 04: #
  27. 05: ################################################################################
  28. 06:
  29. 07: FOO_VERSION = 1.0
  30. 08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
  31. 09: FOO_SITE = http://www.foosoftware.org/download
  32. 10: FOO_LICENSE = GPL-3.0+
  33. 11: FOO_LICENSE_FILES = COPYING
  34. 12:
  35. 13: $(eval $(cargo-package))
  36. --------------------------------
  37. The Makefile starts with the definition of the standard variables for
  38. package declaration (lines 7 to 11).
  39. As seen in line 13, it is based on the +cargo-package+
  40. infrastructure. Cargo will be invoked automatically by this
  41. infrastructure to build and install the package.
  42. It is still possible to define custom build commands or install
  43. commands (i.e. with FOO_BUILD_CMDS and FOO_INSTALL_TARGET_CMDS).
  44. Those will then replace the commands from the cargo infrastructure.
  45. ==== +cargo-package+ reference
  46. The main macros for the Cargo package infrastructure are
  47. +cargo-package+ for target packages and +host-cargo-package+ for host
  48. packages.
  49. Just like the generic infrastructure, the Cargo infrastructure works
  50. by defining a number of variables before calling the +cargo-package+
  51. or +host-cargo-package+ macros.
  52. First, all the package metadata information variables that exist in
  53. the generic infrastructure also exist in the Cargo infrastructure:
  54. +FOO_VERSION+, +FOO_SOURCE+, +FOO_PATCH+, +FOO_SITE+,
  55. +FOO_DEPENDENCIES+, +FOO_LICENSE+, +FOO_LICENSE_FILES+, etc.
  56. A few additional variables, specific to the Cargo infrastructure, can
  57. also be defined. Many of them are only useful in very specific cases,
  58. typical packages will therefore only use a few of them.
  59. * +FOO_SUBDIR+ may contain the name of a subdirectory inside the package
  60. that contains the Cargo.toml file. This is useful, if for example, it
  61. is not at the root of the tree extracted by the tarball. If
  62. +HOST_FOO_SUBDIR+ is not specified, it defaults to +FOO_SUBDIR+.
  63. * +FOO_CARGO_ENV+ can be used to pass additional variables in the
  64. environment of +cargo+ invocations. It used at both build and
  65. installation time
  66. * +FOO_CARGO_BUILD_OPTS+ can be used to pass additional options to
  67. +cargo+ at build time.
  68. * +FOO_CARGO_INSTALL_OPTS+ can be used to pass additional options to
  69. +cargo+ at install time.
  70. A crate can depend on other libraries from crates.io or git
  71. repositories, listed in its +Cargo.toml+ file. Buildroot automatically
  72. takes care of downloading such dependencies as part of the download
  73. step of packages that use the +cargo-package+ infrastructure. Such
  74. dependencies are then kept together with the package source code in
  75. the tarball cached in Buildroot's +DL_DIR+, and therefore the hash of
  76. the package's tarball includes such dependencies.
  77. This mechanism ensures that any change in the dependencies will be
  78. detected, and allows the build to be performed completely offline.