Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
Created October 2, 2020 15:29
Show Gist options
  • Save CoderPuppy/fdcaea0ef8c85fdfc69e4af02e2d893f to your computer and use it in GitHub Desktop.
Save CoderPuppy/fdcaea0ef8c85fdfc69e4af02e2d893f to your computer and use it in GitHub Desktop.
Guix packages for Idris 2, bootstrapping all the way
(use-modules
(guix profiles)
(gnu packages idris)
(guix packages)
(guix git-download)
(guix download)
(guix build-system gnu)
((guix licenses) #:prefix license:)
(gnu packages multiprecision)
(gnu packages llvm)
(gnu packages chez))
(define idris2-boot
(let ((commit "0fb1192cd30ec4747cbc727f26ddbfad515d1363"))
(package
(name "idris2-boot")
(version (git-version "0.1.0" "1" commit))
(source (origin
(method git-fetch)
(uri (git-reference
(url "git://github.com/edwinb/idris2-boot.git")
(commit commit)))
(sha256 (base32 "1f0b2mb7xahc4mrhbw8vp5b6iv3ci1z7yz7h12i8mnmy3nddpsfn"))
(file-name (git-file-name name version))))
(build-system gnu-build-system)
(arguments `(#:phases (modify-phases %standard-phases
(replace 'configure (lambda _
(let ((out (assoc-ref %outputs "out")))
(setenv "PREFIX" out)
(setenv "IDRIS_CC" "clang"))))
(replace 'build (lambda _
(invoke "make" (string-append "PREFIX=" (getenv "PREFIX")) "idris2boot" "libs")))
(replace 'install (lambda _
(invoke "make" (string-append "PREFIX=" (getenv "PREFIX")) "install-all")))
(delete 'check)
)))
(inputs `(
("clang" ,clang)
("idris" ,idris)
("gmp" ,gmp)
("chez-scheme" ,chez-scheme)))
(home-page "https://idris-lang.org/")
(synopsis "A dependently typed programming language, a successor to Idris")
(description "This is the bootstrapping version of Idris 2, the successor to Idris. Its sole purpose is to build Idris 2 proper.")
(license license:bsd-3))))
; if the new stdlib has a dependency on the new compiler, libs-first must be false
; this happens if new primitives are introduced
; for example 7d046652d8c7746fc4dff4f63a454ae0542dcf9b
; if the new compiler has a dependency on the new stdlib, libs-first must be true
; for example d105dd11a7e76dae28c34a43f931608b0e08c95e
; if the new compiler depends on the new C support library, force-prefix must be true
; it's very hacky and requires that the old stdlib works with the new C support library
; it may also be required if libs-first is true and the new stdlib depends on the new C support library
; and it may also require that the old compiler works with the new C support library
; sometimes the new C support library is not backwards-compatible
; for example f696335f2d9cbb3a02a93d898fd67a87ef3450ee
(define*
(make-idris2
version hash boot
#:key
(uri (string-append
"https://github.com/idris-lang/Idris2/archive/v"
version
".tar.gz"))
(boot-bin-name "idris2")
(libs-first #f)
(force-prefix #f))
(package
(name "idris2")
(version version)
(source (origin
(method url-fetch)
(uri uri)
(sha256 (base32 hash))))
(build-system gnu-build-system)
(arguments `(
#:phases (modify-phases %standard-phases
(replace 'configure (lambda* (#:key inputs outputs #:allow-other-keys)
(setenv "PREFIX" (assoc-ref outputs "out"))
(setenv "CC" "clang")
#t))
(delete 'bootstrap)
(replace 'build (lambda* (#:key inputs outputs #:allow-other-keys)
(use-modules
((ice-9 popen))
((rnrs io ports)))
(define cwd (getcwd))
(define boot-libdir (let*
(
(pipe (open-pipe* OPEN_READ ,boot-bin-name "--libdir"))
(text (get-string-all pipe))
)
(unless (zero? (close-pipe pipe))
(error "failed to get the libdir of the bootstrapping Idris2"))
(string-trim-both text)))
(define prefix (getenv "PREFIX"))
(when ,force-prefix
(setenv "IDRIS2_PREFIX" (assoc-ref outputs "out")))
(invoke "make"
(string-append "PREFIX=" prefix)
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
"support")
(invoke "make"
(string-append "PREFIX=" prefix)
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
"install-support")
(when ,libs-first
(copy-recursively
(string-append (assoc-ref inputs "idris2-boot") "/bin")
(string-append cwd "/build/exec"))
(invoke "make"
(string-append "PREFIX=" prefix)
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
"libs")
(delete-file-recursively (string-append cwd "/build")))
(invoke "make"
(string-append "PREFIX=" prefix)
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
(if ,libs-first
(string-append "IDRIS2_PATH="
cwd "/libs/prelude/build/ttc:"
cwd "/libs/base/build/ttc:"
cwd "/libs/contrib/build/ttc:"
cwd "/libs/network/build/ttc")
(string-append "IDRIS2_PATH="
boot-libdir "/prelude:"
boot-libdir "/base:"
boot-libdir "/contrib:"
boot-libdir "/network"))
(string-append "IDRIS2_DATA="
(if ,libs-first
cwd boot-libdir)
"/support")
"build/exec/idris2" "testbin")
(patch-shebang (string-append cwd "/build/exec/idris2"))
(when ,libs-first
(invoke "make"
(string-append "PREFIX=" (getenv "PREFIX"))
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
"clean-libs"))
(invoke "make"
(string-append "PREFIX=" (getenv "PREFIX"))
(string-append "IDRIS2_BOOT=" ,boot-bin-name)
"libs")))
(replace 'install (lambda _
(invoke "make"
(string-append "PREFIX=" (getenv "PREFIX"))
"install")))
(delete 'check)
)
))
(native-inputs `(
("idris2-boot" ,boot)
("clang" ,clang)))
(inputs `(
("chez-scheme" ,chez-scheme)))
(home-page "https://idris-lang.org/")
(synopsis "A dependently typed programming language, a successor to Idris")
(description "")
(license license:bsd-3)))
; last version which supports idris2-boot
(define idris2-0.2.1-boot (make-idris2
"0.2.1" "1izw68vnic9rh5yzvq85f9bm9qnkbdiipfqymgq04a2rr59n5qbv"
idris2-boot #:boot-bin-name "idris2boot"))
; current stable
(define idris2 (make-idris2
"0.2.1" "1izw68vnic9rh5yzvq85f9bm9qnkbdiipfqymgq04a2rr59n5qbv"
idris2-0.2.1-boot))
; adds some new primitives, requires compiler first
(define idris2-7d04665 (make-idris2
"0.2.1.7d04665" "13cgvn3bm6xs9hl32l7lcri5lmzqjxllxza3831nyrgmgvqjfz3d"
idris2-0.2.1-boot #:uri "https://github.com/idris-lang/Idris2/archive/7d046652d8c7746fc4dff4f63a454ae0542dcf9b.tar.gz"
; this forces it to use the new support library
; which is not good in general
; in this case it works because new one is backwards compatible
#:force-prefix #t))
; new stdlib features, requires libs first
(define idris2-1619206 (make-idris2
"0.2.1.1619206" "1nm75aiy6zmd0pfd7kjj9hc35pw9rqgq5lzfkhpb376dkz0m3gpl"
idris2-7d04665 #:uri "https://github.com/idris-lang/Idris2/archive/1619206d241075f0bff5b0cba0ed68769b4987ef.tar.gz"
#:libs-first #t))
(packages->manifest (list
idris idris-lens
idris2-1619206
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment