Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure js-sources are used only with JavaScript arch (backport #8748) #8761

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion Cabal/src/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion cabal-testsuite/PackageTests/JS/JsSources/jssources.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsSources/other-arch.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -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..
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsSources/other-arch.test.hs
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion cabal-testsuite/PackageTests/JS/JsSources/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Lib where

foreign import javascript foo :: IO ()
foo :: IO ()
foo = putStrLn "Hello Not JS!"
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/JS/JsSources/srcJS/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Lib where

foreign import javascript foo :: IO ()