aboutsummaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLiliana Marie Prikler <liliana.prikler@gmail.com>2024-01-21 09:59:52 +0100
committerLiliana Marie Prikler <liliana.prikler@gmail.com>2024-01-21 09:59:55 +0100
commitff1ec930e5baa00b483f1ce43fa8bec18c797c03 (patch)
tree1c102408d5d79e12b70fe81f97602d3856ed334e /guix/build
parent60c97924e9519361494aaf0686e28eb831a42315 (diff)
parentc7f937cfdd9a08bad81705fe731e9fa5937cf562 (diff)
downloadguix-ff1ec930e5baa00b483f1ce43fa8bec18c797c03.tar
guix-ff1ec930e5baa00b483f1ce43fa8bec18c797c03.tar.gz
Merge branch 'master' into emacs-team
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/ant-build-system.scm31
-rw-r--r--guix/build/cargo-build-system.scm69
-rw-r--r--guix/build/composer-build-system.scm301
-rw-r--r--guix/build/git.scm19
-rw-r--r--guix/build/guile-build-system.scm13
-rw-r--r--guix/build/minetest-build-system.scm3
-rw-r--r--guix/build/mix-build-system.scm161
-rw-r--r--guix/build/syscalls.scm22
-rw-r--r--guix/build/vim-build-system.scm119
-rw-r--r--guix/build/zig-build-system.scm7
10 files changed, 722 insertions, 23 deletions
diff --git a/guix/build/ant-build-system.scm b/guix/build/ant-build-system.scm
index d29912bf59..ced34177f4 100644
--- a/guix/build/ant-build-system.scm
+++ b/guix/build/ant-build-system.scm
@@ -37,6 +37,7 @@
(define* (default-build.xml jar-name prefix #:optional
(source-dir ".") (test-dir "./test") (main-class #f)
+ (use-java-modules? #f)
(test-include '("**/*Test.java"))
(test-exclude '("**/Abstract*Test.java")))
"Create a simple build.xml with standard targets for Ant."
@@ -65,7 +66,7 @@
(value "first")))
(property (@ (environment "env")))
(path (@ (id "classpath"))
- (pathelement (@ (location "${env.CLASSPATH}"))))
+ (pathelement (@ (path "${env.CLASSPATH}"))))
(target (@ (name "manifest"))
(mkdir (@ (dir "${manifest.dir}")))
@@ -79,18 +80,30 @@
(mkdir (@ (dir "${classes.dir}")))
(javac (@ (includeantruntime "false")
(srcdir ,source-dir)
- (destdir "${classes.dir}")
- (classpath (@ (refid "classpath"))))))
+ (destdir "${classes.dir}"))
+ ,(if use-java-modules?
+ `((modulepath (@ (refid "classpath"))))
+ '())
+ (classpath (@ (refid "classpath")))))
(target (@ (name "compile-tests"))
(mkdir (@ (dir "${test.classes.dir}")))
(javac (@ (includeantruntime "false")
(srcdir ,test-dir)
(destdir "${test.classes.dir}"))
- (classpath
- (pathelement (@ (path "${env.CLASSPATH}")))
- (pathelement (@ (location "${classes.dir}")))
- (pathelement (@ (location "${test.classes.dir}"))))))
+ ,(if use-java-modules?
+ `((classpath
+ (pathelement
+ (@ (path "${env.CLASSPATH}")))
+ (pathelement
+ (@ (location "${classes.dir}")))
+ (pathelement
+ (@ (location "${test.classes.dir}")))))
+ '())
+ (classpath
+ (pathelement (@ (path "${env.CLASSPATH}")))
+ (pathelement (@ (location "${classes.dir}")))
+ (pathelement (@ (location "${test.classes.dir}"))))))
(target (@ (name "check")
(depends "compile-tests"))
@@ -156,13 +169,15 @@ to the default GNU unpack strategy."
(source-dir "src")
(test-dir "src/test")
(main-class #f)
+ (use-java-modules? #f)
(test-include '("**/*Test.java"))
(test-exclude '("**/Abstract*.java")) #:allow-other-keys)
(when jar-name
(default-build.xml jar-name
(string-append (assoc-ref outputs "out")
"/share/java")
- source-dir test-dir main-class test-include test-exclude))
+ source-dir test-dir main-class use-java-modules?
+ test-include test-exclude))
(setenv "JAVA_HOME" (assoc-ref inputs "jdk"))
(setenv "CLASSPATH" (generate-classpath inputs))
#t)
diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
index 505c0b4b01..ffb2ec898e 100644
--- a/guix/build/cargo-build-system.scm
+++ b/guix/build/cargo-build-system.scm
@@ -119,6 +119,7 @@ libraries or executables."
(error "Possible pre-generated files found:" pregenerated-files))))
(define* (configure #:key inputs
+ target
(vendor-dir "guix-vendor")
#:allow-other-keys)
"Vendor Cargo.toml dependencies as guix inputs."
@@ -146,27 +147,75 @@ libraries or executables."
(invoke "tar" "xf" path "-C" crate-dir "--strip-components" "1")))))
inputs)
- ;; Configure cargo to actually use this new directory.
+ ;; For cross-building
+ (when target
+ (setenv "CARGO_BUILD_TARGET"
+ ;; Can this be replaced with platform-rust-architecture?
+ ;; Keep this synchronized with (guix platforms *)
+ (match target
+ ("aarch64-linux-gnu" "aarch64-unknown-linux-gnu")
+ ("arm-linux-gnueabihf" "armv7-unknown-linux-gnueabihf")
+ ("i686-linux-gnu" "i686-unknown-linux-gnu")
+ ("mips64el-linux-gnu" "mips64el-unknown-linux-gnuabi64")
+ ("powerpc-linux-gnu" "powerpc-unknown-linux-gnu")
+ ("powerpc64-linux-gnu" "powerpc64-unknown-linux-gnu")
+ ("powerpc64le-linux-gnu" "powerpc64le-unknown-linux-gnu")
+ ("riscv64-linux-gnu" "riscv64gc-unknown-linux-gnu")
+ ("x86_64-linux-gnu" "x86_64-unknown-linux-gnu")
+ ("i586-pc-gnu" "i686-unknown-hurd-gnu")
+ ("i686-w64-mingw32" "i686-pc-windows-gnu")
+ ("x86_64-w64-mingw32" "x86_64-pc-windows-gnu")
+ (else #f)))
+ (setenv "RUSTFLAGS" (string-append
+ (or (getenv "RUSTFLAGS") "")
+ " --sysroot " (assoc-ref inputs "rust-sysroot")))
+
+ (setenv "PKG_CONFIG" (string-append target "-pkg-config"))
+
+ ;; We've removed all the bundled libraries, don't look for them.
+ (setenv "WINAPI_NO_BUNDLED_LIBRARIES" "1")
+
+ ;; Prevent targeting the build machine.
+ (setenv "CRATE_CC_NO_DEFAULTS" "1"))
+
+ ;; Configure cargo to actually use this new directory with all the crates.
(setenv "CARGO_HOME" (string-append (getcwd) "/.cargo"))
(mkdir-p ".cargo")
+ ;; Not .cargo/config.toml, rustc/cargo will generate .cargo/config otherwise.
(let ((port (open-file ".cargo/config" "w" #:encoding "utf-8")))
- (display "
+ ;; Placed here so it doesn't cause random rebuilds. Neither of these work.
+ ;; sysroot = '" (assoc-ref inputs "rust-sysroot") "'
+ ;; rustflags = ['--sysroot', '" (assoc-ref inputs "rust-sysroot") "']
+ (when target
+ (display (string-append "
+[target." (getenv "CARGO_BUILD_TARGET") "]
+linker = '" target "-gcc'
+
+[build]
+target = ['" (getenv "CARGO_BUILD_TARGET") "']") port))
+ (display (string-append "
[source.crates-io]
replace-with = 'vendored-sources'
[source.vendored-sources]
-directory = '" port)
- (display (string-append (getcwd) "/" vendor-dir) port)
- (display "'
-" port)
+directory = '" vendor-dir "'") port)
(close-port port))
;; Lift restriction on any lints: a crate author may have decided to opt
;; into stricter lints (e.g. #![deny(warnings)]) during their own builds
;; but we don't want any build failures that could be caused later by
;; upgrading the compiler for example.
- (setenv "RUSTFLAGS" "--cap-lints allow")
- (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
+ (setenv "RUSTFLAGS" (string-append (or (getenv "RUSTFLAGS") "")
+ " --cap-lints allow"))
+
+ (if (assoc-ref inputs "cross-gcc")
+ (begin
+ (setenv "HOST_CC" "gcc")
+ (setenv "TARGET_CC" (string-append target "-gcc"))
+ (setenv "TARGET_AR" (string-append target "-ar"))
+ (setenv "TARGET_PKG_CONFIG" (string-append target "-pkg-config")))
+ (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc")))
+
(setenv "LIBGIT2_SYS_USE_PKG_CONFIG" "1")
(setenv "LIBSSH2_SYS_USE_PKG_CONFIG" "1")
(when (assoc-ref inputs "openssl")
@@ -264,7 +313,11 @@ directory = '" port)
(unless (eq? (stat:type s) 'symlink)
(utime file 0 0 0 0))))
(find-files dir #:directories? #t))
+
(apply invoke "tar" "czf" (string-append dir ".crate")
+ ;; avoid non-determinism in the archive
+ "--sort=name" "--mtime=@0"
+ "--owner=root:0" "--group=root:0"
(find-files dir #:directories? #t))
(delete-file-recursively dir)))
(find-files "." "\\.crate$")))))
diff --git a/guix/build/composer-build-system.scm b/guix/build/composer-build-system.scm
new file mode 100644
index 0000000000..8896384e0a
--- /dev/null
+++ b/guix/build/composer-build-system.scm
@@ -0,0 +1,301 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
+;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build composer-build-system)
+ #:use-module ((guix build gnu-build-system) #:prefix gnu:)
+ #:use-module (guix build utils)
+ #:use-module (ice-9 match)
+ #:use-module (json)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:export (%standard-phases
+ composer-build))
+
+;; Commentary:
+;;
+;; Builder-side code of the standard composer build procedure.
+;;
+;; Code:
+
+(define (json->require dict)
+ (if dict
+ (let loop ((result '()) (require dict))
+ (match require
+ (() result)
+ ((((? (cut string-contains <> "/") name) . _)
+ require ...)
+ (loop (cons name result) require))
+ ((_ require ...) (loop result require))
+ (_ result)))
+ '()))
+
+(define (if-specified-to-list fn)
+ (match-lambda
+ ((? unspecified?) '())
+ (arg (fn arg))
+ (_ '())))
+
+(define-json-mapping <composer-autoload> make-composer-autoload
+ composer-autoload?
+ json->composer-autoload
+ (psr-4 composer-autoload-psr-4 "psr-4"
+ (match-lambda
+ ((? unspecified?) '())
+ ((? (lambda (al)
+ (and (list? al) (pair? (car al)) (vector? (cdar al)))) al)
+ (append-map
+ (lambda (vect-el)
+ (list (cons (caar al) vect-el)))
+ (vector->list (cdar al))))
+ ((? list? l) l)
+ (_ '())))
+ (psr-0 composer-autoload-psr-0 "psr-0" (if-specified-to-list identity))
+ (classmap composer-autoload-classmap "classmap"
+ (if-specified-to-list vector->list))
+ (files composer-autoload-files "files"
+ (if-specified-to-list vector->list)))
+
+(define-json-mapping <composer-package> make-composer-package composer-package?
+ json->composer-package
+ (name composer-package-name)
+ (autoload composer-package-autoload "autoload"
+ (if-specified-to-list json->composer-autoload))
+ (autoload-dev composer-package-autoload-dev "autoload-dev"
+ (if-specified-to-list json->composer-autoload))
+ (require composer-package-require "require" json->require)
+ (dev-require composer-package-dev-require "require-dev" json->require)
+ (scripts composer-package-scripts "scripts"
+ (if-specified-to-list identity))
+ (binaries composer-package-binaries "bin"
+ (if-specified-to-list vector->list)))
+
+(define* (read-package-data #:key (filename "composer.json"))
+ (call-with-input-file filename
+ (lambda (port)
+ (json->composer-package (json->scm port)))))
+
+(define* (create-test-autoload #:key composer-file inputs outputs tests?
+ #:allow-other-keys)
+ "Create the autoload.php file for tests. This is a standalone phase so that
+the autoload.php file can be edited before the check phase."
+ (when tests?
+ (mkdir-p "vendor")
+ (create-autoload (string-append (getcwd) "/vendor") composer-file
+ inputs #:dev-dependencies? #t)))
+
+(define (find-bin script inputs)
+ (search-input-file inputs
+ (string-append
+ "bin/"
+ (string-drop script (string-length "vendor/bin/")))))
+
+(define* (check #:key composer-file inputs
+ tests? test-target test-flags #:allow-other-keys)
+ "Test the given package.
+Please note that none of the PHP packages at the time of the rewrite of the
+build-system did use the test-script field. This means that the @code{match
+test-script} part is not tested on a real example and relies on the original
+implementation."
+ (if tests?
+ (let* ((package-data (read-package-data #:filename composer-file))
+ (scripts (composer-package-scripts package-data))
+ (test-script (assoc-ref scripts test-target)))
+ (match test-script
+ ((? string? bin)
+ (let ((command (find-bin bin inputs)))
+ (unless (zero? (apply system command test-flags))
+ (throw 'failed-command command))))
+ (('@ (? string? bins) ...)
+ (for-each
+ (lambda (c)
+ (let ((command (find-bin c inputs)))
+ (unless (zero? (apply system command test-flags))
+ (throw 'failed-command command))))
+ bins))
+ (_ (if (file-exists? "phpunit.xml.dist")
+ (apply invoke
+ (with-exception-handler
+ (lambda (exn)
+ (if (search-error? exn)
+ (error "\
+Missing php-phpunit-phpunit native input.~%")
+ (raise exn)))
+ (lambda ()
+ (search-input-file (or inputs '()) "bin/phpunit")))
+ test-flags))
+ (format #t "No test suite found.~%"))))
+ (format #t "Test suite not run.~%")))
+
+(define* (create-autoload vendor composer-file inputs #:key dev-dependencies?)
+ "creates an autoload.php file that sets up the class locations for this package,
+so it can be autoloaded by PHP when the package classes are required."
+ (with-output-to-file (string-append vendor "/autoload.php")
+ (lambda _
+ (display (string-append
+ "<?php
+// autoload.php @generated by Guix
+$psr4map = $classmap = array();
+require_once '" vendor "/autoload_conf.php';
+require_once '" (assoc-ref inputs "composer-classloader") "/share/web/composer/ClassLoader.php';
+$loader = new \\Composer\\Autoload\\ClassLoader();
+foreach ($psr4map as $namespace => $paths) {
+ foreach ($paths as $path) {
+ $loader->addPsr4($namespace, $path);
+ }
+}
+$loader->addClassMap($classmap);
+$loader->register();
+"))))
+ ;; Now, create autoload_conf.php that contains the actual data, as a set
+ ;; of arrays
+ (let* ((package-data (read-package-data #:filename composer-file))
+ (autoload (composer-package-autoload package-data))
+ (autoload-dev (composer-package-autoload-dev package-data))
+ (dependencies (composer-package-require package-data))
+ (dependencies-dev (composer-package-dev-require package-data)))
+ (with-output-to-file (string-append vendor "/autoload_conf.php")
+ (lambda _
+ (format #t "<?php~%")
+ (format #t "// autoload_conf.php @generated by Guix~%")
+ (force-output)
+ (for-each
+ (match-lambda
+ ((key . value)
+ (let ((vals (if (list? value)
+ (reverse value)
+ (list value))))
+ (apply
+ format
+ #t
+ (string-append
+ "$psr4map['~a'][] = ["
+ (string-join
+ (make-list (length vals) "'~a/../~a'") ",")
+ "];~%")
+ (cons* (string-join (string-split key #\\) "\\\\")
+ (append-map (lambda (v) (list vendor v)) vals)))))
+ (_ (format #t "")))
+ (delete-duplicates
+ (append
+ (composer-autoload-psr-4 autoload)
+ (if (and dev-dependencies? (not (null? autoload-dev)))
+ (composer-autoload-psr-4 autoload-dev)
+ '()))
+ '()))
+ (for-each
+ (lambda (psr0)
+ (match psr0
+ ((key . value)
+ (format #t "$psr4map['~a'][] = ['~a/../~a/~a'];~%"
+ (string-join (string-split key #\\) "\\\\")
+ vendor
+ value
+ (string-join (string-split key #\\) "/")))
+ (_ (format #t ""))))
+ (append
+ (composer-autoload-psr-0 autoload)
+ (if (and dev-dependencies? (not (null? autoload-dev)))
+ (composer-autoload-psr-0 autoload-dev)
+ '())))
+ (for-each
+ (lambda (classmap)
+ (for-each
+ (lambda (file)
+ (invoke "php" (assoc-ref inputs "findclass.php")
+ "-i" (string-append vendor "/..") "-f" file))
+ (find-files classmap ".(php|hh|inc)$")))
+ (append
+ (composer-autoload-classmap autoload)
+ (if (and dev-dependencies? (not (null? autoload-dev)))
+ (composer-autoload-classmap autoload-dev)
+ '())))
+ (for-each
+ (lambda (file)
+ (format #t "require_once '~a/../~a';~%" vendor file))
+ (append
+ (composer-autoload-files autoload)
+ (if (and dev-dependencies? (not (null? autoload-dev)))
+ (composer-autoload-files autoload-dev)
+ '())))
+ (for-each
+ (lambda (dep)
+ (format
+ #t "require_once '~a';~%"
+ (search-input-file
+ inputs
+ (string-append "/share/web/" dep "/vendor/autoload_conf.php"))))
+ dependencies)
+ ;; Also add native-inputs that are not necessarily given in the
+ ;; composer.json. This allows to simply add a package in tests by
+ ;; adding it in native-inputs, without the need to patch composer.json.
+ (for-each
+ (match-lambda
+ ((name . loc)
+ (match (find-files loc "autoload_conf\\.php$")
+ (() #t)
+ (((? string? conf) . ())
+ (format #t "require_once '~a';~%" conf))
+ (_ #t)))
+ (_ #t))
+ (or inputs '()))))))
+
+(define* (install #:key inputs outputs composer-file #:allow-other-keys)
+ "Install the given package."
+ (let* ((out (assoc-ref outputs "out"))
+ (package-data (read-package-data #:filename composer-file))
+ (name (composer-package-name package-data))
+ (php-dir (string-append out "/share/web/" name))
+ (bin-dir (string-append php-dir "/vendor/bin"))
+ (bin (string-append out "/bin"))
+ (binaries (composer-package-binaries package-data)))
+ (mkdir-p php-dir)
+ (copy-recursively "." php-dir)
+ (mkdir-p (string-append php-dir "/vendor"))
+ (when binaries
+ (mkdir-p bin-dir)
+ (mkdir-p bin)
+ (for-each
+ (lambda (file)
+ (let ((installed-file (string-append bin-dir "/" (basename file)))
+ (bin-file (string-append bin "/" (basename file)))
+ (original-file (string-append php-dir "/" file)))
+ (symlink original-file installed-file)
+ (symlink original-file bin-file)))
+ binaries))
+ (create-autoload (string-append php-dir "/vendor")
+ composer-file inputs)))
+
+(define %standard-phases
+ ;; Everything is as with the GNU Build System except for the `configure'
+ ;; , `build', `check' and `install' phases.
+ (modify-phases gnu:%standard-phases
+ (delete 'bootstrap)
+ (delete 'configure)
+ (delete 'build)
+ (delete 'check)
+ (replace 'install install)
+ (add-after 'install 'check check)
+ (add-after 'install 'create-test-autoload create-test-autoload)))
+
+(define* (composer-build #:key inputs (phases %standard-phases)
+ #:allow-other-keys #:rest args)
+ "Build the given package, applying all of PHASES in order."
+ (apply gnu:gnu-build #:inputs inputs #:phases phases args))
+
+;;; composer-build-system.scm ends here
diff --git a/guix/build/git.scm b/guix/build/git.scm
index 0ff263c81b..867cade2c4 100644
--- a/guix/build/git.scm
+++ b/guix/build/git.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2016, 2019, 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -33,10 +34,13 @@
;;; Code:
(define* (git-fetch url commit directory
- #:key (git-command "git") recursive?)
+ #:key (git-command "git")
+ lfs? recursive?)
"Fetch COMMIT from URL into DIRECTORY. COMMIT must be a valid Git commit
-identifier. When RECURSIVE? is true, all the sub-modules of URL are fetched,
-recursively. Return #t on success, #f otherwise."
+identifier. When LFS? is true, configure Git to also fetch Large File
+Storage (LFS) files; it assumes that the @code{git-lfs} extension is available
+in the environment. When RECURSIVE? is true, all the sub-modules of URL are
+fetched, recursively. Return #t on success, #f otherwise."
;; Disable TLS certificate verification. The hash of the checkout is known
;; in advance anyway.
@@ -57,6 +61,11 @@ recursively. Return #t on success, #f otherwise."
(with-directory-excursion directory
(invoke git-command "init" "--initial-branch=main")
(invoke git-command "remote" "add" "origin" url)
+
+ (when lfs?
+ (setenv "HOME" "/tmp")
+ (invoke git-command "lfs" "install"))
+
(if (zero? (system* git-command "fetch" "--depth" "1" "origin" commit))
(invoke git-command "checkout" "FETCH_HEAD")
(begin
@@ -81,11 +90,13 @@ recursively. Return #t on success, #f otherwise."
(define* (git-fetch-with-fallback url commit directory
- #:key (git-command "git") recursive?)
+ #:key (git-command "git")
+ lfs? recursive?)
"Like 'git-fetch', fetch COMMIT from URL into DIRECTORY, but fall back to
alternative methods when fetching from URL fails: attempt to download a nar,
and if that also fails, download from the Software Heritage archive."
(or (git-fetch url commit directory
+ #:lfs? lfs?
#:recursive? recursive?
#:git-command git-command)
(download-nar directory)
diff --git a/guix/build/guile-build-system.scm b/guix/build/guile-build-system.scm
index 32a431d347..e7e7f2d0be 100644
--- a/guix/build/guile-build-system.scm
+++ b/guix/build/guile-build-system.scm
@@ -28,6 +28,7 @@
#:use-module (ice-9 format)
#:use-module (guix build utils)
#:export (target-guile-effective-version
+ target-guile-scm+go
%standard-phases
guile-build))
@@ -44,7 +45,17 @@ Return #false if it cannot be determined."
(string? line)
line)))
-(define (file-sans-extension file) ;TODO: factorize
+(define* (target-guile-scm+go output #:optional guile)
+ "Return paths under `output' for scm and go files for effective version of
+GUILE or whichever `guile' is in $PATH. Raises an error if they cannot be
+determined."
+ (let* ((version (or (target-guile-effective-version guile)
+ (error "Cannot determine the effective target guile version.")))
+ (scm (string-append output "/share/guile/site/" version))
+ (go (string-append output "/lib/guile/" version "/site-ccache")))
+ (values scm go)))
+
+(define (file-sans-extension file) ;TODO: factorize
"Return the substring of FILE without its extension, if any."
(let ((dot (string-rindex file #\.)))
(if dot
diff --git a/guix/build/minetest-build-system.scm b/guix/build/minetest-build-system.scm
index 4a7a87ab83..3bf083e004 100644
--- a/guix/build/minetest-build-system.scm
+++ b/guix/build/minetest-build-system.scm
@@ -126,7 +126,8 @@ If it is unknown, make an educated guess."
(/ total-old-size (expt 1024 2))
(/ total-new-size (expt 1024 2)))))))
-(define name-regexp (make-regexp "^name[ ]*=(.+)$"))
+(define name-regexp
+ (make-regexp "^name[[:space:]]*=[[:space:]]*([[:graph:]]+)[[:space:]]*$"))
(define* (read-mod-name mod.conf #:optional not-found)
"Read the name of a mod from MOD.CONF. If MOD.CONF
diff --git a/guix/build/mix-build-system.scm b/guix/build/mix-build-system.scm
new file mode 100644
index 0000000000..fe2e36d184
--- /dev/null
+++ b/guix/build/mix-build-system.scm
@@ -0,0 +1,161 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2023 Pierre-Henry Fröhring <contact@phfrohring.com>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+;; Commentary:
+;;
+;; Code:
+
+(define-module (guix build mix-build-system)
+ #:use-module ((guix build gnu-build-system) #:prefix gnu:)
+ #:use-module (guix build utils)
+ #:use-module (ice-9 ftw)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 regex)
+ #:use-module (ice-9 string-fun)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-71)
+ #:export (mix-build
+ %standard-phases))
+
+;; The Elixir version is constant as soon as it is computable from the current
+;; execution. It is a X.Y string where X and Y are respectively the major and
+;; minor version number of the Elixir used in the build.
+(define %elixir-version (make-parameter "X.Y"))
+
+(define* (elixir-libdir path #:optional (version (%elixir-version)))
+ "Return the path where all libraries under PATH for a specified Elixir
+VERSION are installed."
+ (string-append path "/lib/elixir/" version))
+
+(define* (strip-prefix name #:optional (prefix "elixir-"))
+ "Return NAME without the prefix PREFIX."
+ (if (string-prefix? prefix name)
+ (string-drop name (string-length prefix))
+ name))
+
+(define (mix-build-dir mix-build-root mix-env)
+ "Return the directory where build artifacts are to be installed according to
+en environment MIX-ENV in the current directory. MIX-BUILD-ROOT depends on the
+package arguments. See: https://hexdocs.pm/mix/1.15/Mix.html#module-environment-variables"
+ (string-append mix-build-root "/" mix-env "/lib"))
+
+(define (elixir-version inputs)
+ "Return an X.Y string where X and Y are respectively the major and minor version number of PACKAGE.
+Example: /gnu/store/…-elixir-1.14.0 → 1.14"
+ ((compose
+ (cute string-join <> ".")
+ (cute take <> 2)
+ (cute string-split <> #\.)
+ strip-prefix
+ strip-store-file-name)
+ (assoc-ref inputs "elixir")))
+
+(define* (unpack #:key source mix-path #:allow-other-keys)
+ "Unpack SOURCE in the working directory, and change directory within the
+source. When SOURCE is a directory, copy it in a sub-directory of the current
+working directory."
+ (let ((gnu-unpack (assoc-ref gnu:%standard-phases 'unpack)))
+ (gnu-unpack #:source source)
+ (when (file-exists? "contents.tar.gz")
+ (invoke "tar" "xvf" "contents.tar.gz"))))
+
+(define (list-directories dir)
+ "List absolute paths of directories directly under the directory DIR."
+ (map (cute string-append dir "/" <>)
+ (scandir dir (lambda (filename)
+ (and (not (member filename '("." "..")))
+ (directory-exists? (string-append dir "/" filename)))))))
+
+(define* (set-mix-env #:key inputs mix-path mix-exs #:allow-other-keys)
+ "Set environment variables.
+See: https://hexdocs.pm/mix/1.15.7/Mix.html#module-environment-variables"
+ (setenv "MIX_ARCHIVES" "archives")
+ (setenv "MIX_BUILD_ROOT" "_build")
+ (setenv "MIX_DEPS_PATH" "deps")
+ (setenv "MIX_EXS" mix-exs)
+ (setenv "MIX_HOME" (getcwd))
+ (setenv "MIX_PATH" (or mix-path ""))
+ (setenv "MIX_REBAR3" (string-append (assoc-ref inputs "rebar3") "/bin/rebar3")))
+
+(define* (set-elixir-version #:key inputs #:allow-other-keys)
+ "Store the version number of the Elixir input in a parameter."
+ (%elixir-version (elixir-version inputs))
+ (format #t "Elixir version: ~a~%" (%elixir-version)))
+
+(define* (build #:key mix-environments #:allow-other-keys)
+ "Builds the Mix project."
+ (for-each (lambda (mix-env)
+ (setenv "MIX_ENV" mix-env)
+ (invoke "mix" "compile" "--no-deps-check"))
+ mix-environments))
+
+(define* (check #:key (tests? #t) #:allow-other-keys)
+ "Test the Mix project."
+ (if tests?
+ (invoke "mix" "test" "--no-deps-check")
+ (format #t "tests? = ~a~%" tests?)))
+
+(define* (remove-mix-dirs . _)
+ "Remove all .mix/ directories.
+We do not want to copy them to the installation directory."
+ (for-each delete-file-recursively
+ (find-files "." (file-name-predicate "\\.mix$") #:directories? #t)))
+
+(define (package-name->elixir-name name+ver)
+ "Convert the Guix package NAME-VER to the corresponding Elixir name-version
+format. Example: elixir-a-pkg-1.2.3 -> a_pkg"
+ ((compose
+ (cute string-join <> "_")
+ (cute drop-right <> 1)
+ (cute string-split <> #\-))
+ (strip-prefix name+ver)))
+
+(define* (install #:key
+ inputs
+ outputs
+ name
+ build-per-environment
+ #:allow-other-keys)
+ "Install build artifacts in the store."
+ (let* ((lib-name (package-name->elixir-name name))
+ (lib-dir (string-append (elixir-libdir (assoc-ref outputs "out")) "/" lib-name))
+ (root (getenv "MIX_BUILD_ROOT"))
+ (env (if build-per-environment "prod" "shared")))
+ (mkdir-p lib-dir)
+ (copy-recursively (string-append (mix-build-dir root env) "/" lib-name) lib-dir
+ #:follow-symlinks? #t)))
+
+(define %standard-phases
+ (modify-phases gnu:%standard-phases
+ (delete 'bootstrap)
+ (delete 'configure)
+ (add-after 'install-locale 'set-mix-env set-mix-env)
+ (add-after 'set-mix-env 'set-elixir-version set-elixir-version)
+ (replace 'unpack unpack)
+ (replace 'build build)
+ (replace 'check check)
+ (add-before 'install 'remove-mix-dirs remove-mix-dirs)
+ (replace 'install install)))
+
+(define* (mix-build #:key inputs (phases %standard-phases)
+ #:allow-other-keys #:rest args)
+ "Build the given Mix package, applying all of PHASES in order."
+ (apply gnu:gnu-build #:inputs inputs #:phases phases args))
+
+;;; mix-build-system.scm ends here
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index b845b8aab9..b2871c3c10 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -192,6 +192,7 @@
terminal-window-size
terminal-columns
terminal-rows
+ terminal-string-width
openpty
login-tty
@@ -1097,6 +1098,7 @@ Turning finalization off shuts down the finalization thread as a side effect."
("armv7l" 120)
("aarch64" 220)
("ppc64le" 120)
+ ("riscv64" 220)
(_ #f))))
(lambda (flags)
"Create a new child process by duplicating the current parent process.
@@ -2336,6 +2338,26 @@ PORT, trying to guess a reasonable value if all else fails. The result is
always a positive integer."
(terminal-dimension window-size-rows port (const 25)))
+(define terminal-string-width
+ (let ((mbstowcs (and=> (false-if-exception
+ (dynamic-func "mbstowcs" (dynamic-link)))
+ (cute pointer->procedure int <> (list '* '* size_t))))
+ (wcswidth (and=> (false-if-exception
+ (dynamic-func "wcswidth" (dynamic-link)))
+ (cute pointer->procedure int <> (list '* size_t)))))
+ (if (and mbstowcs wcswidth)
+ (lambda (str)
+ "Return the width of a string as it would be printed on the terminal.
+This procedure accounts for characters that have a different width than 1, such
+as CJK double-width characters."
+ (let ((wchar (make-bytevector (* (+ (string-length str) 1) 4))))
+ (mbstowcs (bytevector->pointer wchar)
+ (string->pointer str)
+ (string-length str))
+ (wcswidth (bytevector->pointer wchar)
+ (string-length str))))
+ string-length))) ;using a statically-linked Guile
+
(define openpty
(let ((proc (syscall->procedure int "openpty" '(* * * * *)
#:library "libutil")))
diff --git a/guix/build/vim-build-system.scm b/guix/build/vim-build-system.scm
new file mode 100644
index 0000000000..e11965cc27
--- /dev/null
+++ b/guix/build/vim-build-system.scm
@@ -0,0 +1,119 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Jonathan Scoresby <me@jonscoresby.com>
+;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build vim-build-system)
+ #:use-module ((guix build copy-build-system)
+ #:prefix copy:)
+ #:use-module (guix build utils)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 ftw)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-26)
+ #:export (%standard-phases vim-build))
+
+;; Commentary:
+;;
+;; System for installing vim and neovim plugins. It downloads
+;; the source and copies the appropriate files to vim and nvim
+;; packpaths. It then generates helptags.
+;;
+;; Code:
+
+(define copy:install
+ (assoc-ref copy:%standard-phases 'install))
+
+(define vim-path
+ "/share/vim/vimfiles/pack/guix/")
+(define nvim-path
+ "/share/nvim/site/pack/guix/")
+
+(define* (install #:key plugin-name
+ install-plan
+ neovim?
+ vim?
+ mode
+ outputs
+ #:allow-other-keys)
+
+ (let* ((include-regexp '(".*\\/.*\\/.*"))
+ (exclude-regexp '("^scripts/.*"
+ "tests?/.*" "^t/.*"
+ "assets/.*"
+ ".*\\/\\..*"))
+ (vim-install
+ (if vim?
+ `(("." ,(string-append vim-path mode "/" plugin-name "/")
+ #:include-regexp ,include-regexp
+ #:exclude-regexp ,exclude-regexp))
+ '()))
+ (neovim-install
+ (if neovim?
+ `(("." ,(string-append nvim-path mode "/" plugin-name "/")
+ #:include-regexp ,include-regexp
+ #:exclude-regexp ,exclude-regexp))
+ '())))
+ (copy:install #:outputs outputs
+ #:install-plan (append vim-install
+ neovim-install
+ install-plan))))
+
+(define* (generate-helptags #:key plugin-name
+ neovim?
+ vim?
+ mode
+ outputs
+ #:allow-other-keys)
+
+ (define (vim-generate-helptags output)
+ (invoke "vim" "--clean" "-en" "--cmd"
+ (string-append "helptags "
+ output vim-path mode "/" plugin-name "/doc")
+ "--cmd" "q"))
+
+ (define (neovim-generate-helptags output)
+ (invoke "nvim" "--clean" "--headless" "-en" "--cmd"
+ (string-append "helptags "
+ output nvim-path mode "/" plugin-name "/doc")
+ "--cmd" "q"))
+
+ (when (scandir "./doc")
+ (let ((out (assoc-ref outputs "out")))
+ (when vim?
+ (vim-generate-helptags out))
+ (when neovim?
+ (neovim-generate-helptags out)))))
+
+(define %standard-phases
+ ;; Everything is as with the Copy Build System except for
+ ;; the addition of the generate-helptags phase and a few
+ ;; custom actions are added to the install phase
+ (modify-phases copy:%standard-phases
+ (replace 'install install)
+ (add-after 'install 'generate-helptags generate-helptags)))
+
+(define* (vim-build #:key inputs
+ (phases %standard-phases)
+ #:allow-other-keys #:rest args)
+ "Build the given package, applying all of PHASES in order."
+ (apply copy:copy-build
+ #:inputs inputs
+ #:phases phases
+ args))
+
+;;; vim-build-system.scm ends here
diff --git a/guix/build/zig-build-system.scm b/guix/build/zig-build-system.scm
index d414ebfb17..8352a73324 100644
--- a/guix/build/zig-build-system.scm
+++ b/guix/build/zig-build-system.scm
@@ -47,6 +47,7 @@
zig-build-flags
zig-release-type ;; "safe", "fast" or "small" empty for a
;; debug build"
+ target
#:allow-other-keys)
"Build a given Zig package."
@@ -56,6 +57,9 @@
"--prefix-lib-dir" "lib"
"--prefix-exe-dir" "bin"
"--prefix-include-dir" "include"
+ ,@(if target
+ (list (string-append "-Dtarget=" target))
+ '())
,@(if zig-release-type
(list (string-append "-Drelease-" zig-release-type))
'())
@@ -65,9 +69,10 @@
(define* (check #:key tests?
zig-test-flags
+ target
#:allow-other-keys)
"Run all the tests"
- (when tests?
+ (when (and tests? (not target))
(let ((old-destdir (getenv "DESTDIR")))
(setenv "DESTDIR" "test-out") ;; Avoid colisions with the build output
(let ((call `("zig" "build" "test"