# How to compile print debugs only when a certain environment variable is set?

**URL:** <https://community.spritely.institute/t/how-to-compile-print-debugs-only-when-a-certain-environment-variable-is-set/724>\
**Category:** Uncategorized\
**Tags:** debugging, wasm, hoot\
**Created:** [May 19, 2025, 4:03pm UTC](https://community.spritely.institute/t/how-to-compile-print-debugs-only-when-a-certain-environment-variable-is-set/724 "2025-05-19T16:03:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kakafarm](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/kakafarm/32/360_2.png) [@kakafarm](https://community.spritely.institute/u/kakafarm)\
**Post date:** [May 19, 2025, 4:03pm UTC](https://community.spritely.institute/t/how-to-compile-print-debugs-only-when-a-certain-environment-variable-is-set/724/1 "2025-05-19T16:03:12Z")

</div>

I have a bunch of debug prints all over my code. In mass, they take a ton of resources to run.

In the module `(console)` I do this:

```auto
(define-module (console)
  #:export (debug log warn)
  #:use-module (hoot ffi))

(define *debug* #t)

(define-foreign %debug "console" "debug" (ref string) -> none)
(define-foreign %log "console" "log" (ref string) -> none)
(define-foreign %warn "console" "warn" (ref string) -> none)

(define debug (if *debug*
                  (lambda* (s #:rest rest) (%debug (apply format #f s rest)))
                  (lambda (. _) '())))
(define* (log s #:rest rest) (%log (apply format #f s rest)))
(define* (warn s #:rest rest) (%warn (apply format #f s rest)))

```

Changing `*debug*`'s value manually is a bit of a PITA.

Is there a way of defining `*debug*` in such a way that by default its value would be `#f`, but `#t` when some specific environment variable is set?

---

<div class="post-metadata">

**Author:** ![dthompson](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dthompson/32/95_2.png) [@dthompson](https://community.spritely.institute/u/dthompson)\
**Post date:** [May 19, 2025, 5:26pm UTC](https://community.spritely.institute/t/how-to-compile-print-debugs-only-when-a-certain-environment-variable-is-set/724/2 "2025-05-19T17:26:32Z")

</div>

There’s no built-in solution for this particular thing. On the web, there is no equivalent of UNIX environment variables, so you have to do something else. One thing you could do is `(define-foreign debug-mode? "debug" "isDebugMode" -> i32)` and write a host function that does… something. Maybe it checks for a `<meta>` tag value or maybe it does something else. Hope this helps a bit.

---

<div class="post-metadata">

**Author:** ![kakafarm](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/kakafarm/32/360_2.png) [@kakafarm](https://community.spritely.institute/u/kakafarm)\
**Post date:** [May 19, 2025, 7:58pm UTC](https://community.spritely.institute/t/how-to-compile-print-debugs-only-when-a-certain-environment-variable-is-set/724/3 "2025-05-19T19:58:29Z")

</div>

I was thinking of something that conditionally compiles that procedure, not changes how it runs at runtime.

Like some way of providing the `guild` compiler system with variables. In C compilers there are CFLAGS.

…  
…  
…

Now that I have looked into `guild compile-wasm --help`, maybe I could just define two alternative `(debug-flag)` modules.

One in `./debug-flag/debugflag.scm`:

```scheme
(define-module (debug-flag) #:export (*debug*))
(define *debug* #t)

```

The other in `./release-flag/debug-flag.scm`:

```scheme
(define-module (debug-flag) #:export (*debug*))
(define *debug* #f)

```

Then I would run either `guild compile-wasm -L debug-flag …` or `guild compile-wasm -L release-flag …`.

The `(console)` module which `#:use-module (debug-flag)` would then get the right value.

A bit of work, but it’s something!
