AtlatestRepositorysigil-ui

sigil-ui / tree / scripts / macosaudit-native-groups.sgl

1(import (sigil shell prelude))
2(load (path (script-dir) "setup.sgl"))
3(import (sigil package) (sigil build))
4(define registry (realpath (arg 13)))
5(define inventory '())
6(define (package-root name version)
7 (define matches (glob (path registry (str "sigil%2Fsigil-" name "-" version "-*" "/package.sgl"))))
8 (unless (= 1 (length matches)) (error "Expected exact locked source" name version matches))
9 (dirname (car matches)))
10(define crypto (package-root "crypto" "0.19.2"))
11(define crypto-includes
12 (map (lambda (file) (path crypto file))
13 '("vendor/mbedtls/include" "vendor/mbedtls"
14 "vendor/monocypher/src" "vendor/monocypher/src/optional")))
15(each group '(("ffi" "0.16.6") ("crypto" "0.19.2") ("tls" "0.16.11") ("svg" "0.1.0"))
16 (define name (car group))
17 (define source-root (package-root name (cadr group)))
18 (define package (load-package (path source-root "package.sgl")))
19 (unless (= 1 (length (package-libraries package))) (error "Unexpected native library count" name))
20 (define library (car (package-libraries package)))
21 (define sources
22 (apply append (map (lambda (pattern) (glob (path source-root pattern)))
23 (library-c-sources library))))
24 (unless (pair? sources) (error "No selected native sources" name))
25 (define includes
26 (append (list headers (path (dirname headers) "src"))
27 (map (lambda (file) (path source-root file)) (library-c-include-dirs library))
28 (cond
29 ((equal? name "ffi")
30 (map (lambda (file) (path source-root file))
31 '("vendor/dyncall/dyncall" "vendor/dyncall/dyncallback")))
32 ((equal? name "tls") crypto-includes)
33 (else '()))))
34 (set! inventory (cons (list name (cadr group) source-root sources includes
35 (library-c-flags library)) inventory))
36 (each arch '("aarch64" "x86_64")
37 (define output (path build "native-audit" arch name))
38 (ensure-directory output)
39 (each source sources
40 (define relative (path-relative source-root source))
41 (define object (str (string-replace relative "/" "_") ".o"))
42 (compile! (str "audit-" arch "-" name "-" object)
43 (append (list "-target" (str arch "-macos.15.0-none") "-mmacosx-version-min=15.0"
44 "-std=c11" "-O1" "-D_DARWIN_C_SOURCE" "-D_GNU_SOURCE"
45 "-Wall" "-Wextra" "-Wno-unused-parameter")
46 (apply append (map (lambda (directory) (list "-I" directory)) includes))
47 (library-c-flags library)
48 (list "-c" source "-o" (path output object)))))))
49(write-text (path build "native-audit/INPUTS.sgl") (format "~s\n" (reverse inventory)))
50(println "PASS: all selected FFI, crypto, TLS and SVG units on both Mac architectures")