cargo_common.bbclass: Support local github repos

Since disable network was added cargo configurations which reference git
repos fail as they attempt to fetch across the network as part of
do_compile, even if EXTRA_OECARGO_PATHS to add them as part of `paths`
is used, as this is documented as only working for packages which exist
in crates.io.

Add parsing of the SRC_URIs for git repos and include `[patch]` sections
to redirect to the checked out source repos which the bitbake fetcher
has already populated.

There are still cases which don't work - if you have multiple copies of
the same repo with different revisions, there's currently no way to
represent that and anything using a repo which has a virtual manifest
will fail to build (see https://github.com/rust-lang/cargo/issues/4934).

(From OE-Core rev: 684a8af41c5bb70db68e75f72bdc4c9b09630810)

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Alex Kiernan
2023-03-31 07:45:22 +02:00
committed by Richard Purdie
parent 15dc92a4b1
commit 0d099fa404

View File

@@ -116,6 +116,36 @@ cargo_common_do_configure () {
EOF
}
python cargo_common_do_patch_paths() {
cargo_config = os.path.join(d.getVar("CARGO_HOME"), "config")
if not os.path.exists(cargo_config):
return
src_uri = (d.getVar('SRC_URI') or "").split()
if len(src_uri) == 0:
return
patches = dict()
workdir = d.getVar('WORKDIR')
fetcher = bb.fetch2.Fetch(src_uri, d)
for url in fetcher.urls:
ud = fetcher.ud[url]
if ud.type == 'git':
name = ud.parm.get('name')
destsuffix = ud.parm.get('destsuffix')
if name is not None and destsuffix is not None:
repo = '%s://%s%s' % (ud.proto, ud.host, ud.path)
path = '%s = { path = "%s" }' % (name, os.path.join(workdir, destsuffix))
patches.setdefault(repo, []).append(path)
with open(cargo_config, "a+") as config:
for k, v in patches.items():
print('\n[patch."%s"]' % k, file=config)
for name in v:
print(name, file=config)
}
do_configure[postfuncs] += "cargo_common_do_patch_paths"
oe_cargo_fix_env () {
export CC="${RUST_TARGET_CC}"
export CXX="${RUST_TARGET_CXX}"