Skip to content

Commit 96ce5a8

Browse files
authored
Merge pull request #10949 from zlonast/master
If ghc-options is not passed when compiling js, Cmm or asm, that's a bug
2 parents 83a909d + c9935c4 commit 96ce5a8

File tree

10 files changed

+91
-1
lines changed

10 files changed

+91
-1
lines changed

Cabal/src/Distribution/Simple/GHC/Internal.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

492493
componentJsGhcOptions
@@ -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

514516
componentGhcOptions
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Lib
4+
5+
main :: IO ()
6+
main = foo
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

changelog.d/pr-10949.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+

0 commit comments

Comments
 (0)