-
Notifications
You must be signed in to change notification settings - Fork 704
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
base: master
Are you sure you want to change the base?
Add js-options field to cabal file to allow passing custom preprocessing options for js (#10721) #10722
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Main where | ||
|
||
import Lib | ||
|
||
main :: IO () | ||
main = foo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = do | ||
skipUnlessJavaScript | ||
skipIfWindows "" | ||
setupAndCabalTest $ do | ||
skipUnlessGhcVersion ">= 9.12" | ||
res <- cabal' "v2-run" ["demo"] | ||
assertOutputContains "Hello definition!" res |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//#OPTIONS: CPP | ||
|
||
function foo() { | ||
#ifdef PRINT_DEF | ||
console.log("Hello definition!"); | ||
#else | ||
console.log("Hello!"); | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cabal-version: 3.14 | ||
name: jsoptions | ||
version: 0 | ||
build-type: Simple | ||
|
||
library | ||
default-language: Haskell2010 | ||
exposed-modules: Lib | ||
build-depends: base | ||
|
||
if impl(javascript) | ||
js-sources: jsbits/lib.js | ||
js-options: -optJSP-DPRINT_DEF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. Now it's just a new name for If Also these are jsp options, i.e. JavaScript Preprocessor options. (c.f. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If what I need was achievable through 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's a different issue. As @hsyl20 pointed on GHC tracker
and that's the bug. If there say Note: if In other words: |
||
|
||
executable demo | ||
default-language: Haskell2010 | ||
main-is: Main.hs | ||
hs-source-dirs: demo | ||
build-depends: base, jsoptions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# cabal v2-run | ||
Configuration is affected by the following files: | ||
- cabal.project | ||
Resolving dependencies... | ||
Build profile: -w ghc-<GHCVER> -O1 | ||
In order, the following will be built: | ||
- jsoptions-exe-0 (lib) (first run) | ||
- jsoptions-exe-0 (exe:demo) (first run) | ||
Configuring library for jsoptions-exe-0... | ||
Preprocessing library for jsoptions-exe-0... | ||
Building library for jsoptions-exe-0... | ||
Configuring executable 'demo' for jsoptions-exe-0... | ||
Preprocessing executable 'demo' for jsoptions-exe-0... | ||
Building executable 'demo' for jsoptions-exe-0... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = do | ||
skipIfJavaScript | ||
cabalTest $ do | ||
-- Ensure the field `js-options` does not raise issues | ||
res <- cabal' "v2-run" ["demo"] | ||
assertOutputContains "foo_fallback" res |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE CPP #-} | ||
module Lib where | ||
|
||
#if defined(javascript_HOST_ARCH) | ||
foreign import javascript foo :: IO () | ||
#else | ||
foo :: IO () | ||
foo = putStrLn "foo_fallback" | ||
#endif |
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.
See above, needs to be guarded by
availableSince
.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.
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?
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.
@mpickering ? Should I add version 3.16?