Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve development workflow (ghcid with jsaddle-warp) #1323

Merged
merged 5 commits into from
Feb 25, 2025

Conversation

georgefst
Copy link
Contributor

@dhess Can you let me know whether make develop-frontend works for you? I think I've solved all the issues from #1304 (comment), but I haven't tested on MacOS.

GHC 9.10 doesn't work on Linux due to an incompatibility in the file watching library: haskell-fswatch/hinotify#38.

Signed-off-by: George Thomas <[email protected]>
This has been broken since we split in to separate executable and library components. Cabal defaults to the library in the case of ambiguity, and the `primer-miso` library doesn't contain a `main`.

Signed-off-by: George Thomas <[email protected]>
The old version was actually fairly useless, since the executable component barely contained any interesting code.

Signed-off-by: George Thomas <[email protected]>
@@ -4,5 +4,11 @@

include ../makefiles/common.mk

# TODO The last line here shouldn't be necessary.
# For some reason, GHCID is failing to discover the right paths to watch.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to look in to why we need to manually specify the paths. I think it's to do with using multiple components, but I still couldn't reproduce the issue in a simpler project. Anyway, I'd prefer to move to Ghciwatch eventually, but it doesn't yet support multiple components at all: MercuryTechnologies/ghciwatch#316.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I considered adding lib:primer and --reload ../primer/src, in order to also pick up changes to the core library. But this brings the minimum reload time from about 0.5s on my machine to around 3s, even when the only changes are in the frontend components.

Without any of these issues, the command could be as simple as ghcid -c "cabal repl all" -Wr --reload frontend/style.css.

@dhess
Copy link
Member

dhess commented Feb 24, 2025

Is make develop-frontend meant to be run in the nix develop shell, or the nix develop .#wasm shell? I assume the latter, but in either case, I get an error on macOS:

$ nix develop
Restored session: Mon Feb 24 16:01:07 WET 2025
bash-5.2$ make develop-frontend
make -C primer-miso develop-frontend
make[1]: Entering directory '/Users/dhess/git/primer/primer-miso'
ghcid \
	-c "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" \
	-W -T Main.main \
	--reload frontend/style.css \
	--reload exe --reload src --ignore-loaded \

Loading cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso ...
Error: [Cabal-5490]
Cannot find the program 'ghc'. User-specified path '/nix/store/z712k8z69c4h2c8303j30f2x6ims36mr-wasm32-wasi-ghc-9.10/bin/wasm32-wasi-ghc' does not refer to an executable and the program is not on the system path.

Command "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" exited unexpectedly with error message: 
make[1]: *** [Makefile:10: develop-frontend] Error 1
make[1]: Leaving directory '/Users/dhess/git/primer/primer-miso'
make: *** [Makefile:28: develop-frontend] Error 2

$  nix develop .#wasm
evaluation warning: Explicitly set the ABI version of 'webkitgtk'
bash-5.2$ make develop-frontend
make -C primer-miso develop-frontend
make[1]: Entering directory '/Users/dhess/git/primer/primer-miso'
ghcid \
	-c "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" \
	-W -T Main.main \
	--reload frontend/style.css \
	--reload exe --reload src --ignore-loaded \

Loading cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso ...
Error: [Cabal-5490]
Cannot find the program 'ghc'. User-specified path '/nix/store/z712k8z69c4h2c8303j30f2x6ims36mr-wasm32-wasi-ghc-9.10/bin/wasm32-wasi-ghc' does not refer to an executable and the program is not on the system path.

Command "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" exited unexpectedly with error message: 
make[1]: *** [Makefile:10: develop-frontend] Error 1
make[1]: Leaving directory '/Users/dhess/git/primer/primer-miso'
make: *** [Makefile:28: develop-frontend] Error 2

@dhess
Copy link
Member

dhess commented Feb 24, 2025

On a related note, I tried to unify the shells so that we only need one, as I understand it's a bit of a pain, but until haskell.nix supports Wasm, I don't think it's worth the major refactoring that would be required: see #1307

@georgefst
Copy link
Contributor Author

Is make develop-frontend meant to be run in the nix develop shell, or the nix develop .#wasm shell? I assume the latter

It's actually the former. This workflow doesn't use Wasm at all.

, but in either case, I get an error on macOS:

I suspect you've got a cabal.project.local file hanging around that you need to delete. The output you pasted shows the non-Wasm shell is still trying to use the Wasm GHC, which is very bad. See #1304 (comment).

@dhess
Copy link
Member

dhess commented Feb 24, 2025

I did remove configure targets from the Makefiles in response to your comment, FWIW: 1917c33

For whatever reason, I did have one lying around. I deleted that and ran make develop-frontend from the nix develop shell and got this:

$ nix develop                                                                                 ──(Mon,Feb24)─┘
Restored session: Mon Feb 24 16:37:54 WET 2025
bash-5.2$ make develop-frontend
make -C primer-miso develop-frontend
make[1]: Entering directory '/Users/dhess/git/primer/primer-miso'
ghcid \
	-c "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" \
	-W -T Main.main \
	--reload frontend/style.css \
	--reload exe --reload src --ignore-loaded \

Loading cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso ...
Configuration is affected by the following files:
- cabal.project
Warning: The package list for 'hackage.haskell.org' is 76 days old.
Run 'cabal update' to get the latest list of available packages.
Error: [Cabal-7159]
Latest known index-state for 'hackage.haskell.org' (2024-12-10T04:56:07Z) is older than the requested index-state (2025-01-07T00:00:00Z).
Run 'cabal update' or set the index-state to a value at or before 2024-12-10T04:56:07Z.

Command "cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso" exited unexpectedly with error message: 
make[1]: *** [Makefile:10: develop-frontend] Error 1
make[1]: Leaving directory '/Users/dhess/git/primer/primer-miso'
make: *** [Makefile:28: develop-frontend] Error 2

I ran cabal update, which isn't something I'd normally expect to need when using a haskell.nix shell, but perhaps there's no way around it?

Anyway, I am able to load the editor in the browser now, which is cool! I guess this means we can have native Primer in the browser, as well as Wasm?

@georgefst
Copy link
Contributor Author

I ran cabal update, which isn't something I'd normally expect to need when using a haskell.nix shell, but perhaps there's no way around it?

Hmm. I don't know how to explain that. I didn't have to do it, but then I regularly use a non-Nix Haskell toolchain anyway and regularly update my index.

Anyway, I am able to load the editor in the browser now, which is cool!

That's odd as well, given that it looks like GHCI has crashed. Plus it's not clear why it's crashed. What happens when you just run cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso?

I guess this means we can have native Primer in the browser, as well as Wasm?

Sort of. With jsaddle-warp the Haskell code still runs natively outside of the browser, but uses websockets to tell the frontend what JS to run (or something like that - this isn't really documented anywhere AFAICT). Anyway, it's a bit flaky, and annoyingly doesn't work in Firefox, but it's useful for us until the Wasm backend has better GHCI support.

@dhess
Copy link
Member

dhess commented Feb 24, 2025

Anyway, I am able to load the editor in the browser now, which is cool!

That's odd as well, given that it looks like GHCI has crashed. Plus it's not clear why it's crashed. What happens when you just run cabal repl --enable-multi-repl exe:primer-miso lib:primer-miso?

Sorry, I see that my earlier comment was confusing.

The error message I showed is what I got before I ran cabal update. After I ran cabal update, the make develop-frontend target built Primer and successfully launched Primer, with interaction via the browser at http://localhost:8081. IOW, it's working fine now.

I guess this means we can have native Primer in the browser, as well as Wasm?

Sort of. With jsaddle-warp the Haskell code still runs natively outside of the browser, but uses websockets to tell the frontend what JS to run (or something like that - this isn't really documented anywhere AFAICT). Anyway, it's a bit flaky, and annoyingly doesn't work in Firefox, but it's useful for us until the Wasm backend has better GHCI support.

Yeah, it's never exactly been clear to me how this part of the stack works, either. In any case, what I meant by "native Primer in the browser" is that we can run the native executable (at native speeds), but interact with it in the browser, and we don't need a JS/TS frontend.

@georgefst georgefst requested a review from dhess February 24, 2025 22:23
@georgefst georgefst added this pull request to the merge queue Feb 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 24, 2025
@georgefst
Copy link
Contributor Author

Property test failure with interpreter. May be worth recording.

@georgefst georgefst added this pull request to the merge queue Feb 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 24, 2025
@dhess
Copy link
Member

dhess commented Feb 25, 2025

Yeah, this is a common failure: #1240

I'll merge manually.

@dhess dhess merged commit 07b629c into main Feb 25, 2025
82 checks passed
@dhess dhess deleted the georgefst/frontend-ghcid-improvements branch February 25, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants