[2/2] add example how to use derived sbuild chroots

Message ID 20230413070026.3511123-2-felix.moessbauer@siemens.com
State Accepted, archived
Headers show
Series [1/2] add support for derived sbuild chroots | expand

Commit Message

MOESSBAUER, Felix April 13, 2023, 7 a.m. UTC
This patch extends the samefile recipe to use a derived sbuild chroot to
compile the tool using clang instead of gcc. While there are easier ways
to achive this goal, it is still valuable to demonstrate how to use the
infrastructure.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta-isar/recipes-app/samefile/samefile_2.14.bb       |  8 ++++++++
 .../sbuild-chroot/sbuild-chroot-target-clang.bb       | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb

Comments

Jan Kiszka April 14, 2023, 8:46 a.m. UTC | #1
On 13.04.23 09:00, Felix Moessbauer wrote:
> This patch extends the samefile recipe to use a derived sbuild chroot to
> compile the tool using clang instead of gcc. While there are easier ways
> to achive this goal, it is still valuable to demonstrate how to use the
> infrastructure.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta-isar/recipes-app/samefile/samefile_2.14.bb       |  8 ++++++++
>  .../sbuild-chroot/sbuild-chroot-target-clang.bb       | 11 +++++++++++
>  2 files changed, 19 insertions(+)
>  create mode 100644 meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> 
> diff --git a/meta-isar/recipes-app/samefile/samefile_2.14.bb b/meta-isar/recipes-app/samefile/samefile_2.14.bb
> index c53c9445..989e1983 100644
> --- a/meta-isar/recipes-app/samefile/samefile_2.14.bb
> +++ b/meta-isar/recipes-app/samefile/samefile_2.14.bb
> @@ -5,6 +5,9 @@
>  
>  inherit dpkg
>  
> +# for demo reasons, we compile with clang if not cross-compiling
> +SBUILD_FLAVOR = "${@ 'clang' if d.getVar('ISAR_CROSS_COMPILE') != '1' else '' }"
> +
>  DEBIAN_DEPENDS = "\${misc:Depends}"
>  DESCRIPTION = "utility that finds files with identical contents"
>  
> @@ -42,4 +45,9 @@ EOF
>  
>      # We can also customize afterwards, in this case change the package section.
>      sed -i -e 's/Section: misc/Section: utils/g' ${S}/debian/control
> +
> +    # use clang to compile (no cross support yet)
> +    if [ "${SBUILD_FLAVOR}" = "clang" ]; then
> +        sed -i -e 's/\(#\!.*\)/\1\nexport CC=clang/g' ${S}/debian/rules
> +    fi
>  }
> diff --git a/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> new file mode 100644
> index 00000000..3df16368
> --- /dev/null
> +++ b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> @@ -0,0 +1,11 @@
> +# Root filesystem for packages building with clang
> +#
> +# This software is a part of ISAR.
> +# Copyright (C) 2023 Siemens AG
> +
> +DESCRIPTION = "Isar sbuild/schroot filesystem for target (clang variant)"
> +
> +require recipes-devtools/sbuild-chroot/sbuild-chroot-target.bb
> +
> +SBUILD_FLAVOR = "clang"

Could this be auto-derived from a helper-include by taking the recipe
name and sub-tracting a conventional prefix?

Jan

> +SBUILD_CHROOT_PREINSTALL_COMMON += "clang"
Henning Schild June 21, 2023, 12:33 p.m. UTC | #2
Am Thu, 13 Apr 2023 07:00:26 +0000
schrieb "'Felix Moessbauer' via isar-users"
<isar-users@googlegroups.com>:

> This patch extends the samefile recipe to use a derived sbuild chroot
> to compile the tool using clang instead of gcc. While there are
> easier ways to achive this goal, it is still valuable to demonstrate
> how to use the infrastructure.
> 
> Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
> ---
>  meta-isar/recipes-app/samefile/samefile_2.14.bb       |  8 ++++++++
>  .../sbuild-chroot/sbuild-chroot-target-clang.bb       | 11
> +++++++++++ 2 files changed, 19 insertions(+)
>  create mode 100644
> meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> 
> diff --git a/meta-isar/recipes-app/samefile/samefile_2.14.bb
> b/meta-isar/recipes-app/samefile/samefile_2.14.bb index
> c53c9445..989e1983 100644 ---
> a/meta-isar/recipes-app/samefile/samefile_2.14.bb +++
> b/meta-isar/recipes-app/samefile/samefile_2.14.bb @@ -5,6 +5,9 @@
>  
>  inherit dpkg
>  
> +# for demo reasons, we compile with clang if not cross-compiling
> +SBUILD_FLAVOR = "${@ 'clang' if d.getVar('ISAR_CROSS_COMPILE') !=
> '1' else '' }" +
>  DEBIAN_DEPENDS = "\${misc:Depends}"
>  DESCRIPTION = "utility that finds files with identical contents"
>  
> @@ -42,4 +45,9 @@ EOF
>  
>      # We can also customize afterwards, in this case change the
> package section. sed -i -e 's/Section: misc/Section: utils/g'
> ${S}/debian/control +
> +    # use clang to compile (no cross support yet)
> +    if [ "${SBUILD_FLAVOR}" = "clang" ]; then
> +        sed -i -e 's/\(#\!.*\)/\1\nexport CC=clang/g'
> ${S}/debian/rules

This is going pretty far to demo the case. Even so far that
Build-Depends might be wrong and only satisfied with the magic.

You do not demo speed-ups by preinstalled build-deps, you demo hackery.

> +    fi
>  }
> diff --git
> a/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> new file mode 100644 index 00000000..3df16368 --- /dev/null
> +++
> b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
> @@ -0,0 +1,11 @@ +# Root filesystem for packages building with clang
> +#
> +# This software is a part of ISAR.
> +# Copyright (C) 2023 Siemens AG
> +
> +DESCRIPTION = "Isar sbuild/schroot filesystem for target (clang
> variant)" +
> +require recipes-devtools/sbuild-chroot/sbuild-chroot-target.bb
> +
> +SBUILD_FLAVOR = "clang"
> +SBUILD_CHROOT_PREINSTALL_COMMON += "clang"

A bit unfortunate that the only one package name was also chosen as the
flavor name.

Maybe add some comments here, which one is a "name" and which one is a
"package list", or try to pick different strings as name.

Does that package benefit in any way from clang being preinstalled? I
guess only artificially because you patched in the CC=clang ...

Henning

Patch

diff --git a/meta-isar/recipes-app/samefile/samefile_2.14.bb b/meta-isar/recipes-app/samefile/samefile_2.14.bb
index c53c9445..989e1983 100644
--- a/meta-isar/recipes-app/samefile/samefile_2.14.bb
+++ b/meta-isar/recipes-app/samefile/samefile_2.14.bb
@@ -5,6 +5,9 @@ 
 
 inherit dpkg
 
+# for demo reasons, we compile with clang if not cross-compiling
+SBUILD_FLAVOR = "${@ 'clang' if d.getVar('ISAR_CROSS_COMPILE') != '1' else '' }"
+
 DEBIAN_DEPENDS = "\${misc:Depends}"
 DESCRIPTION = "utility that finds files with identical contents"
 
@@ -42,4 +45,9 @@  EOF
 
     # We can also customize afterwards, in this case change the package section.
     sed -i -e 's/Section: misc/Section: utils/g' ${S}/debian/control
+
+    # use clang to compile (no cross support yet)
+    if [ "${SBUILD_FLAVOR}" = "clang" ]; then
+        sed -i -e 's/\(#\!.*\)/\1\nexport CC=clang/g' ${S}/debian/rules
+    fi
 }
diff --git a/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
new file mode 100644
index 00000000..3df16368
--- /dev/null
+++ b/meta-isar/recipes-devtools/sbuild-chroot/sbuild-chroot-target-clang.bb
@@ -0,0 +1,11 @@ 
+# Root filesystem for packages building with clang
+#
+# This software is a part of ISAR.
+# Copyright (C) 2023 Siemens AG
+
+DESCRIPTION = "Isar sbuild/schroot filesystem for target (clang variant)"
+
+require recipes-devtools/sbuild-chroot/sbuild-chroot-target.bb
+
+SBUILD_FLAVOR = "clang"
+SBUILD_CHROOT_PREINSTALL_COMMON += "clang"