diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index d5d9241a8ed..d8e48adb425 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -523,7 +523,8 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do comp = compiler lbi ghcVersion = compilerVersion comp implInfo = getImplInfo comp - platform@(Platform _hostArch hostOS) = hostPlatform lbi + platform@(Platform hostArch hostOS) = hostPlatform lbi + hasJsSupport = hostArch == JavaScript has_code = not (componentIsIndefinite clbi) relLibTargetDir <- makeRelativeToCurrentDirectory libTargetDir @@ -567,11 +568,13 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do , toNubListR (cxxSources libBi) , toNubListR (cmmSources libBi) , toNubListR (asmSources libBi) - , toNubListR (jsSources libBi) + , if hasJsSupport -- JS files are C-like with GHC's JS backend: they are -- "compiled" into `.o` files (renamed with a header). -- This is a difference from GHCJS, for which we only -- pass the JS files at link time. + then toNubListR (jsSources libBi) + else mempty ] cLikeObjs = map (`replaceExtension` objExtension) cLikeSources baseOpts = componentGhcOptions verbosity lbi libBi clbi libTargetDir @@ -730,7 +733,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do | filename <- cSources libBi] -- build any JS sources - unless (not has_code || null (jsSources libBi)) $ do + unless (not has_code || not hasJsSupport || null (jsSources libBi)) $ do info verbosity "Building JS Sources..." sequence_ [ do let vanillaJsOpts = Internal.componentJsGhcOptions verbosity implInfo @@ -2087,7 +2090,10 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do && null (cxxSources (libBuildInfo lib)) && null (cmmSources (libBuildInfo lib)) && null (asmSources (libBuildInfo lib)) - && null (jsSources (libBuildInfo lib)) + && (null (jsSources (libBuildInfo lib)) || not hasJsSupport) + hasJsSupport = case hostPlatform lbi of + Platform JavaScript _ -> True + _ -> False has_code = not (componentIsIndefinite clbi) whenHasCode = when has_code whenVanilla = when (hasLib && withVanillaLib lbi) diff --git a/Cabal/src/Distribution/Simple/Register.hs b/Cabal/src/Distribution/Simple/Register.hs index 29b839e261f..c4dc22c7b7a 100644 --- a/Cabal/src/Distribution/Simple/Register.hs +++ b/Cabal/src/Distribution/Simple/Register.hs @@ -466,8 +466,11 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi || not (null (asmSources bi)) || not (null (cmmSources bi)) || not (null (cxxSources bi)) - || not (null (jsSources bi))) + || (not (null (jsSources bi)) && hasJsSupport)) && not (componentIsIndefinite clbi) + hasJsSupport = case hostPlatform lbi of + Platform JavaScript _ -> True + _ -> False libdirsStatic | hasLibrary = libdir installDirs : extraLibDirsStaticOrFallback | otherwise = extraLibDirsStaticOrFallback diff --git a/cabal-testsuite/PackageTests/JS/JsSources/cabal.test.hs b/cabal-testsuite/PackageTests/JS/JsSources/js-arch.test.hs similarity index 100% rename from cabal-testsuite/PackageTests/JS/JsSources/cabal.test.hs rename to cabal-testsuite/PackageTests/JS/JsSources/js-arch.test.hs diff --git a/cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal b/cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal index 581d8921026..4595a6cfc2b 100644 --- a/cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal +++ b/cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal @@ -6,7 +6,10 @@ build-type: Simple library default-language: Haskell2010 js-sources: jsbits/lib.js - hs-source-dirs: src + if arch(JavaScript) + hs-source-dirs: srcJS + else + hs-source-dirs: src exposed-modules: Lib build-depends: base diff --git a/cabal-testsuite/PackageTests/JS/JsSources/other-arch.out b/cabal-testsuite/PackageTests/JS/JsSources/other-arch.out new file mode 100644 index 00000000000..9f64e6764c5 --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSources/other-arch.out @@ -0,0 +1,12 @@ +# cabal v2-run +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - jssources-0 (lib) (first run) + - jssources-0 (exe:demo) (first run) +Configuring library for jssources-0.. +Preprocessing library for jssources-0.. +Building library for jssources-0.. +Configuring executable 'demo' for jssources-0.. +Preprocessing executable 'demo' for jssources-0.. +Building executable 'demo' for jssources-0.. diff --git a/cabal-testsuite/PackageTests/JS/JsSources/other-arch.test.hs b/cabal-testsuite/PackageTests/JS/JsSources/other-arch.test.hs new file mode 100644 index 00000000000..187a9cf73bd --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSources/other-arch.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + skipIfJavaScript + -- Ensure the field `js-sources` does not raise issues + res <- cabal' "v2-run" ["demo"] + assertOutputContains "Hello Not JS!" res diff --git a/cabal-testsuite/PackageTests/JS/JsSources/src/Lib.hs b/cabal-testsuite/PackageTests/JS/JsSources/src/Lib.hs index af628af03ec..7937e6f34ed 100644 --- a/cabal-testsuite/PackageTests/JS/JsSources/src/Lib.hs +++ b/cabal-testsuite/PackageTests/JS/JsSources/src/Lib.hs @@ -1,3 +1,4 @@ module Lib where -foreign import javascript foo :: IO () +foo :: IO () +foo = putStrLn "Hello Not JS!" diff --git a/cabal-testsuite/PackageTests/JS/JsSources/srcJS/Lib.hs b/cabal-testsuite/PackageTests/JS/JsSources/srcJS/Lib.hs new file mode 100644 index 00000000000..af628af03ec --- /dev/null +++ b/cabal-testsuite/PackageTests/JS/JsSources/srcJS/Lib.hs @@ -0,0 +1,3 @@ +module Lib where + +foreign import javascript foo :: IO ()