me
/
guix
Archived
1
0
Fork 0

pack: Add '--target'.

* guix/scripts/pack.scm (self-contained-tarball): Add #:target.
(docker-image): Add #:target.
[build]: Pass it to 'build-docker-image'.
(%options, show-help): Add '--target'.
(guix-pack): Pass TARGET to 'profile-derivation' and to 'build-image'.
* guix/docker.scm (build-docker-image): Add #:system parameter and honor it.
* doc/guix.texi (Invoking guix pack): Document '--target'.
(Additional Build Options): Refer to the Autoconf manual instead of the
obsolete 'configure.info' for cross-compilation.
master
Ludovic Courtès 2017-03-17 22:45:32 +01:00
parent 176febe377
commit 5461115e8f
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
3 changed files with 42 additions and 12 deletions

View File

@ -2476,6 +2476,12 @@ Docker Image Specification}.
Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
the system type of the build host. the system type of the build host.
@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{Specifying target triplets, GNU
configuration triplets,, autoconf, Autoconf}).
@item --compression=@var{tool} @item --compression=@var{tool}
@itemx -C @var{tool} @itemx -C @var{tool}
Compress the resulting tarball using @var{tool}---one of @code{gzip}, Compress the resulting tarball using @var{tool}---one of @code{gzip},
@ -5063,8 +5069,8 @@ to build packages in a complete 32-bit environment.
@item --target=@var{triplet} @item --target=@var{triplet}
@cindex cross-compilation @cindex cross-compilation
Cross-build for @var{triplet}, which must be a valid GNU triplet, such Cross-build for @var{triplet}, which must be a valid GNU triplet, such
as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
configuration triplets,, configure, GNU Configure and Build System}). configuration triplets,, autoconf, Autoconf}).
@anchor{build-check} @anchor{build-check}
@item --check @item --check

View File

