Skip to content

BUILD: Build the native libraries with every warning on and as an error - #238

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 native builds of the Device Detection and IP Intelligence engines turned some compiler warnings off and did not stop on the rest. Every C and C++ warning is now shown and stops the build, at /W4 with MSVC and -Wall -Wextra with gcc and clang.

What changes

  • device-detection/device-detection.hash.engine.on-premise/src/main/cxx/CMakeLists.txt and ip-intelligence/ip-intelligence.engine.on-premise/src/main/cxx/CMakeLists.txt:
    • Every target warns at /W4 with MSVC and at -Wall -Wextra with gcc and clang, the wrapper at -Wall -Wextra -Werror, and CMAKE_COMPILE_WARNING_AS_ERROR makes every warning an error. These files include the cxx CMake files, so this covers the cxx libraries as well as the SWIG wrapper. Both engines ask for C++17, which the included cxx files set anyway.
    • In this repository's files, MSVC warnings 5105 and 4100 are no longer turned off, and the wrapper no longer defines _CRT_SECURE_NO_WARNINGS. The cxx sources at the pinned commit still turn some warnings off, which the cxx check below lists.
    • The wrapper is built with SWIG_MSC_UNSUPPRESS_4505, SWIG_NO_CRT_SECURE_NO_DEPRECATE and SWIG_NO_SCL_SECURE_NO_DEPRECATE, which keep on the warnings that SWIG's generated code would otherwise turn off. Its link warnings are errors too (/WX).
    • CMake 3.24 or later is needed, as cxx already needs. From 3.15, CMake adds no warning level of its own to the MSVC flags.
  • PreBuild.bat in both engines stops at the first CMake command that fails, so a failed 32 bit build is no longer followed by the 64 bit build as if it had passed.
  • hash_java.i in both engines: the helpers that add evidence and look up properties by name read each byte array up to its first zero or its length, whichever comes first, using the lengths SWIG passes. Java_Hash_Engine.cpp and Java_Ipi_Engine.cpp are SWIG's output for the changed files, and the Java proxy classes are unchanged.
  • SWIG: both CMake SWIG runs and RegenSwig.ps1 pass -Wall -Werror, and the CMake configure stops when SWIG fails (COMMAND_ERROR_IS_FATAL ANY).
  • SWIG runs: RegenSwig.ps1 and the -DRebuildSwig=ON configure of both engines write into a new folder, and replace the committed wrapper and Java proxies only when SWIG succeeds, so a SWIG warning leaves every committed file as it was. The IP Intelligence CMake run writes its proxies to fiftyone/ipintelligence/engine/onpremise, where they are, rather than to a folder that does not exist. The README's SWIG command passes -Wall -Werror.
  • Both Java wrapper targets build with -fno-strict-aliasing on gcc and clang, as section 27.2.4 of the SWIG Java documentation asks for an optimized gcc build, because the wrapper passes C++ pointers to Java through casts to jlong. Without it gcc 13 stops both wrappers with -Werror=strict-aliasing on those casts. The cxx libraries keep strict aliasing.
  • ci/native-warnings.Tests.ps1 (new) checks all of the above. It also reads RegenSwig.ps1, checks that each generated wrapper turns no warning off outside SWIG's own guards, and reads every source and CMake file under the cxx submodule. .github/workflows/ci-script-tests.yml checks out the cxx submodule (depth 1) for that, and runs when the native build files or the submodule change.

