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

Add js-options field to cabal file to allow passing custom preprocessing options for js (#10721) #10722

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Swordlash
Copy link

@Swordlash Swordlash commented Jan 6, 2025

The PR fixes the issue (#10721) by adding a new js-options field to cabal file that are passed to componentJsGhcOptions.

Please advise on the testing strategy, if any.
Thank you @hsyl20 for investigation and suggestion how to fix it.

@Swordlash
Copy link
Author

Please let me know if this is an acceptable feature at all, if so I'm gonna add any needed doc changes / changelogs.

@Swordlash Swordlash changed the title Add js-sources field to cabal file to allow passing custom preprocessing options for js (#10721) Add js-options field to cabal file to allow passing custom preprocessing options for js (#10721) Jan 6, 2025
@Mikolaj Mikolaj requested review from hsyl20 and geekosaur January 6, 2025 20:42
@@ -621,6 +621,7 @@ buildInfoFieldGrammar =
<*> monoidalFieldAla "cc-options" (alaList' NoCommaFSep Token') L.ccOptions
<*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions
^^^ availableSince CabalSpecV2_2 []
<*> monoidalFieldAla "js-options" (alaList' NoCommaFSep Token') L.jsOptions
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above, needs to be guarded by availableSince.

Copy link
Author

Choose a reason for hiding this comment

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

I thought about it but got confused by a fact js-sources are not guarded. Is it an omission?

Which value should I put here?

Copy link
Author

@Swordlash Swordlash Jan 12, 2025

Choose a reason for hiding this comment

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

@mpickering ? Should I add version 3.16?

@mpickering
Copy link
Collaborator

Can you please add some tests?

  • js-options used with old cabal-spec version
  • js-options used with correct cabal-spec version

@Mikolaj
Copy link
Member

Mikolaj commented Feb 1, 2025

@mpickering: are you satisfied with the PR now?

Let me rebase in order to prod CI.

@Mikolaj
Copy link
Member

Mikolaj commented Feb 1, 2025

@mergify rebase

Copy link
Contributor

mergify bot commented Feb 1, 2025

rebase

✅ Branch has been successfully rebased

@Mikolaj
Copy link
Member

Mikolaj commented Feb 1, 2025

Hah, it seems the whitespace check is failing.


if impl(javascript)
js-sources: jsbits/lib.js
js-options: -optJSP-DPRINT_DEF
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is wrong. Now it's just a new name for ghc-options.

If js-options is introduced as a separate field, they should be prepended by -optJSP automatically (like cpp-options or cxx-options are prepended with appropriate -opt flag).

Also these are jsp options, i.e. JavaScript Preprocessor options. (c.f. cc-options and cpp-options).

Copy link
Author

Choose a reason for hiding this comment

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

This is wrong. Now it's just a new name for ghc-options.

If what I need was achievable through ghc-options, there would be no ticket!

Your suggestion for remame and prepend makes sense, I was merely following a hint of how to implement it. If there is a better way to make those options be passed rather than by separate field, let me know.

Copy link
Collaborator

@phadej phadej Feb 9, 2025

Choose a reason for hiding this comment

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

If what I need was achievable through ghc-options, there would be no ticket!

That's a different issue.

As @hsyl20 pointed on GHC tracker

So it looks like the ghc-options isn't passed by Cabal when building the js-sources

and that's the bug.

If there say ghc-options: -Werror is not passed by cabal when building js-sources, that's out right bug, which is not fixed by this PR.

Note: if ghc-options is not passed when compiling Cmm or asm, that's also a bug. This is not unique, IMHO Cabal should simply dump all possible options to GHC and not try to filter them; e.g. #9801 is another issue where Cabal omits options, which in fact can affect GHC when compiling "other stuff". TL;DR, Cabal tries to be too smart here.

In other words: jsp-options should be passed to GHC even when it's compiling ordinary Haskell files. Who knows, maybe GHC will allow inline JS which needs to be preprocessed. (It kind of allows inline C with CApiFFI!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants