From e2dbcf3ff233ea7dfd8fbce3545057fae557489b Mon Sep 17 00:00:00 2001 From: retropikzel Date: Fri, 20 Jun 2025 08:47:03 +0300 Subject: [PATCH 1/4] Add support for --foreign-depends args. Fix library install compilation bug. --- doc/chibi.scrbl | 5 +++++ lib/chibi/snow/commands.scm | 35 +++++++++++++++-------------------- tools/snow-chibi.scm | 1 + 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/doc/chibi.scrbl b/doc/chibi.scrbl index 9baf174e..10733eb0 100755 --- a/doc/chibi.scrbl +++ b/doc/chibi.scrbl @@ -1613,6 +1613,11 @@ can specify any option, for example: (license gpl)))) } +\itemlist[ +\item{\scheme{--foreign-depends} - specify foreign libraries the library +depends on (comma-delimited) (for example ffi,sqlite3 for -lffi -lsqlite3)} +] + Top-level snow options are represented as a flat alist. Options specific to a command are nested under \scheme{(command (name ...))}, with most options here being for \scheme{package}. Here unless diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index eae77d94..fbf773c1 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -129,7 +129,8 @@ declarations ...) (let* ((dir (library-path-base file name)) (lib-file (path-relative file dir)) - (lib-dir (path-directory lib-file))) + (lib-dir (path-directory lib-file)) + (foreign-depends (conf-get-list cfg 'foreign-depends))) (define (resolve file) (let ((dest-path (if (equal? lib-dir ".") file @@ -158,7 +159,8 @@ (warn "couldn't find ffi stub or c source" base) '())))) (let lp ((ls declarations) - (info `(,@(cond + (info `((foreign-depends ,@foreign-depends) + ,@(cond ((conf-get cfg '(command package author)) => (lambda (x) (list (list 'author x)))) (else '())) @@ -210,7 +212,8 @@ files chibi-ffi?)) (('cond-expand clauses ...) - (let ((libs+files (map (lambda (c) (lp c '() '() '() #f)) clauses))) + (let ((libs+files (map (lambda (c) + (lp c '() '() '() #f)) clauses))) (lp (cdr ls) (cons (cons 'cond-expand (map cons @@ -2045,34 +2048,26 @@ (so-file (string-append base (cond-expand (macosx ".dylib") (else ".so")))) (so-flags (cond-expand (macosx '("-dynamiclib" "-Oz")) - (else '("-fPIC" "-shared" "-Os")))) + (else '("-fPIC" "-shared""-Os")))) (lib-flags - (map (lambda (lib) (string-append "-l" lib)) + (map (lambda (lib) + (string-append "-l" lib)) (library-foreign-dependencies impl cfg library))) - (ffi-cmd - `(,@chibi-ffi - "-c" "-cc" ,(car cc) - "-f" ,(string-join cflags " ") - "-f" ,(string-join lib-flags " ") - ,@(if local-test? '("-f" "-Iinclude -L.") '()) - ,@(if (pair? (cdr cc)) - (list "-f" (string-join (cdr cc) " ")) - '()) - ,stub-file)) + (ffi-cmd `(,@chibi-ffi ,stub-file)) (cc-cmd `(,@cc ,@cflags ,@so-flags ,@(if local-test? '("-Iinclude" "-L.") '()) "-o" ,so-file ,c-file "-lchibi-scheme" ,@lib-flags))) - (when (or (and (file-exists? c-file) + (when (or (and (file-exists? stub-file) + (or (system? ffi-cmd) + (yes-or-no? cfg "couldn't compile stub: " + stub-file " - install anyway?"))) + (and (file-exists? c-file) (or (system? cc-cmd) (yes-or-no? cfg "couldn't compile chibi ffi c code: " c-file " - install anyway?"))) - (and (file-exists? stub-file) - (or (system? ffi-cmd) - (yes-or-no? cfg "couldn't compile stub: " - stub-file " - install anyway?"))) (yes-or-no? cfg "can't find ffi stub or c source for: " base " - install anyway?")) (lp (cdr ls)))))))) diff --git a/tools/snow-chibi.scm b/tools/snow-chibi.scm index ddd14021..f0e09ff8 100755 --- a/tools/snow-chibi.scm +++ b/tools/snow-chibi.scm @@ -90,6 +90,7 @@ (chibi-path filename "path to chibi-scheme executable") (cc string "path to c compiler") (cflags string "flags for c compiler") + (foreign-depends (list string) "foreign libraries library depends on") (use-curl? boolean ("use-curl") "use curl for file uploads") (sexp? boolean ("sexp") "output information in sexp format") )) From bf5f1278218176d2db63d95e08733efde6af0d1b Mon Sep 17 00:00:00 2001 From: retropikzel Date: Fri, 20 Jun 2025 09:01:22 +0300 Subject: [PATCH 2/4] Minor fixes --- lib/chibi/snow/commands.scm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index fbf773c1..9c5dd843 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -212,8 +212,7 @@ files chibi-ffi?)) (('cond-expand clauses ...) - (let ((libs+files (map (lambda (c) - (lp c '() '() '() #f)) clauses))) + (let ((libs+files (map (lambda (c) (lp c '() '() '() #f)) clauses))) (lp (cdr ls) (cons (cons 'cond-expand (map cons @@ -2048,10 +2047,9 @@ (so-file (string-append base (cond-expand (macosx ".dylib") (else ".so")))) (so-flags (cond-expand (macosx '("-dynamiclib" "-Oz")) - (else '("-fPIC" "-shared""-Os")))) + (else '("-fPIC" "-shared" "-Os")))) (lib-flags - (map (lambda (lib) - (string-append "-l" lib)) + (map (lambda (lib) (string-append "-l" lib)) (library-foreign-dependencies impl cfg library))) (ffi-cmd `(,@chibi-ffi ,stub-file)) (cc-cmd From 3142fc2fdc937b77d8d4fbe3aeb6799fb46e4a98 Mon Sep 17 00:00:00 2001 From: retropikzel Date: Fri, 20 Jun 2025 13:08:33 +0300 Subject: [PATCH 3/4] If C file already exists do not run chibi-ffi --- lib/chibi/snow/commands.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index 9c5dd843..06ad4bd3 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -2057,7 +2057,8 @@ ,@(if local-test? '("-Iinclude" "-L.") '()) "-o" ,so-file ,c-file "-lchibi-scheme" ,@lib-flags))) - (when (or (and (file-exists? stub-file) + (when (or (and (not (file-exists? c-file)) + (file-exists? stub-file) (or (system? ffi-cmd) (yes-or-no? cfg "couldn't compile stub: " stub-file " - install anyway?"))) From 28490661cf5a6d27188dc431c78cbcfd3cf0a7ba Mon Sep 17 00:00:00 2001 From: retropikzel Date: Wed, 25 Jun 2025 07:40:40 +0300 Subject: [PATCH 4/4] Change the ffi and compile commands back --- lib/chibi/snow/commands.scm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/chibi/snow/commands.scm b/lib/chibi/snow/commands.scm index 06ad4bd3..9411e18c 100644 --- a/lib/chibi/snow/commands.scm +++ b/lib/chibi/snow/commands.scm @@ -2051,22 +2051,30 @@ (lib-flags (map (lambda (lib) (string-append "-l" lib)) (library-foreign-dependencies impl cfg library))) - (ffi-cmd `(,@chibi-ffi ,stub-file)) + (ffi-cmd + `(,@chibi-ffi + "-c" "-cc" ,(car cc) + "-f" ,(string-join cflags " ") + "-f" ,(string-join lib-flags " ") + ,@(if local-test? '("-f" "-Iinclude -L.") '()) + ,@(if (pair? (cdr cc)) + (list "-f" (string-join (cdr cc) " ")) + '()) + ,stub-file)) (cc-cmd `(,@cc ,@cflags ,@so-flags ,@(if local-test? '("-Iinclude" "-L.") '()) "-o" ,so-file ,c-file "-lchibi-scheme" ,@lib-flags))) - (when (or (and (not (file-exists? c-file)) - (file-exists? stub-file) - (or (system? ffi-cmd) - (yes-or-no? cfg "couldn't compile stub: " - stub-file " - install anyway?"))) - (and (file-exists? c-file) + (when (or (and (file-exists? c-file) (or (system? cc-cmd) (yes-or-no? cfg "couldn't compile chibi ffi c code: " c-file " - install anyway?"))) + (and (file-exists? stub-file) + (or (system? ffi-cmd) + (yes-or-no? cfg "couldn't compile stub: " + stub-file " - install anyway?"))) (yes-or-no? cfg "can't find ffi stub or c source for: " base " - install anyway?")) (lp (cdr ls))))))))