home: hub: zuo

Download patch

ref: 41ff8acc4af96fb161fa0fa3e46b5a3b510590dc
parent: 6cb4a63ba2279892e830289d3b879a29c9edc075
author: Matthew Flatt <mflatt@racket-lang.org>
date: Tue May 3 14:15:09 CDT 2022

zuo: add 'toolchain-type to `(runtime-env)`

On Windows, the value for 'toolchain-type is 'windows (meaning Visual
Studio) or 'unix (meaning CC, etc.), depending on which compiler is
used to build Zuo. The inferred toolchain type can be override with
preprocessor definitions.

--- a/lib/zuo/c.zuo
+++ b/lib/zuo/c.zuo
@@ -19,7 +19,7 @@
               (and (list? .c) (andmap path-string? .c)))
     (arg-error 'c-compile "path string or list of paths strings" .c))
   (unless (hash? config) (arg-error 'c-compile "hash table" config))
-  (define windows? (eq? (hash-ref (runtime-env) 'system-type) 'windows))
+  (define windows? (eq? (hash-ref (runtime-env) 'toolchain-type) 'windows))
   (define lookup (make-lookup config))
   (define command
     (build-shell (or (lookup 'CC)
@@ -42,7 +42,7 @@
   (unless (path-string? .exe) (arg-error 'c-link "path string" .exe))
   (unless (and (list? ins) (andmap path-string? ins)) (arg-error 'c-link "list of path strings" ins))
   (unless (hash? config) (arg-error 'c-link "hash table" config))
-  (define windows? (eq? (hash-ref (runtime-env) 'system-type) 'windows))
+  (define windows? (eq? (hash-ref (runtime-env) 'toolchain-type) 'windows))
   (define lookup (make-lookup config))
   (define command
     (build-shell (or (lookup 'CC)
@@ -60,7 +60,7 @@
   (unless (path-string? .a) (arg-error 'c-ar "path string" .exe))
   (unless (and (list? ins) (andmap path-string? ins)) (arg-error 'c-ar "list of path strings" ins))
   (unless (hash? config) (arg-error 'c-ar "hash table" config))
-  (define windows? (eq? (hash-ref (runtime-env) 'system-type) 'windows))
+  (define windows? (eq? (hash-ref (runtime-env) 'toolchain-type) 'windows))
   (define lookup (make-lookup config))
   (shell/wait
    (build-shell (or (lookup 'AR)
@@ -78,7 +78,7 @@
 
 (define (.c->.o .c)
   (unless (path-string? .c) (arg-error '.c->.o "path string" .c))
-  (path-replace-extension .c (if (eq? (hash-ref (runtime-env) 'system-type) 'windows)
+  (path-replace-extension .c (if (eq? (hash-ref (runtime-env) 'toolchain-type) 'windows)
                                  ".obj"
                                  ".o")))
 
@@ -90,7 +90,7 @@
 
 (define (.a name)
   (unless (path-string? name) (arg-error '.a "string" name))
-  (if (eq? (hash-ref (runtime-env) 'system-type) 'windows)
+  (if (eq? (hash-ref (runtime-env) 'toolchain-type) 'windows)
       (~a name ".lib")
       (let ([l (split-path name)])
         (build-path (or (car l) ".") (~a "lib" (cdr l) ".a")))))
--- a/zuo-doc/lang-zuo.scrbl
+++ b/zuo-doc/lang-zuo.scrbl
@@ -1282,6 +1282,13 @@
 
 @item{@racket['system-type]: @racket['unix] or @racket['windows]}
 
+@item{@racket['toolchain-type]: @racket['unix] (@exec{cc}, etc.) or
+      @racket['windows] (@exec{cl.exe}, etc.); on Windows, the default
+      is determined by the compiler used to build the Zuo executable,
+      but it can be set explicitly by defining either the
+      @tt{ZUO_WINDOWS_TOOLCHAIN} or @tt{ZUO_UNIX_TOOLCHAIN}
+      preprocessor symbol when compiliing Zuo}
+
 @item{@racket['sys-dir] (Windows only): the path to the system directory}
 
 @item{@racket['can-exec?]: a boolean whether @racket[process] supports
--- a/zuo-doc/zuo-lib.scrbl
+++ b/zuo-doc/zuo-lib.scrbl
@@ -226,7 +226,9 @@
 The C-tool procedures provided by @racketmodname[zuo/c] accept a
 @deftech{tool configuration} hash table to describe a C compiler,
 linker, archiver, and associated flags. When potential configuration
-is missing, a default suitable for the current system is used. Values
+is missing, a default suitable for the current toolchain is used,
+where the toolchain is determined through @racket[(hash-ref
+(runtime-env) 'toolchain-type)]. Values
 in a tool configuration hash table are shell-command fragments, not
 individual arguments. For example, it could make sense to configure
 @racket['CC] as @racket["libtool cc"], which would run @exec{libtool}
--- a/zuo.c
+++ b/zuo.c
@@ -3995,15 +3995,22 @@
   ht = zuo_hash_set(ht, zuo_symbol("env"), zuo_get_envvars());
 
   {
+    zuo_t *type, *toolchain;
 #ifdef ZUO_UNIX
-    zuo_t *type = zuo_symbol("unix");
+    type = toolchain = zuo_symbol("unix");
     ht = zuo_hash_set(ht, zuo_symbol("can-exec?"), z.o_true);
 #endif
 #ifdef ZUO_WINDOWS
-    zuo_t *type = zuo_symbol("windows");
-    ht = zuo_hash_set(ht, zuo_symbol("can-exec?"), z.o_true);
+    type = zuo_symbol("windows");
+# if defined(ZUO_WINDOWS_TOOLCHAIN) || (!defined(ZUO_UNIX_TOOLCHAIN) && defined(_MSC_VER))
+    toolchain = type;
+# else
+    toolchain = zuo_symbol("unix");
+# endif
+    ht = zuo_hash_set(ht, zuo_symbol("can-exec?"), z.o_false);
 #endif
     ht = zuo_hash_set(ht, zuo_symbol("system-type"), type);
+    ht = zuo_hash_set(ht, zuo_symbol("toolchain-type"), toolchain);
   }
 
 #ifdef ZUO_WINDOWS