Fork me on GitHub
#shadow-cljs
<
2022-12-27
>
mbertheau22:12:21

I want to use the self-hosted clojurescript compiler in the browser to compile code that uses com.rpl.specter. It says com.rpl.specter/select is an undeclared var. A JS symbol com.rpl.specter.select indeed doesn't appear in any of the js/com.rpl.specter* files in the output of the :bootstrap build. In the source select's a macro https://github.com/redplanetlabs/specter/blob/67e86806020b9d02fbca8cdb1efad3002fc81a32/src/clj/com/rpl/specter.cljc#L347-L351 My :bootstrap build config is:

{:target           :bootstrap
   :output-dir       "public/bootstrap"
   :compiler-options {:warnings {:infer false}}
   :exclude          #{cljs.js}
   :entries          [cljs.js com.rpl.specter]}
I copied {:warnings {:infer false}} from other examples of self-hosted cljs, without knowing what it does and whether it's necessary. I didn't find statements that self-hosted cljs doesn't support macros. Should this work? What am I missing? Thanks! Addendum: It seems that certain macro syntax isn't supported by the self-hosted clojurescript clojurescript compiler. There's a PR in specter that seems to address this partly. I'll see if that gets me further. https://github.com/redplanetlabs/specter/pull/299

mbertheau00:12:00

I wonder if separating the cljc files into clj and cljs might help.

thheller06:12:00

yeah, lots of lib written in cljc do not account for self-hosted. can't comment on what exactly the problem is though

thheller06:12:10

macros do work just fine but still need to be used correctly, as in the regular CLJS version

thheller06:12:13

quick glance suggests that at least there is a macros.cljs, or it written as .cljc with the proper :require-macros for itself

mbertheau09:12:23

@U05224H0W When it works, the com.rpl.specter/select macro should appear as com.rpl.specter$macros.select in the JS source, right? Also, when you say that macros need to be used correctly, one of the things you mean in particular is that wrapping macro definitions in #?(:clj ..)would be wrong. While that works for Clojure and Clojure-hosted ClojureScript, it doesn't work for self-hosted Clojurescript.

thheller09:12:37

yes, :clj branches are ignored

thheller09:12:52

and yes, macros are in special $macros namespaces. that separation is what I mean by using it correctly. can't put macros in the com.rpl.specter ns directly even though it might appear so

mbertheau10:12:03

With macros in Clojure, you just use defmacro and that's it. With macros in Clojure-hosted ClojureScript, you describe the problems in https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html With macros in self-hosted ClojureScript, assuming that that's the only target you intend to support, would it be enough to just use defmacro in the .cljs file, similar to the Clojure case, where you just use defmacro in the .clj file, and that's it? Are all the shenanigans that net.cgrand.macrovich deals with and reader conditionals and so forth only necessary to support the mixed ClojureScript on Clojure target?

thheller15:12:01

macros are NOT supported in .cljs files no

thheller15:12:04

has to be clj or cljc

mbertheau18:12:58

@U05224H0W Can this work with shadow-cljs's bootstrapped self-hosted cljs compiler? https://github.com/cgrand/macrovich/blob/e80fb37cb795201821d0e75f73119802227e9620/src/net/cgrand/macrovich.cljc#L11 In my experiments *ns* is always null.

thheller18:12:43

thats fine. *ns* is always bound to the current ns when macroexpanding, but not otherwise