summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-05-24 22:52:52 +0200
committerLudovic Courtès <ludo@gnu.org>2013-05-24 22:52:52 +0200
commite55ec43d8b98fed6c51d536c000f4fba72641c53 (patch)
tree421f467a7617c3534e2319d80d596670fff3a8d6
parent264218a47ed8f80eb516ae6b960de686ab32c226 (diff)
downloadgnu-guix-e55ec43d8b98fed6c51d536c000f4fba72641c53.tar
gnu-guix-e55ec43d8b98fed6c51d536c000f4fba72641c53.tar.gz
build: Add `--target' option.
* guix/scripts/build.scm (derivations-from-package-expressions): Add `package-derivation' parameter. (show-help, %options): Add `--target'. (guix-build): Use `package-cross-derivation' when `--target' is passed. * tests/guix-build.sh: Add dry-run test with `--target'. * doc/guix.texi (Invoking guix build): Document `--target'.
-rw-r--r--doc/guix.texi6
-rw-r--r--guix/scripts/build.scm24
-rw-r--r--tests/guix-build.sh3
3 files changed, 28 insertions, 5 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 1cf5849dd3..cf54fe4215 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -1198,6 +1198,12 @@ different personalities. For instance, passing
@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
to build packages in a complete 32-bit environment.
+@item --target=@var{triplet}
+@cindex cross-compilation
+Cross-build for @var{triplet}, which must be a valid GNU triplet, such
+as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
+configuration triplets,, configure, GNU Configure and Build System}).
+
@item --derivations
@itemx -d
Return the derivation paths, not the output paths, of the given
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index ca2fe46e98..995d96362b 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -38,9 +38,11 @@
(define %store
(make-parameter #f))
-(define (derivations-from-package-expressions str system source?)
+(define (derivations-from-package-expressions str package-derivation
+ system source?)
"Read/eval STR and return the corresponding derivation path for SYSTEM.
-When SOURCE? is true, return the derivations of the package sources."
+When SOURCE? is true, return the derivations of the package sources;
+otherwise, use PACKAGE-DERIVATION to compute the derivation of a package."
(let ((p (read/eval-package-expression str)))
(if source?
(let ((source (package-source p)))
@@ -72,6 +74,8 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(display (_ "
-s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\""))
(display (_ "
+ --target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\""))
+ (display (_ "
-d, --derivations return the derivation paths of the given packages"))
(display (_ "
-K, --keep-failed keep build tree of failed builds"))
@@ -114,6 +118,10 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(lambda (opt name arg result)
(alist-cons 'system arg
(alist-delete 'system result eq?))))
+ (option '("target") #t #f
+ (lambda (opt name arg result)
+ (alist-cons 'target arg
+ (alist-delete 'target result eq?))))
(option '(#\d "derivations") #f #f
(lambda (opt name arg result)
(alist-cons 'derivations-only? #t result)))
@@ -222,13 +230,19 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(with-error-handling
(let ((opts (parse-options)))
+ (define package->derivation
+ (match (assoc-ref opts 'target)
+ (#f package-derivation)
+ (triplet
+ (cut package-cross-derivation <> <> triplet <>))))
+
(parameterize ((%store (open-connection)))
(let* ((src? (assoc-ref opts 'source?))
(sys (assoc-ref opts 'system))
(drv (filter-map (match-lambda
(('expression . str)
- (derivations-from-package-expressions str sys
- src?))
+ (derivations-from-package-expressions
+ str package->derivation sys src?))
(('argument . (? derivation-path? drv))
drv)
(('argument . (? string? x))
@@ -237,7 +251,7 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(let ((s (package-source p)))
(package-source-derivation
(%store) s))
- (package-derivation (%store) p sys))))
+ (package->derivation (%store) p sys))))
(_ #f))
opts))
(roots (filter-map (match-lambda
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index 721a7c6769..83de9f5285 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -51,6 +51,9 @@ then false; else true; fi
rm -f "$result"
+# Cross building.
+guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
+
# Parsing package names and versions.
guix build -n time # PASS
guix build -n time-1.7 # PASS, version found