2018-02-04 19:07:48 +01:00
|
|
|
// -*- mode:doc; -*-
|
|
|
|
// vim: set syntax=asciidoc:
|
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
=== Infrastructure for Cargo-based packages
|
2018-02-04 19:07:48 +01:00
|
|
|
|
|
|
|
Cargo is the package manager for the Rust programming language. It allows the
|
|
|
|
user to build programs or libraries written in Rust, but it also downloads and
|
|
|
|
manages their dependencies, to ensure repeatable builds. Cargo packages are
|
|
|
|
called "crates".
|
|
|
|
|
|
|
|
[[cargo-package-tutorial]]
|
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
==== +cargo-package+ tutorial
|
2018-02-04 19:07:48 +01:00
|
|
|
|
|
|
|
The +Config.in+ file of Cargo-based package 'foo' should contain:
|
|
|
|
|
2024-07-12 20:23:24 +02:00
|
|
|
----
|
2018-02-04 19:07:48 +01:00
|
|
|
01: config BR2_PACKAGE_FOO
|
|
|
|
02: bool "foo"
|
2019-10-05 23:45:10 +02:00
|
|
|
03: depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
|
2020-02-07 19:08:27 +01:00
|
|
|
04: select BR2_PACKAGE_HOST_RUSTC
|
2018-02-04 19:07:48 +01:00
|
|
|
05: help
|
|
|
|
06: This is a comment that explains what foo is.
|
|
|
|
07:
|
|
|
|
08: http://foosoftware.org/foo/
|
2024-07-12 20:23:24 +02:00
|
|
|
----
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
And the +.mk+ file for this package should contain:
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2024-07-12 20:23:24 +02:00
|
|
|
----
|
2018-02-04 19:07:48 +01:00
|
|
|
01: ################################################################################
|
|
|
|
02: #
|
|
|
|
03: # foo
|
|
|
|
04: #
|
|
|
|
05: ################################################################################
|
|
|
|
06:
|
|
|
|
07: FOO_VERSION = 1.0
|
|
|
|
08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
|
|
|
|
09: FOO_SITE = http://www.foosoftware.org/download
|
2018-04-05 20:13:24 +02:00
|
|
|
10: FOO_LICENSE = GPL-3.0+
|
2018-02-04 19:07:48 +01:00
|
|
|
11: FOO_LICENSE_FILES = COPYING
|
|
|
|
12:
|
2020-12-19 16:35:21 +01:00
|
|
|
13: $(eval $(cargo-package))
|
2024-07-12 20:23:24 +02:00
|
|
|
----
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
The Makefile starts with the definition of the standard variables for
|
|
|
|
package declaration (lines 7 to 11).
|
|
|
|
|
|
|
|
As seen in line 13, it is based on the +cargo-package+
|
|
|
|
infrastructure. Cargo will be invoked automatically by this
|
|
|
|
infrastructure to build and install the package.
|
|
|
|
|
|
|
|
It is still possible to define custom build commands or install
|
|
|
|
commands (i.e. with FOO_BUILD_CMDS and FOO_INSTALL_TARGET_CMDS).
|
|
|
|
Those will then replace the commands from the cargo infrastructure.
|
|
|
|
|
|
|
|
==== +cargo-package+ reference
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
The main macros for the Cargo package infrastructure are
|
|
|
|
+cargo-package+ for target packages and +host-cargo-package+ for host
|
|
|
|
packages.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
Just like the generic infrastructure, the Cargo infrastructure works
|
|
|
|
by defining a number of variables before calling the +cargo-package+
|
|
|
|
or +host-cargo-package+ macros.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
docs/manual: standardize references to the generic infra
Currently the text for each package infra that mentions the usage of
variables already provided by the generic infra diverge from each other:
- some (golang, kconfig, python) add a cross-referece to the generic
infra chapter;
- kconfig does not list any example;
- some mention _LICENSE as an example, others don't;
- some (cargo, golang, python) add an 'etc.' at the end of the examples,
giving the idea that can be more symbols provided by the generic
infra than the ones listed;
- most have the text 'works by defining a number of variables before
calling the +<macro-name>+ macro', except golang and kconfig;
- some actually list 'A few additional variables' but keep using some
old reference as 'An additional variable';
- some say 'First, all the package metadata' and other only 'All the
package metadata';
- most mention _SUBDIR as an example of variable supported by the
generic infra, even the generic infra manual not mentioning it.
Improve the correctness for the manual by standardizing the text among
the package infras:
- use the same text "All the package metadata information variables that
exist in the generic package infrastructure also exist in the
<name> infrastructure:" for all of them;
- add the cross-reference for all of them;
- remove the examples of variables inherited from the generic infra -
this also solves the _SUBDIR problem, there no longer is any reference
to _SUBDIR;
- wrap the modified text at 80 columns;
- add "macro" to golang and luarocks infra;
- use "A few additional variables" for qmake and waf.
At same time, add a missing format on golang manual for
BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS.
Cc: Eric Le Bihan <eric.le.bihan.dev@free.fr>
Cc: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
[Arnout:
- remove the examples;
- add "the" where "macro" was added;
- rewrite the preceding paragraphs for kconfig to make it more
consistent.
]
Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
(cherry picked from commit 4286c89f9d987f5f3bcbb14dfd58ba440944f4c2)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2023-01-02 00:36:53 +01:00
|
|
|
All the package metadata information variables that exist in the
|
|
|
|
xref:generic-package-reference[generic package infrastructure] also
|
|
|
|
exist in the Cargo infrastructure.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
A few additional variables, specific to the Cargo infrastructure, can
|
|
|
|
also be defined. Many of them are only useful in very specific cases,
|
|
|
|
typical packages will therefore only use a few of them.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2022-02-10 16:29:25 +01:00
|
|
|
* +FOO_SUBDIR+ may contain the name of a subdirectory inside the package
|
|
|
|
that contains the Cargo.toml file. This is useful, if for example, it
|
|
|
|
is not at the root of the tree extracted by the tarball. If
|
|
|
|
+HOST_FOO_SUBDIR+ is not specified, it defaults to +FOO_SUBDIR+.
|
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
* +FOO_CARGO_ENV+ can be used to pass additional variables in the
|
|
|
|
environment of +cargo+ invocations. It used at both build and
|
|
|
|
installation time
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
* +FOO_CARGO_BUILD_OPTS+ can be used to pass additional options to
|
|
|
|
+cargo+ at build time.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
* +FOO_CARGO_INSTALL_OPTS+ can be used to pass additional options to
|
|
|
|
+cargo+ at install time.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
A crate can depend on other libraries from crates.io or git
|
|
|
|
repositories, listed in its +Cargo.toml+ file. Buildroot automatically
|
|
|
|
takes care of downloading such dependencies as part of the download
|
|
|
|
step of packages that use the +cargo-package+ infrastructure. Such
|
|
|
|
dependencies are then kept together with the package source code in
|
|
|
|
the tarball cached in Buildroot's +DL_DIR+, and therefore the hash of
|
|
|
|
the package's tarball includes such dependencies.
|
2018-02-04 19:07:48 +01:00
|
|
|
|
2020-12-19 16:35:21 +01:00
|
|
|
This mechanism ensures that any change in the dependencies will be
|
|
|
|
detected, and allows the build to be performed completely offline.
|