rustcompilationrust-cargocc

How can I add a "std=c99" flag to cc when compiling using cargo?


I'm trying to install ripgrep (link to repo) with the pcre2 feature from source. To do so I run the command cargo build --release --feature 'pcre2' to build the exec.

When doing so, cargo tries to build some C files and throws a error: ‘for’ loop initial declarations are only allowed in C99 mode as well as note: use option -std=c99 or -std=gnu99 to compile your code and stops.

The command it launches is cc -O3 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 [more args...] -o <path-to>-pcre2_script_run.o -c upstream/src/pcre2_script_run.c.

I've tried to alias cc to some different compilers but it does not have an effect. How can I specify a flag to cc (std=c99 in this case) so I can compile this project ?


Solution

  • pcre2-sys (which ripgrep depends on) fails to compile on CentOS indeed.

    A fix proposed in the issue is to use export CC=c99, since the cc crate (which pcre2-sys uses to compile PCRE) uses that environment variable, if defined, to select the C compiler.