From a9b4223ec11eb2a5f50b883aa3706c0194e71835 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Mon, 23 Sep 2024 19:04:36 +0200 Subject: [PATCH] fix: another arm none eabi fix --- ruther/packages/embedded.scm | 91 ++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/ruther/packages/embedded.scm b/ruther/packages/embedded.scm index f1abc26..a2c6dd4 100644 --- a/ruther/packages/embedded.scm +++ b/ruther/packages/embedded.scm @@ -250,7 +250,8 @@ libsupc\\+\\+.a)$")) ; newlib. configure will conclude getentropy is present, ; random will use getentropy, and any linking with random will fail. (if (version>=? (package-version xgcc) "12.0") - (search-patches "newlib-getentropy.patch") + (list + (local-file "patches/newlib-getentropy.patch")) '()) (origin-patches src))))) (name "libstdc++-arm-none-eabi") @@ -288,16 +289,100 @@ libsupc\\+\\+.a)$")) ("xgcc" ,xgcc) ,@(package-native-inputs libstdc++))))))) +(define make-libstdc++-nano-arm-none-eabi + (mlambda (xgcc newlib-nano) + (let ((base (make-libstdc++-arm-none-eabi xgcc newlib-nano))) + (package + (inherit base) + (name "libstdc++-nano-arm-none-eabi") + (arguments (substitute-keyword-arguments (package-arguments base) + ((#:make-flags flags) + #~(map (lambda (flag) + (if (or (string-prefix? "CFLAGS=" flag) + (string-prefix? "CXXFLAGS=" flag)) + (string-append flag " -fno-exceptions") + flag)) + #$flags)) + ((#:phases phases) + #~(modify-phases #$phases + (add-after 'install 'hardlink-libstdc++ + ;; XXX: Most arm toolchains offer both *.a and *_nano.a as + ;; newlib and newlib-nano respectively. The headers are + ;; usually arm-none-eabi/include/newlib.h for newlib and + ;; arm-none-eabi/include/newlib-nano/newlib.h for newlib-nano. + ;; We have two different toolchain packages for each which + ;; works but is a little strange. + (lambda* (#:key outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out"))) + ;; The nano.specs file says that newlib-nano files should + ;; end in "_nano.a" instead of just ".a". Note that this + ;; applies to all the multilib folders too. + (for-each + (lambda (file) + (link file + (string-append + ;; Strip ".a" off the end + (substring file 0 (- (string-length file) 2)) + ;; Add "_nano.a" onto the end + "_nano.a"))) + (find-files + out "^(libstdc\\+\\+.a|libsupc\\+\\+.a)$"))))))))))))) + +(define make-arm-none-eabi-toolchain + (mlambda (xgcc newlib) + "Produce a cross-compiler toolchain package with the compiler XGCC and the +C library variant NEWLIB." + (let* ((nano? (string=? (package-name newlib) + "newlib-nano")) + (newlib-with-xgcc + (package + (inherit newlib) + (native-inputs + (alist-replace "xgcc" (list xgcc) + (package-native-inputs newlib))))) + (libstdc++ + (if nano? + (make-libstdc++-nano-arm-none-eabi xgcc newlib-with-xgcc) + (make-libstdc++-arm-none-eabi xgcc newlib-with-xgcc)))) + (package + (name (string-append "arm-none-eabi" + (if nano? "-nano" "") + "-toolchain")) + (version (package-version xgcc)) + (source #f) + (build-system trivial-build-system) + (arguments + '(#:modules ((guix build union)) + #:builder + (begin + (use-modules (ice-9 match) + (guix build union)) + (match %build-inputs + (((names . directories) ...) + (union-build (assoc-ref %outputs "out") + directories)))))) + (propagated-inputs + `(("binutils" ,(cross-binutils "arm-none-eabi")) + ("libstdc++" ,libstdc++) + ("gcc" ,xgcc) + ("newlib" ,newlib-with-xgcc))) + (synopsis "Complete GCC tool chain for ARM bare metal development") + (description "This package provides a complete GCC tool chain for ARM +bare metal development. This includes the GCC arm-none-eabi cross compiler +and newlib (or newlib-nano) as the C library. The supported programming +languages are C and C++.") + (home-page (package-home-page xgcc)) + (license (package-license xgcc)))))) (define make-arm-none-eabi-toolchain-12.3.rel1 (mlambda () - ((@@ (gnu packages embedded) make-arm-none-eabi-toolchain) + (make-arm-none-eabi-toolchain (make-gcc-arm-none-eabi-12.3.rel1) (make-newlib-arm-none-eabi-12.3.rel1)))) (define make-arm-none-eabi-nano-toolchain-12.3.rel1 (mlambda () - ((@@ (gnu packages embedded) make-arm-none-eabi-toolchain) + (make-arm-none-eabi-toolchain (make-gcc-arm-none-eabi-12.3.rel1) (make-newlib-nano-arm-none-eabi-12.3.rel1)))) -- 2.48.1