[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/03: syscalls: 'define-c-struct' supports cross-compilation.
From: |
guix-commits |
Subject: |
01/03: syscalls: 'define-c-struct' supports cross-compilation. |
Date: |
Tue, 5 May 2020 17:46:24 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 86f5decd2066889bf2e60df388d6c812aede0917
Author: Ludovic Courtès <address@hidden>
AuthorDate: Tue May 5 12:13:43 2020 +0200
syscalls: 'define-c-struct' supports cross-compilation.
Reported by Jan (janneke) Nieuwenhuizen <address@hidden>.
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'.
---
guix/build/syscalls.scm | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 73b439f..00d8ceb 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)