Skip to content

BLD: Verify the ability to compile C++ sources before initiating the build#20354

Merged
rgommers merged 2 commits intonumpy:mainfrom
seiko2plus:test_cpp
Nov 14, 2021
Merged

BLD: Verify the ability to compile C++ sources before initiating the build#20354
rgommers merged 2 commits intonumpy:mainfrom
seiko2plus:test_cpp

Conversation

@seiko2plus
Copy link
Member

related to #20335

@seiko2plus seiko2plus added 36 - Build Build related PR C++ Related to introduction and use of C++ in the NumPy code base labels Nov 12, 2021
@seiko2plus seiko2plus added the 09 - Backport-Candidate PRs tagged should be backported label Nov 12, 2021
@rgommers
Copy link
Member

The one CI failure is:

cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++

@rgommers
Copy link
Member

This seems like a good idea, thanks @seiko2plus! I'll do some local testing.

@rgommers
Copy link
Member

The debug CI job still trips on the same flag:

C compiler: x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -g -Og -Wall -g -Og -fstack-protector-strong -Wformat -Werror=format-security -g -Og -fstack-protector-strong -Wformat -Werror=format-security -Wno-unused-result -Wsign-compare -g -Og -Wall -g -Og -fstack-protector-strong -Wformat -Werror=format-security -g -Og -fstack-protector-strong -Wformat -Werror=format-security -Werror=vla -Werror=nonnull -Werror=pointer-arith -Werror=implicit-function-declaration -Wlogical-op -Wno-sign-compare -Wno-maybe-uninitialized -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC

compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/src/_simd -I/home/runner/work/numpy/numpy/builds/venv/include -I/usr/include/python3.8d -c'
x86_64-linux-gnu-gcc: _configtest.cxx
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++

Looks like the config test attempts to use a C compiler on a .cxx test file here.

@mattip
Copy link
Member

mattip commented Nov 13, 2021

This is a cc1plus warning, so it is a c++ compiler and somehow it is getting a c-only option. NumPy defines the flag twice in the codebase, in numpy/testing/_private/extbuild.py and tools/travis-test.sh

The complete snippet
C compiler: x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare \
    -g -Og -Wall \
    -g -Og -fstack-protector-strong -Wformat -Werror=format-security \
    -g -Og -fstack-protector-strong -Wformat -Werror=format-security -Wno-unused-result -Wsign-compare 
    -g -Og -Wall \
    -g -Og -fstack-protector-strong -Wformat -Werror=format-security \
    -g -Og -fstack-protector-strong -Wformat -Werror=format-security \
    -Werror=vla -Werror=nonnull -Werror=pointer-arith -Werror=implicit-function-declaration \
    -Wlogical-op -Wno-sign-compare -Wno-maybe-uninitialized -Wdate-time \
    -D_FORTIFY_SOURCE=2 -fPIC

compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath \
    -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort \
    -Inumpy/core/src/_simd -I/home/runner/work/numpy/numpy/builds/venv/include \
    -I/usr/include/python3.8d -c'
x86_64-linux-gnu-gcc: _configtest.cxx
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
x86_64-linux-gnu-g++ -pthread _configtest.o -o _configtest

@rgommers
Copy link
Member

Looking at the other -Werror flags, that issue is clearly coming from travis-test.sh. That said, some extra protection for extbuild.py couldn't hurt. I pushed a commit with a proposed fix.

@rgommers
Copy link
Member

Okay never mind, removed again. Should test more locally first.

@seiko2plus
Copy link
Member Author

seiko2plus commented Nov 13, 2021

that issue is clearly coming from travis-test.sh

I have a workaround for this issue lay down in #19753, see:

but I don't think it's a good idea. however, manually filtering any invalid c++ flags isn't a better idea too. it seems that I need to move the invalid c++ filter to UnixCCompiler__compile because after tracing config_cmd.try_link() I found it doesn't call CCompiler_customize()

ignore_c_flags = {
'-Werror=implicit-function-declaration', '-Wstrict-prototypes'
}
if hasattr(self, 'compiler_so'):
Copy link
Member

Choose a reason for hiding this comment

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

Just a guess, but the -Werror=implicit-function-declaration flag is present in both self.compiler_so and self.compiler. It's only removed from the former here. Maybe removing it from both is healthy; the code is too much of a spaghetti to be sure that only compiler_so will be used.

Copy link
Member Author

@seiko2plus seiko2plus Nov 14, 2021

Choose a reason for hiding this comment

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

parm need_cxx only used by build_ext and build_clib that's why this filter has never been called, I took my changes back, kept the original one as-is inside compiler_cxx() now we have two C++ filters and we should to put them in one place.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suggest just calling customize(need_cxx) inside cxx_compiler() which already clones the compiler instance, and we count only on method cxx_compiler() in the following code and the other one in build_clib to avoid duplicate initializing and unnecessary copying.

if need_cxx_compiler:
self._cxx_compiler = new_compiler(compiler=compiler_type,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
compiler = self._cxx_compiler
compiler.customize(self.distribution, need_cxx=need_cxx_compiler)
compiler.customize_cmd(self)
compiler.show_customization()
self._cxx_compiler = compiler.cxx_compiler()

@rgommers
Copy link
Member

it seems that I need to move the invalid c++ filter to UnixCCompiler__compile because after tracing config_cmd.try_link() I found it doesn't call CCompiler_customize()

Hmm, that's not good. IIRC that must always be done. try_link will end up calling finalize_options on the build command. I'm wondering is we can call .customize() there (like in customized_ccompiler in numpy/distutils/__init__.py).

Or implement try_link, calling customize() and then deferring to the distutils version of try_link.

@seiko2plus
Copy link
Member Author

I was mistaken it was actually called customize but without need_cxx, I had to dig more to understand what is going on, so I ended up with an ugly workaround to avoid big changes.

@seiko2plus
Copy link
Member Author

nothing better then the green color :)

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Nice workaround, LGTM. Thanks @seiko2plus!

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Nov 25, 2021
@charris charris removed this from the 1.21.5 release milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

36 - Build Build related PR C++ Related to introduction and use of C++ in the NumPy code base

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants