File tree Expand file tree Collapse file tree 10 files changed +91
-1
lines changed
Cabal/src/Distribution/Simple/GHC
cabal-testsuite/PackageTests/JS/GhcOptions Expand file tree Collapse file tree 10 files changed +91
-1
lines changed Original file line number Diff line number Diff line change @@ -487,6 +487,7 @@ componentAsmGhcOptions verbosity lbi bi clbi odir filename =
487487 )
488488 ++ asmOptions bi
489489 , ghcOptObjDir = toFlag odir
490+ , ghcOptExtra = hcOptions GHC bi
490491 }
491492
492493componentJsGhcOptions
@@ -509,6 +510,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
509510 , ghcOptPackageDBs = withPackageDB lbi
510511 , ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
511512 , ghcOptObjDir = toFlag odir
513+ , ghcOptExtra = hcOptions GHC bi
512514 }
513515
514516componentGhcOptions
@@ -622,7 +624,7 @@ componentCmmGhcOptions verbosity lbi bi clbi odir filename =
622624 , ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
623625 , ghcOptOptimisation = toGhcOptimisation (withOptimization lbi)
624626 , ghcOptDebugInfo = toFlag (withDebugInfo lbi)
625- , ghcOptExtra = cmmOptions bi
627+ , ghcOptExtra = hcOptions GHC bi <> cmmOptions bi
626628 , ghcOptObjDir = toFlag odir
627629 }
628630
Original file line number Diff line number Diff line change 1+ packages : .
Original file line number Diff line number Diff line change 1+ module Main where
2+
3+ import Lib
4+
5+ main :: IO ()
6+ main = foo
Original file line number Diff line number Diff line change 1+ import Test.Cabal.Prelude
2+
3+ main = do
4+ skipUnlessJavaScript
5+ skipIfWindows " "
6+ setupAndCabalTest $ do
7+ skipUnlessGhcVersion " >= 9.12"
8+ res <- cabal' " v2-run" [" demo" ]
9+ assertOutputContains " Hello definition!" res
Original file line number Diff line number Diff line change 1+ //#OPTIONS: CPP
2+
3+ function foo ( ) {
4+ #ifdef PRINT_DEF
5+ console . log ( "Hello definition!" ) ;
6+ #else
7+ console . log ( "Hello!" ) ;
8+ #endif
9+ }
Original file line number Diff line number Diff line change 1+ cabal-version : 3.0
2+ name : jsghcoptions
3+ version : 0
4+ build-type : Simple
5+
6+ library
7+ default-language : Haskell2010
8+ js-sources : jsbits/lib.js
9+ if arch(JavaScript)
10+ ghc-options : -optJSP-DPRINT_DEF
11+ hs-source-dirs : src
12+ exposed-modules : Lib
13+ build-depends : base
14+
15+ executable demo
16+ default-language : Haskell2010
17+ main-is : Main.hs
18+ hs-source-dirs : demo
19+ build-depends : base, jsghcoptions
Original file line number Diff line number Diff line change 1+ # cabal v2-run
2+ Configuration is affected by the following files:
3+ - cabal.project
4+ Resolving dependencies...
5+ Build profile: -w ghc-<GHCVER> -O1
6+ In order, the following will be built:
7+ - jsghcoptions-0 (lib) (first run)
8+ - jsghcoptions-0 (exe:demo) (first run)
9+ Configuring library for jsghcoptions-0...
10+ Preprocessing library for jsghcoptions-0...
11+ Building library for jsghcoptions-0...
12+ Configuring executable 'demo' for jsghcoptions-0...
13+ Preprocessing executable 'demo' for jsghcoptions-0...
14+ Building executable 'demo' for jsghcoptions-0...
Original file line number Diff line number Diff line change 1+ import Test.Cabal.Prelude
2+
3+ main = do
4+ skipIfJavaScript
5+ cabalTest $ do
6+ -- Ensure the field `js-sources` does not raise issues
7+ res <- cabal' " v2-run" [" demo" ]
8+ assertOutputContains " Not JS foo" res
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE CPP #-}
2+ module Lib where
3+
4+ #if defined(javascript_HOST_ARCH)
5+ foreign import javascript foo :: IO ()
6+ #else
7+ foo :: IO ()
8+ foo = putStrLn " Not JS foo"
9+ #endif
Original file line number Diff line number Diff line change 1+ ---
2+ synopsis : " ghc-options added to js, cmm and asm"
3+ packages : [Cabal]
4+ prs : 10949
5+ ---
6+
7+ Now we have the ability to pass ghc-options flags to all component.
8+
9+ ```
10+ js-sources: jsbits/lib.js
11+ ghc-options: -optJSP-your_flag
12+ ```
13+
You can’t perform that action at this time.
0 commit comments