unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Rust cross-compilation support.
@ 2023-06-07 12:39 Jean-Pierre De Jesus Diaz
  0 siblings, 0 replies; only message in thread
From: Jean-Pierre De Jesus Diaz @ 2023-06-07 12:39 UTC (permalink / raw)
  To: guix-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-11 18:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 12:39 Rust cross-compilation support Jean-Pierre De Jesus Diaz

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).