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