0

How do I inject my own desired C++ compiler flags into a conda-build flow?

I tried this, in my conda_build_config.yaml file:

cxx_compiler:
  - gxx                        # [linux]
  - clangxx -Wno-c++11-narrowing  # [osx]
  - vs2019                     # [win]

And I got:

conda.exceptions.InvalidVersionSpec: Invalid version '-Wno-c++11-narrowing_osx-64': invalid character(s)

Then I tried this:

CXXFLAGS="-Wno-c++11-narrowing" conda build ...

but I got the same error I was getting originally:

  kiva/agg/src/kiva_graphics_context_base.cpp:637:27: error: non-constant-expression cannot be narrowed from type 'int' to 'double' in initializer list [-Wc++11-narrowing]
      double tmp[] = {0, 0, img->width(), img->height()};

So, I'm guessing my explicit setting of the CXXFLAGS environment variable is just being ignored by conda-build. (Is that correct?)

Then, I tried this, in the meta.yaml file:

build:
  number: 3
  script: "CXXFLAGS='-Wno-c++11-narrowing' {{ PYTHON }} -m pip install . --no-deps --ignore-installed -vv "

But, I still got the same original error.

Digging deeper, I found the Inherited Environment Variables section of the conda-build documentation, which suggests doing this:

build:
  {snip}
  script_env:
    - CXXFLAGS=-Wno-c++11-narrowing

But, I still get the same error when I try this.

How does one get a custom compiler flag inserted into a conda-build flow?

I think my last attempt above is actually doing what it's supposed to, because I find this line in my ~/miniconda3/conda-bld/enable_1680434176391/work/build_env_setup.sh file:

export CXXFLAGS="-Wno-c++11-narrowing"

So, is the problem really that my build command:

python -m pip install . --no-deps --ignore-installed -vv

is ignoring the setting of the CXXFLAGS environment variable?

dbanas
  • 1,707
  • 14
  • 24

2 Answers2

0

D'oh! This (in the meta.yaml file) worked:

build:
  {snip}
  script_env:
    - CFLAGS=-Wno-c++11-narrowing

Sure enough, buried in the conda-build documentation (Scroll to the end of the section.) I find this:

The environment variables listed in the following table are defined only on macOS.

CFLAGS -arch flag
CXXFLAGS Same as CFLAGS

{snip}

If ever there was a candidate for a top-of-the-page "quick alert". :(

dbanas
  • 1,707
  • 14
  • 24
-1

To add custom C++ compiler flags in a conda-build process, bld.bat file (Windows) in the recipe directory. Add the desired flags to the CXXFLAGS environment variable in the build script. On Windows, add set CXXFLAGS=%CXXFLAGS% -Wno-c++11-narrowing to bld.bat. Ensure the build script uses CXXFLAGS when invoking the compiler, and then run the conda build. hope it helps.

Milad Sikaroudi
  • 677
  • 6
  • 16
  • Can you expand upon this: "Ensure the build script uses CXXFLAGS when invoking the compiler"? – dbanas Apr 02 '23 at 20:13