-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add WASI initialization support #73
base: master
Are you sure you want to change the base?
Conversation
Is it possible to test GHC WASM on the CI. Can I e.g. install GHC-WASM with ghcup? Until then I consider that experimental and not worth having, it's as simple as: it will bitrot if there is no CI setup. |
There is a new CI job testing via the WASM backend in this PR already, also see the last sentence in the PR description. |
.github/workflows/simple.yml
Outdated
- name: setup-ghc-wasm32-wasi | ||
run: | | ||
cd $(mktemp -d) | ||
curl -L https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this pinned bindist? I don't want "moving targets" in CI.
EDIT: I guess FLAVOUR is making it somehow. I'd still prefer something ghcup
based, so people can more easily test locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, it would be the latest 9.6 release (see the "flavour" below, see the ghc-wasm-meta README). I will pin ghc-wasm-meta to the latest commit 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, just noticed your edit; I don't think it is easy ATM to install it via ghcup as you need to install a WASI-specific toolchain in addition to the bindist. Personally, I use ghc-wasm-meta via Nix, but there are also community-provided Docker containers as another alternative to ghc-wasm-meta's setup.sh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't WASI toolchains available as apt
packages? I wish I could get GHC from apt
repository instead of ghcup
too. I guess every community has their own way to install their stuff nowadays. I honestly don't like that, as one has to (get and) learn N install tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. wasi-sdk seems not to be packaged in Debian/Ubuntu (e.g. via Repology); and the GHC WASM backend needs a wasi-sdk fork anyway.
Pinging @TerrorJack in case you have an estimate whether/when a ghcup- or apt-based installation of the WASM backend could become feasible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phadej If you prefer, you can pin to a specific ghc-wasm-meta
revision, since each revision pins to specific bindists, and that'll make the installed cross compiler binary-reproducible. @amesgen Would you do that in your next push? Thanks :)
We can't use vanilla wasm32-wasi
toolchains from upstreams yet due to certain necessary changes in our fork. I understand the reluctance of using another installation method, but getting ghcup
to work with cross toolchains would be a quite non-trivial amount of work that I haven't gotten enough time to implement yet 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compared to ghcup
, it'll be much easier to have an aptitude repo that distributes these tools. I'll look into the possibility this week, though no ETA can be quickly given at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phadej how does it look? I understand that it falls somewhat short of "install FWIW I had a decent experience with this CI job in several projects: |
@Bodigrim please understand me. You (as part of CLC) has very strict policy of say changes in Sorry, there's too much dissonance in that. To be clear. I don't really care if the change is somewhat trivial. it's a principle. WASI folks can (and in my opinion should) setup EDIT: To clarify, the recent GHC stability discussions had made me change my opinions. The |
There might be bugs and missing features, but fundamentally WASI is no more experimental than, say, ARM backend was couple of years ago. It's just another backend for another platform, the more we test it the sooner it gets production ready. |
ARM backend was in GHC proper, no need to jump through the hoops to test it. I want to test stuff reasonably in CI (thanks for workflow links), but also locally - as debugging on GHA is quite frustrating. |
Testing GHCJS was easy. And I guess (because I don't know), before GHCJS tooling was made easy, people were using Nix overlays with forks to develop stuff with GHCJS. I don't see why that approach doesn't work with WASI or/and JS backend. |
In addition to getting the GHC WASM backend via ghc-wasm-meta (both with Nix and without Nix), it is nowadays also possible to install the GHC WASM bindists via ghcup: https://www.haskell.org/ghcup/guide/#ghc-wasm-cross-bindists-experimental (note that one still needs to install wasi-sdk beforehand, as described there, so it is not as smooth as a hypothetical
That definitely works (eg a WASM-specific hackage repo is conceivable), but I think it is still desirable to upstream changes if possible (in particular, the corresponding maintainers have to be on board ofc) for less overall complexity, but that indeed doesn't have to happen immediately. How do we want to proceed with this PR? Shall I close it, or do we want keep it open until some time in the future when everything around the WASM backend is more mature (until then, I will only occasionally rebase this PR on top of |
Does GHC WASM works with https://github.com/WebAssembly/wasi-sdk, or do one needs a GHC specific fork? It would be great if GHC had location / paths of wasi-sdk tools configurable, so one would not need to have them in PATH. |
The latter: https://gitlab.haskell.org/ghc/wasi-sdk
I think that is possible by passing appropriate flags to the bindist configure step, but I don't know the details. cc @TerrorJack |
See https://www.haskell.org/ghcup/guide/#cross-support, you do not need |
What is |
I'm sorry, I think I have enough on my plate already. |
If you use Vanilla cabal works fine as long as you tell it to use the right ghc. |
Ah, cabal store isn't layered by target architecture, that's unfortunate. Anyway,
Up to you. I'm not merging it now. The whole cross-compilation story feels fragile, and I'm not ready to dive deep into it. I'd say that
is your best way forward. There seems to be tools for that https://github.com/andreabedini/foliage-template |
Please understand my stance. I have burned multiple times by this pattern:
By having your own repository we can avoid that. People would report issues directly to you. |
@phadej Thanks, that makes a lot of sense 👍 I will then convert this PR to draft for now and occasionally rebase it, and it can be reconsidered at some point in the future. |
The current unix logic does not work for the new GHC WASM backend for two reasons:
/dev/urandom
exists (e.g. it is only given access to a confined directory, or the host systen is non-unix, or it is run in a browser context etc.)clock
,getpid
) not being available.The current WASI snapshot (as well as future planned versions) do specify an entropy source,
random_get
which is used to back e.g.getentropy
.In this PR, I added
cbits
for WASI callinggetentropy
, but alternative approaches (i.e. merging this into the existing unix logic and e.g. disabling the fallback on WASI; or simply usinggetentropy
directly in the unix logic) are also feasible, happy to change.I only run two test suites on CI (the
initialization
one should be most relevant here) as e.g. thesplitmix-tests
suite does not yet build.