Skip to content

Fix linking issue with cxx-options and cxx-sources fields in non-library components #5315

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

Merged
merged 12 commits into from
May 25, 2018
Merged

Conversation

recursion-ninja
Copy link
Contributor

@recursion-ninja recursion-ninja commented May 12, 2018

Standard checklist

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • If the change is docs-only, [ci skip] is used to avoid triggering the build bots.

Changes

I have updated the Cabal library's cxx-options and cxx-sources fields to correctly link when building non-library components (benchmark, executable, test-suite). This pull requests should resolve #5309 and complete the feature I (unknowingly) didn't fully implement in #4810 which partially resolved #3700.

Specific fixes

The main culprit of the C++ object not being passed to the linker can be seen here.

I also removed the following warning when invoking hsc2hs while the cxx-options field is present:

cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C

Before we merge

I did not add any tests to the test suite. I looked through the Cabal/test and it wasn't immediately apparent where I would add tests for this functionality or what form the tests would take. However I think it would be prudent to add some tests for this functionality before we merge the pull request.

  1. Should the tests be added for Cabal the library or cabal-install the executable?. I assume Cabal, but I might be wrong.

  2. Should the tests be added in an existing module or a new module?

  3. How do I add the new tests into the existing test suite for the Cabal.

I'd appreciate some direction on the testing front @23Skidoo, @amigalemming, @ezyang, @hvr, @quasicomputational.

@quasicomputational
Copy link
Contributor

RE tests, could one go in cabal-testsuite? Seems like you have a suitable sketch of a test-case in the issue that can more or less be translated directly.

ghcOptFPic = toFlag True,
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptObjSuffix = toFlag "dyn_o"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this whitespace change noise be removed, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace removed.

++ "flag."
"'"++prefix++": -O[n]' is generally not needed. When building with "
++ " optimisations Cabal automatically adds '-O2' for "++label++" code. "
++ "Setting it yourself interferes with the --disable-optimization flag."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cabal/tests/ParserTests has some tests for warnings from check, which you might want to add to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the following test files to ensure that the check provides correct warnings:
regressions/cc-options-with-optimization
regressions/cxx-options-with-optimization

@@ -1088,15 +1088,15 @@ gbuildSources :: Verbosity
-> Version -- ^ specVersion
-> FilePath
-> GBuildMode
-> IO ([FilePath], [FilePath], [ModuleName])
-> IO ([FilePath], [FilePath], [FilePath], [ModuleName])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth defining a data type for these, rather than relying on 4-tuples and remembering which FilePath is which?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a labeled "record" in place of the 4-tuple.

when needsRecomp $
runGhcProg opts
| filename <- cxxSrcs ]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be personal taste, but is this nicer than for_ cxxSrcs $ \ filename -> ...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind. I see it's patterned on the code below. Best to keep them obviously parallel.

@@ -449,7 +449,7 @@ allSourcesBuildInfo verbosity bi pps modules = do
in findFileWithExtension fileExts (hsSourceDirs bi) file
| module_ <- modules ++ otherModules bi ]

return $ sources ++ catMaybes bootFiles ++ cSources bi ++ jsSources bi
return $ sources ++ catMaybes bootFiles ++ cSources bi ++ cxxSources bi ++ jsSources bi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cabal-testsuite/PackageTests/SDlist has a test for sdist. Might be worth adding to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the test cases in cabal-testsuite directory, but I'm unsure how to invoke these tests. Is there a script to run through these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out how to run the tests locally.

