Issue #365 - Allow c-linker-options to work as a top-level expression in a program

This commit is contained in:
Justin Ethier 2021-01-18 15:57:45 -05:00
parent 065a8bdd15
commit dc597a9926
2 changed files with 22 additions and 7 deletions

View file

@ -6,6 +6,7 @@ TODO: consider creating a revised overview of our GC that unifies the original w
Features
- Added the `c-compiler-options` expression and `-COPT` Cyclone compiler option to allow specifying options for the C compiler.
- Allow `c-linker-options` to work as a top-level expression in a program.
Bug Fixes

View file

@ -692,11 +692,21 @@
(lambda (port)
(read-all/source port filename))))
;; Parse given expression and return data from any instances
;; of c-compiler-options
(define (program-c-compiler-opts! in-prog)
(get-options! 'c-compiler-options in-prog))
(define (program-c-linker-opts! in-prog)
(get-options! 'c-linker-options in-prog))
(define (get-options! opt in-prog)
(foldl
(lambda (expr acc)
(cond
((tagged-list? 'c-compiler-options expr)
((tagged-list? opt expr)
;; Replace expression since it is only used in this initial
;; pass, and would cause problems downstream
(set-car! expr (string->symbol "quote"))
(cons (cadr expr) acc))
(else
@ -730,21 +740,25 @@
(lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs expander)
'()))
;; Read all linker options from dependent libs
;; TODO: also read from program if applicable
(c-linker-options
(lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs))
(let ((lib-options (lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs)))
(if program?
(string-append ;; Also read from current program
(string-join (program-c-linker-opts! in-prog) " ")
" "
lib-options)
lib-options)))
;; Only read C compiler options from module being compiled
;; TODO: allow these to be read from a program
(cc-opts*
(cond
(program?
(string-join
(string-join ;; Check current program for options
(program-c-compiler-opts! in-prog)
""))
" "))
(else
(string-join
(lib:c-compiler-options (car in-prog))
""))))
" "))))
(exec-file (basename in-file))
(src-file (string-append exec-file ".c"))
(meta-file (string-append exec-file ".meta"))