Skip to content

Commit fa101ca

Browse files
committed
Deduplicate arguments that hsc2hs passes to gcc and ld
If extra-lib-dirs and/or extra-include-dirs are specified via either command line or project files, they’re going to be added for each package in the dendency graph. With enough long enough directories the command-line length limits for gcc may be hit and calls to the C compiler made from hsc2hs will start failing. Ideally hsc2hs should be using repsonse files, but needlessly specifying myriad of command-line parameters is redundant anyway.
1 parent 02e3942 commit fa101ca

File tree

1 file changed

+77
-78
lines changed

1 file changed

+77
-78
lines changed

Cabal/src/Distribution/Simple/PreProcess.hs

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -527,89 +527,88 @@ ppHsc2hs bi lbi clbi =
527527
where
528528
ldflags =
529529
map ("--lflag=" ++) $
530-
concat
531-
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
532-
, osxFrameworkDirs
533-
, [ arg
534-
| isOSX
535-
, opt <- map getSymbolicPath (PD.frameworks bi) ++ concatMap Installed.frameworks pkgs
536-
, arg <- ["-framework", opt]
537-
]
538-
, -- Note that on ELF systems, wherever we use -L, we must also use -R
539-
-- because presumably that -L dir is not on the normal path for the
540-
-- system's dynamic linker. This is needed because hsc2hs works by
541-
-- compiling a C program and then running it.
542-
543-
-- Options from the current package:
544-
[ "-L" ++ u opt
545-
| opt <-
546-
if withFullyStaticExe lbi
547-
then PD.extraLibDirsStatic bi
548-
else PD.extraLibDirs bi
549-
]
550-
, [ "-Wl,-R," ++ u opt
551-
| isELF
552-
, opt <-
553-
if withFullyStaticExe lbi
554-
then PD.extraLibDirsStatic bi
555-
else PD.extraLibDirs bi
556-
]
557-
, ["-l" ++ opt | opt <- PD.extraLibs bi]
558-
, PD.ldOptions bi
559-
, -- Options from dependent packages
560-
[ opt
561-
| pkg <- pkgs
562-
, opt <-
563-
["-L" ++ opt | opt <- Installed.libraryDirs pkg]
564-
++ [ "-Wl,-R," ++ opt | isELF, opt <- Installed.libraryDirs pkg
565-
]
566-
++ [ "-l" ++ opt
567-
| opt <-
568-
if withFullyStaticExe lbi
569-
then Installed.extraLibrariesStatic pkg
570-
else Installed.extraLibraries pkg
571-
]
572-
++ Installed.ldOptions pkg
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+
]
573575
]
574-
]
575576

576577
cflags =
577578
map ("--cflag=" ++) $
578-
concat
579-
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
580-
, osxFrameworkDirs
581-
, platformDefines lbi
582-
, -- Options from the current package:
583-
["-I" ++ u dir | dir <- PD.includeDirs bi]
584-
, [ "-I" ++ u (buildDir lbi </> unsafeCoerceSymbolicPath relDir)
585-
| relDir <- mapMaybe symbolicPathRelative_maybe $ PD.includeDirs bi
586-
]
587-
588-
, -- hsc2hs uses the C ABI
589-
-- We assume that there are only C sources
590-
-- and C++ functions are exported via a C
591-
-- interface and wrapped in a C source file.
592-
-- Therefore we do not supply C++ flags
593-
-- because there will not be C++ sources.
594-
--
595-
-- DO NOT add PD.cxxOptions unless this changes!
596-
PD.ccOptions bi ++ PD.cppOptions bi
597-
598-
,
599-
[ "-I" ++ u (autogenComponentModulesDir lbi clbi)
600-
, "-I" ++ u (autogenPackageModulesDir lbi)
601-
, "-include"
602-
, u $ autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName
603-
]
604-
605-
, -- Options from dependent packages
606-
[ opt
607-
| pkg <- pkgs
608-
, opt <-
609-
["-I" ++ opt | opt <- Installed.includeDirs pkg]
610-
++ Installed.ccOptions pkg
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+
]
611611
]
612-
]
613612

614613
osxFrameworkDirs =
615614
[ "-F" ++ opt

0 commit comments

Comments
 (0)