2
1

adding-packages-cargo.adoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. All the package metadata information variables that exist in the
  53. xref:generic-package-reference[generic package infrastructure] also
  54. exist in the Cargo infrastructure.
  55. A few additional variables, specific to the Cargo infrastructure, can
  56. also be defined. Many of them are only useful in very specific cases,
  57. typical packages will therefore only use a few of them.
  58. * +FOO_SUBDIR+ may contain the name of a subdirectory inside the package
  59. that contains the Cargo.toml file. This is useful, if for example, it
  60. is not at the root of the tree extracted by the tarball. If
  61. +HOST_FOO_SUBDIR+ is not specified, it defaults to +FOO_SUBDIR+.
  62. * +FOO_CARGO_ENV+ can be used to pass additional variables in the
  63. environment of +cargo+ invocations. It used at both build and
  64. installation time
  65. * +FOO_CARGO_BUILD_OPTS+ can be used to pass additional options to
  66. +cargo+ at build time.
  67. * +FOO_CARGO_INSTALL_OPTS+ can be used to pass additional options to
  68. +cargo+ at install time.
  69. A crate can depend on other libraries from crates.io or git
  70. repositories, listed in its +Cargo.toml+ file. Buildroot automatically
  71. takes care of downloading such dependencies as part of the download
  72. step of packages that use the +cargo-package+ infrastructure. Such
  73. dependencies are then kept together with the package source code in
  74. the tarball cached in Buildroot's +DL_DIR+, and therefore the hash of
  75. the package's tarball includes such dependencies.
  76. This mechanism ensures that any change in the dependencies will be
  77. detected, and allows the build to be performed completely offline.