diff mbox series

fetch2/crate: support user-defined protocols

Message ID LV8PR18MB5783EC1D3247161CBB9FFFB482E42@LV8PR18MB5783.namprd18.prod.outlook.com
State New
Headers show
Series fetch2/crate: support user-defined protocols | expand

Commit Message

Gabriel A Smith June 17, 2026, 6:59 p.m. UTC
From cd89f0c841d9611d79047c70045a05f6ac41da56 Mon Sep 17 00:00:00 2001
From: Gabriel Smith <gabriel.smith@belden.com>
Date: Wed, 17 Jun 2026 17:53:56 +0000
Subject: [PATCH] fetch2/crate: support user-defined protocols

By default HTTPS is used for crate downloads, but both HTTP and FTP are
also supported by wget. FTP is not supported by crate registries so
it is not recommended. This adds a protocol parameter similar to the
git fetcher to allow a user to specify a different protocol.

Documentation has been updated to mention the new parameter.

Signed-off-by: Gabriel Smith <gabriel.smith@belden.com>
---
 .../bitbake-user-manual-fetching.rst          |  5 ++++
 lib/bb/fetch2/crate.py                        | 24 +++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst b/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst
index c2747c401..b96018a4e 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst
+++ b/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst
@@ -716,6 +716,11 @@  The format for the :term:`SRC_URI` setting must be::
 
    SRC_URI = "crate://REGISTRY/NAME/VERSION"
 
+This fetcher supports the following parameters:
+
+-  *"protocol":* The protocol used to fetch the crates. The default is "https".
+   You can also use "http".
+
 Here is an example URL::
 
    SRC_URI = "crate://crates.io/glob/0.2.11"
diff --git a/lib/bb/fetch2/crate.py b/lib/bb/fetch2/crate.py
index f94e153ee..830612c98 100644
--- a/lib/bb/fetch2/crate.py
+++ b/lib/bb/fetch2/crate.py
@@ -1,7 +1,16 @@ 
 # ex:ts=4:sw=4:sts=4:et
 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
 """
-BitBake 'Fetch' implementation for crates.io
+BitBake 'Fetch' implementation for cargo registries, e.g. crates.io
+
+SRC_URI = "crate://some.host/crate_name/version;OptionA=xxx;OptionB=xxx;..."
+
+Supported SRC_URI options are:
+
+- protocol
+   The method to use to download the crate file. Common options are "http",
+   "https", and "ftp". The default is "https".
+
 """
 
 # Copyright (C) 2016 Doug Goldstein
@@ -63,7 +72,7 @@  class Crate(Wget):
         Sets up the download for a crate
         """
 
-        # URL syntax is: crate://NAME/VERSION
+        # URL syntax is: crate://HOST/NAME/VERSION
         # break the URL apart by /
         parts = ud.url.split('/')
         if len(parts) < 5:
@@ -78,13 +87,20 @@  class Crate(Wget):
         # host (this is to allow custom crate registries to be specified
         host = '/'.join(parts[2:-2])
 
+        if 'protocol' in ud.parm:
+            proto = ud.parm['protocol']
+        else:
+            proto = 'https'
+
         # If using crates.io use the CDN directly as per https://crates.io/data-access
         if host == 'crates.io':
+            if proto != 'https':
+                bb.warn("URL: %s does the %s protocol which is not supported by crates.io. Please change to ;protocol=https in the url." % (ud.url, proto))
             ud.url = "https://static.crates.io/crates/%s/%s/download" % (name, version)
             ud.versionsurl = 'https://index.crates.io/' + self._generate_index_path(name)
         else:
-            ud.url = "https://%s/%s/%s/download" % (host, name, version)
-            ud.versionsurl = "https://%s/%s/versions" % (host, name)
+            ud.url = "%s://%s/%s/%s/download" % (proto, host, name, version)
+            ud.versionsurl = "%s://%s/%s/versions" % (proto, host, name)
 
         ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version)
         if 'name' not in ud.parm: