1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-05-28 12:01:49 +02:00

gnu: nim: Update to 2.2.2

* gnu/packages/nim.scm (atlas, sat): New variables.
(nim): Update to 2.2.0. [arguments]: Use G-expressions.
<#:modules> Import modules used by phases. <#:phases>:
Add phase "copy-deps". Update phases "patch-installer",
"patch-dynamic-libraries", and "patch-more-shebangs".

Change-Id: I3f88dd6a3b78699e91e59b23ededf9f1923eb721
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Ashish SHUKLA
2025-02-24 22:27:35 +00:00
committed by Ludovic Courtès
parent a145be2834
commit 7810b6acb3
+189 -96
View File
@@ -6,6 +6,7 @@
;;; Copyright © 2022 (unmatched parenthesis <paren@disroot.org> ;;; Copyright © 2022 (unmatched parenthesis <paren@disroot.org>
;;; Copyright © 2022 Trevor Richards <trev@trevdev.ca> ;;; Copyright © 2022 Trevor Richards <trev@trevdev.ca>
;;; Copyright © 2023 Gruruya <greytest@disroot.org> ;;; Copyright © 2023 Gruruya <greytest@disroot.org>
;;; Copyright © 2025 Ashish SHUKLA <ashish.is@lostca.se>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@@ -25,6 +26,8 @@
(define-module (gnu packages nim) (define-module (gnu packages nim)
#:use-module (guix build-system gnu) #:use-module (guix build-system gnu)
#:use-module (guix download) #:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix gexp)
#:use-module ((guix licenses) #:prefix license:) #:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages) #:use-module (guix packages)
#:use-module (gnu packages bdw-gc) #:use-module (gnu packages bdw-gc)
@@ -34,120 +37,210 @@
#:use-module (gnu packages sqlite) #:use-module (gnu packages sqlite)
#:use-module (gnu packages tls)) #:use-module (gnu packages tls))
(define atlas
(origin
(method git-fetch)
(file-name "atlas-checkout")
(uri
(git-reference
(url "https://github.com/nim-lang/atlas.git")
;; referenced in koch.nim
(commit "5faec3e9a33afe99a7d22377dd1b45a5391f5504")))
(sha256 (base32 "1yd3pcg46blkxfkpcvymfln44wgryq9v1mcxblqjhgfi0rvdjm0v"))))
(define sat
(origin
(method git-fetch)
(file-name "sat-checkout")
(uri
(git-reference
(url "https://github.com/nim-lang/sat.git")
;; referenced in koch.nim
(commit "faf1617f44d7632ee9601ebc13887644925dcc01")))
(sha256 (base32 "1dxbc41wbvkpdp6q3qz1r38lpn32447qkkgyh2s12ym6bx4ynni4"))))
(define-public nim (define-public nim
(package (package
(name "nim") (name "nim")
(version "1.6.12") (version "2.2.2")
(source (source
(origin (origin
(method url-fetch) (method url-fetch)
(uri (string-append "https://nim-lang.org/download/" (uri (string-append "https://nim-lang.org/download/"
name "-" version ".tar.xz")) name "-" version ".tar.xz"))
(sha256 (sha256
(base32 "1hjd9dxhqzn2ifr988li8q7v6kxpxlcqbdllfd6lsq3knw50pvxc")))) (base32 "07wazlsj3yby4vb008b2rairdkl0hhnnxhpxi6jaa2wwmj3rpk3z"))))
(build-system gnu-build-system) (build-system gnu-build-system)
(arguments (arguments
`(#:tests? #f ; TODO: Investigate tests failures. `(#:tests? #f ; TODO: Investigate tests failures.
#:modules
((ice-9 rdelim)
(ice-9 regex)
(ice-9 match)
,@%default-gnu-modules)
#:phases #:phases
(modify-phases %standard-phases ,#~(modify-phases %standard-phases
(delete 'configure) ; no configure script (delete 'configure) ; no configure script
(add-after 'unpack 'patch-installer (add-after 'unpack 'copy-deps:www
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let ((out (assoc-ref outputs "out"))) (copy-recursively #$(this-package-input "atlas-checkout") "dist/atlas"
(substitute* "install.sh" #:keep-permissions? #f)
(("/usr/local") out) (copy-recursively #$(this-package-input "sat-checkout") "dist/atlas/dist/sat"
(("/lib/nim") "/lib") #:keep-permissions? #f)))
(("/opt/nimble") (string-append out "/share/nimble")) (add-after 'unpack 'patch-installer
(("configdir=/etc/nim") (lambda* (#:key outputs #:allow-other-keys)
(string-append "configdir=" out "/etc/nim")))))) (let ((out (assoc-ref outputs "out")))
(add-after 'unpack 'patch-dynamic-libraries (substitute* "install.sh"
(lambda* (#:key inputs native-inputs #:allow-other-keys) (("/usr/local") out)
;(substitute* "compiler/nodejs.nim" (("/lib/nim") "/")
; (("nodejs") (("/opt/nimble") (string-append out "/share/nimble"))
; (search-input-file (or native-inputs inputs) (("configdir=\"/etc/nim\"")
; "/bin/nodejs")) (string-append "configdir=\"" out "/etc/nim\""))))))
; (("node") (add-after 'unpack 'patch-dynamic-libraries
; (search-input-file (or native-inputs inputs) (lambda* (#:key inputs native-inputs #:allow-other-keys)
; "/bin/node"))) (substitute* "lib/system.nim"
(substitute* "lib/system.nim" (("libgc\\.so")
(("libgc\\.so") (search-input-file (or native-inputs inputs)
(search-input-file (or native-inputs inputs) "/lib/libgc.so")))
"/lib/libgc.so"))) (substitute* "lib/wrappers/openssl.nim"
;(substitute* "lib/wrappers/mysql.nim" (("libssl\\.so")
; (("\(libmysqlclient|libmariadbclient\)\\.so") (search-input-file (or native-inputs inputs)
; (search-input-file (or native-inputs inputs) "/lib/libssl.so"))
; "/lib/libmariadbclient.so"))) (("libcrypto\\.so")
(substitute* "lib/wrappers/openssl.nim" (search-input-file (or native-inputs inputs)
(("libssl\\.so") "/lib/libcrypto.so")))
(search-input-file (or native-inputs inputs) (substitute* "lib/wrappers/pcre.nim"
"/lib/libssl.so")) (("libpcre\\.so")
(("libcrypto\\.so") (search-input-file (or native-inputs inputs)
(search-input-file (or native-inputs inputs) "/lib/libpcre.so")))))
"/lib/libcrypto.so"))) (add-after 'patch-source-shebangs 'patch-more-shebangs
(substitute* "lib/wrappers/pcre.nim" (lambda _
(("libpcre\\.so")
(search-input-file (or native-inputs inputs) (define sh (which "sh"))
"/lib/libpcre.so"))) (define sh-len (string-length sh))
;(substitute* "lib/wrappers/postgres.nim"
; (("libpg\\.so") (define rx1 (make-regexp "^(.*NIM_CHAR data\\[)7(\\+1\\];.*)$" regexp/extended))
; (search-input-file (or native-inputs inputs) ;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { 7 | NIM_STRLIT_FLAG, "/bin/sh" };
; "/lib/libpg.so"))) (define rx2 (make-regexp
(substitute* "lib/wrappers/sqlite3.nim" (string-append "^(\\} )"
(("libsqlite3\\.so") "([^[:space:]]+)"
(search-input-file (or native-inputs inputs) "( = \\{ )"
"/lib/libsqlite3.so"))))) "7"
(add-after 'patch-source-shebangs 'patch-more-shebangs "( [|] NIM_STRLIT_FLAG, )"
(lambda _ "\"/bin/sh\""
(let ((sh (which "sh"))) "(.*)$")
regexp/extended))
(define (fixup-1 matches out)
(format out "~a~a~a\n"
;; NI cap; NIM_CHAR data[(string-length (which "sh"))+1];
(match:substring matches 1) ;; NI cap; NIM_CHAR data[
sh-len ;; (string-length (which "sh")
(match:substring matches 2)) ;; +1];
#f)
(define (fixup-2 matches out)
(format out "~a~a~a~a~a~s~a\n"
;; } TM__HZdw8BhppcTQo8DIK46LSg_5 = { (string-length (which "sh")) | NIM_STRLIT_FLAG, (which "sh") };
(match:substring matches 1) ;; }
(match:substring matches 2) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
(match:substring matches 3) ;; = {
sh-len ;; (string-length (which "sh"))
(match:substring matches 4) ;; | NIM_STRLIT_FLAG,
sh ;; (which "sh")
(match:substring matches 5)) ;; };
;; return a reference to patch
(match:substring matches 2)) ;; TM__HZdw8BhppcTQo8DIK46LSg_5
(define fixups
(list (list rx1 fixup-1)
(list rx2 fixup-2)))
(define (rx-match rx-list line in out)
(if (null? rx-list)
(begin
(format out "~a\n" line)
#f)
(match rx-list
(((rx fixup) . rest)
(let ((matches (regexp-exec rx line)))
(if (regexp-match? matches)
(fixup matches out)
(rx-match rest line in out)))))))
(define (fixup-bin-sh-references in out)
(let loop ((line (read-line in))
(flagged #f))
(let* ((pat (and (string? flagged)
(format #f "{7, (NimStrPayload*)&~a};" flagged)))
(pat-len (if (string? pat) (string-length pat) 0)))
(unless (eof-object? line)
(if (and (string? pat) (string-suffix? pat line))
(begin
(format out
"~a{~a, (NimStrPayload*)&~a};\n"
(substring line 0
(- (string-length line) pat-len))
sh-len
flagged)
(loop (read-line in) flagged))
(loop (read-line in)
(rx-match fixups line in out)))))))
(substitute* '("tests/stdlib/tosprocterminate.nim" (substitute* '("tests/stdlib/tosprocterminate.nim"
"tests/stdlib/tstrscans.nim" "tests/stdlib/tstrscans.nim"
"lib/pure/osproc.nim" "lib/pure/osproc.nim"
"lib/pure/strscans.nim") "lib/pure/strscans.nim")
(("/bin/sh") sh)) (("/bin/sh") sh))
(substitute* (find-files "c_code" "@m\\.\\.@slib@spure@sosproc\\.nim\\.c")
(("\"/bin/sh\", 7") (format #f "~s, ~s" sh (string-length sh))))))) (for-each (lambda (f)
(replace 'build (with-atomic-file-replacement f fixup-bin-sh-references))
(lambda* (#:key (parallel-build? #t) #:allow-other-keys) (find-files "c_code" "@m\\.\\.@slib@spure@sosproc\\.nim\\.c"))))
(setenv "XDG_CACHE_HOME" "./cache-home") (replace 'build
(setenv "HOME" "./cache-home") (lambda* (#:key (parallel-build? #t) #:allow-other-keys)
(mkdir-p "./cache-home") (setenv "XDG_CACHE_HOME" "./cache-home")
(invoke "sh" "build.sh" (setenv "HOME" "./cache-home")
"--parallel" (setenv "SHELL" (which "sh"))
(if parallel-build? (mkdir-p "./cache-home")
(number->string (parallel-job-count)) (invoke "sh" "build.sh"
"1")) "--parallel"
(sleep 5) ; Wait for the parallel builds to finish. (if parallel-build?
(invoke "./bin/nim" "c" "-d:release" "koch") (number->string (parallel-job-count))
(invoke "./koch" "boot" "-d:release") "1"))
(invoke "./koch" "tools"))) (sleep 5) ; Wait for the parallel builds to finish.
(replace 'check (invoke "./bin/nim" "c" "-d:release" "koch")
(lambda* (#:key tests? #:allow-other-keys) (invoke "./koch" "boot" "-d:release")
(when tests? (invoke "./koch" "tools")))
(invoke "./koch" "tests")))) (replace 'check
(replace 'install (lambda* (#:key tests? #:allow-other-keys)
(lambda* (#:key outputs #:allow-other-keys) (when tests?
(let ((bin (string-append (assoc-ref outputs "out") "/bin"))) (invoke "./koch" "tests"))))
(mkdir-p bin) (replace 'install
(invoke "./install.sh" bin) (lambda* (#:key outputs #:allow-other-keys)
(for-each (lambda (file) (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
(install-file file bin)) (mkdir-p bin)
(delete "testament" (find-files "bin")))))) (invoke "./install.sh" bin)
(add-after 'install 'install-completions (for-each (lambda (file)
(lambda* (#:key outputs #:allow-other-keys) (install-file file bin))
(let* ((share (string-append (assoc-ref outputs "out") "/share")) (delete "testament" (find-files "bin"))))))
(bash (string-append share "/bash-completion/completions")) (add-after 'install 'install-completions
(zsh (string-append share "/zsh/vendor_completions"))) (lambda* (#:key outputs #:allow-other-keys)
(mkdir-p bash) (let* ((share (string-append (assoc-ref outputs "out") "/share"))
(mkdir-p zsh) (bash (string-append share "/bash-completion/completions"))
(copy-file "tools/nim.bash-completion" (zsh (string-append share "/zsh/vendor_completions")))
(string-append bash "/nim")) (mkdir-p bash)
(copy-file "dist/nimble/nimble.bash-completion" (mkdir-p zsh)
(string-append bash "/nimble")) (copy-file "tools/nim.bash-completion"
(copy-file "tools/nim.zsh-completion" (string-append bash "/nim"))
(string-append zsh "/_nim")) (copy-file "dist/nimble/nimble.bash-completion"
(copy-file "dist/nimble/nimble.bash-completion" (string-append bash "/nimble"))
(string-append zsh "/_nimble")))))))) (copy-file "tools/nim.zsh-completion"
(inputs (list libgc openssl pcre sqlite)) (string-append zsh "/_nim"))
(copy-file "dist/nimble/nimble.bash-completion"
(string-append zsh "/_nimble"))))))))
(inputs (list atlas libgc openssl pcre sat sqlite))
(native-inputs (list nss-certs parallel)) (native-inputs (list nss-certs parallel))
(home-page "https://nim-lang.org") (home-page "https://nim-lang.org")
(synopsis "Statically-typed, imperative programming language") (synopsis "Statically-typed, imperative programming language")