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

Consider cross-compilation in TH mode #342

Open
edsko opened this issue Dec 20, 2024 · 4 comments
Open

Consider cross-compilation in TH mode #342

edsko opened this issue Dec 20, 2024 · 4 comments

Comments

@edsko
Copy link
Collaborator

edsko commented Dec 20, 2024

We need to consider what the workflow will look like; how does the user start a build on their host machine for a particular target machine, and importantly, how do those flags then make it to the TH splice? We could require users to do set this up themselves (as long as we accept clang args, #341, that's at least possible), but it would be good to provide some out-of-the-box support.

@phadej
Copy link
Collaborator

phadej commented Dec 20, 2024

Cross compilation doesn't really make sense for the current TH setup. TH is always run on the target architecture, so for now the TH story is actually quite straight forward.

@edsko
Copy link
Collaborator Author

edsko commented Jan 8, 2025

@phadej I don't understand what you mean. Surely TH is always run on the host, not the target? We must mean different things. Here's the kind of thing I had in mind. Suppose we are on platform A, and are compiling for platform B, and we're using hs-bindgen in TH mode. The important thing is that when we invoke libclang from TH, we pass the appropriate flags. Perhaps we do this through setting an environment variable which we read from TH

export TARGET=B

We then read this environment variable, set appropriate libclang flags, and generate splices as normal, for platform B. The code is running on platform A, but that's fine: the code that's running is code that generates code; it doesn't matter what platform that runs on, as long as it generates code for B.

Do you see a problem with that setup?

@phadej
Copy link
Collaborator

phadej commented Jan 8, 2025

Surely TH is always run on the host, not the target?

TH is always run on the target. GHCJS runs node, new JS backend does something among those lines too, I guess WASM too.

Suppose we are on platform A, and are compiling for platform B, and we're using hs-bindgen in TH mode.

The TH has to be run on platform B. I found this post https://medium.com/@zw3rk/cross-compiling-template-haskell-7e38c00c2914 explaining -fexternal-interpreter and as far as I know nothing has considerably changed since.

E.g. https://www.tweag.io/blog/2020-11-25-asterius-th/ says

Asterius uses the external interpreter approach to support Template Haskell. The execution of compiled WebAssembly code and the JavaScript runtime is done in a node process.

@edsko
Copy link
Collaborator Author

edsko commented Jan 9, 2025

I see. Thank you for that clarification, that certainly connected a few dots for me!

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

No branches or pull requests

2 participants