scittle

Gerome 2023-02-24T22:58:21.394609Z

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.

borkdude 2023-02-24T23:04:14.706169Z

@gerome.bochmann You can compile with :optimizations :simple to get one file without optimizations

borkdude 2023-02-24T23:05:38.762459Z

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

Gerome 2023-02-24T23:08:50.057339Z

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

Gerome 2023-02-25T07:33:14.702919Z

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

Gerome 2023-02-25T07:35:07.593449Z

Gerome 2023-02-25T07:37:19.290439Z

Gerome 2023-02-25T07:43:25.157749Z

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.

Gerome 2023-02-27T21:20:08.593129Z

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)

borkdude 2023-02-27T21:47:06.278509Z

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

borkdude 2023-02-27T21:47:22.371899Z

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

borkdude 2023-02-25T08:57:44.099269Z

Try npm install

Gerome 2023-02-25T09:11:29.296389Z

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.

borkdude 2023-02-25T09:13:23.833369Z

What babashka version do you have

borkdude 2023-02-25T09:13:47.755919Z

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

Gerome 2023-02-25T09:13:50.924879Z

borkdude 2023-02-25T09:14:07.684669Z

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

borkdude 2023-02-25T09:14:34.135249Z

I'll take a look in an hour or so

Gerome 2023-02-25T09:15:29.494949Z

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.

👍 1
Gerome 2023-02-25T09:16:06.689589Z

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.

borkdude 2023-02-25T09:17:07.039049Z

Can you also try with the vanilla scittle branch?

borkdude 2023-02-25T09:17:11.177869Z

without making your own changes

Gerome 2023-02-25T09:20:56.936959Z

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

borkdude 2023-02-25T09:21:38.210329Z

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

borkdude 2023-02-25T09:21:48.614489Z

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

Gerome 2023-02-25T09:21:54.633589Z

Sure!

Gerome 2023-02-25T09:39:42.361749Z

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.

Gerome 2023-02-25T09:39:46.017639Z

Gotta run now.

borkdude 2023-02-25T10:17:31.338979Z

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

Gerome 2023-02-25T11:01:27.406869Z

borkdude 2023-02-25T11:03:28.990269Z

Can you do cat deps.edn?

Gerome 2023-02-25T11:04:41.668259Z

borkdude 2023-02-25T11:07:10.248149Z

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

Gerome 2023-02-25T11:07:37.799389Z

Same as without -Sforce

borkdude 2023-02-25T11:07:57.308539Z

weird

borkdude 2023-02-25T11:08:05.076489Z

what is your clojure --version

Gerome 2023-02-25T11:08:26.138449Z

borkdude 2023-02-25T11:08:47.456459Z

can you upgrade? maybe it helps

Gerome 2023-02-25T11:08:53.315269Z

I'll try it

borkdude 2023-02-25T11:09:04.185599Z

or are you missing one digit at the end?

Gerome 2023-02-25T11:09:18.741869Z

Yes, it's 1224, sorry

Gerome 2023-02-25T11:09:22.068499Z

😄

borkdude 2023-02-25T11:09:25.401149Z

ok, that's the newest

borkdude 2023-02-25T11:09:50.513029Z

can you try with -Srepro?

Gerome 2023-02-25T11:10:56.158649Z

Same

borkdude 2023-02-25T11:11:11.940979Z

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

Gerome 2023-02-25T11:11:26.560149Z

Alright, thanks a lot for the patience.

borkdude 2023-02-25T11:11:42.370449Z

it might be your git version perhaps

borkdude 2023-02-25T11:11:50.702169Z

can you do git --version?

borkdude 2023-02-25T11:12:04.542099Z

I have:

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

Gerome 2023-02-25T11:12:09.790229Z

2.39.2

borkdude 2023-02-25T11:12:20.857539Z

should be good I think

Gerome 2023-02-25T11:12:52.601039Z

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

borkdude 2023-02-25T11:12:56.110849Z

ok

borkdude 2023-02-25T11:13:12.240109Z

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

Gerome 2023-02-25T11:13:20.426809Z

Okay

borkdude 2023-02-25T11:13:20.623749Z

and point them to the scittle repo

Gerome 2023-02-25T11:13:28.964009Z

Will do

borkdude 2023-02-25T12:06:37.530959Z

so we got that out of the way now

Gerome 2023-02-25T12:12:10.445369Z

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

👍 1
Gerome 2023-02-25T19:46:12.751809Z

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.

borkdude 2023-02-25T19:47:34.034969Z

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

borkdude 2023-02-25T19:48:32.185809Z

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

Gerome 2023-02-25T19:48:54.952149Z

Alright, I'll take a look.

borkdude 2023-02-25T19:49:23.237199Z

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

borkdude 2023-02-25T19:49:29.458979Z

or delete the stuff you don't need

Gerome 2023-02-25T19:49:51.962399Z

🙂 Okay, I'll take a closer look.

borkdude 2023-02-25T19:50:36.926589Z

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

borkdude 2023-02-25T19:50:44.835979Z

I'll change this in scittle now

borkdude 2023-02-25T19:53:01.364439Z

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

Gerome 2023-02-25T19:54:13.003299Z

Yes, I've done that already.

Gerome 2023-02-25T19:54:47.521119Z

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 🙂

Gerome 2023-02-25T19:56:05.464759Z

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

Gerome 2023-02-25T19:56:25.899549Z

Starting small is always a good idea.

borkdude 2023-02-25T19:56:52.592809Z

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

borkdude 2023-02-25T19:57:19.171579Z

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

borkdude 2023-02-25T20:13:58.325599Z

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