buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
To: James Hilliard <james.hilliard1@gmail.com>,
	Christian Stewart <christian@paral.in>,
	Buildroot List <buildroot@buildroot.org>,
	Matt Weber <Matthew.Weber@rockwellcollins.com>,
	"Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Patrick Havelange <patrick.havelange@essensium.com>,
	Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [Buildroot] [PATCH v3 06/11] docs/manual/cargo: document the cargo-package infrastructure
Date: Thu,  6 Jan 2022 21:59:54 +0100	[thread overview]
Message-ID: <20220106210000.397694-7-thomas.petazzoni@bootlin.com> (raw)
In-Reply-To: <20220106210000.397694-1-thomas.petazzoni@bootlin.com>

From: Patrick Havelange <patrick.havelange@essensium.com>

The Buildroot manual was already providing some details on how to
integrate Cargo packages, and those details now need to be updated
with a proper documentation for the cargo-package infrastructure, as
well as updates related to vendoring support, which affects how
dependencies are handled.

Signed-off-by: Patrick Havelange <patrick.havelange@essensium.com>
[Thomas: numerous updates and extensions.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

docs/manual/adding-packages-cargo.txt: rewrite explanation about dependency management

Now that we have vendoring support for Cargo packages, let's rewrite
the dependency management section in a more accurate way.

We drop the part about the local cache of the registry, because
+CARGO_HOME+ in Buildroot points to $(HOST_DIR)/share/cargo, which is
not shared between builds nor preserved accross builds, so its effect
as a cache is limited.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 docs/manual/adding-packages-cargo.txt | 106 ++++++++++++--------------
 1 file changed, 47 insertions(+), 59 deletions(-)

diff --git a/docs/manual/adding-packages-cargo.txt b/docs/manual/adding-packages-cargo.txt
index 8fcc80bcc6..fb3e7d0780 100644
--- a/docs/manual/adding-packages-cargo.txt
+++ b/docs/manual/adding-packages-cargo.txt
@@ -1,7 +1,7 @@
 // -*- mode:doc; -*-
 // vim: set syntax=asciidoc:
 
-=== Integration of Cargo-based packages
+=== Infrastructure for Cargo-based packages
 
 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
@@ -10,7 +10,7 @@ called "crates".
 
 [[cargo-package-tutorial]]
 
-==== Cargo-based package's +Config.in+ file
+==== +cargo-package+ tutorial
 
 The +Config.in+ file of Cargo-based package 'foo' should contain:
 
@@ -25,11 +25,7 @@ The +Config.in+ file of Cargo-based package 'foo' should contain:
 08: 	  http://foosoftware.org/foo/
 ---------------------------
 
-==== Cargo-based package's +.mk+ file
-
-Buildroot does not (yet) provide a dedicated package infrastructure for
-Cargo-based packages. So, we will explain how to write a +.mk+ file for such a
-package. Let's start with an example:
+And the +.mk+ file for this package should contain:
 
 ------------------------------
 01: ################################################################################
@@ -44,66 +40,58 @@ package. Let's start with an example:
 10: FOO_LICENSE = GPL-3.0+
 11: FOO_LICENSE_FILES = COPYING
 12:
-13: FOO_DEPENDENCIES = host-rustc
-14:
-15: FOO_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
-16:
-17: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE)
-18:
-19: FOO_CARGO_OPTS = \
-20: 	$(if $(BR2_ENABLE_DEBUG),,--release) \
-21: 	--target=$(RUSTC_TARGET_NAME) \
-22: 	--manifest-path=$(@D)/Cargo.toml
-23:
-24: define FOO_BUILD_CMDS
-25: 	$(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \
-26: 		cargo build $(FOO_CARGO_OPTS)
-27: endef
-28:
-29: define FOO_INSTALL_TARGET_CMDS
-30: 	$(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \
-31: 		$(TARGET_DIR)/usr/bin/foo
-32: endef
-33:
-34: $(eval $(generic-package))
+13: $(eval $(cargo-package))
 --------------------------------
 
-The Makefile starts with the definition of the standard variables for package
-declaration (lines 7 to 11).
+The Makefile starts with the definition of the standard variables for
+package declaration (lines 7 to 11).
 
-As seen in line 34, it is based on the
-xref:generic-package-tutorial[+generic-package+ infrastructure]. So, it defines
-the variables required by this particular infrastructure, where Cargo is
-invoked:
+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.
 
-* +FOO_BUILD_CMDS+: Cargo is invoked to perform the build. The options required
-  to configure the cross-compilation of the package are passed via
-  +FOO_CONF_OPTS+.
+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.
 
-* +FOO_INSTALL_TARGET_CMDS+: The binary executable generated is installed on
-  the target.
+==== +cargo-package+ reference
 
-In order to have Cargo available for the build, +FOO_DEPENDENCIES+ needs to
-contain +host-cargo+.
+The main macros for the Cargo package infrastructure are
++cargo-package+ for target packages and +host-cargo-package+ for host
+packages.
 
-To sum it up, to add a new Cargo-based package, the Makefile example can be
-copied verbatim then edited to replace all occurences of +FOO+ with the
-uppercase name of the new package and update the values of the standard
-variables.
+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.
 
-==== About Dependencies Management
+First, all the package metadata information variables that exist in
+the generic infrastructure also exist in the Cargo infrastructure:
++FOO_VERSION+, +FOO_SOURCE+, +FOO_PATCH+, +FOO_SITE+,
++FOO_DEPENDENCIES+, +FOO_LICENSE+, +FOO_LICENSE_FILES+, etc.
+
+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.
+
+* +FOO_CARGO_ENV+ can be used to pass additional variables in the
+  environment of +cargo+ invocations. It used at both build and
+  installation time
 
-A crate can depend on other libraries from crates.io or git repositories, listed
-in its Cargo.toml file. Before starting a build, Cargo usually downloads
-automatically them. This step can also be performed independently, via the
-+cargo fetch+ command.
+* +FOO_CARGO_BUILD_OPTS+ can be used to pass additional options to
+  +cargo+ at build time.
+
+* +FOO_CARGO_INSTALL_OPTS+ can be used to pass additional options to
+  +cargo+ at install time.
+
+==== About Dependencies Management
 
-Cargo maintains a local cache of the registry index and of git checkouts of the
-crates, whose location is given by +$CARGO_HOME+. As seen in the package
-Makefile example at line 15, this environment variable is set to
-+$(HOST_DIR)/share/cargo+.
+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.
 
-This dependency download mechanism is not convenient when performing an offline
-build, as Cargo will fail to fetch the dependencies. In that case, it is advised
-to generate a tarball of the dependencies using the +cargo vendor+ and add it to
-+FOO_EXTRA_DOWNLOADS+.
+This mechanism ensures that any change in the dependencies will be
+detected, and allows the build to be performed completely offline.
-- 
2.33.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2022-01-06 21:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 20:59 [Buildroot] [PATCH v3 00/11] Support for Cargo and Go vendoring Thomas Petazzoni
2022-01-06 20:59 ` [Buildroot] [PATCH v3 01/11] support/download/dl-wrapper: add concept of download post-processing Thomas Petazzoni
2022-01-07 10:28   ` Yann E. MORIN
2022-01-06 20:59 ` [Buildroot] [PATCH v3 02/11] package/pkg-download.mk: add <pkg>_DOWNLOAD_POST_PROCESS variable Thomas Petazzoni
2022-01-07 10:35   ` Yann E. MORIN
2022-01-06 20:59 ` [Buildroot] [PATCH v3 03/11] support/download/post-process-helpers: add helper function for post process scripts Thomas Petazzoni
2022-01-07 10:36   ` Yann E. MORIN
2022-01-06 20:59 ` [Buildroot] [PATCH v3 04/11] package/pkg-golang.mk: implement Go vendoring support Thomas Petazzoni
2022-01-09 11:49   ` Romain Naour
2022-01-06 20:59 ` [Buildroot] [PATCH v3 05/11] package/pkg-cargo.mk: introduce the cargo package infrastructure Thomas Petazzoni
2022-01-07  1:12   ` James Hilliard
2022-01-07  9:52     ` Thomas Petazzoni
2022-01-07 22:30       ` James Hilliard
2022-01-07 22:59         ` Thomas Petazzoni
2022-01-08  3:21           ` James Hilliard
2022-01-08 13:52           ` Juergen Stuber
2022-01-07 10:05   ` Romain Naour
2022-01-07 10:26   ` Romain Naour
2022-01-07 10:44     ` Yann E. MORIN
2022-01-07 11:03       ` Romain Naour
2022-01-07 21:07   ` Romain Naour
2022-01-07 21:53     ` Thomas Petazzoni
2022-01-09 10:04     ` Thomas Petazzoni
2022-01-06 20:59 ` Thomas Petazzoni [this message]
2022-01-06 20:59 ` [Buildroot] [PATCH v3 07/11] package/ripgrep: convert to cargo infrastructure Thomas Petazzoni
2022-01-06 20:59 ` [Buildroot] [PATCH v3 08/11] package/sentry-cli: re-add package Thomas Petazzoni
2022-01-06 22:04   ` Christian Stewart via buildroot
2022-01-06 22:29     ` Thomas Petazzoni
2022-01-06 22:38       ` Christian Stewart via buildroot
2022-01-06 22:59         ` Thomas Petazzoni
2022-01-06 20:59 ` [Buildroot] [PATCH v3 09/11] package/tinifier: new package Thomas Petazzoni
2022-01-06 22:30   ` Christian Stewart via buildroot
2022-01-06 20:59 ` [Buildroot] [PATCH v3 10/11] package/embiggen-disk: " Thomas Petazzoni
2022-01-06 22:11   ` Christian Stewart via buildroot
2022-01-06 20:59 ` [Buildroot] [PATCH v3 11/11] package/gocryptfs: " Thomas Petazzoni
2022-01-06 22:26 ` [Buildroot] [PATCH v3 00/11] Support for Cargo and Go vendoring Christian Stewart via buildroot
2022-01-06 22:29   ` Thomas Petazzoni
2022-01-08 22:39 ` Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220106210000.397694-7-thomas.petazzoni@bootlin.com \
    --to=thomas.petazzoni@bootlin.com \
    --cc=Matthew.Weber@rockwellcollins.com \
    --cc=buildroot@buildroot.org \
    --cc=christian@paral.in \
    --cc=james.hilliard1@gmail.com \
    --cc=patrick.havelange@essensium.com \
    --cc=thomas.de_schampheleire@nokia.com \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).