How to set C options for a Haskell dependency with Cabal?

Hello, I want to build the package minisat-solver as a dependency. However, it does not build anymore since gcc uses C23 as the default. Therefore, I want to build minisat-solver with C11.

I figured the cabal.project configuration seemed like the right place. So I did:

package minisat-solver
  ghc-options: -optc "-std=c11"

However, it does not work. It does not seem like cabal passes the flags when looking at the-v3 build logs. What do I have to do to build a dependency with different GCC options?

6 Likes

the c options are for C sources bundled with your haskell code in minisat-solver? if so you probably need this package configuration 1. Package Description — <package>.cabal File — Cabal 3.17.0.0 User's Guide i recommend bookmarking this page in specific without the #stuff part of the link

I do not think this works in my case. minisat-solver is a dependency, so I cannot add cc-options to minisat-solver.cabal in a convenient manner.

For now, I have a local copy of minisat-solver where I have fixed the issues. Still, it would be convenient to patch minisat-solver in cabal.project until someone makes the effort to fix it upstream. Sadly, minisat-solver does not have a git repo linked so this is a little cumbersome.

My reading of 2. Project Description — cabal.project File — Cabal 3.12.1.0 User's Guide indicates that this is a bug in cabal. Maybe you could open a ticket? (It won’t help you right away, but maybe it’ll help the next person, eventually.)

There’s another possibility, too. Are you sure setting c options by setting ghc options actually works?

Cabal also has a “cxx-options” field: 1. Package Description — <package>.cabal File — Cabal 3.12.1.0 User's Guide

And for all I know, the same is true of ghc.

I’m using something similar to workaround a “-werror” problem. Here’s what I have that is working:

package HsOpenSSL
  ghc-options:
    -optc=-Wno-error=discarded-qualifiers
    -optc=-Wno-error=deprecated-declarations
    -optc=-Wno-error=incompatible-pointer-types

I have it in the cabal.project.local file, but it should work in the cabal.project file.

Can you try it as -optc=-std=c11?