From a4db19d8e07eeb26931edfde0f0e6bca4e0448d3 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Sun, 22 Oct 2023 23:41:22 -0400 Subject: git-download: Add support for Git Large File Storage (LFS). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/git.scm (git-fetch) [lfs?]: New argument, doc and setup code. (git-fetch-with-fallback) [lfs?]: New argument. Pass it to git-fetch. * guix/git-download.scm (git-lfs-package): New procedure. (git-fetch/in-band*): New procedure, made of the logic of git-fetch/in-band, with new git-lfs specifics, with the following changes: New #:git-lfs argument. : Remove labels. Conditionally add git-lfs. : Read "git lfs?" environment variable and pass its value to the #:lfs? argument of git-fetch-with-fallback. Use INPUTS directly; update comment. derivation>: Add "git lfs?" to #:env-vars. (git-fetch/in-band): Express in terms of git-fetch/in-band*. (git-fetch/lfs): New procedure. * doc/guix.texi (origin Reference): Document it. Change-Id: I5b233b8642a7bdb8737b9d9b740e7254a89ccb25 Reviewed-by: Ludovic Courtès --- guix/build/git.scm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'guix/build') 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 +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; 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) -- cgit v1.2.3 From 8882ec71ddec3ff815613883f360f4c01a23983b Mon Sep 17 00:00:00 2001 From: Jonathan Scoresby Date: Mon, 16 Oct 2023 12:15:12 +0300 Subject: build-system: Add vim-build-system. * guix/build-system/vim.scm, * guix/build/vim-build-system.scm: New modules. * Makefile.am (MODULES): Register new files. * doc/guix.texi: Document it. Co-authored-by: Efraim Flashner Signed-off-by: Efraim Flashner --- guix/build/vim-build-system.scm | 119 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 guix/build/vim-build-system.scm (limited to 'guix/build') 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 +;;; Copyright © 2023 Efraim Flashner +;;; +;;; 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 . + +(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 -- cgit v1.2.3 From 00ec39a4e4807957161ae16db04d5d9f75c19b2f Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Thu, 2 Nov 2023 07:50:10 +0100 Subject: guix: ant: Optionally build with java modules. Modules were introduced in Java 9 and are not supported by the default icedtea compiler, so this feature is disabled by default. * guix/build-system/ant.scm (ant-build): Add use-java-modules? parameter. * guix/build/ant-build-system.scm (default-build.xml) (configure): Use it. Change-Id: I3b99238e4cd262332fa5c818be1af5477c7374fd --- guix/build/ant-build-system.scm | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'guix/build') 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) -- cgit v1.2.3 From 9ce47b6fdd742324f3e7a47fa09b54f6b613b52f Mon Sep 17 00:00:00 2001 From: Tristan Cottam Date: Sat, 11 Nov 2023 02:05:08 +0100 Subject: build: minetest-build-system: Match name more strictly. Some Minetest mods, such as the hitherto unpackaged minetest-ambience, have trailing garbage space (e.g. carriage returns) in their name line, that would otherwise end up as part of the mod's directory name. * guix/build/minetest-build-system.scm (name-regexp): Only match graphical characters in the name sub-match. Change-Id: I95f4c201724991a10efba5c859bfef99779ea495 Signed-off-by: Liliana Marie Prikler --- guix/build/minetest-build-system.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guix/build') 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 -- cgit v1.2.3 From fd11d7fbf8e0fcc61ff764dcc0ab737971afc55a Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sat, 26 Aug 2023 07:59:09 +0200 Subject: guix: syscalls: Add terminal-string-width. * guix/build/syscalls.scm (terminal-width): New procedure. * tests/syscalls.scm: Add tests. Change-Id: I6c2caa9fbaffb1e8f4b8933103399be970d5a8f3 --- guix/build/syscalls.scm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'guix/build') diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index b845b8aab9..b29b6f78b6 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 @@ -2336,6 +2337,20 @@ 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 (syscall->procedure int "mbstowcs" (list '* '* size_t))) + (wcswidth (syscall->procedure int "wcswidth" (list '* size_t)))) + (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)))))) + (define openpty (let ((proc (syscall->procedure int "openpty" '(* * * * *) #:library "libutil"))) -- cgit v1.2.3 From 3493832260fdb7298c2f661e1c9fbe366e578693 Mon Sep 17 00:00:00 2001 From: Tomas Volf Date: Sun, 29 Oct 2023 13:56:13 +0100 Subject: build-system/guile: Add target-guile-scm+go procedure. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The paths to .scm and .go files can be constructed given a guile version and a base directory. However it is few lines of code that needs to be copy&pasted. This new procedure returns both of them reducing the maintenance cost. * guix/build/guile-build-system.scm (target-guile-scm+go): New procedure. Change-Id: I58615f2cfe0ec1e58d3fbb47b738ed5dce1bb252 Signed-off-by: Ludovic Courtès --- guix/build/guile-build-system.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'guix/build') 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 -- cgit v1.2.3 From a14dafaa01497f733419b5a738baf5822544ebc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 23 Nov 2023 15:18:32 +0100 Subject: =?UTF-8?q?syscalls:=20Add=20fallback=20case=20for=20=E2=80=98term?= =?UTF-8?q?inal-string-width=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes ‘terminal-string-width’ synonymous with ‘string-length’ when running one a statically-linked Guile, as is the case in some unit tests, instead of throwing ENOSYS. * guix/build/syscalls.scm (terminal-string-width): Use ‘dynamic-func’ and ‘pointer->procedure’ instead of ‘syscall->procedure’. Return ‘string-length’ when one of the ‘dynamic-func’ calls fails. Change-Id: Icf55c9e7c34b46fac91b665fb4a2ecb02160f22e --- guix/build/syscalls.scm | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'guix/build') diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index b29b6f78b6..4afe6d2f87 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -2338,18 +2338,24 @@ always a positive integer." (terminal-dimension window-size-rows port (const 25))) (define terminal-string-width - (let ((mbstowcs (syscall->procedure int "mbstowcs" (list '* '* size_t))) - (wcswidth (syscall->procedure int "wcswidth" (list '* size_t)))) - (lambda (str) - "Return the width of a string as it would be printed on the terminal. + (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)))))) + (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" '(* * * * *) -- cgit v1.2.3 From 63ccceb976fd14b6934fb95e1ef100642d31b89e Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Sat, 28 Oct 2023 18:09:05 +0300 Subject: build: cargo-build-system: Pack crates reproducibly. This fixes reproducibility in rust crates from the package phase, again, see . Reported by: Christopher Baines (in person). * guix/build/cargo-build-system.scm (package): When repacking the crate tarball use standard reproducibility flags. Change-Id: Ifb1440a023226bf0718e99ce9f95ef981e510cbc --- guix/build/cargo-build-system.scm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index 505c0b4b01..1694ab973c 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -264,7 +264,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$"))))) -- cgit v1.2.3 From e604972d9c697302691aeb22e9c50c933a1a3c72 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Mon, 20 Nov 2023 12:21:52 +0200 Subject: build/cargo-build-system: Enable cross-compiling. * guix/build-system/cargo.scm (default-rust): Accept an argument. (default-rust-sysroot, cargo-cross-build): New procedures. (lower): Accept a rust-sysroot. [private-kewords]: Add rust-sysroot. Remove target if cross-compiling. [bag]: Allow cross-compiling. In host-inputs only have inputs when cross-compiling, move crate sources to here, remove standard-packages. In build-inputs add the inputs when not cross-compiling, add the standard-cross-packages when cross-compiling, add the standard-packages to here. Add target-inputs with the standard-cross-packages and rust-sysroot when cross-compiling. * guix/build/cargo-build-system.scm (configure): Accept target argument. When cross-compiling set some environment variables. Adjust the .config/cargo.toml to have configure options for cross-compiling. Change-Id: I388d1e1f48943e45ff01f55af8efc0746f383b4a --- guix/build/cargo-build-system.scm | 66 +++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index 1694ab973c..2e6aeb78be 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,74 @@ 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") - (let ((port (open-file ".cargo/config" "w" #:encoding "utf-8"))) - (display " + (let ((port (open-file ".cargo/config.toml" "w" #:encoding "utf-8"))) + ;; 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") -- cgit v1.2.3 From 55faf486c7b0d4d3e924b0923e8065cd4386af93 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Tue, 28 Nov 2023 12:58:36 +0200 Subject: build: cargo: Use correct config file for cargo config. * guix/build/cargo-build-system.scm (configure): Use .cargo/config as the config file. Add a note. Change-Id: Ice006c11184d4c8e1bdb765c3998b06ad299e55b --- guix/build/cargo-build-system.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guix/build') diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index 2e6aeb78be..ffb2ec898e 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -181,7 +181,8 @@ libraries or executables." ;; Configure cargo to actually use this new directory with all the crates. (setenv "CARGO_HOME" (string-append (getcwd) "/.cargo")) (mkdir-p ".cargo") - (let ((port (open-file ".cargo/config.toml" "w" #:encoding "utf-8"))) + ;; Not .cargo/config.toml, rustc/cargo will generate .cargo/config otherwise. + (let ((port (open-file ".cargo/config" "w" #:encoding "utf-8"))) ;; 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") "'] -- cgit v1.2.3 From d5ca4d4fd713a9f7e17e074a1e37dda99bbb09fc Mon Sep 17 00:00:00 2001 From: MarcoFalke <_@721217.xyz> Date: Thu, 7 Dec 2023 16:15:18 +0000 Subject: syscalls: Define riscv64 syscall ID for clone. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/syscalls.scm (clone): Add an entry for riscv64. This allows the use of --container on riscv64. Change-Id: I12b3cb5e2aa248266d006b6e456082f4ddc70e62 Signed-off-by: Ludovic Courtès --- guix/build/syscalls.scm | 1 + 1 file changed, 1 insertion(+) (limited to 'guix/build') diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 4afe6d2f87..b2871c3c10 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -1098,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. -- cgit v1.2.3 From e0e6d659b5d798068b9b03860cc2d3e391f6b74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Henry=20Fr=C3=B6hring?= Date: Sun, 10 Dec 2023 14:03:54 +0100 Subject: build-system: Add mix-build-system. * guix/build-system/mix.scm: New file. * guix/build/mix-build-system.scm: New file. Change-Id: I8066d00f7ada4a384621bf541e679bc512e93435 Signed-off-by: Liliana Marie Prikler --- guix/build/mix-build-system.scm | 161 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 guix/build/mix-build-system.scm (limited to 'guix/build') 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 +;;; +;;; 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 . + +;; 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 -- cgit v1.2.3 From 9dab75879140d0f6ca0a25e1f2e3c5b912090d7c Mon Sep 17 00:00:00 2001 From: Nicolas Graves Date: Thu, 2 Nov 2023 16:16:50 +0100 Subject: =?UTF-8?q?build-system:=20Add=20=E2=80=98composer-build-system?= =?UTF-8?q?=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build-system/composer.scm: New file. * guix/build/composer-build-system.scm: New file. * gnu/packages/aux-files/findclass.php: New file. * Makefile.am: Add them. * doc/guix.texi (Build Systems): Document it. Co-authored-by: Julien Lepiller Signed-off-by: Ludovic Courtès Change-Id: Ie6a05b42ff04d3ad774a0a20278a77e4820bb8f6 --- guix/build/composer-build-system.scm | 301 +++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 guix/build/composer-build-system.scm (limited to 'guix/build') 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 +;;; Copyright © 2023 Nicolas Graves +;;; +;;; 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 . + +(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 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 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 + " $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 " Date: Sat, 18 Nov 2023 23:54:03 +0100 Subject: build-system/zig: Add cross-compilation support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build/zig-build-system.scm (zig-cross-build): New function (lower): Add cross-compilation support * guix/build-system/zig.scm (build): Add --target flag with target input (check): Disable with cross compilation Change-Id: I5f42ff897bfe00c92c6576900221a15ef210d669 Signed-off-by: Ludovic Courtès --- guix/build/zig-build-system.scm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'guix/build') 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" -- cgit v1.2.3