Skip to contentSkip to conversation

package/pkg-cargo.mk: Introduce the cargo package infrastructure.

PATCH Superseded Patrick Havelange 2 participants 11 messages Feb 14, 2020 – Feb 17, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/10 package/pkg-cargo.mk: Introduce the cargo package infrastructure.

In order to be package agnostic, the install phase is now using cargo instead of install.

---
This is the V2 of the previously posted series :
http://patchwork.ozlabs.org/project/buildroot/list/?series=156166&state=%2A&archive=both

A lot of changes following the buildroot developer meeting's decisions from February 2020.

Needs to be applied on top of the rust 1.40 bump

---
 package/Makefile.in  |  1 +
 package/pkg-cargo.mk | 89 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 package/pkg-cargo.mk
package/Makefile.in +1 -0
index 285e2837ef..650d7c166e 100644
@@ -426,3 +426,4 @@ include package/pkg-kernel-module.mk
 include package/pkg-waf.mk
 include package/pkg-golang.mk
 include package/pkg-meson.mk
+include package/pkg-cargo.mk
package/pkg-cargo.mk new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/10 docs/manual/cargo: Update manual for cargo packages.

---
 docs/manual/adding-packages-cargo.txt | 54 +++++----------------------
 1 file changed, 10 insertions(+), 44 deletions(-)
docs/manual/adding-packages-cargo.txt +10 -44
index bb078b6981..9a496224e3 100644
@@ -27,9 +27,9 @@ The +Config.in+ file of Cargo-based package 'foo' should contain:
 
 ==== 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:
+Buildroot provides 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:
 
 ------------------------------
 01: ################################################################################
@@ -44,53 +44,19 @@ 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: FOO_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
-17:
-18: FOO_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(FOO_CARGO_MODE)
-19:
-20: FOO_CARGO_OPTS = \
-21:   --$(FOO_CARGO_MODE) \
-22: 	--target=$(RUSTC_TARGET_NAME) \
-23: 	--manifest-path=$(@D)/Cargo.toml
-24:
-25: define FOO_BUILD_CMDS
-26: 	$(TARGET_MAKE_ENV) $(FOO_CARGO_ENV) \
-27: 		cargo build $(FOO_CARGO_OPTS)
-28: endef
-29:
-30: define FOO_INSTALL_TARGET_CMDS
-31: 	$(INSTALL) -D -m 0755 $(@D)/$(FOO_BIN_DIR)/foo \
-32: 		$(TARGET_DIR)/usr/bin/foo
-33: endef
-34:
-35: $(eval $(generic-package))
+13: $(eval $(cargo-package))
 --------------------------------
 
 The Makefile starts with the definition of the standard variables for package
 declaration (lines 7 to 11).
 
-As seen in line 35, 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. The required dependencies of the
+crate will be downloaded and the buildroot dependencies will also be set.
 
-* +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+.
-
-* +FOO_INSTALL_TARGET_CMDS+: The binary executable generated is installed on
-  the target.
-
-In order to have Cargo available for the build, +FOO_DEPENDENCIES+ needs to
-contain +host-cargo+.
-
-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.
+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.
 
 ==== About Dependencies Management
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 3/10 package/ripgrep: convert to cargo infrastructure

In reply to Patrick Havelange
---
 package/ripgrep/ripgrep.mk | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)
package/ripgrep/ripgrep.mk +1 -22
index 832c076f26..97e9e2ce5f 100644
@@ -9,25 +9,4 @@ RIPGREP_SITE = $(call github,burntsushi,ripgrep,$(RIPGREP_VERSION))
 RIPGREP_LICENSE = MIT
 RIPGREP_LICENSE_FILES = LICENSE-MIT
 
