summaryrefslogtreecommitdiff
path: root/gnu/packages/commencement.scm
diff options
context:
space:
mode:
authorEfraim Flashner <efraim@flashner.co.il>2025-07-28 09:56:23 +0300
committerJanneke Nieuwenhuizen <janneke@gnu.org>2026-01-28 21:47:41 +0100
commitec2ba23a3914acbdf8918add47ddca16deee5ce7 (patch)
tree560213933a17933d96d832ee25066386cba3a894 /gnu/packages/commencement.scm
parent108b89f8eb7ab2da47a9090a69bcc289b3faa374 (diff)
WIP: maybe add gcc-musl-boot0
Change-Id: I23378f4d2be678874b3e4a1c0e7c088644c4b208
Diffstat (limited to 'gnu/packages/commencement.scm')
-rw-r--r--gnu/packages/commencement.scm189
1 files changed, 189 insertions, 0 deletions
diff --git a/gnu/packages/commencement.scm b/gnu/packages/commencement.scm
index 638816eb882..54e39b19eb4 100644
--- a/gnu/packages/commencement.scm
+++ b/gnu/packages/commencement.scm
@@ -3447,6 +3447,195 @@ exec " gcc "/bin/" program
3447 (inputs (%boot0-inputs)) 3447 (inputs (%boot0-inputs))
3448 (native-inputs '())))) 3448 (native-inputs '()))))
3449 3449
3450;; This is used to build libstdc++-boot0-gcc7 when coming from riscv64,
3451;; since it doesn't seem that gcc-4.6 can build libstdc++@7 by itself.
3452(define gcc-musl-boot0
3453 (package
3454 (inherit gcc-7)
3455 (name "gcc")
3456 (source (bootstrap-origin (package-source gcc-7)))
3457 (inputs `(;("gmp-source" ,(bootstrap-origin (package-source gmp-6.0)))
3458 ;("mpfr-source" ,(bootstrap-origin (package-source mpfr)))
3459 ;("mpc-source" ,(bootstrap-origin (package-source mpc)))
3460 ("gmp-boot" ,gmp-boot)
3461 ("mpfr-boot" ,mpfr-boot)
3462 ("mpc-boot" ,mpc-boot)
3463 ;,@(modify-inputs (%boot0-inputs)
3464 ; (replace "libc" musl-boot-static))))
3465 ,@(%boot0-inputs)))
3466 (propagated-inputs '())
3467 (native-inputs '())
3468 (arguments
3469 (substitute-keyword-arguments (package-arguments gcc-7)
3470 ((#:guile _ %bootstrap-guile) %bootstrap-guile)
3471 ((#:implicit-inputs? _ #f) #f)
3472 ((#:phases phases)
3473 #~(modify-phases #$phases
3474 (add-after 'patch-source-shebangs 'patch-extra-shebangs
3475 (lambda _
3476 (substitute* "gcc/genmultilib"
3477 (("#!/bin/sh") (string-append "#!" (which "sh"))))))
3478 (add-before 'patch-source-shebangs 'delete-broken-shebangs
3479 (lambda _
3480 (for-each (lambda (file)
3481 (delete-file-recursively file))
3482 (find-files "gcc/testsuite/gdc.test/compilable" "\\.d$"))))
3483 (add-after 'pre-configure 'fix-dynamic-linker-for-musl
3484 (lambda* (#:key inputs #:allow-other-keys)
3485 (let ((libc (assoc-ref inputs "libc")))
3486 ;; Fix the dynamic linker's file name.
3487 ;; This should work on gcc-13 for all architectures except loongarch.
3488 (substitute* (find-files "gcc/config"
3489 "^(aarch64-)?(linux|gnu|sysv4)(64|-elf|-eabi)?\\.h$")
3490 (("(#define MUSL_DYNAMIC_LINKER*).*$" _ dynamic-linker)
3491 ;; TODO: Make this use architecture specific ld-musl-*.so
3492 (string-append dynamic-linker " \"" libc "/lib/libc.so\""))
3493 ;; We also need to adjust the references made for glibc
3494 ;; to point to the musl linker location
3495 #;
3496 (("#define (GLIBC|GNU_USER)_DYNAMIC_LINKER([^ \t]*).*$"
3497 _ gnu-user suffix)
3498 (format #f "#define ~a_DYNAMIC_LINKER~a \"~a\"~%"
3499 gnu-user suffix
3500 (string-append libc "/lib/libc.so")))))))
3501 (add-after 'unpack 'adjust-cplus-include-path
3502 (lambda* (#:key outputs #:allow-other-keys)
3503 (let* ((bash (assoc-ref %build-inputs "bash"))
3504 (gcc (assoc-ref %build-inputs "gcc")))
3505 (setenv "C_INCLUDE_PATH" (string-append
3506 (getenv "C_INCLUDE_PATH") ":"
3507 gcc "/lib/gcc-lib/"
3508 #$(commencement-build-target)
3509 "/4.6.4/include"
3510 ;":" (getcwd) "/mpfr/src"
3511 ))
3512 (setenv "CPLUS_INCLUDE_PATH" (string-append
3513 (getenv "CPLUS_INCLUDE_PATH") ":"
3514 gcc "/lib/gcc-lib/"
3515 #$(commencement-build-target)
3516 "/4.6.4/include"
3517 ;":" (getcwd) "/mpfr/src"
3518 ))
3519 (format (current-error-port) "C_INCLUDE_PATH=~a\n" (getenv "C_INCLUDE_PATH"))
3520 (format (current-error-port) "CPLUS_INCLUDE_PATH=~a\n" (getenv "CPLUS_INCLUDE_PATH"))
3521 (format (current-error-port) "LIBRARY_PATH=~a\n"
3522 (getenv "LIBRARY_PATH")))))
3523 #;
3524 (add-after 'unpack 'unpack-gmp&co
3525 (lambda* (#:key inputs #:allow-other-keys)
3526 (let ((gmp (assoc-ref %build-inputs "gmp-source"))
3527 (mpfr (assoc-ref %build-inputs "mpfr-source"))
3528 (mpc (assoc-ref %build-inputs "mpc-source")))
3529
3530 ;; To reduce the set of pre-built bootstrap inputs, build
3531 ;; GMP & co. from GCC.
3532 (for-each (lambda (source)
3533 (invoke "tar" "xvf" source))
3534 (list gmp mpfr mpc))
3535
3536 ;; Create symlinks like `gmp' -> `gmp-x.y.z'.
3537 #$@(map (lambda (lib)
3538 ;; Drop trailing letters, as gmp-6.0.0a unpacks
3539 ;; into gmp-6.0.0.
3540 #~(symlink #$(string-trim-right
3541 (package-full-name lib "-")
3542 char-set:letter)
3543 #$(package-name lib)))
3544 (list gmp-6.0 mpfr mpc)))))
3545 #;
3546 (add-before 'configure 'adjust-os-defines-h
3547 (lambda _
3548 ;; The gnu-linux version chokes on '__GLIBC_PREREQ(2,15)'
3549 ;; We need to use the generic version for musl.
3550 (copy-file "libstdc++-v3/config/os/generic/os_defines.h"
3551 "libstdc++-v3/config/os/gnu-linux/os_defines.h")
3552 #;
3553 (with-output-to-file "libstdc++-v3/config/os/gnu-linux/os_defines.h"
3554 (lambda _
3555 (display "#ifndef _GLIBCXX_OS_DEFINES
3556#define _GLIBCXX_OS_DEFINES 1
3557#define __NO_CTYPE 1
3558#include <features.h>
3559#endif")))))
3560 #;
3561 (add-before 'configure 'setenv
3562 (lambda _
3563 ;; This is needed to wrap gcc to use musl correctly.
3564 (setenv "CC" "musl-gcc")))))
3565 ;; gimple-match.c:43995:1: internal compiler error: Segmentation fault
3566 ;; Only with --disable-bootstrap?
3567 ;; Also with plenty of items disabled. Needs more investigation.
3568 ((#:parallel-build? _ #t) #f)
3569 ((#:make-flags _ #~'())
3570 ;; Remove the LDFLAGS for libc from the make-flags
3571 #~(list "CFLAGS=-g0 -O2"
3572 "BOOT_CFLAGS=-O2 -g0"
3573 ))
3574 ((#:configure-flags _ #~'())
3575 #~(let ((out (assoc-ref %outputs "out"))
3576 (musl (assoc-ref %build-inputs "libc")))
3577 (list ;"LDFLAGS=-static"
3578 (string-append "--prefix=" out)
3579 ;"--with-local-prefix=/no-gcc-local-prefix"
3580 (string-append "--build=" #$(commencement-build-target))
3581 (string-append "--host=" #$(commencement-build-target))
3582 ;"--host=riscv64-unknown-linux-musl"
3583 ;"--build=riscv64-unknown-linux-musl"
3584 ;(string-append "--host=" #$(commencement-build-target))
3585 ;(string-append "--build=" #$(commencement-build-target))
3586 ;(string-append "--with-build-sysroot=" musl )
3587 (string-append "--with-native-system-header-dir=" musl "/include")
3588 (string-append "--with-gxx-include-dir=" out "/include/c++")
3589
3590 ;; These 3 seem necessary after switching CC to musl-gcc.
3591 (string-append "--with-gmp=" (assoc-ref %build-inputs "gmp-boot"))
3592 (string-append "--with-mpfr=" (assoc-ref %build-inputs "mpfr-boot"))
3593 (string-append "--with-mpc=" (assoc-ref %build-inputs "mpc-boot"))
3594
3595 ;"--with-stage1-ldflags=-static"
3596
3597 "--disable-bootstrap"
3598 "--disable-decimal-float"
3599 "--disable-libatomic"
3600 "--disable-libcilkrts"
3601 "--disable-libgomp"
3602 "--disable-libitm"
3603 "--disable-libmudflap"
3604 "--disable-libquadmath"
3605 "--disable-libsanitizer"
3606 "--disable-libssp"
3607 "--disable-libvtv"
3608
3609 ;; Need to recompile musl with -fPIC
3610 ;; ld: unrecognized option '-plugin'
3611 "--disable-lto"
3612 "--disable-lto-plugin"
3613
3614 "--disable-multilib"
3615
3616 ;; Building GCC with plugin support requires a host that supports
3617 ;; -fPIC, -shared, -ldl and -rdynamic.
3618 ;; ld: unrecognized option '-plugin'
3619 ;; Is that even relevant for this flag?
3620 ;"--enable-plugin"
3621 "--disable-plugin"
3622
3623 "--disable-threads"
3624 ;"--enable-languages=c,c++"
3625 "--enable-languages=c"
3626
3627 ;; libgcc recompile with -fPIC
3628 ;"--enable-static"
3629 ;"--disable-static"
3630 "--disable-shared"
3631
3632 ;"--enable-threads=single"
3633 "--disable-libstdc++-v3"
3634 "--disable-libstdcxx-pch"
3635 "--disable-build-with-cxx"
3636 "--without-headers"
3637 )))))))
3638
3450(define (make-libstdc++-boot0 gcc) 3639(define (make-libstdc++-boot0 gcc)
3451 ;; GCC >= 7 is needed by architectures which use C++-14 features. 3640 ;; GCC >= 7 is needed by architectures which use C++-14 features.
3452 (let ((lib (make-libstdc++ gcc))) 3641 (let ((lib (make-libstdc++ gcc)))