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'.
This commit is contained in:
Ludovic Courtès 2013-05-24 22:52:52 +02:00
parent 264218a47e
commit e55ec43d8b
3 changed files with 28 additions and 5 deletions

View file

@ -1198,6 +1198,12 @@ different personalities. For instance, passing
@code{--system=i686-linux} on an @code{x86_64-linux} system allows users @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
to build packages in a complete 32-bit environment. 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 @item --derivations
@itemx -d @itemx -d
Return the derivation paths, not the output paths, of the given Return the derivation paths, not the output paths, of the given

View file

@ -38,9 +38,11 @@ (define-module (guix scripts build)
(define %store (define %store
(make-parameter #f)) (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. "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))) (let ((p (read/eval-package-expression str)))
(if source? (if source?
(let ((source (package-source p))) (let ((source (package-source p)))
@ -71,6 +73,8 @@ (define (show-help)
-S, --source build the packages' source derivations")) -S, --source build the packages' source derivations"))
(display (_ " (display (_ "
-s, --system=SYSTEM attempt to build for SYSTEM--e.g., \"i686-linux\"")) -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 (_ " (display (_ "
-d, --derivations return the derivation paths of the given packages")) -d, --derivations return the derivation paths of the given packages"))
(display (_ " (display (_ "
@ -114,6 +118,10 @@ (define %options
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'system arg (alist-cons 'system arg
(alist-delete 'system result eq?)))) (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 (option '(#\d "derivations") #f #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'derivations-only? #t result))) (alist-cons 'derivations-only? #t result)))
@ -222,13 +230,19 @@ (define (find-package request)
(with-error-handling (with-error-handling
(let ((opts (parse-options))) (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))) (parameterize ((%store (open-connection)))
(let* ((src? (assoc-ref opts 'source?)) (let* ((src? (assoc-ref opts 'source?))
(sys (assoc-ref opts 'system)) (sys (assoc-ref opts 'system))
(drv (filter-map (match-lambda (drv (filter-map (match-lambda
(('expression . str) (('expression . str)
(derivations-from-package-expressions str sys (derivations-from-package-expressions
src?)) str package->derivation sys src?))
(('argument . (? derivation-path? drv)) (('argument . (? derivation-path? drv))
drv) drv)
(('argument . (? string? x)) (('argument . (? string? x))
@ -237,7 +251,7 @@ (define (find-package request)
(let ((s (package-source p))) (let ((s (package-source p)))
(package-source-derivation (package-source-derivation
(%store) s)) (%store) s))
(package-derivation (%store) p sys)))) (package->derivation (%store) p sys))))
(_ #f)) (_ #f))
opts)) opts))
(roots (filter-map (match-lambda (roots (filter-map (match-lambda

View file

@ -51,6 +51,9 @@ then false; else true; fi
rm -f "$result" rm -f "$result"
# Cross building.
guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes
# Parsing package names and versions. # Parsing package names and versions.
guix build -n time # PASS guix build -n time # PASS
guix build -n time-1.7 # PASS, version found guix build -n time-1.7 # PASS, version found