-RIPGREP_DEPENDENCIES = host-rustc
-RIPGREP_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
-RIPGREP_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
-
-RIPGREP_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(RIPGREP_CARGO_MODE)
-
-RIPGREP_CARGO_OPTS = \
-	--$(RIPGREP_CARGO_MODE) \
-	--target=$(RUSTC_TARGET_NAME) \
-	--manifest-path=$(@D)/Cargo.toml
-
-define RIPGREP_BUILD_CMDS
-	$(TARGET_MAKE_ENV) $(RIPGREP_CARGO_ENV) \
-		cargo build $(RIPGREP_CARGO_OPTS)
-endef
-
-define RIPGREP_INSTALL_TARGET_CMDS
-	$(INSTALL) -D -m 0755 $(@D)/$(RIPGREP_BIN_DIR)/rg \
-		$(TARGET_DIR)/usr/bin/rg
-endef
-
-$(eval $(generic-package))
+$(eval $(cargo-package))
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 4/10 support/download/dl-wrapper: rework backend parsing

In reply to Patrick Havelange

The point of this modification is to be more generic in the way the backends/options are parsed from the urls.
The '+' char serves as delimiter between the backends and the actual url.
The '|' char serves as separator between the different options or backends.
This will be useful later when more options or backends would be needed.

pkg-generic.mk now passes the optional FOO_PKGMGR value in case a package needs to use a second backend.

---
 package/pkg-generic.mk      |  2 +-
 support/download/dl-wrapper | 34 ++++++++++++++++++++++------------
 2 files changed, 23 insertions(+), 13 deletions(-)
package/pkg-generic.mk +1 -1
index 268d999efb..a5038ebff4 100644
@@ -541,7 +541,7 @@ ifndef $(2)_PATCH
 endif
 
 $(2)_ALL_DOWNLOADS = \
-	$$(if $$($(2)_SOURCE),$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$($(2)_SOURCE)) \
+	$$(if $$($(2)_SOURCE),$$($(2)_PKGMGR)$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$($(2)_SOURCE)) \
 	$$(foreach p,$$($(2)_PATCH) $$($(2)_EXTRA_DOWNLOADS),\
 		$$(if $$(findstring ://,$$(p)),$$(p),\
 			$$($(2)_SITE_METHOD)+$$($(2)_SITE)/$$(p)))
support/download/dl-wrapper +22 -12
index 3315bd410e..3f613bb622 100755
@@ -21,8 +21,8 @@ export BR_BACKEND_DL_GETOPTS=":hc:d:o:n:N:H:ru:qf:e"
 
 main() {
     local OPT OPTARG
-    local backend output hfile recurse quiet rc
-    local -a uris
+    local backend backends_str output hfile recurse quiet rc backend2
+    local -a uris backends
 
     # Parse our options; anything after '--' is for the backend
     while getopts ":c:d:D:o:n:N:H:rf:u:q" OPT; do
@@ -85,18 +85,24 @@ main() {
     download_and_check=0
     rc=1
     for uri in "${uris[@]}"; do
-        backend_urlencode="${uri%%+*}"
-        backend="${backend_urlencode%|*}"
-        case "${backend}" in
-            git|svn|cvs|bzr|file|scp|hg) ;;
-            *) backend="wget" ;;
-        esac
+        urlencode=""
+        backend="wget"
+        backend2=""
+
+        # Extract the backends list, separated by '+' from the actual url
+        backends_str="${uri%%+*}"
+        # make an array out of it, backends are '|' separated
+        IFS='|' read -r -a backends <<< "${backends_str}"
+        # parse each of them, set flags and set the real backend
+        for b in "${backends[@]}" ; do
+            case "${b}" in
+                urlencode) urlencode="${b}" ;;
+                git|svn|cvs|bzr|file|scp|hg) backend="${b}" ;;
+                # insert here supported second backends) backend2="${b}" ;;
+            esac
+        done
         uri=${uri#*+}
 
-        urlencode=${backend_urlencode#*|}
-        # urlencode must be "urlencode"
-        [ "${urlencode}" != "urlencode" ] && urlencode=""
-
         # tmpd is a temporary directory in which backends may store
         # intermediate by-products of the download.
         # tmpf is the file in which the backends should put the downloaded
@@ -138,6 +144,10 @@ main() {
         # cd back to free the temp-dir, so we can remove it later
         cd "${OLDPWD}"
 
+        if [ -n "${backend2}" ] ; then
+	    support/download/${backend2} "${tmpf}" "${tmpd}" "${old_dl_dir}"
+        fi
+
         # Check if the downloaded file is sane, and matches the stored hashes
         # for that file
         if support/download/check-hash ${quiet} "${hfile}" "${tmpf}" "${output##*/}"; then
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 5/10 docs/manual/adding-packages-generic: update for new FOO_PKGMGR value

In reply to Patrick Havelange
---
 docs/manual/adding-packages-generic.txt | 7 +++++++
 1 file changed, 7 insertions(+)
docs/manual/adding-packages-generic.txt +7 -0
index baa052e31c..7fd58ed9a7 100644
@@ -265,6 +265,13 @@ not and can not work as people would expect it should:
     +LIBFOO_SITE=/opt/software/libfoo.tar.gz+ +
     +LIBFOO_SITE=$(TOPDIR)/../src/libfoo+
 
+* +LIBFOO_PKGMGR+ may contain the name of the second backend used
+  to complete the sources tarball. This second backend is called after
+  the first archive has been generated (e.g. git) or simply downloaded
+  (wget). It can be useful in the case where some other files are
+  needed for the build and require to be downloaded by a specific tool.
+  The value of this variable must end with a '|' (serves as a separator).
+
 * +LIBFOO_DL_OPTS+ is a space-separated list of additional options to
   pass to the downloader. Useful for retrieving documents with
   server-side checking for user logins and passwords, or to use a proxy.
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 6/10 package/pkg-cargo.mk: Introduce the cargo dl backend

In reply to Patrick Havelange

Cargo is now a fully supported PKGMGR, automatically set for any package using the cargo infrastructure.
This effectively splits the download phase and the build phase.

The cargo backend will set CARGO_HOME inside DL_DIR during download. The cached files in CARGO_HOME permits to download only once the crates index and each dependencies.
During download phase, it will call cargo vendor to copy the dependencies inside the VENDOR directory inside the source archive.

A local cargo config is also inserted inside the archive in order to use the VENDOR dir during the build phase.
The build phase is forced to not query the online repository anymore and thus will be using the vendored dependencies from the tarball. This also permits to have offline builds.

---
 package/pkg-cargo.mk         | 10 ++++--
 package/ripgrep/ripgrep.hash |  2 +-
 support/download/cargo       | 65 ++++++++++++++++++++++++++++++++++++
 support/download/dl-wrapper  |  2 +-
 4 files changed, 75 insertions(+), 4 deletions(-)
 create mode 100755 support/download/cargo
package/pkg-cargo.mk +8 -2
index 2242f3a082..3067b12a56 100644
@@ -39,6 +39,8 @@ define inner-cargo-package
 # We need host-rustc to run cargo
 $(2)_DEPENDENCIES += host-rustc
 
+$(2)_PKGMGR = cargo\|
+
 $(2)_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
 $(2)_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
 
@@ -52,11 +54,13 @@ endif
 #
 ifndef $(2)_BUILD_CMDS
 define $(2)_BUILD_CMDS
+	cd $$(@D) && \
 	$(TARGET_MAKE_ENV) $$($(2)_CARGO_ENV) \
 		cargo build \
 			--$$($(2)_CARGO_MODE) \
 			$$($(2)_CARGO_TARGET_OPT) \
-			--manifest-path $$(@D)/Cargo.toml
+			--manifest-path Cargo.toml \
+			--offline
 endef
 endif
 
@@ -66,12 +70,14 @@ endif
 #
 ifndef $(2)_INSTALL_TARGET_CMDS
 define $(2)_INSTALL_TARGET_CMDS
+	cd $$(@D) && \
 	$(TARGET_MAKE_ENV) $$($(2)_CARGO_ENV) \
 		cargo install \
 			--root $(TARGET_DIR)/usr/ \
 			--bins \
-			--path $$(@D) \
+			--path ./ \
 			$$($(2)_CARGO_TARGET_OPT) \
+			--offline \
 			--force
 endef
 endif
package/ripgrep/ripgrep.hash +1 -1
index 0841c0185c..8c48458cd8 100644
@@ -1,3 +1,3 @@
 # Locally calculated
-sha256 7035379fce0c1e32552e8ee528b92c3d01b8d3935ea31d26c51a73287be74bb3 ripgrep-0.8.1.tar.gz
+sha256 cb895cff182740c219fefbbaaf903e60f005a4ac4688cac1e43e5fbbbccc5a94 ripgrep-0.8.1.tar.gz
 sha256 0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f LICENSE-MIT
support/download/cargo new file +65 -0

65 lines not on this page · raw message

support/download/dl-wrapper +1 -1
index 3f613bb622..5e52b3e60f 100755
@@ -98,7 +98,7 @@ main() {
             case "${b}" in
                 urlencode) urlencode="${b}" ;;
                 git|svn|cvs|bzr|file|scp|hg) backend="${b}" ;;
-                # insert here supported second backends) backend2="${b}" ;;
+                cargo) backend2="${b}" ;;
             esac
         done
         uri=${uri#*+}
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 7/10 docs/manual/adding-packages-cargo: update doc for new infra

In reply to Patrick Havelange
---
 docs/manual/adding-packages-cargo.txt | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
docs/manual/adding-packages-cargo.txt +4 -12
index 9a496224e3..e7d03eb7b5 100644
@@ -61,16 +61,8 @@ Those will then replace the commands from the cargo infrastructure.
 ==== About Dependencies Management
 
 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.
+in its Cargo.toml file. Before starting a build, the +cargo vendor+ command
+will be run and will take care of downloading those dependencies.
 
-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+.
-
-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+.
+The final source tarball will contain all the required dependencies, effectively
+permitting us to do an offline build.
Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 8/10 package/ripgrep: bump to version 11.0.1

In reply to Patrick Havelange

This bump is needed because the old cached archive of the tarball of ripgrep is still using the old format and can't be used anymore (as the expected content of the final archive has changed with the recent infrastructure changes for cargo packages).

---
 package/ripgrep/ripgrep.hash | 2 +-
 package/ripgrep/ripgrep.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/ripgrep/ripgrep.hash +1 -1
index 8c48458cd8..1e70cbae5a 100644
@@ -1,3 +1,3 @@
 # Locally calculated
-sha256 cb895cff182740c219fefbbaaf903e60f005a4ac4688cac1e43e5fbbbccc5a94 ripgrep-0.8.1.tar.gz
+sha256 c02fe3077c95872175b098d002f872a619195436569a7dff443bbb605bc27474 ripgrep-11.0.1.tar.gz
 sha256 0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f LICENSE-MIT
package/ripgrep/ripgrep.mk +1 -1
index 97e9e2ce5f..1023b4bad8 100644
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-RIPGREP_VERSION = 0.8.1
+RIPGREP_VERSION = 11.0.1
 RIPGREP_SITE = $(call github,burntsushi,ripgrep,$(RIPGREP_VERSION))
 RIPGREP_LICENSE = MIT
 RIPGREP_LICENSE_FILES = LICENSE-MIT
Signature · 1 line
2.17.1
#8 lore raw

PATCH v2 9/10 package/ripgrep: add legal-info for dependencies

In reply to Patrick Havelange

As the dependencies are now vendored in the tarball, we can extract them easily. Added a helper script to list them. Updated the .hash & .mk files with those new licenses.

---
 package/ripgrep/find_vendor_licenses.sh |   6 +
 package/ripgrep/ripgrep.hash            | 167 +++++++++++++++++++++++
 package/ripgrep/ripgrep.mk              |   4 +-
 package/ripgrep/vendor.inc              | 169 ++++++++++++++++++++++++
 4 files changed, 345 insertions(+), 1 deletion(-)
 create mode 100755 package/ripgrep/find_vendor_licenses.sh
 create mode 100644 package/ripgrep/vendor.inc
package/ripgrep/find_vendor_licenses.sh new file +6 -0
new file mode 100755
index 0000000000..fd8638e399
@@ -0,0 +1,6 @@
+#!/bin/sh
+# to run from the extracted final sources
+find VENDOR/ -type f \
+    \( -iname '*license*' -o -iname 'licence*' -o -iname 'copying*' -o -iname 'copyright*' \) \
+    -a -not -name '*.a' | \
+    sort
package/ripgrep/ripgrep.hash +167 -0

170 lines not on this page · raw message

package/ripgrep/ripgrep.mk +3 -1
index 1023b4bad8..3be143e15c 100644
@@ -4,9 +4,11 @@
 #
 ################################################################################
 
+include package/ripgrep/vendor.inc
+
 RIPGREP_VERSION = 11.0.1
 RIPGREP_SITE = $(call github,burntsushi,ripgrep,$(RIPGREP_VERSION))
 RIPGREP_LICENSE = MIT
-RIPGREP_LICENSE_FILES = LICENSE-MIT
+RIPGREP_LICENSE_FILES = LICENSE-MIT $(RIPGREP_VENDOR_LICENSE_FILES)
 
 $(eval $(cargo-package))
package/ripgrep/vendor.inc new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
2.17.1
#9 lore raw

PATCH v2 10/10 docs/manual/adding-packages-cargo: Update for legal-info

In reply to Patrick Havelange

Added a bit of explanations regarding the vendored licenses.

---
 docs/manual/adding-packages-cargo.txt | 45 ++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 11 deletions(-)
docs/manual/adding-packages-cargo.txt +34 -11
index e7d03eb7b5..e92b8bc353 100644
@@ -38,19 +38,25 @@ with an example:
 04: #
 05: ################################################################################
 06:
-07: FOO_VERSION = 1.0
-08: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
-09: FOO_SITE = http://www.foosoftware.org/download
-10: FOO_LICENSE = GPL-3.0+
-11: FOO_LICENSE_FILES = COPYING
-12:
-13: $(eval $(cargo-package))
+07: include package/foo/vendor.inc
+08:
+09: FOO_VERSION = 1.0
+10: FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
+11: FOO_SITE = http://www.foosoftware.org/download
+12: FOO_LICENSE = GPL-3.0+
+13: FOO_LICENSE_FILES = COPYING $(FOO_VENDOR_LICENSE_FILES)
+14:
+15: $(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 inclusion of a second file that
+contains the vendored licenses, more info on that topic later.
+Then it continues with the definition of the standard variables
+for package declaration (lines 9 to 13).
 
-As seen in line 13, it is based on the cargo-package infrastructure. Cargo will
+FOO_VENDOR_LICENSE_FILES is defined in the previously included file vendor.inc
+
+As seen in line 15, it is based on the cargo-package infrastructure. Cargo will
 be invoked automatically by this infrastructure. The required dependencies of the
 crate will be downloaded and the buildroot dependencies will also be set.
 
@@ -58,7 +64,20 @@ 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.
 
-==== About Dependencies Management
+The file vendor.inc contains only one variable :
+
+------------------------------
+01: FOO_VENDOR_LICENSES_FILES = \
+02: 	VENDOR/bar/COPYING \
+03: 	VENDOR/blah/LICENSE-MIT \
+04:	VENDOR/bleh/COPYING \
+05: 
+--------------------------------
+
+It is recommended to generate the list via scripting.
+A script example can be found in the ripgrep directory.
+
+==== About Dependencies Management and Licenses
 
 A crate can depend on other libraries from crates.io or git repositories, listed
 in its Cargo.toml file. Before starting a build, the +cargo vendor+ command
@@ -66,3 +85,7 @@ will be run and will take care of downloading those dependencies.
 
 The final source tarball will contain all the required dependencies, effectively
 permitting us to do an offline build.
+
+In order for the +legal-info+ target to work as expected, it is necessary to list
+the licenses of the vendored dependencies. Each of those entries should be added
+to the +.mk+ and +.hash+ files.
Signature · 1 line
2.17.1
#10 lore raw

PATCH v2 1/10 package/pkg-cargo.mk: Introduce the cargo package infrastructure.

In reply to Patrick Havelange

Patrick, All,

Quoted 67 lines · Patrick Havelange

In order to be package agnostic, the install phase is now using cargo instead of install.

---
This is the V2 of the previously posted series :
http://patchwork.ozlabs.org/project/buildroot/list/?series=156166&state=%2A&archive=both

A lot of changes following the buildroot developer meeting's decisions from February 2020.

Needs to be applied on top of the rust 1.40 bump

---
 package/Makefile.in  |  1 +
 package/pkg-cargo.mk | 89 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
 create mode 100644 package/pkg-cargo.mk
package/Makefile.in +1 -0
index 285e2837ef..650d7c166e 100644
@@ -426,3 +426,4 @@ include package/pkg-kernel-module.mk
 include package/pkg-waf.mk
 include package/pkg-golang.mk
 include package/pkg-meson.mk
+include package/pkg-cargo.mk
package/pkg-cargo.mk new file +32 -0
new file mode 100644
index 0000000000..2242f3a082
@@ -0,0 +1,89 @@
+################################################################################
+# Cargo package infrastructure
+#
+# This file implements an infrastructure that eases development of package
+# .mk files for Cargo packages. It should be used for all packages that use
+# Cargo as their build system.
+#
+# See the Buildroot documentation for details on the usage of this
+# infrastructure
+#
+# In terms of implementation, this Cargo infrastructure requires the .mk file
+# to only specify metadata information about the package: name, version,
+# download URL, etc.
+#
+# We still allow the package .mk file to override what the different steps
+# are doing, if needed. For example, if <PKG>_BUILD_CMDS is already defined,
+# it is used as the list of commands to perform to build the package,
+# instead of the default Cargo behaviour. The package can also define some
+# post operation hooks.
+#
+################################################################################
+
+################################################################################
+# inner-cargo-package -- defines how the configuration, compilation and
+# installation of a cargo package should be done, implements a few hooks
+# to tune the build process for cargo specifities and calls the generic
+# package infrastructure to generate the necessary make targets
+#
+#  argument 1 is the lowercase package name
+#  argument 2 is the uppercase package name, including a HOST_ prefix
+#             for host packages
+#  argument 3 is the uppercase package name, without the HOST_ prefix

package/pkg-cargo.mk line 42

Quoted 10 lines
package/pkg-cargo.mk new file +10 -0
+#             for host packages
+#  argument 4 is the type (target or host)
+################################################################################
+
+define inner-cargo-package
+
+# We need host-rustc to run cargo
+$(2)_DEPENDENCIES += host-rustc
+
+$(2)_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo

Rust has the ability to use c code, and as such has to compile/link[1] against it. To do this when cross compiling, it uses cargo's --target=<arch> flag to find the compiler. This does not take into account the vendor portion of the toolchain name, such as buildroot when using an "internal" toolchain.

cc-rs allows the compiler to be passed down with the standard CC variables, so we will need to add $(TARGET_CONFIGURE_OPTS) somewhere.

I just did a very quick test and put it here under $(2)_CARGO_ENV and it worked when testing with the procs package at version v0.9.11 - with the exact same $(eval $(cargo-package)) as ripgrep is in this same series.

Let me know if you need more information, but this variable will pass down those standard variables.

1: https://github.com/alexcrichton/cc-rs

Signature · 13 lines
Sam Voss | Sr. Software Engineer | Commercial Avionics
COLLINS AEROSPACE
400 Collins Road NE, Cedar Rapids, Iowa 52498, USA
Tel: +1 319 263 4039
sam.voss at collins.com | collinsaerospace.com

CONFIDENTIALITY WARNING: This message may contain proprietary and/or
privileged information of Collins Aerospace and its affiliated
companies. If you are not the intended recipient, please 1) Do not
disclose, copy, distribute or use this message or its contents. 2)
Advise the sender by return email. 3) Delete all copies (including all
attachments) from your computer. Your cooperation is greatly
appreciated.