How to have an optional dependency?

Tomas Volf <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <ZnnA6uG_FidZcEAX@ws>
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.
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEt4NJs4wUfTYpiGikL7/ufbZ/wakFAmZ5wOoACgkQL7/ufbZ/
wamySQ//dUwcttw00HOYWiCN3q5ToI0P6JHdoDW5DgZLWeyAXVE4f+OHHeATZ8XU
FzfQ75S4BEL79lQ3/XYZ8W4dv8penqar7v6LBw97sDE9iRivd3JIRkE3NbNL/I7Q
vzoaCO26UuhhkZ+LHAD63FcPp3j/a9Ti/Il5Jap0RNVE3ADETw/9fYYNt+UPElot
GTe52dNz4ubf3xw314JLDRpKdoVbTSM2puYCglE0AxqvqxgEEiGLUnP+1tqDLt0b
oKQagUs+slkd/sKkfU+hPm/H4j1pQw7dJHI/VqYMzK3lB0hHgryj/344XgQTb7rM
txARGnKU1eVApN9Nyv9nPzAk7p5makjRSrm/PBYPFlgcRL1IpcojEgF67Su/WzoY
8cxqQT5MjTPv2ThCysm3O4EzGsV5DTVBGtkCjgFZosj8arR4/9cU8NRRhG9pP6Re
H8pGSi2TE3O3q0+co/8Vh1X+gxme8IicOz6wraozH6Wp/7BTBxkfA2A48fE+D1a4
Y3RFZIDYJrWhjcbXTI6JJ2awaFWJJHOKRyhq2iwSIDcVrjgXqdKY9/0NsgeC8Kmx
gXe0EmltzWEC76YTXgf62NMKMzAILSlF5dYfAti6mNyhK/XL+ZaLBiGHMoG8pQ1f
1Wj8QjnqO+jSvEzH7XcpXysFAyXvxLbi2Wd5ju76MNd6KOQnopc=
=4hmx
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.