Skip to content

Commit 78be2d5

Browse files
authored
Merge pull request #8748 from wismill/wip/fix8741
Ensure js-sources are used only with JavaScript arch
2 parents bae536f + 4d33ba6 commit 78be2d5

File tree

8 files changed

+42
-7
lines changed

8 files changed

+42
-7
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
523523
comp = compiler lbi
524524
ghcVersion = compilerVersion comp
525525
implInfo = getImplInfo comp
526-
platform@(Platform _hostArch hostOS) = hostPlatform lbi
526+
platform@(Platform hostArch hostOS) = hostPlatform lbi
527+
hasJsSupport = hostArch == JavaScript
527528
has_code = not (componentIsIndefinite clbi)
528529

529530
relLibTargetDir <- makeRelativeToCurrentDirectory libTargetDir
@@ -567,11 +568,13 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
567568
, toNubListR (cxxSources libBi)
568569
, toNubListR (cmmSources libBi)
569570
, toNubListR (asmSources libBi)
570-
, toNubListR (jsSources libBi)
571+
, if hasJsSupport
571572
-- JS files are C-like with GHC's JS backend: they are
572573
-- "compiled" into `.o` files (renamed with a header).
573574
-- This is a difference from GHCJS, for which we only
574575
-- pass the JS files at link time.
576+
then toNubListR (jsSources libBi)
577+
else mempty
575578
]
576579
cLikeObjs = map (`replaceExtension` objExtension) cLikeSources
577580
baseOpts = componentGhcOptions verbosity lbi libBi clbi libTargetDir
@@ -730,7 +733,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
730733
| filename <- cSources libBi]
731734

732735
-- build any JS sources
733-
unless (not has_code || null (jsSources libBi)) $ do
736+
unless (not has_code || not hasJsSupport || null (jsSources libBi)) $ do
734737
info verbosity "Building JS Sources..."
735738
sequence_
736739
[ do let vanillaJsOpts = Internal.componentJsGhcOptions verbosity implInfo
@@ -2087,7 +2090,10 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
20872090
&& null (cxxSources (libBuildInfo lib))
20882091
&& null (cmmSources (libBuildInfo lib))
20892092
&& null (asmSources (libBuildInfo lib))
2090-
&& null (jsSources (libBuildInfo lib))
2093+
&& (null (jsSources (libBuildInfo lib)) || not hasJsSupport)
2094+
hasJsSupport = case hostPlatform lbi of
2095+
Platform JavaScript _ -> True
2096+
_ -> False
20912097
has_code = not (componentIsIndefinite clbi)
20922098
whenHasCode = when has_code
20932099
whenVanilla = when (hasLib && withVanillaLib lbi)

Cabal/src/Distribution/Simple/Register.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,11 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
466466
|| not (null (asmSources bi))
467467
|| not (null (cmmSources bi))
468468
|| not (null (cxxSources bi))
469-
|| not (null (jsSources bi)))
469+
|| (not (null (jsSources bi)) && hasJsSupport))
470470
&& not (componentIsIndefinite clbi)
471+
hasJsSupport = case hostPlatform lbi of
472+
Platform JavaScript _ -> True
473+
_ -> False
471474
libdirsStatic
472475
| hasLibrary = libdir installDirs : extraLibDirsStaticOrFallback
473476
| otherwise = extraLibDirsStaticOrFallback

cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ build-type: Simple
66
library
77
default-language: Haskell2010
88
js-sources: jsbits/lib.js
9-
hs-source-dirs: src
9+
if arch(JavaScript)
10+
hs-source-dirs: srcJS
11+
else
12+
hs-source-dirs: src
1013
exposed-modules: Lib
1114
build-depends: base
1215

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# cabal v2-run
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- jssources-0 (lib) (first run)
6+
- jssources-0 (exe:demo) (first run)
7+
Configuring library for jssources-0..
8+
Preprocessing library for jssources-0..
9+
Building library for jssources-0..
10+
Configuring executable 'demo' for jssources-0..
11+
Preprocessing executable 'demo' for jssources-0..
12+
Building executable 'demo' for jssources-0..
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
skipIfJavaScript
5+
-- Ensure the field `js-sources` does not raise issues
6+
res <- cabal' "v2-run" ["demo"]
7+
assertOutputContains "Hello Not JS!" res
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module Lib where
22

3-
foreign import javascript foo :: IO ()
3+
foo :: IO ()
4+
foo = putStrLn "Hello Not JS!"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Lib where
2+
3+
foreign import javascript foo :: IO ()

0 commit comments

Comments
 (0)