@ -105,12 +105,14 @@ return \"a\"."
(define* (build-docker-image image path (define* (build-docker-image image path
#:key closure compressor #:key closure compressor
(symlinks '()) (symlinks '())
(system (utsname:machine (uname)))
(creation-time (current-time time-utc))) (creation-time (current-time time-utc)))
"Write to IMAGE a Docker image archive from the given store PATH. The image "Write to IMAGE a Docker image archive from the given store PATH. The image
contains the closure of PATH, as specified in CLOSURE (a file produced by contains the closure of PATH, as specified in CLOSURE (a file produced by
#:references-graphs). SYMLINKS must be a list of (SOURCE -> TARGET) tuples #:references-graphs). SYMLINKS must be a list of (SOURCE -> TARGET) tuples
describing symlinks to be created in the image, where each TARGET is relative describing symlinks to be created in the image, where each TARGET is relative
to PATH. to PATH. SYSTEM is a GNU triplet (or prefix thereof) of the system the
binaries at PATH are for; it is used to produce metadata in the image.
Use COMPRESSOR, a command such as '(\"gzip\" \"-9n\"), to compress IMAGE. Use Use COMPRESSOR, a command such as '(\"gzip\" \"-9n\"), to compress IMAGE. Use
CREATION-TIME, a SRFI-19 time-utc object, as the creation time in metadata." CREATION-TIME, a SRFI-19 time-utc object, as the creation time in metadata."
@ -118,11 +120,18 @@ CREATION-TIME, a SRFI-19 time-utc object, as the creation time in metadata."
(closure (canonicalize-path closure)) (closure (canonicalize-path closure))
(id (docker-id path)) (id (docker-id path))
(time (date->string (time-utc->date creation-time) "~4")) (time (date->string (time-utc->date creation-time) "~4"))
(arch (match (utsname:machine (uname)) (arch (let-syntax ((cond* (syntax-rules ()
("x86_64" "amd64") ((_ (pattern clause) ...)
("i686" "386") (cond ((string-prefix? pattern system)
("armv7l" "arm") clause)
("mips64" "mips64le")))) ...
(else
(error "unsupported system"
system)))))))
(cond* ("x86_64" "amd64")
("i686" "386")
("arm" "arm")
("mips64" "mips64le")))))
;; Make sure we start with a fresh, empty working directory. ;; Make sure we start with a fresh, empty working directory.
(mkdir directory) (mkdir directory)

View File

@ -73,7 +73,8 @@ found."
(leave (_ "~a: compressor not found~%") name))) (leave (_ "~a: compressor not found~%") name)))
(define* (self-contained-tarball name profile (define* (self-contained-tarball name profile
#:key deduplicate? #:key target
deduplicate?
(compressor (first %compressors)) (compressor (first %compressors))
localstatedir? localstatedir?
(symlinks '()) (symlinks '())
@ -184,14 +185,17 @@ added to the pack."
#:references-graphs `(("profile" ,profile)))) #:references-graphs `(("profile" ,profile))))
(define* (docker-image name profile (define* (docker-image name profile
#:key deduplicate? #:key target
deduplicate?
(compressor (first %compressors)) (compressor (first %compressors))
localstatedir? localstatedir?
(symlinks '()) (symlinks '())
(tar tar)) (tar tar))
"Return a derivation to construct a Docker image of PROFILE. The "Return a derivation to construct a Docker image of PROFILE. The
image is a tarball conforming to the Docker Image Specification, compressed image is a tarball conforming to the Docker Image Specification, compressed
with COMPRESSOR. It can be passed to 'docker load'." with COMPRESSOR. It can be passed to 'docker load'. If TARGET is true, it
must a be a GNU triplet and it is used to derive the architecture metadata in
the image."
;; FIXME: Honor LOCALSTATEDIR?. ;; FIXME: Honor LOCALSTATEDIR?.
(define not-config? (define not-config?
(match-lambda (match-lambda
@ -227,6 +231,7 @@ with COMPRESSOR. It can be passed to 'docker load'."
(setenv "PATH" (string-append #$tar "/bin")) (setenv "PATH" (string-append #$tar "/bin"))
(build-docker-image #$output #$profile (build-docker-image #$output #$profile
#:system (or #$target (utsname:machine (uname)))
#:closure "profile" #:closure "profile"
#:symlinks '#$symlinks #:symlinks '#$symlinks
#:compressor '#$(compressor-command compressor) #:compressor '#$(compressor-command compressor)
@ -278,6 +283,10 @@ with COMPRESSOR. It can be passed to 'docker load'."
(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 '(#\C "compression") #t #f (option '(#\C "compression") #t #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'compressor (lookup-compressor arg) (alist-cons 'compressor (lookup-compressor arg)
@ -314,6 +323,8 @@ Create a bundle of PACKAGE.\n"))
-f, --format=FORMAT build a pack in the given FORMAT")) -f, --format=FORMAT build a pack in the given FORMAT"))
(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 (_ "
-C, --compression=TOOL compress using TOOL--e.g., \"lzip\"")) -C, --compression=TOOL compress using TOOL--e.g., \"lzip\""))
(display (_ " (display (_ "
@ -354,6 +365,7 @@ Create a bundle of PACKAGE.\n"))
(pack-format (assoc-ref opts 'format)) (pack-format (assoc-ref opts 'format))
(name (string-append (symbol->string pack-format) (name (string-append (symbol->string pack-format)
"-pack")) "-pack"))
(target (assoc-ref opts 'target))
(compressor (assoc-ref opts 'compressor)) (compressor (assoc-ref opts 'compressor))
(symlinks (assoc-ref opts 'symlinks)) (symlinks (assoc-ref opts 'symlinks))
(build-image (match (assq-ref %formats pack-format) (build-image (match (assq-ref %formats pack-format)
@ -368,8 +380,11 @@ Create a bundle of PACKAGE.\n"))
(run-with-store store (run-with-store store
(mlet* %store-monad ((profile (profile-derivation (mlet* %store-monad ((profile (profile-derivation
(packages->manifest packages))) (packages->manifest packages)
#:target target))
(drv (build-image name profile (drv (build-image name profile
#:target
target
#:compressor #:compressor
compressor compressor
#:symlinks #:symlinks