unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to have an optional dependency?
@ 2024-06-24 18:54 Tomas Volf
  2024-06-24 19:21 ` Maxime Devos via General Guile related discussions
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Volf @ 2024-06-24 18:54 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 2316 bytes --]

Hi!

I am writing a module in Guile, and I would like to have an optional dependency
on another library.  And I am not sure how to express it.  So far I found that
#:autoload can be used for it.

I have tried two approaches:

      #:autoload (guix derivations) (build-derivations
                                     derivation?
                                     derivation->output-path)
      #:autoload (guix gexp) (lower-object)
      #:autoload (guix store) (run-with-store store-protocol-error? with-store)

This works, but when I try to compile my library in environment without Guix, I
get a lot of warnings in the build log:

    ;;; Failed to autoload with-store in (guix store):
    ;;; no code for module (guix store)
    ;;; Failed to autoload run-with-store in (guix store):
    ;;; no code for module (guix store)
    ...

The build does succeed, but the spam in the logs is annoying.  The other
approach I discovered is using module-autoload!:

    (module-autoload!
     (current-module)
     '(guix derivations) '(build-derivations derivation? derivation->output-path)
     '(guix gexp)        '(lower-object)
     '(guix store)       '(run-with-store store-protocol-error? with-store))

This *also* works, but *also* leads to (different) warnings:

    wolfsden/guix/utils.scm:62:14: warning: possibly unbound variable `with-store'
    wolfsden/guix/utils.scm:62:25: warning: possibly unbound variable `%store'
    wolfsden/guix/utils.scm:63:16: warning: possibly unbound variable `run-with-store'
    wolfsden/guix/utils.scm:64:18: warning: possibly unbound variable `lower-object'
    wolfsden/guix/utils.scm:66:14: warning: possibly unbound variable `store-protocol-error?'
    wolfsden/guix/utils.scm:70:9: warning: possibly unbound variable `build-derivations'
    wolfsden/guix/utils.scm:71:20: warning: possibly unbound variable `derivation?'
    wolfsden/guix/utils.scm:72:20: warning: possibly unbound variable `derivation->output-path'

Is there a way to have a module as an optional dependency without any warnings?
For example, is there a way to convince the Guile that those specific variables
will be bound?  How do people commonly approach this?

Thanks,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-24 19:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24 18:54 How to have an optional dependency? Tomas Volf
2024-06-24 19:21 ` Maxime Devos via General Guile related discussions

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).