separate compilation of C++ source files to correctly build and link
non-library components (#5309).
* Reduced warnings generated by hsc2hs and c2hs when `cxx-options` field
is present in a omponent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: s/omponent/component/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I corrected this.

@23Skidoo
Copy link
Member

There seem to be some genuine failures on AppVeyor.

@@ -657,14 +657,14 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
info verbosity "Building C++ Sources..."
sequence_
[ do let baseCxxOpts = Internal.componentCxxGhcOptions verbosity implInfo
lbi libBi clbi libTargetDir filename
lbi libBi clbi libTargetDir filename
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a spurious whitespace change here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want the arguments to be vertically aligned the the function call above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure. So long as it's deliberate and not just random reformatting noise.

}
ghcOptProfilingMode = toFlag True,
ghcOptObjSuffix = toFlag "p_o"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And more whitespace changes here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deliberate, vertical alignment with this whitespace.

@recursion-ninja
Copy link
Contributor Author

I added this test case, cabal-testsuite/PackageTests/Regression/T5309.

Unfortunately, I'm getting this error when running the test suite:

cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs                                                                       FAIL (0.03s)
$ /usr/local/bin/runghc -- '--ghc-arg=-i' '--ghc-arg=-no-user-package-db' '--ghc-arg=-package-db' '--ghc-arg=/home/washburn/.cabal/store/ghc-8.2.2/package.db' '--ghc-arg=-package-db' '--ghc-arg=/home/washburn/Code/cabal/dist-newstyle/packagedb/ghc-8.2.2' '--ghc-arg=-package-id' '--ghc-arg=Cabal-2.3.0.0-inplace' '--ghc-arg=-package-id' '--ghc-arg=async-2.1.1.1-H3j65XcXMHtBvmNwGCQ80G' '--ghc-arg=-package-id' '--ghc-arg=base-4.10.1.0' '--ghc-arg=-package-id' '--ghc-arg=cabal-testsuite-2.3.0.0-inplace' '--ghc-arg=-package-id' '--ghc-arg=clock-0.7.2-7c1444262a97961f79ec17849dbc10b53740bf835b4f1d79cf747e71b1d837f2' '--ghc-arg=-package-id' '--ghc-arg=exceptions-0.10.0-4a32c341144c5dc0a9ef4472b7272bfaf7e0cb4f64e97ebb952391bb7254d5fd' '--ghc-arg=-package-id' '--ghc-arg=filepath-1.4.1.2' '--ghc-arg=-package-id' '--ghc-arg=optparse-applicative-0.14.2.0-3dba83640de58524187465e129f9d0dd9ac3a9f1c5a8ae9afbf31e9b8e713aee' '--ghc-arg=-package-id' '--ghc-arg=process-1.6.1.0' '--ghc-arg=-package-id' '--ghc-arg=transformers-0.5.2.0' cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs --builddir /home/washburn/Code/cabal/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-testsuite-2.3.0.0 cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs
stdout:
# cabal new-build

stderr:
*** Exception: dieVerbatim: user error (<interactive>: The program 'cabal' is required but it could not be found.
)

*** unexpected failure for cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs

I'm not sure how to correct this? Any pointers @quasicomputational @23Skidoo

@quasicomputational
Copy link
Contributor

I ran into that issue before; I think that it's a bug in setupAndCabalTest but I haven't poked around further. If you turn setupAndCabalTest into just cabalTest, I think it'll work---at least it did for me.

@recursion-ninja
Copy link
Contributor Author

@quasicomputational I changed setupAndCabalTest to cabalTest and the test ran "successfully" but was marked as SKIP.

cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs                      SKIP (0.03s)

I'm guessing SKIP isn't what I want for the test case, I'd like it to try and build the local test project.

@quasicomputational
Copy link
Contributor

quasicomputational commented May 17, 2018

Oh, run it (e: it = cabal-testsuite) with --with-cabal.

@23Skidoo
Copy link
Member

cabal-testsuite/PackageTests/Regression/T5309/cabal.test.hs

This seems to be happening on master as well, so apparently not caused by this PR.

@recursion-ninja
Copy link
Contributor Author

@23Skidoo I believe I corrected issues related to the IPIs test cases.

@recursion-ninja
Copy link
Contributor Author

@quasicomputational, could you help me diagnose this error message? I'm still trying to add a stripped down version of this repository as a test case for the cxx-options & cxx-sources fields.

The error message is a bit incomprehensible to me. It seems to me that it's trying to install Cabal as a dependency, but I don't know why.

PackageTests\Regression\T5309\cabal.test.hs                                                                       FAIL (1.13s)
$ "C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\runghc.exe" "--" "--ghc-arg=-i" "--ghc-arg=-package-id" "--ghc-arg=Cabal-2.3.0.0-HTGg0qjuxXbBSwurLDB7ad" "--ghc-arg=-package-id" "--ghc-arg=async-2.2.1-FtyEBgS0La811OtEcI8hQO" "--ghc-arg=-package-id" "--ghc-arg=base-4.9.1.0" "--ghc-arg=-package-id" "--ghc-arg=cabal-testsuite-2.3.0.0-6oreefIYDsR8Jl4uC6dgsK" "--ghc-arg=-package-id" "--ghc-arg=clock-0.7.2-2aZP57zFattJce1nK6pmuj" "--ghc-arg=-package-id" "--ghc-arg=exceptions-0.10.0-D3l6tOLudZU9YCvtoPHr4p" "--ghc-arg=-package-id" "--ghc-arg=filepath-1.4.1.1" "--ghc-arg=-package-id" "--ghc-arg=optparse-applicative-0.14.2.0-8qLJq3LaLRK948X9OctCJT" "--ghc-arg=-package-id" "--ghc-arg=process-1.4.3.0" "--ghc-arg=-package-id" "--ghc-arg=transformers-0.5.2.0" "PackageTests\Regression\T5309\cabal.test.hs" "--builddir" "C:\projects\cabal\cabal-testsuite\dist" "PackageTests\Regression\T5309\cabal.test.hs" "--with-cabal" "..\cabal-install\dist\build\cabal\cabal.exe" "--skip-setup-tests"
stdout:
# cabal new-build
+ "C:\projects\cabal\cabal-testsuite\..\cabal-install\dist\build\cabal\cabal.exe" "new-build" "-vverbose +markoutput +nowrap" "--builddir" "C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\.\dist" "--project-file" "cabal.project" "-j1" "all"
Project settings changed, reconfiguring...
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist\cache
this build was affected by the following (project) config files:
- C:\projects\cabal\cabal.project
Compiler settings changed, reconfiguring...
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--numeric-version"
looking for tool ghc-pkg near compiler in C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin
found ghc-pkg in C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc-pkg.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc-pkg.exe" "--version"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--supported-languages"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--info"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--print-global-package-db"
Warning: No remote package servers have been specified. Usually you would have one specified in the config file.
Failed to query pkg-config, Cabal will continue without solving for pkg-config constraints: dieVerbatim: user error (CallStack (from HasCallStack):
  die', called at .\Distribution\Simple\Program\Db.hs:423:28 in Cabal-2.3.0.0-HTGg0qjuxXbBSwurLDB7ad:Distribution.Simple.Program.Db
  requireProgram, called at .\Distribution\Solver\Types\PkgConfigDb.hs:65:21 in cabal-install-2.3.0.0-Cck6obqWNqJKjo9mr2iSL:Distribution.Solver.Types.PkgConfigDb
cabal.exe: The program 'pkg-config' is required but it could not be found.
)
-----BEGIN CABAL OUTPUT-----
Resolving dependencies...
-----END CABAL OUTPUT-----
CallStack (from HasCallStack):
  die', called at .\Distribution\Client\ProjectPlanning.hs:568:42 in cabal-install-2.3.0.0-Cck6obqWNqJKjo9mr2iSL:Distribution.Client.ProjectPlanning
-----BEGIN CABAL OUTPUT-----
cabal.exe: Could not resolve dependencies:
[__0] trying: Cabal-2.3.0.0 (user goal)
[__1] unknown package: text (dependency of Cabal)
[__1] fail (backjumping, conflict set: Cabal, text)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: Cabal (3), text (1)
-----END CABAL OUTPUT-----
stderr:
*** Exception: Command "C:\projects\cabal\cabal-testsuite\..\cabal-install\dist\build\cabal\cabal.exe" "new-build" "-vverbose +markoutput +nowrap" "--builddir" "C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\.\dist" "--project-file" "cabal.project" "-j1" "all" failed.
Output:
Project settings changed, reconfiguring...
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist
creating C:\projects\cabal\cabal-testsuite\PackageTests\Regression\T5309\cabal.dist\work\dist\cache
this build was affected by the following (project) config files:
- C:\projects\cabal\cabal.project
Compiler settings changed, reconfiguring...
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--numeric-version"
looking for tool ghc-pkg near compiler in C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin
found ghc-pkg in C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc-pkg.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc-pkg.exe" "--version"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--supported-languages"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--info"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.0.2\bin\ghc.exe" "--print-global-package-db"
Warning: No remote package servers have been specified. Usually you would have one specified in the config file.
Failed to query pkg-config, Cabal will continue without solving for pkg-config constraints: dieVerbatim: user error (CallStack (from HasCallStack):
  die', called at .\Distribution\Simple\Program\Db.hs:423:28 in Cabal-2.3.0.0-HTGg0qjuxXbBSwurLDB7ad:Distribution.Simple.Program.Db
  requireProgram, called at .\Distribution\Solver\Types\PkgConfigDb.hs:65:21 in cabal-install-2.3.0.0-Cck6obqWNqJKjo9mr2iSL:Distribution.Solver.Types.PkgConfigDb
cabal.exe: The program 'pkg-config' is required but it could not be found.
)
-----BEGIN CABAL OUTPUT-----
Resolving dependencies...
-----END CABAL OUTPUT-----
CallStack (from HasCallStack):
  die', called at .\Distribution\Client\ProjectPlanning.hs:568:42 in cabal-install-2.3.0.0-Cck6obqWNqJKjo9mr2iSL:Distribution.Client.ProjectPlanning
-----BEGIN CABAL OUTPUT-----
cabal.exe: Could not resolve dependencies:
[__0] trying: Cabal-2.3.0.0 (user goal)
[__1] unknown package: text (dependency of Cabal)
[__1] fail (backjumping, conflict set: Cabal, text)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: Cabal (3), text (1)
-----END CABAL OUTPUT-----
*** unexpected failure for PackageTests\Regression\T5309\cabal.test.hs

@recursion-ninja
Copy link
Contributor Author

I fixed the T5309 test case and the IPIS test cases. AppVeyor is passing. Travis is not. I'm not sure if the Travis failures are things that need to be addressed. @quasicomputational , @23Skidoo could you inform me if there are any more test cases that need to be remedied?

For example, this Travis job failure doesn't look like something that needs to be fixed. It appears to be failing because files were added between two git commits.

However, it kooks like most of the failures involve authentication failures via SSH keys.

@quasicomputational
Copy link
Contributor

Travis is broken at the moment, yeah. Should be fixed soon and then you can rebase on master and try again.

A couple of things:

  • Can the test case be cut down any more? It's about 2/3 of the diff at the moment, and it's taking 35-40s to run, which is a lot for a single test case.

  • The meta check is failing because you need to run make gen-extra-source-files.

  • I dunno what anyone else's opinion is here, but the PR's commit history is a bit messy with the merges. This isn't a requirement for merging, but if you've got spare cycles, maybe rebase and tify it up and squash a bit?

@recursion-ninja
Copy link
Contributor Author

recursion-ninja commented May 23, 2018

@quasicomputational I'll try and cut down the test suite a bit, but it does need to do a lot of things to test that the functionality is correct:

  • Require C sources via c-sources
  • Require C++ sources via cxx-sources
  • Have the C++ sources depend on some C sources
  • Have some C sources depend on some C++ sources
  • Build a library with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build an executable from scratch with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build an executable which depends on a library with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build a benchmark from scratch with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build a benchmark which depends on a library with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build a test suite from scratch with C & C++ sources with different compiler options via cc-options and cxx-options
  • Build a test suite which depends on a library with C & C++ sources with different compiler options via cc-options and cxx-options

Since all the main functions are all stubs, I can try and remove some of the C & C++ code's functionality, as it's never invoked. Aside from that, I'm not sure how else to pare down the test suite.

I'll look into squashing some of the commits, but after I try and truncate the C & C++ code.

@quasicomputational
Copy link
Contributor

Stubbing out the functionality is what I had in mind. Thanks a bunch!

@quasicomputational
Copy link
Contributor

quasicomputational commented May 24, 2018

HEAD has the Travis stuff fixed now, so you probably want to rebase. Edit: Oh, it's been merged in. Carry on!

@recursion-ninja
Copy link
Contributor Author

The test suite has been pared down, however the run time didn't noticeably decrease.

The make command has been run and the meta check passes.

All of the test suite tinkering commits have been squashed together.

@quasicomputational, I believe that this is ready to be merged. Should we wait until Travis is fixed on master and test things one last time with those changes before merging back into master?

filter (/= mainModName) (exeModules exe))
return BuildSources {
cSourcesFiles = cSources bnfo,
cxxSourceFiles = cxxSources bnfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code formatting here: equals aren't aligned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

else return (main : cSources bnfo, [], exeModules exe)
else return BuildSources {
cSourcesFiles = cSources bnfo,
cxxSourceFiles = cxxSources bnfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not aligned here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
else return BuildSources {
cSourcesFiles = main : cSources bnfo,
cxxSourceFiles = main : cxxSources bnfo,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines don't look right. What if the main module is C++? (Are C++ main modules even supported?) What if it's in the C++-incompatible part of C? Don't we need to be able to tell between a C++ and a C module and then only add it to the appropriate list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't anticipating supporting a C++ main module, only linking to C++ though the C ABI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. So the main module shouldn't be added to cxxSourceFiles at all? This is definitely worth having a test for, with a main module that uses some C++-breaking construct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to address this by checking if main is a C++ source. If it is neither a Haskell source nor a C++ source file, then we default to C. Defaulting to C (appeared) to have been the previous functionality.

opts | needProfiling = profCxxOpts
| needDynamic = sharedCxxOpts
| otherwise = vanillaCxxOpts
odir = fromFlag (ghcOptObjDir opts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly stupid question: the C++ and C files are sharing an output directory here, so collisions are a possibility. Is that user error if it happens, or do we need to guard against it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume that collisions here is a user error. I also don't want the added complexity of a separate object directory for each (currently 2) FFI language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Might be an idea to warn about it (either here or in cabal check or both), but that can be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a TODO for this potential collision issue. Should I create a GitHub issue for this so that it is visibly tracked.

-- interface and wrapped in a C source file.
-- Therefore we do not supply C++ flags
-- because there will not be C++ sources
{- ++ PD.cxxOptions bi -} ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the commented-out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -525,7 +541,7 @@ getCppOptions bi lbi
= platformDefines lbi
++ cppOptions bi
++ ["-I" ++ dir | dir <- PD.includeDirs bi]
++ [opt | opt@('-':c:_) <- PD.ccOptions bi, c `elem` "DIU"]
++ [opt | opt@('-':c:_) <- PD.ccOptions bi ++ PD.cxxOptions bi, c `elem` "DIU"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit messy: what if the C and C++ files need different CPP options? But we're already muddling up C and CPPed Haskell, so I guess this isn't a huge problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a vague recollection of something breaking without the cxx-options being added here, but that was over a month ago so I don't recall exactly what it was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look like it works at the moment for the common case, and without this change C++ CPP options won't be plumbed through at all. I think the ideal solution here would be to have separate getCppOptionsForHs, getCppOptionsForCxx, getCppOptionsForC, etc functions, but, like I said, it's already a bit messy; I think it's sensible to leave that for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that ideally this would be refactored out into separate functions.

However, I think leaving this for later would be best. I've already invested a lot of company time in this pull request and need to get back to implementing new features on our product.

I added a TODO above this function. Should I add a GitHub issue for this so that it is visibly tracked?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine. There's already a TODO about this, so let's open an issue and punt; it's evidently not causing anyone trouble today.

@@ -438,7 +445,8 @@ ppHsc2hs bi lbi clbi =
++ [ "--cflag=" ++ opt
| pkg <- pkgs
, opt <- [ "-I" ++ opt | opt <- Installed.includeDirs pkg ]
++ [ opt | opt <- Installed.ccOptions pkg ] ]
++ [ opt | opt <- Installed.ccOptions pkg
{- ++ Installed.cxxOptions pkg -} ] ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

-- Therefore we do not supply C++ flags
-- because there will not be C++ sources
--
-- ++ Installed.cxxOptions pkg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another bit of commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@quasicomputational
Copy link
Contributor

Looks good to me. I've verified that the test case fails with cabal-install 2.2 and passes with this PR, and I don't see any potential show-stoppers.

@recursion-ninja
Copy link
Contributor Author

@quasicomputational, I merged upstream master into my fork to re-run the Travis tests before finalizing this pull request. An AppVeyor test failed after the merge from master, but it doesn't seem to involve any changes in this pull request. Do you think it's safe to merge and close out this pull request? I don't want to "break the build."

@quasicomputational
Copy link
Contributor

That test's flaky; I've seen it randomly fail before. I'm currently failing at getting it not to be skipped locally, but, if Travis comes back green-ish, it should be good to go.

@recursion-ninja recursion-ninja merged commit cc5f025 into haskell:master May 25, 2018
davetapley added a commit to davetapley/haskell-opencv that referenced this pull request Sep 22, 2018
This is currently broken with:

/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file
requires compiler and library support for the ISO C++ 2011 standard.
This support must be enabled with the -std=c++11 or -std=gnu++11
compiler options.

I thought this was fixed by haskell/cabal#4810
(which is in Cabal 2.2), but it might be broken because this:
haskell/cabal#5315
(which is in is in Cabal 2.4, which isn't yet in LTS).
@domenkozar
Copy link
Collaborator

Using cxx-options: --std=c++11 with clang (on darwin) library and then a different package executable will fail to apply that flag with Cabal 2.4.0.1. I suppose that should also propagate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cxx-options and cxx-sources build info fields not fully implemented Cxx-Options for -std=c++11
4 participants