Skip to content

Commit 81d95a0

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 1f97215 commit 81d95a0

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

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

609608
osxFrameworkDirs =
610609
[ "-F" ++ opt

0 commit comments

Comments
 (0)