Subject: [bug#48767] [PATCH] gnu: gcc-arm-none-eabi-7-2018-q2-update: Simplify build

From: Maxime Devos <[email-masked]>
Date: Fri, 01 Oct 2021 10:56:57 +0200

[email-masked] schreef op ma 27-09-2021 om 17:59 [-0400]:
> From: Morgan Smith <[email-masked]>
> 
> * gnu/packages/embedded.scm
> (gcc-arm-none-eabi-4.9)[phases]: Add expand-version-string phase
> 
> (gcc-arm-none-eabi-7-2018-q2-update): Inherit from gcc-arm-none-eabi-4.9 and
> remove all the redundant bits.
> ---

I see you moved the definition of gcc-arm-none-eabi-7-2018-q2-update.  This patch
would be easier to review if it wasn't moved, as the diff would then be smaller.

> 
> Hello Maxime,
> 
> Thanks for the review!
> 
> Is this the appropriate time to tell you I also have a very eerily similar
> patch set read to go for a riscv cross compiler? Maybe trying to make this
> stuff reusable is a good thing to do. First step is to clean up the arm stuff I
> suppose.

I'm not really familiar with cross-compilation as done in (gnu packages embedded);
I'm more familiar with cross-compilation with "guix build PACKAGE --target=riscv64-...".
If you're doing the latter, you'll need to look at glibc-dynamic-linker in
(gnu packages bootstrap) and (gnu packages cross-base).

> I pretty sure this patch doesn't really change the packages at all in any
> meaningful way. Adding the DEV-PHASE version thing means that now when people
> type 'arm-none-eabi-gcc --version' they'll see in brackets the guix version
> number beside the actual version number.

> Also gcc-arm-none-eabi-7-2018-q2-update now has the 'with-multilib-list' configure
> flag set twice but it's pretty clear it just uses the latter value as it won't
> even compile with the inherited flag value.
> 
> There seems to be a weird glitch when you inherit a phase the uses
> `this-package' but you also specify arguments. I found a work around though.

Alternatively, you could use

  (receive (name version)
    (package-name->name+version (strip-store-file-name (assoc-ref outputs "out")))
    (write version to gcc/DEV-PHASE))

in the 'expand-version-string build phase of gcc-arm-none-eabi-4.9.
Or set the version in a snippet of the 'origin' records (gcc/DEV-PHASE is source
code, right?).  Possibly using (display ,version) instead of
(display ,(package-version this-package)) avoids the issue (not 100% sure though).

[...]

> +;;; The following definitions are for the "7-2018-q2-update" variant of the
> +;;; ARM cross toolchain as offered on https://developer.arm.com
> +(define-public gcc-arm-none-eabi-7-2018-q2-update
> +  (let ((revision "2")
> +        (svn-revision 261907))
> +    (package (inherit gcc-arm-none-eabi-6)
> +      (version (string-append "7-2018-q2-update-"

The version strings of GCC are things like "11.2.0" or "6.5.0",
not strings like "7.5.0".  As this is a SVN snapshot, and appears to be
based on the 7.?.? series, maybe something like "7.MINOR.PATCH-REVISION-SVNREVISION"
would be appropriate?

I'm wondering why a SVN revision revision is used, as presumably the embedded-7-branch
has been merged and would be available from an appropriately-configured [email-masked], [email-masked],
or [email-masked]?

A comment next to gcc-arm-none-eabi-4.9 says

;; We must not use the released GCC sources here, because the cross-compiler
;; does not produce working binaries.  Instead we take the very same SVN
;; revision from the branch that is used for a release of the "GCC ARM
;; embedded" project on launchpad.
;; See https://launchpadlibrarian.net/218827644/release.txt

but maybe these bugs have been solved by now, or is using the branch still required?

> +                              revision "." (number->string svn-revision)))
> +      (source
> +       (origin
> +         (method svn-fetch)
> +         (uri (svn-reference
> +               (url "svn://gcc.gnu.org/svn/gcc/branches/ARM/embedded-7-branch/")
> +               (revision svn-revision)))
> +         (file-name (string-append "gcc-arm-embedded-" version "-checkout"))
> +         (sha256
> +          (base32
> +           "192ggs63bixf3irpijgfkjks73yx1r3a4i6grk1y0i0iny76pmx5"))
> +         (patches
> +          (append
> +           (origin-patches (package-source gcc-7))
> +           (search-patches "gcc-7-cross-environment-variables.patch")))))
> +      (arguments
> +       (substitute-keyword-arguments (package-arguments gcc-arm-none-eabi-4.9)
> +         ((#:configure-flags flags)
> +          ;; I add this flag on the end so it overrides the previously set value
> +          `(append ,flags (list "--with-multilib-list=rmprofile")))
> +         ((#:phases phases)
> +          `(modify-phases ,phases
> +             ;; XXX: I replicated this phase just so that the version is
> +             ;; correct.  This phase automatically gets the correct version if
> +             ;; I don't specify any arguments for a package for some reason
> +             ;; (see gcc-arm-none-eabi-6)
> +             (replace 'expand-version-string
> +               (lambda _
> +                 (make-file-writable "gcc/DEV-PHASE")
> +                 (with-output-to-file "gcc/DEV-PHASE"
> +                   (lambda ()
> +                     (display ,(package-version this-package)))))))))))))
> +

Greetings,
Maxime.