Skip to content

BUILD: Make the -Wall -Wextra and /W4 warnings errors in the native builds - #279

Draft
jwrosewell wants to merge 3 commits into
rcfrom
build/c-warnings-as-errors
Draft

jwrosewell wants to merge 3 commits into
rcfrom
build/c-warnings-as-errors

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

The on-premise packages now build their native code with the warnings of -Wall -Wextra and /W4 on and treated as errors, on each compiler the release uses.

What changes

  • device-detection/fiftyone_devicedetection_onpremise/setup.py and ip-intelligence/fiftyone_ipintelligence_onpremise/setup.py:
    • MSVC builds the wrapper, the C++ and the C at /W4 /WX, and the /wd4127 /wd4456 /wd4701 /wd4703 /wd4706 list is gone.
    • GCC and Clang, on Linux and macOS and for free-threaded Python, build them with -Wall -Wextra -Werror. -Wno-strict-prototypes, -Wno-unused-variable, -Wno-missing-braces, -Wno-strict-aliasing, -Wno-atomic-alignment and the Python 3.8 -Wno-deprecated-declarations are gone. -Wunused-result comes after the flags Python was built with, which can turn it off.
  • hash_python.i and ipi_python.i:
    • SWIG is asked to leave on the warnings it turns off for the whole wrapper (SWIG_MSC_UNSUPPRESS_4505, SWIG_NO_CRT_SECURE_NO_DEPRECATE, SWIG_NO_SCL_SECURE_NO_DEPRECATE). The interface file comment lists the pragmas SWIG still writes, which no SWIG setting removes, and why none of them changes this build.
    • Overloads use fast dispatch, which checks only the arguments that tell the overloads apart, each in a scope of its own, so no local in the dispatch code hides another (C4456, 117 places in the Device Detection wrapper and 218 in the IP Intelligence one).
    • On MSVC, SWIG's runtime helpers are static inline, so those a module does not call are not reported (C4505). GCC and Clang already get SWIG's unused attribute.
  • hash_python_wrap.cxx and ipi_python_wrap.cxx are generated again from the interface files with SWIG 4.4.1, the version that made them. The Python proxy modules do not change.
  • The cxx submodule moves from 699a9789 to 98701d9c, the head of the 51degrees-cxx rc branch, which holds FIX: Build the C and C++ sources without compiler warnings 51degrees-cxx#214. Its C and C++ sources build with -Wall -Wextra -Werror and /W4 /WX and turn no warning off.
  • Neither setup.py gives /D_CRT_SECURE_NO_WARNINGS to anything. The wrapper, the C++ and the C get the same warning options.
  • On MSVC, each setup.py takes the /W<n> options setuptools gives cl out of the compiler's options before it builds the libraries and the extension, so /W4 is the only level and cl gives no D9025. Other compilers are unchanged.
  • ci/native-warnings.Tests.ps1 checks both setup.py files and both wrappers for a warning turned off, a lower level, a commented out -Werror or /WX, a C runtime deprecation define anywhere in either setup.py, /external:W0, a /w1<n> to /w4<n> option, or a pragma the interface file does not list. It also checks that both setup.py files remove the MSVC level for the libraries and the extension.
  • tests/test_overload_type_error.py in each package checks the TypeError for a constructor call that matches no overload.

Tests

At 248f746, on Windows with MSVC 14.51 and Python 3.12:

  • Both native modules built at /W4 /WX, but cl printed D9025 on every compile, as /W4 overrode the /W3 setuptools gives, and /WX does not make D9025 an error. The level change at this head is for that.
  • fiftyone_devicedetection_onpremise: 119 passed, 2 skipped. fiftyone_ipintelligence_onpremise: 89 passed, 2 skipped. The skipped tests are the free-threaded ones, which skip on a build with the GIL.
  • The CI script tests: 446 passed.
  • Nothing has been built or tested at this head yet.

Before this leaves draft

Not ready to merge until these are done.

  1. The Windows job at this head builds both modules with no D9025, no /W3 on a cl.exe line and no warning C or warning LNK line, and the Pull Requests workflow with the full matrix passes, macOS included.
  2. A decision on whether -Werror and /WX apply to every source install of these packages, so a newer compiler with a new warning stops a customer's build, as the native builds of the other languages now do, or only to the builds 51Degrees runs.
  3. #240 also changes the cxx submodule, so whichever merges second takes the other's pointer.

Mykhailo51D and others added 2 commits November 24, 2026 01:40
The Device Detection and IP Intelligence on-premise packages now build their
native code with every warning on and treated as an error.

- MSVC: /W4 /WX for the wrapper, the C++ and the C. The /wd list is gone.
- GCC and Clang: -Wall -Wextra -Werror for the wrapper, the C++ and the C.
  The -Wno-* flags are gone. -Wunused-result comes after the flags Python
  was built with, which can turn it off.

The SWIG interface files now ask SWIG not to turn off any warning in the
wrapper, and use fast dispatch for overloads. Fast dispatch checks only the
arguments that tell overloads apart, each in a scope of its own, so no local
in the dispatch code hides another (C4456). On MSVC, SWIG's runtime helpers
are static inline, so those a module does not call are not reported as
removed (C4505). GCC and Clang already get SWIG's unused attribute.

Both wrappers are regenerated from the interface files with SWIG 4.4.1, the
version that made them.
In each on-premise package, MSVC gets /D_CRT_SECURE_NO_WARNINGS for the
cxx C and C++ sources only, which still call C runtime functions MSVC
marks as deprecated, and no longer for the SWIG wrapper. setup.py says
to remove it once those calls are gone, and names the warnings that are
on, those of -Wall -Wextra and /W4. The comment in hash_python.i and
ipi_python.i lists the pragmas SWIG still writes in the wrapper and why
none changes this build. The wrappers are unchanged.

ci/native-warnings.Tests.ps1 reads both setup.py files and both
wrappers, and fails if a warning is turned off, the level is lowered,
-Werror or /WX is commented out, the wrapper gets the C runtime define,
or a wrapper has a pragma the interface file does not list. A new
test_overload_type_error.py in each package checks that a constructor
call matching no overload raises a TypeError that names it.
@jwrosewell jwrosewell changed the title BUILD: Make every C and C++ warning an error in the native builds BUILD: Make the -Wall -Wextra and /W4 warnings errors in the native builds Nov 24, 2026
The cxx submodule moves from 699a9789 to 98701d9c, the head of the
51degrees-cxx rc branch. Its C and C++ sources build with -Wall
-Wextra -Werror and /W4 /WX and turn no warning off, so neither
setup.py gives /D_CRT_SECURE_NO_WARNINGS to the cxx sources any more.
The wrapper, the C++ and the C now get the same warning options.

setuptools gives cl /W3, and with /W4 after it cl printed D9025 on
every compile, which /WX does not make an error. On MSVC each setup.py
now takes the /W<n> options setuptools gives out of the compiler's
options before it builds the libraries and the extension, so /W4 is
the only level. Other compilers are unchanged.

ci/native-warnings.Tests.ps1 fails on a C runtime deprecation define
in either setup.py, on /external:W0 and on a /w1<n> to /w4<n> option,
and checks that both setup.py files remove the MSVC level for the
libraries and the extension.
@jwrosewell jwrosewell mentioned this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants