unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Mitchell Schmeisser <mitchellschmeisser@librem.one>
Cc: 61765@debbugs.gnu.org
Subject: [bug#61765] custom toolchain blog post
Date: Mon, 27 Feb 2023 13:50:17 +0100	[thread overview]
Message-ID: <87fsarmfw6.fsf@gnu.org> (raw)
In-Reply-To: <87sfeuucab.fsf@librem.one> (Mitchell Schmeisser's message of "Fri, 24 Feb 2023 13:51:56 -0500")

Hello Mitchell,

Mitchell Schmeisser <mitchellschmeisser@librem.one> skribis:

> Here is a rough draft of my toolchain post.
> I hope it can make an interesting contribution to the Guix literature.

Yay, definitely!

>>From 4f6c43091ffd67cdbc5f041e496f61bc8a06070e Mon Sep 17 00:00:00 2001
> From: Mitchell Schmeisser <mitchellschmeisser@librem.one>
> Date: Fri, 24 Feb 2023 13:02:05 -0500
> Subject: [PATCH] website: Add custom toolchain blog post
>
> * website/posts/custom-toolchains-with-guix.md: New file.

This looks great to me!  It’s useful insight for anyone who might want
to add a cross-compilation target to Guix or simply learn how this is
implemented.

> +++ b/website/posts/custom-toolchains-with-guix.md
> @@ -0,0 +1,557 @@
> +# Table of Contents
> +
> +1.  [Overview](#org2633a51)
> +2.  [Anatomy of a toolchain](#orgc440e9e)
> +3.  [Bootstrapping a Toolchain](#orgd42b6c3)
> +4.  [Defining the Packages](#org55042c5)
> +	1.  [Binutils](#org67da1ec)
> +	2.  [GCC sans libc](#org82d6f83)
> +	3.  [Newlib(-nano)](#orgf6bafbc)
> +	4.  [Complete toolchain](#org052f2a2)
> +5.  [Integrating with Zephyr Build System](#orgc3f87f4)
> +	1.  [Testing](#org9f3c314)
> +
> +All code is available at [guix-zephyr](https://github.com/paperclip4465/guix-zephyr) channel.
> +
> +
> +<a id="org2633a51"></a>

You can remove the table of contents and all the HTML snippets that
pandoc added—I don’t think that works as expected with Haunt/CommonMark.

> +# Overview

You can drop the heading.

> +In order to deploy embedded software using Guix we first need to teach Guix
> +how to build it. Since Guix bootstraps everything this means we must teach Guix
> +how to build our toolchain.
> +
> +The [Zephyr Project](https://zephyrproject.org) uses its own fork of GCC with custom configs for
> +the architectures supported by the project.

We want blog posts to be widely accessible so I would recommend
providing more context in the intro.  In particular, I’d suggest:

  1. Mentioning that Guix supports cross-compilation (not everyone is
     aware of that), with a link to
     <https://guix.gnu.org/en/manual/en/html_node/Cross_002dCompilation.html>.

  2. Adding a couple of sentences saying what Zephyr is (I didn’t know
     about it before :-)).

  3. Saying a few words as to why Zephyr uses a GCC fork.

  4. Clearly stating that you added support for cross-compilation to
     Zephyr with Guix in a channel, linking to said channel, and that
     this is what the remainder of the post will describe.

You can check out posts at <https://guix.gnu.org/blog> for inspiration.

> +# Anatomy of a toolchain
> +
> +Toolchains are responsible for taking high level descriptions of programs
> +and lowering them down to a series of equivalent machine instructions.
> +This process involves more than just a compiler. The compiler uses the `binutils`
> +to manipulate it's internal representation down to a given architecture.
> +It also needs the use of the C standard library as well as a few other libraries
> +needed for some compiler optimizations.
> +
> +The C library provides the interface to the underlying kernel. System calls like `write`
> +and `read` are provided by `Glibc` on most Linux distributions.
>
> +In embedded systems smaller implementations like `newlib` and `newlib-nano` are used.

I’d suggest not using fixed-width font (backquotes) for proper nouns;
you can write “glibc” or “the GNU C Library (glibc)”, “Binutils” or “the
GNU Binary Utilities (Binutils)”, etc.

> +First thing we need to build is the `arm-zephyr-eabi` binutils.
> +This is very easy in Guix.
> +
> +	(define-module (zephyr packages zephyr)
> +	  #:use-module (guix packages))
> +
> +	(define-public arm-zephyr-eabi-binutils
> +	  (let ((xbinutils (cross-binutils "arm-zephyr-eabi")))
> +		(package
> +		  (inherit xbinutils)
> +		  (name "arm-zephyr-eabi-binutils")
> +		  (version "2.38")
> +		  (source
> +		   (origin (method git-fetch)
> +				   (uri (git-reference
> +						 (url "https://github.com/zephyrproject-rtos/binutils-gdb")
> +						 (commit "6a1be1a6a571957fea8b130e4ca2dcc65e753469")))
> +				   (file-name (git-file-name name version))
> +				   (sha256 (base32 "0ylnl48jj5jk3jrmvfx5zf8byvwg7g7my7jwwyqw3a95qcyh0isr"))))
> +		  (arguments
> +		   `(#:tests? #f
> +			 ,@(substitute-keyword-arguments (package-arguments xbinutils)
> +				 ((#:configure-flags flags)
> +				  `(cons "--program-prefix=arm-zephyr-eabi-" ,flags)))))
> +		  (native-inputs
> +		   (append
> +			(list texinfo
> +				  bison
> +				  flex
> +				  gmp
> +				  dejagnu)
> +			(package-native-inputs xbinutils)))
> +		  (home-page "https://zephyrproject.org")
> +		  (synopsis "binutils for zephyr RTOS"))))

Code snippets should be written like this, without leading indentation:

  ```scheme
  (define …)
  ```

This will enable syntax highlighting.

> +We can test our package definition using the `-L` flag with `guix build`
> +to add our packages.
> +
> +	guix build -L guix-zephyr zephyr-binutils
> +
> +	/gnu/store/...-zephyr-binutils-2.38

Likewise:

  ```
  guix build foo
  ```

> +# Integrating with Zephyr Build System
> +
> +Zephyr uses CMake as it's build system. It contains numerous CMake

s/it's/its/

One thing that’s not clear to me: with this in place, can you do “guix
build --target=arm-zephyr-eabi hello”, for instance?  If not, what’s
missing to support it?

It would be great if you could finish with a short conclusion stating,
for instance, the key takeaway message, lessons learned, and/or your
thoughts on how this could benefit others in the broader community.

I wonder if it would be worth mentioning
<https://guix.gnu.org/manual/en/html_node/Platforms.html> too, and how
one would go about adding a  module.  WDYT?

Could you send an updated patch?

Thanks for contributing this article!

Ludo’.




  reply	other threads:[~2023-02-27 12:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 18:51 [bug#61765] custom toolchain blog post Mitchell Schmeisser via Guix-patches via
2023-02-27 12:50 ` Ludovic Courtès [this message]
2023-02-27 15:35   ` Mitchell Schmeisser via Guix-patches
2023-03-11 12:11     ` Ludovic Courtès
2023-03-11 16:50       ` Mitchell Schmeisser via Guix-patches via
2023-03-13 13:52       ` Mitchell Schmeisser via Guix-patches via
2023-03-15 14:45         ` Ludovic Courtès
2023-03-16  1:55           ` Mitchell Schmeisser via Guix-patches via

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fsarmfw6.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=61765@debbugs.gnu.org \
    --cc=mitchellschmeisser@librem.one \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).