From eca0d2ea05573df84e20c8bb1ff595b257e8eaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Go=C5=9Blinowski?= Date: Mon, 6 Jan 2025 19:25:00 +0100 Subject: [PATCH] Add js-sources field to cabal file to allow passing custom preprocessing options for js (#10721) --- .../src/Distribution/PackageDescription/FieldGrammar.hs | 1 + Cabal-syntax/src/Distribution/Types/BuildInfo.hs | 4 ++++ Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs | 4 ++++ Cabal/src/Distribution/Simple/GHC/Internal.hs | 1 + 4 files changed, 10 insertions(+) diff --git a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs index 49db03ee3c1..433c410fadc 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs @@ -621,6 +621,7 @@ buildInfoFieldGrammar = <*> monoidalFieldAla "cc-options" (alaList' NoCommaFSep Token') L.ccOptions <*> monoidalFieldAla "cxx-options" (alaList' NoCommaFSep Token') L.cxxOptions ^^^ availableSince CabalSpecV2_2 [] + <*> monoidalFieldAla "js-options" (alaList' NoCommaFSep Token') L.jsOptions <*> monoidalFieldAla "ld-options" (alaList' NoCommaFSep Token') L.ldOptions <*> monoidalFieldAla "hsc2hs-options" (alaList' NoCommaFSep Token') L.hsc2hsOptions ^^^ availableSince CabalSpecV3_6 [] diff --git a/Cabal-syntax/src/Distribution/Types/BuildInfo.hs b/Cabal-syntax/src/Distribution/Types/BuildInfo.hs index 2d7a5edeae1..8ea6423e65c 100644 --- a/Cabal-syntax/src/Distribution/Types/BuildInfo.hs +++ b/Cabal-syntax/src/Distribution/Types/BuildInfo.hs @@ -61,6 +61,8 @@ data BuildInfo = BuildInfo -- ^ options for C compiler , cxxOptions :: [String] -- ^ options for C++ compiler + , jsOptions :: [String] + -- ^ options for pre-processing JavaScript code , ldOptions :: [String] -- ^ options for linker , hsc2hsOptions :: [String] @@ -161,6 +163,7 @@ instance Monoid BuildInfo where , cmmOptions = [] , ccOptions = [] , cxxOptions = [] + , jsOptions = [] , ldOptions = [] , hsc2hsOptions = [] , pkgconfigDepends = [] @@ -214,6 +217,7 @@ instance Semigroup BuildInfo where , cmmOptions = combine cmmOptions , ccOptions = combine ccOptions , cxxOptions = combine cxxOptions + , jsOptions = combine jsOptions , ldOptions = combine ldOptions , hsc2hsOptions = combine hsc2hsOptions , pkgconfigDepends = combine pkgconfigDepends diff --git a/Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs b/Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs index ac99f3c65a5..c80698681f3 100644 --- a/Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs +++ b/Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs @@ -59,6 +59,10 @@ class HasBuildInfo a where cxxOptions = buildInfo . cxxOptions {-# INLINE cxxOptions #-} + jsOptions :: Lens' a [String] + jsOptions = buildInfo . jsOptions + {-# INLINE jsOptions #-} + ldOptions :: Lens' a [String] ldOptions = buildInfo . ldOptions {-# INLINE ldOptions #-} diff --git a/Cabal/src/Distribution/Simple/GHC/Internal.hs b/Cabal/src/Distribution/Simple/GHC/Internal.hs index 6e27b41bc83..f5353a3d2ab 100644 --- a/Cabal/src/Distribution/Simple/GHC/Internal.hs +++ b/Cabal/src/Distribution/Simple/GHC/Internal.hs @@ -489,6 +489,7 @@ componentJsGhcOptions verbosity lbi bi clbi odir filename = , ghcOptPackageDBs = withPackageDB lbi , ghcOptPackages = toNubListR $ mkGhcOptPackages (promisedPkgs lbi) clbi , ghcOptObjDir = toFlag odir + , ghcOptExtra = jsOptions bi } componentGhcOptions