unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Tomas Volf <~@wolfsden.cz>
To: guile-user@gnu.org
Subject: How to have an optional dependency?
Date: Mon, 24 Jun 2024 20:54:34 +0200	[thread overview]
Message-ID: <ZnnA6uG_FidZcEAX@ws> (raw)

[-- 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 --]

             reply	other threads:[~2024-06-24 18:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 18:54 Tomas Volf [this message]
2024-06-24 19:21 ` How to have an optional dependency? Maxime Devos via General Guile related discussions

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZnnA6uG_FidZcEAX@ws \
    --to=~@wolfsden.cz \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).