From: "'Jan Kiszka' via isar-users" <isar-users@googlegroups.com>
To: Quirin Gylstorff <Quirin.Gylstorff@siemens.com>,
isar-users@googlegroups.com
Subject: Re: [RFC PATCH 1/3] Add script to generate a recipe for cargo.io crates
Date: Mon, 23 Mar 2026 12:21:13 +0100 [thread overview]
Message-ID: <a3d04266-0ac9-47b6-aed9-23a7b66a5877@siemens.com> (raw)
In-Reply-To: <20260323105332.2721282-2-Quirin.Gylstorff@siemens.com>
On 23.03.26 11:52, 'Quirin Gylstorff' via isar-users wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
>
> This script allows to create a recipe for building rust crates which
> are not part of Debian. It uses for this `debcargo package` and follows
> the process defined in https://rust-team.pages.debian.net/book.
>
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
> scripts/generate_cargo_crate.sh | 85 +++++++++++++++++++++++++++++++++
> 1 file changed, 85 insertions(+)
> create mode 100755 scripts/generate_cargo_crate.sh
>
> diff --git a/scripts/generate_cargo_crate.sh b/scripts/generate_cargo_crate.sh
> new file mode 100755
> index 00000000..759bbc9e
> --- /dev/null
> +++ b/scripts/generate_cargo_crate.sh
> @@ -0,0 +1,85 @@
> +#!/bin/bash
> +# This software is a part of ISAR.
> +# Copyright (C) 2026 Siemens AG
> +
> +usage() {
> + echo "This script generates a scaffold for rust crates from crates.io."
> + echo "It uses debcargo to download and generate the debian folder."
> + echo "USAGE: $0 <CRATE_NAME> [CRATE_VERSION]"
> +}
> +
> +if [ $# -eq 0 ]; then
> + usage
> + exit 1
> +fi
> +case $1 in
> + -h|--help)
> + usage
> + exit 0
> + ;;
> + *)
> + true
> + ;;
> +esac
> +
> +package_name=$1
> +package_version=
> +if [ $# -gt 1 ]; then
> + package_version=$2
> +fi
> +
> +export NAME="isar-users isar"
> +
> +for dep in jq debcargo curl; do
> + if ! command -v "$dep" ;then
> + echo "Could not find tool dependency $dep !"
> + exit 1
> + fi
> +done
> +
> +source_name="rust-$package_name"
> +mkdir -p "$source_name/files"
> +# generate in the current directory to avoid the following
> +# debcargo error:
> +# Invalid cross-device link (os error 18)
> +TMP_DIR=$(mktemp -d -p .)
> +pushd "$source_name" || exit 1
> +debcargo package "$package_name" "$package_version" --directory "$TMP_DIR"
> +cp -r "${TMP_DIR}"/debian files/
> +if [ -z "$package_version" ]; then
> + package_version=$(grep -oP "X-Cargo-Crate-Version:\K.*" "${TMP_DIR}"/debian/control | tr -d "[:blank:]")
> +fi
> +rm -rf "$TMP_DIR"
> +tarball_checksum="$(curl --silent "https://crates.io/api/v1/crates/${package_name}/${package_version}" | jq ".version.checksum" )"
> +if [ "${tarball_checksum}" = "null" ] ; then
> + echo "$package_name in $package_version could not be found in crates.io"
> + exit 1
> +fi
> +cat << EOF >> "${source_name}_${package_version}".bb
Maybe leave a comment like this behind:
# Created by generate_cargo_crate.sh.
# SPDX-License-Identifier: MIT-0
That license is like the MIT, except that it comes without the
attribution paragraph, thus allows re-licensing without hassles.
> +inherit dpkg
> +
> +SRC_URI = "https://crates.io/api/v1/crates/${package_name}/\${PV}/download;downloadfilename=${PN}_${PV}.tar.gz"
> +SRC_URI += "file://debian"
> +
> +SRC_URI[sha256sum] = ${tarball_checksum}
> +
> +S = "\${WORKDIR}/${package_name}-\${PV}"
> +
> +# In most cases we want to package a library crate from crates.io
> +PROVIDES += "librust-${package_name}-dev"
> +
> +do_prepare_build() {
> + cp -r \${WORKDIR}/debian \${S}/
> + cd \${WORKDIR}
> + tar cJf \${PN}_\${PV}.orig.tar.xz \${TAR_REPRO_OPTS} ${package_name}-\${PV}
> +}
> +EOF
> +
> +
> +popd || exit 1
> +
> +echo "Finished generating isar scaffold for package $package_name in version $package_version"
> +echo ""
> +echo "Next steps:"
> +echo " - Check if the package builds and add the necessary patches, e.g. relax dependencies to the debian folder."
> +echo " - Also add the package to Debian by following https://rust-team.pages.debian.net/book/"
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/a3d04266-0ac9-47b6-aed9-23a7b66a5877%40siemens.com.
next prev parent reply other threads:[~2026-03-23 11:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 10:52 [RFC PATCH 0/3] Add helper and documentation for rust packaging 'Quirin Gylstorff' via isar-users
2026-03-23 10:52 ` [RFC PATCH 1/3] Add script to generate a recipe for cargo.io crates 'Quirin Gylstorff' via isar-users
2026-03-23 11:21 ` 'Jan Kiszka' via isar-users [this message]
2026-03-23 10:52 ` [RFC PATCH 2/3] Add example of a rust hello world as isar recipe 'Quirin Gylstorff' via isar-users
2026-03-23 11:21 ` 'Jan Kiszka' via isar-users
2026-03-23 12:03 ` 'Quirin Gylstorff' via isar-users
2026-03-23 12:06 ` 'Quirin Gylstorff' via isar-users
2026-03-24 9:17 ` 'MOESSBAUER, Felix' via isar-users
2026-03-24 10:03 ` 'Quirin Gylstorff' via isar-users
2026-03-23 10:52 ` [RFC PATCH 3/3] user_manual: add rust section 'Quirin Gylstorff' via isar-users
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=a3d04266-0ac9-47b6-aed9-23a7b66a5877@siemens.com \
--to=isar-users@googlegroups.com \
--cc=Quirin.Gylstorff@siemens.com \
--cc=jan.kiszka@siemens.com \
/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