File tree 10 files changed +91
-1
lines changed
Cabal/src/Distribution/Simple/GHC
cabal-testsuite/PackageTests/JS/GhcOptions
10 files changed +91
-1
lines changed Original file line number Diff line number Diff line change @@ -486,6 +486,7 @@ componentAsmGhcOptions verbosity lbi bi clbi odir filename =
486
486
)
487
487
++ asmOptions bi
488
488
, ghcOptObjDir = toFlag odir
489
+ , ghcOptExtra = hcOptions GHC bi
489
490
}
490
491
491
492
componentJsGhcOptions
@@ -508,6 +509,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
508
509
, ghcOptPackageDBs = withPackageDB lbi
509
510
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
510
511
, ghcOptObjDir = toFlag odir
512
+ , ghcOptExtra = hcOptions GHC bi
511
513
}
512
514
513
515
componentGhcOptions
@@ -621,7 +623,7 @@ componentCmmGhcOptions verbosity lbi bi clbi odir filename =
621
623
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
622
624
, ghcOptOptimisation = toGhcOptimisation (withOptimization lbi)
623
625
, ghcOptDebugInfo = toFlag (withDebugInfo lbi)
624
- , ghcOptExtra = cmmOptions bi
626
+ , ghcOptExtra = hcOptions GHC bi <> cmmOptions bi
625
627
, ghcOptObjDir = toFlag odir
626
628
}
627
629
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