Tests

  • Pester 6.2.0 on Windows, every ci/*.Tests.ps1 except the environment variable names test: 369 passed, 29 failed. All 29 are the cxx source check, one for each cxx file that still turns a warning off at the pinned commit.
  • MSVC 19.51 with CMake from the Visual Studio 18 Build Tools, through PreBuild.bat as Maven runs it: Device Detection built for x86 and x64, and IP Intelligence for x64, with 0 warnings and 0 errors. The generated projects show Level4 and warnings as errors.
  • SWIG 4.5.0 with -Wall -Werror: Device Detection gives no warning. IP Intelligence stops on SWIG Warning 404 from cxx/src/ipi/WeightedValue.i line 52, a template the cxx interface files declare twice.
  • On Linux x64 after the third commit, with cxx at FIX: Build the C and C++ sources without compiler warnings 51degrees-cxx#214 (c215ac10), and also merged with BUILD: Treat every warning as an error in the tests and examples 51degrees-cxx#222: both wrapper targets build with gcc 13 and clang 18 at -Wall -Wextra -Werror with no warning. With cxx at the pinned 699a9789, both compilers stop in cxx/src, as expected.
  • SWIG 4.5.1 at -Wall -Werror: at 699a9789 RegenSwig.ps1 exits 1 on Warning 404 and the IP Intelligence configure fails, and no file in the tree changes. At c215ac10 both engines regenerate with no warning, and the output equals the committed wrappers and proxies apart from the source paths in SWIG's comments.
  • ci/native-warnings.Tests.ps1: 300 of 300 at c215ac10, and the 29 cxx files fail at 699a9789. Taking -fno-strict-aliasing out, or going back to the SWIG runs that wrote in place, fails the new cases.
  • Maven with JDK 17 on Linux: both engines build with no compiler or SWIG warning, and the Device Detection engine tests pass on the Lite data file, 77 run, 0 failed, 5 skipped. The IP Intelligence engine tests were not run against data.

Expected in CI

"Test the CI scripts" fails on both runners until the cxx submodule moves to a commit whose sources turn no warning off, which is intended. The Linux and macOS native builds are expected to stop on the cxx warnings that gcc and clang give, now with -Wextra as well, for example -Wmissing-field-initializers and -Wunused-parameter. Those are being fixed in 51degrees-cxx (51Degrees/51degrees-cxx#214).

Before this leaves draft

Not ready to merge until these are done.

  1. The cxx submodule moves to a 51degrees-cxx rc commit with no switch or pragma that turns a warning off, which rc 98701d9c now is, and both wrappers are made again with SWIG from that commit, with no SWIG Warning 404. Until then "Test the CI scripts" fails on both runners at this head, 29 cases, all cxx sources.
  2. -fno-strict-aliasing leaves the wrapper. gcc gives -Wstrict-aliasing only with -fstrict-aliasing, so the switch turns that warning off. The wrappers cast jlong to pointers through SWIG's pointer typemaps (for example Java_Hash_Engine.cpp line 1615), so those typemaps in both hash_java.i files convert through intptr_t or memcpy, and ci/native-warnings.Tests.ps1 then forbids the switch rather than asking for it.
  3. Linker warnings are errors on every system. The wrapper's link has /WX on MSVC only, with no -Wl,--fatal-warnings on Linux or -Wl,-fatal_warnings on macOS, and lib.exe gets no /WX for the static cxx libraries.
  4. A Java test that fails without the hash_java.i change.
  5. The Pull Requests workflow with the full matrix on this branch, with no compiler, linker or SWIG warning in any native log, and the Java unit and integration tests passing. No native build has run at this head.

The Device Detection and IP Intelligence native builds include the cxx
CMake files, so these settings cover the cxx libraries as well as the
SWIG wrapper. Every target warns at /W4 with MSVC and at -Wall with gcc
and clang, the level cxx builds its own tests with, and every warning
is an error through CMAKE_COMPILE_WARNING_AS_ERROR. The wrapper's link
warnings are errors too. MSVC warnings 5105 and 4100 are no longer
turned off, the wrapper no longer defines _CRT_SECURE_NO_WARNINGS, and
it is built with the SWIG macros that keep warning 4505 and the CRT and
C++ library deprecation warnings on. CMake 3.24 or later is needed, as
cxx already needs. PreBuild.bat stops at the first CMake command that
fails.

The helpers in hash_java.i that add evidence and look up a property by
name read each byte array up to its first zero or its length, whichever
comes first, so the lengths SWIG passes are used. Java_Hash_Engine.cpp
and Java_Ipi_Engine.cpp are SWIG's output for the changed files.

ci/native-warnings.Tests.ps1 checks these settings, and the CI script
tests now run on a change to the native build files.
gcc and clang now build every target with -Wall -Wextra, and the SWIG
wrapper with -Wall -Wextra -Werror, the level the cxx libraries build
at. Both CMake SWIG runs and RegenSwig.ps1 pass -Wall -Werror, and the
CMake configure stops when SWIG fails. Both engines ask for C++17,
which the included cxx files already set.

ci/native-warnings.Tests.ps1 also reads RegenSwig.ps1, checks that each
generated wrapper turns no warning off outside SWIG's own guards, and
checks the -Wextra and SWIG options. It reads every source and CMake
file under the cxx submodule too, and ci-script-tests.yml checks out
the submodule for that and runs when it moves. That check fails at the
current submodule commit and passes once those sources turn no warning
off.
RegenSwig.ps1 and the -DRebuildSwig=ON configure of both engines now
run SWIG into a new folder, and replace the committed wrapper and Java
proxies only when SWIG succeeds. With SWIG at -Wall -Werror, a SWIG
warning, such as Warning 404 for a template the cxx interface files
declared twice, stopped the run with the committed files already gone.
The IP Intelligence CMake run now writes its proxies to
fiftyone/ipintelligence/engine/onpremise, where they are.

Both Java wrapper targets build with -fno-strict-aliasing on gcc and
clang, as section 27.2.4 of the SWIG Java documentation asks for an
optimized gcc build, because the wrapper passes C++ pointers to Java
through casts to jlong. gcc 13 had stopped both wrappers with
-Werror=strict-aliasing on those casts. The cxx libraries keep strict
aliasing.
https://www.swig.org/Doc4.3/Java.html#Java_compiling_dynamic

ci/native-warnings.Tests.ps1 checks both, and the README's SWIG command
passes -Wall -Werror.
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.

1 participant