summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-05-05 12:13:43 +0200
committerLudovic Courtès <ludo@gnu.org>2020-05-05 23:45:56 +0200
commit86f5decd2066889bf2e60df388d6c812aede0917 (patch)
tree0c2f259b3c7705238d9e92947e654a07a96cdee0
parent751d1f01e4f0607d41e4c859d944753b18466652 (diff)
downloadpatches-86f5decd2066889bf2e60df388d6c812aede0917.tar
patches-86f5decd2066889bf2e60df388d6c812aede0917.tar.gz
syscalls: 'define-c-struct' supports cross-compilation.
Reported by Jan (janneke) Nieuwenhuizen <janneke@gnu.org>. Before that, we'd always use the 'sizeof' and 'alignof' value obtained from the host at macro-expansion time. * guix/build/syscalls.scm (sizeof*, alignof*): When the target word size differs from the host word size, emit a call to 'sizeof'/'alignof'.
-rw-r--r--guix/build/syscalls.scm23
1 files changed, 17 insertions, 6 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 73b439fb7d..00d8ceb480 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -23,6 +23,7 @@
(define-module (guix build syscalls)
#:use-module (system foreign)
+ #:use-module (system base target)
#:use-module (rnrs bytevectors)
#:autoload (ice-9 binary-ports) (get-bytevector-n)
#:use-module (srfi srfi-1)
@@ -194,9 +195,14 @@
(* (sizeof* type) n))
((_ type)
(let-syntax ((v (lambda (s)
- (let ((val (sizeof type)))
- (syntax-case s ()
- (_ val))))))
+ ;; When compiling natively, call 'sizeof' at expansion
+ ;; time; otherwise, emit code to call it at run time.
+ (syntax-case s ()
+ (_
+ (if (= (target-word-size)
+ (with-target %host-type target-word-size))
+ (sizeof type)
+ #'(sizeof type)))))))
v))))
(define-syntax alignof*
@@ -208,9 +214,14 @@
(alignof* type))
((_ type)
(let-syntax ((v (lambda (s)
- (let ((val (alignof type)))
- (syntax-case s ()
- (_ val))))))
+ ;; When compiling natively, call 'sizeof' at expansion
+ ;; time; otherwise, emit code to call it at run time.
+ (syntax-case s ()
+ (_
+ (if (= (target-word-size)
+ (with-target %host-type target-word-size))
+ (alignof type)
+ #'(alignof type)))))))
v))))
(define-syntax align ;as found in (system foreign)