Fork me on GitHub
#scittle
<
2023-02-24
>
Gerome22:02:21

I would like to see if I can use scittle from inside a Swift playground. It must be possible. I was able to load the file and evaluate the module without errors. However, after that I'm pretty much lost. The file I'm using is scittle.min.js from JSDelivr. Before I set up the scittle dev env on my system, is there some way I can bundle everything in one file but it's not optimized? There is a bb dev task but that might not be bundled.

borkdude23:02:14

@UPJP9G4G1 You can compile with :optimizations :simple to get one file without optimizations

borkdude23:02:38

I'm not sure how Swift relates to JavaScript but I'd like to hear more about it. I'll check back in tomorrow after getting some sleep

Gerome23:02:50

Yes, I’m going to need some of that too.

Gerome07:02:14

So, I added a new task, created a new build for shadow-cljs. I ran npm install and then bb tasks to see if my task had registered. Afterwards, I ran bb ios and got the attached error. I also got this error when I opened VSCoded because Calva complained about it and told me that the build might not work correctly. I'll attach the changed files, also because I'm not sure if I'm doing this right :D

Gerome07:02:25

Alright, now calva says that shadow-cljs is not installed. I might have to read the docs for shadow-cljs. My only project in cljs was done with figwheel-main.

borkdude08:02:44

Try npm install

Gerome09:02:29

Hm, I did that and when I run it again, it says all is installed. The error log above is looking for some .cp file in .cpcache but I thought that is only available after compilation.

borkdude09:02:23

What babashka version do you have

borkdude09:02:47

> Library org.babashka/sci has prefix sha, use full sha or add tag Do you still get that?

borkdude09:02:07

Can you push the branch you're working on? This is easier than looking at snippets of code in slack

borkdude09:02:34

I'll take a look in an hour or so

Gerome09:02:29

Sure, no hurry, though. I have errands to run today and my family needs me as well. I'll try to find some time later on. I'll let you know.

👍 2
Gerome09:02:06

It could also be that this is something with my system. I'll go and see if something similar is occurring in other repos as well.

borkdude09:02:07

Can you also try with the vanilla scittle branch?

borkdude09:02:11

without making your own changes

Gerome09:02:56

I’ll try but as I wrote, this error occurred right when I opened Calva for the first time.

borkdude09:02:38

I'm only interested in the output of bb dev in the main branch of scittle without any of your changes

borkdude09:02:48

let's leave calva out of the equation for a minute

Gerome09:02:42

Here's the output. I also tried on a different system, and did get an error but a different one. 😊 So, it's probably my system configuration.

Gerome09:02:46

Gotta run now.

borkdude10:02:31

Can you just execute clj -Stree -A:dev and pos the output here?

borkdude11:02:28

Can you do cat deps.edn?

borkdude11:02:10

I can't explain this error. Can you do clj -Sforce -Stree -A:dev?

Gerome11:02:37

Same as without -Sforce

borkdude11:02:05

what is your clojure --version

borkdude11:02:47

can you upgrade? maybe it helps

Gerome11:02:53

I'll try it

borkdude11:02:04

or are you missing one digit at the end?

Gerome11:02:18

Yes, it's 1224, sorry

borkdude11:02:25

ok, that's the newest

borkdude11:02:50

can you try with -Srepro?

borkdude11:02:11

I would bring this to #C6QH853H8 - I don't know what's wrong

Gerome11:02:26

Alright, thanks a lot for the patience.

borkdude11:02:42

it might be your git version perhaps

borkdude11:02:50

can you do git --version?

borkdude11:02:04

I have:

$ git --version
git version 2.37.0 (Apple Git-136)

borkdude11:02:20

should be good I think

Gerome11:02:52

Let me talk to #C6QH853H8 and see what they're saying. I'll get back to you as soon as I know what's wrong.

borkdude11:02:12

Just tell them that clj -Stree -A:dev isn't working

borkdude11:02:20

and point them to the scittle repo

borkdude12:02:37

so we got that out of the way now

Gerome12:02:10

Yeah, I just ran my custom ios task. I’m going to have lunch with my family now. Will get back to you later.

👍 2
Gerome19:02:12

Alright, I was able to compile scittle with different optimizations but I run into a couple of problems on the Swift side of things. First of all, this should in principle be possible. iOS has https://developer.apple.com/documentation/javascriptcore which allows evaluation of JavaScript. It's specifically meant for running JS code from within Swift and even treat JavaScript entities such as functions and data structures like Swift entities. This is pretty cool. However, what I need is just Scittle's (eval-string). I was hoping that if I evaluate Scittle I will have access to the module somehow but I'm not even sure if it's properly loaded as the evaluation function just returns undefined for stuff like 1 + which is obviously broken JS and should cause some kind of error. I think part of the problem is that Scittle is meant to be run in the browser and there are references to window in the compiled code. So, I suspect it's not even loading. If I try to run it in node it just breaks. I tried changing the target to :node-library but that caused some errors, so I need to take some time and look into it more closely.

borkdude19:02:34

If you're not going to use a browser, it may be better to use SCI directly

borkdude19:02:32

Just look how SCI is used in scittle. There isn't much going on there

Gerome19:02:54

Alright, I'll take a look.

borkdude19:02:23

core.cljs is only 100 lines or so, you can just rip out the stuff you need

borkdude19:02:29

or delete the stuff you don't need

Gerome19:02:51

🙂 Okay, I'll take a closer look.

borkdude19:02:36

Instead of this 'js js/window it's better to write js/globalThis

borkdude19:02:44

I'll change this in scittle now

borkdude19:02:01

and also you won't need reagent etc, so I'd also leave that out (just delete it from the shadow-cljs.edn)

Gerome19:02:13

Yes, I've done that already.

Gerome19:02:47

About the window reference. That was in the compiled code. So, I'm not sure if you have actual references to it in the cljs code 🙂

Gerome19:02:05

These are good ideas. I'll take them into account with my next steps.

Gerome19:02:25

Starting small is always a good idea.

borkdude19:02:52

I removed the window reference from scittle core.cljs now on master

borkdude19:02:19

but it still has references to js/document to load the script tags, you can remove those

borkdude20:02:58

sorry, my push didn't work, it's now there

Gerome21:02:08

Alright, so, I’m in a little bit of a dead end right now. I created a minimal project and targeted node and none and in both cases the Google Closure code relied on something that did not exist and the code execution did not reach the namespace I created. I managed to get the namespace to run and execute my function but only by manually deleting Google Closure code from the compiled js file. However, I still think that this is possible. I hear that there is react native applications written in ClojureScript that run in iOS. However, I used cljs.main for this. Maybe I should use shadow-cljs. In addition to that there is [replete](https://github.com/replete-repl) which is using some compiles version of clojurescript from [planck](https://github.com/planck-repl/planck)

borkdude21:02:06

Ah I see. I think what you might need is :target :esm which is fairly neutral, as in, it doesn't assume any target specific stuff

borkdude21:02:22

This is the same target that nbb uses so if you're looking for an example, look over there