Skip to content

Commit cfbe545

Browse files
authored
Merge pull request #11005 from sergv/deduplicate-hsc2hs-args
Deduplicate hsc2hs args
2 parents 9a343d1 + c3b3b82 commit cfbe545

File tree

129 files changed

+1585
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1585
-90
lines changed

Cabal/src/Distribution/Simple/PreProcess.hs

Lines changed: 93 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -518,101 +518,104 @@ ppHsc2hs bi lbi clbi =
518518
-- directly, or via a response file.
519519
genPureArgs :: Version -> ConfiguredProgram -> String -> String -> [String]
520520
genPureArgs hsc2hsVersion gccProg inFile outFile =
521-
-- Additional gcc options
522-
[ "--cflag=" ++ opt
523-
| opt <-
524-
programDefaultArgs gccProg
525-
++ programOverrideArgs gccProg
526-
]
527-
++ [ "--lflag=" ++ opt
528-
| opt <-
529-
programDefaultArgs gccProg
530-
++ programOverrideArgs gccProg
531-
]
532-
-- OSX frameworks:
533-
++ [ what ++ "=-F" ++ opt
534-
| isOSX
535-
, opt <- nub (concatMap Installed.frameworkDirs pkgs)
536-
, what <- ["--cflag", "--lflag"]
537-
]
538-
++ [ "--lflag=" ++ arg
539-
| isOSX
540-
, opt <- map getSymbolicPath (PD.frameworks bi) ++ concatMap Installed.frameworks pkgs
541-
, arg <- ["-framework", opt]
542-
]
543-
-- Note that on ELF systems, wherever we use -L, we must also use -R
544-
-- because presumably that -L dir is not on the normal path for the
545-
-- system's dynamic linker. This is needed because hsc2hs works by
546-
-- compiling a C program and then running it.
547-
548-
++ ["--cflag=" ++ opt | opt <- platformDefines lbi]
549-
-- Options from the current package:
550-
++ ["--cflag=-I" ++ u dir | dir <- PD.includeDirs bi]
551-
++ [ "--cflag=-I" ++ u (buildDir lbi </> unsafeCoerceSymbolicPath relDir)
552-
| relDir <- mapMaybe symbolicPathRelative_maybe $ PD.includeDirs bi
553-
]
554-
++ [ "--cflag=" ++ opt
555-
| opt <-
556-
PD.ccOptions bi
557-
++ PD.cppOptions bi
558-
-- hsc2hs uses the C ABI
559-
-- We assume that there are only C sources
560-
-- and C++ functions are exported via a C
561-
-- interface and wrapped in a C source file.
562-
-- Therefore we do not supply C++ flags
563-
-- because there will not be C++ sources.
564-
--
565-
-- DO NOT add PD.cxxOptions unless this changes!
566-
]
567-
++ [ "--cflag=" ++ opt
568-
| opt <-
569-
[ "-I" ++ u (autogenComponentModulesDir lbi clbi)
570-
, "-I" ++ u (autogenPackageModulesDir lbi)
571-
, "-include"
572-
, u $ autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName
573-
]
574-
]
575-
++ [ "--lflag=-L" ++ u opt
576-
| opt <-
577-
if withFullyStaticExe lbi
578-
then PD.extraLibDirsStatic bi
579-
else PD.extraLibDirs bi
580-
]
581-
++ [ "--lflag=-Wl,-R," ++ u opt
582-
| isELF
583-
, opt <-
584-
if withFullyStaticExe lbi
585-
then PD.extraLibDirsStatic bi
586-
else PD.extraLibDirs bi
587-
]
588-
++ ["--lflag=-l" ++ opt | opt <- PD.extraLibs bi]
589-
++ ["--lflag=" ++ opt | opt <- PD.ldOptions bi]
590-
-- Options from dependent packages
591-
++ [ "--cflag=" ++ opt
592-
| pkg <- pkgs
593-
, opt <-
594-
["-I" ++ opt | opt <- Installed.includeDirs pkg]
595-
++ Installed.ccOptions pkg
596-
]
597-
++ [ "--lflag=" ++ opt
598-
| pkg <- pkgs
599-
, opt <-
600-
["-L" ++ opt | opt <- Installed.libraryDirs pkg]
601-
++ [ "-Wl,-R," ++ opt | isELF, opt <- Installed.libraryDirs pkg
602-
]
603-
++ [ "-l" ++ opt
604-
| opt <-
605-
if withFullyStaticExe lbi
606-
then Installed.extraLibrariesStatic pkg
607-
else Installed.extraLibraries pkg
608-
]
609-
++ Installed.ldOptions pkg
610-
]
521+
cflags
522+
++ ldflags
611523
++ preccldFlags
612524
++ hsc2hsOptions bi
613525
++ postccldFlags
614526
++ ["-o", outFile, inFile]
615527
where
528+
ldflags =
529+
map ("--lflag=" ++) $
530+
ordNub $
531+
concat
532+
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
533+
, osxFrameworkDirs
534+
, [ arg
535+
| isOSX
536+
, opt <- map getSymbolicPath (PD.frameworks bi) ++ concatMap Installed.frameworks pkgs
537+
, arg <- ["-framework", opt]
538+
]
539+
, -- Note that on ELF systems, wherever we use -L, we must also use -R
540+
-- because presumably that -L dir is not on the normal path for the
541+
-- system's dynamic linker. This is needed because hsc2hs works by
542+
-- compiling a C program and then running it.
543+
544+
-- Options from the current package:
545+
[ "-L" ++ u opt
546+
| opt <-
547+
if withFullyStaticExe lbi
548+
then PD.extraLibDirsStatic bi
549+
else PD.extraLibDirs bi
550+
]
551+
, [ "-Wl,-R," ++ u opt
552+
| isELF
553+
, opt <-
554+
if withFullyStaticExe lbi
555+
then PD.extraLibDirsStatic bi
556+
else PD.extraLibDirs bi
557+
]
558+
, ["-l" ++ opt | opt <- PD.extraLibs bi]
559+
, PD.ldOptions bi
560+
, -- Options from dependent packages
561+
[ opt
562+
| pkg <- pkgs
563+
, opt <-
564+
["-L" ++ opt | opt <- Installed.libraryDirs pkg]
565+
++ [ "-Wl,-R," ++ opt | isELF, opt <- Installed.libraryDirs pkg
566+
]
567+
++ [ "-l" ++ opt
568+
| opt <-
569+
if withFullyStaticExe lbi
570+
then Installed.extraLibrariesStatic pkg
571+
else Installed.extraLibraries pkg
572+
]
573+
++ Installed.ldOptions pkg
574+
]
575+
]
576+
577+
cflags =
578+
map ("--cflag=" ++) $
579+
ordNub $
580+
concat
581+
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
582+
, osxFrameworkDirs
583+
, platformDefines lbi
584+
, -- Options from the current package:
585+
["-I" ++ u dir | dir <- PD.includeDirs bi]
586+
, [ "-I" ++ u (buildDir lbi </> unsafeCoerceSymbolicPath relDir)
587+
| relDir <- mapMaybe symbolicPathRelative_maybe $ PD.includeDirs bi
588+
]
589+
, -- hsc2hs uses the C ABI
590+
-- We assume that there are only C sources
591+
-- and C++ functions are exported via a C
592+
-- interface and wrapped in a C source file.
593+
-- Therefore we do not supply C++ flags
594+
-- because there will not be C++ sources.
595+
--
596+
-- DO NOT add PD.cxxOptions unless this changes!
597+
PD.ccOptions bi ++ PD.cppOptions bi
598+
,
599+
[ "-I" ++ u (autogenComponentModulesDir lbi clbi)
600+
, "-I" ++ u (autogenPackageModulesDir lbi)
601+
, "-include"
602+
, u $ autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName
603+
]
604+
, -- Options from dependent packages
605+
[ opt
606+
| pkg <- pkgs
607+
, opt <-
608+
["-I" ++ opt | opt <- Installed.includeDirs pkg]
609+
++ Installed.ccOptions pkg
610+
]
611+
]
612+
613+
osxFrameworkDirs =
614+
[ "-F" ++ opt
615+
| isOSX
616+
, opt <- ordNub (concatMap Installed.frameworkDirs pkgs)
617+
]
618+
616619
-- hsc2hs flag parsing was wrong
617620
-- (see -- https://github.com/haskell/hsc2hs/issues/35)
618621
-- so we need to put -- --cc/--ld *after* hsc2hsOptions,
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
-- |
2+
-- Module: Foo
3+
-- Copyright: (c) Sergey Vinokurov 2025
4+
-- License: Apache-2.0 (see LICENSE)
5+
-- Maintainer: [email protected]
6+
7+
{-# LANGUAGE CPP #-}
8+
9+
module Foo (foo) where
10+
11+
import Foo01
12+
import Foo02
13+
import Foo03
14+
import Foo04
15+
import Foo05
16+
import Foo06
17+
import Foo07
18+
import Foo08
19+
import Foo09
20+
import Foo10
21+
22+
#include <include_Foo01.h>
23+
#include <include_Foo02.h>
24+
#include <include_Foo03.h>
25+
#include <include_Foo04.h>
26+
#include <include_Foo05.h>
27+
#include <include_Foo06.h>
28+
#include <include_Foo07.h>
29+
#include <include_Foo08.h>
30+
#include <include_Foo09.h>
31+
#include <include_Foo10.h>
32+
#include <include_FooDep01.h>
33+
#include <include_FooDep02.h>
34+
#include <include_FooDep03.h>
35+
#include <include_FooDep04.h>
36+
#include <include_FooDep05.h>
37+
#include <include_FooDep06.h>
38+
#include <include_FooDep07.h>
39+
#include <include_FooDep08.h>
40+
#include <include_FooDep09.h>
41+
#include <include_FooDep10.h>
42+
#include <include_FooDepDep01.h>
43+
#include <include_FooDepDep02.h>
44+
#include <include_FooDepDep03.h>
45+
#include <include_FooDepDep04.h>
46+
#include <include_FooDepDep05.h>
47+
#include <include_FooDepDep06.h>
48+
#include <include_FooDepDep07.h>
49+
#include <include_FooDepDep08.h>
50+
#include <include_FooDepDep09.h>
51+
#include <include_FooDepDep10.h>
52+
53+
foo :: Int
54+
foo = sum
55+
[ #{const TEST_OPTION}
56+
, foo01
57+
, foo02
58+
, foo03
59+
, foo04
60+
, foo05
61+
, foo06
62+
, foo07
63+
, foo08
64+
, foo09
65+
, foo10
66+
67+
, #{const DEF_foo01}
68+
, #{const DEF_foo02}
69+
, #{const DEF_foo03}
70+
, #{const DEF_foo04}
71+
, #{const DEF_foo05}
72+
, #{const DEF_foo06}
73+
, #{const DEF_foo07}
74+
, #{const DEF_foo08}
75+
, #{const DEF_foo09}
76+
, #{const DEF_foo10}
77+
78+
, #{const DEF_fooDep01}
79+
, #{const DEF_fooDep02}
80+
, #{const DEF_fooDep03}
81+
, #{const DEF_fooDep04}
82+
, #{const DEF_fooDep05}
83+
, #{const DEF_fooDep06}
84+
, #{const DEF_fooDep07}
85+
, #{const DEF_fooDep08}
86+
, #{const DEF_fooDep09}
87+
, #{const DEF_fooDep10}
88+
89+
, #{const DEF_fooDepDep01}
90+
, #{const DEF_fooDepDep02}
91+
, #{const DEF_fooDepDep03}
92+
, #{const DEF_fooDepDep04}
93+
, #{const DEF_fooDepDep05}
94+
, #{const DEF_fooDepDep06}
95+
, #{const DEF_fooDepDep07}
96+
, #{const DEF_fooDepDep08}
97+
, #{const DEF_fooDepDep09}
98+
, #{const DEF_fooDepDep10}
99+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main (main) where
2+
3+
import Foo
4+
5+
main :: IO ()
6+
main = putStrLn $ "Result = " ++ show foo
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packages:
2+
my-toplevel.cabal
3+
deps/my01/my01.cabal
4+
deps/my02/my02.cabal
5+
deps/my03/my03.cabal
6+
deps/my04/my04.cabal
7+
deps/my05/my05.cabal
8+
deps/my06/my06.cabal
9+
deps/my07/my07.cabal
10+
deps/my08/my08.cabal
11+
deps/my09/my09.cabal
12+
deps/my10/my10.cabal
13+
14+
deps/my-dep01/my-dep01.cabal
15+
deps/my-dep02/my-dep02.cabal
16+
deps/my-dep03/my-dep03.cabal
17+
deps/my-dep04/my-dep04.cabal
18+
deps/my-dep05/my-dep05.cabal
19+
deps/my-dep06/my-dep06.cabal
20+
deps/my-dep07/my-dep07.cabal
21+
deps/my-dep08/my-dep08.cabal
22+
deps/my-dep09/my-dep09.cabal
23+
deps/my-dep10/my-dep10.cabal
24+
25+
deps/my-dep-dep01/my-dep-dep01.cabal
26+
deps/my-dep-dep02/my-dep-dep02.cabal
27+
deps/my-dep-dep03/my-dep-dep03.cabal
28+
deps/my-dep-dep04/my-dep-dep04.cabal
29+
deps/my-dep-dep05/my-dep-dep05.cabal
30+
deps/my-dep-dep06/my-dep-dep06.cabal
31+
deps/my-dep-dep07/my-dep-dep07.cabal
32+
deps/my-dep-dep08/my-dep-dep08.cabal
33+
deps/my-dep-dep09/my-dep-dep09.cabal
34+
deps/my-dep-dep10/my-dep-dep10.cabal

0 commit comments

Comments
 (0)