Skip to content

Commit 54f0e09

Browse files
committed
ghc-options added to js, cmm and asm
add GhcOptions test partial fix for #10721
1 parent 2b0ccee commit 54f0e09

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
@@ -486,6 +486,7 @@ componentAsmGhcOptions verbosity lbi bi clbi odir filename =
486486
)
487487
++ asmOptions bi
488488
, ghcOptObjDir = toFlag odir
489+
, ghcOptExtra = hcOptions GHC bi
489490
}
490491

491492
componentJsGhcOptions
@@ -508,6 +509,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename =
508509
, ghcOptPackageDBs = withPackageDB lbi
509510
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
510511
, ghcOptObjDir = toFlag odir
512+
, ghcOptExtra = hcOptions GHC bi
511513
}
512514

513515
componentGhcOptions
@@ -621,7 +623,7 @@ componentCmmGhcOptions verbosity lbi bi clbi odir filename =
621623
, ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi
622624
, ghcOptOptimisation = toGhcOptimisation (withOptimization lbi)
623625
, ghcOptDebugInfo = toFlag (withDebugInfo lbi)
624-
, ghcOptExtra = cmmOptions bi
626+
, ghcOptExtra = hcOptions GHC bi <> cmmOptions bi
625627
, ghcOptObjDir = toFlag odir
626628
}
627629

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)