unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jean-Pierre De Jesus Diaz <jean@foundationdevices.com>
To: guix-devel@gnu.org
Subject: Rust cross-compilation support.
Date: Wed, 7 Jun 2023 14:39:55 +0200	[thread overview]
Message-ID: <CAG1gdUpvgduZzezTFBZWuEvyRGo_VTdKgE5aw0+f7oH5xa=9YQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2966 bytes --]

Hello,

I'd like to use GNU Guix to build embedded software using Rust.

Currently I'm thinking of using GNU Guix and Rust for embedded
development but currently Rust does not support cross-compilation
as libstd is only compiled for the "host" target.

I was thinking that GNU Guix could provide a separate package
(or output) containing those targets like rustup does.  This could
also enable cross-compilation support in cargo-build-system (or
antioxidant).

The thing is that I haven't found an efficient way of doing it since
building libstd/libcore for another target requires re-building rustc
again.  So using a freshly built rust package as the input for another
rust-extra-targets package loses any potential benefit.

Maybe the same Rust package can build a select list of tier-1/2/3
targets and add a new output containing those.  But that approach
would slow down the build of the rust package.

Do you people see any other solutions to this?

FWIW I've managed to compile libcore for thumbv7em-none-eabihf with:

--8<---------------cut here---------------start------------->8---
(define-public rust-with-targets
  (package
    (inherit rust)
    (name "rust-with-targets")
    (arguments
      (substitute-keyword-arguments (package-arguments rust)
        ((#:phases phases)
          `(modify-phases ,phases
             (add-after 'configure 'add-targets-to-config
               (lambda* (#:key inputs #:allow-other-keys)
                 (let ((arm-gcc (assoc-ref inputs
"gcc-cross-sans-libc-arm-none-eabi"))
                       (arm-binutils (assoc-ref inputs
"binutils-cross-arm-none-eabi")))
                 (substitute* "config.toml"
                   (("^python =.*" all)
                    (string-append all
                                   "target = [
  \"" ,((@@ (gnu packages rust) nix-system->gnu-triplet-for-rust)) "\",
  \"thumbv7em-none-eabihf\",
]\n"))
                   (("^ar =.*" all)
                    (string-append all
                                   "[target.thumbv7em-none-eabihf]
ar = \"" arm-binutils "/bin/arm-none-eabi-ar\"
cc = \"" arm-gcc "/bin/arm-none-eabi-gcc\"
cxx = \"" arm-gcc "/bin/arm-none-eabi-g++\"
no-std = true\n"))))))
             ;; Rust tries to compile std for thumbv7em-none-eabihf but that
             ;; does not work as the target does not have a std
implementation.
             ;;
             ;; Maybe this can worked around by only testing for the host
             ;; architecture and compiling tests for libcore only for
             ;; thumbv7em-none-eabihf, but I don't know if that's possible.
             (delete 'check)))))
    (native-inputs
      (modify-inputs (package-native-inputs rust)
        (append (cross-binutils "arm-none-eabi"))
        (append (cross-gcc "arm-none-eabi"))))))
--8<---------------cut here---------------end--------------->8---

Cheers,

—
Jean-Pierre De Jesus DIAZ

[-- Attachment #2: Type: text/html, Size: 3584 bytes --]

                 reply	other threads:[~2023-06-11 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='CAG1gdUpvgduZzezTFBZWuEvyRGo_VTdKgE5aw0+f7oH5xa=9YQ@mail.gmail.com' \
    --to=jean@foundationdevices.com \
    --cc=guix-devel@gnu.org \
    /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).