Repository navigation
BUILD: Build the native libraries with every warning on and as an error - #238
Draft
jwrosewell wants to merge 3 commits into
Draft
jwrosewell wants to merge 3 commits into
jwrosewell wants to merge 3 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
/W4with MSVC and-Wall -Wextrawith gcc and clang.What changes
device-detection/device-detection.hash.engine.on-premise/src/main/cxx/CMakeLists.txtandip-intelligence/ip-intelligence.engine.on-premise/src/main/cxx/CMakeLists.txt:/W4with MSVC and at-Wall -Wextrawith gcc and clang, the wrapper at-Wall -Wextra -Werror, andCMAKE_COMPILE_WARNING_AS_ERRORmakes 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._CRT_SECURE_NO_WARNINGS. The cxx sources at the pinned commit still turn some warnings off, which the cxx check below lists.SWIG_MSC_UNSUPPRESS_4505,SWIG_NO_CRT_SECURE_NO_DEPRECATEandSWIG_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).PreBuild.batin 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.iin 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.cppandJava_Ipi_Engine.cppare SWIG's output for the changed files, and the Java proxy classes are unchanged.RegenSwig.ps1pass-Wall -Werror, and the CMake configure stops when SWIG fails (COMMAND_ERROR_IS_FATAL ANY).RegenSwig.ps1and the-DRebuildSwig=ONconfigure 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 tofiftyone/ipintelligence/engine/onpremise, where they are, rather than to a folder that does not exist. The README's SWIG command passes-Wall -Werror.-fno-strict-aliasingon 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 tojlong. Without it gcc 13 stops both wrappers with-Werror=strict-aliasingon those casts. The cxx libraries keep strict aliasing.ci/native-warnings.Tests.ps1(new) checks all of the above. It also readsRegenSwig.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.ymlchecks out the cxx submodule (depth 1) for that, and runs when the native build files or the submodule change.Tests
ci/*.Tests.ps1except 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.PreBuild.batas 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.-Wall -Werror: Device Detection gives no warning. IP Intelligence stops on SWIG Warning 404 fromcxx/src/ipi/WeightedValue.iline 52, a template the cxx interface files declare twice.-Wall -Wextra -Werrorwith no warning. With cxx at the pinned 699a9789, both compilers stop incxx/src, as expected.-Wall -Werror: at 699a9789RegenSwig.ps1exits 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-aliasingout, or going back to the SWIG runs that wrote in place, fails the new cases.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
-Wextraas well, for example-Wmissing-field-initializersand-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.
-fno-strict-aliasingleaves the wrapper. gcc gives-Wstrict-aliasingonly with-fstrict-aliasing, so the switch turns that warning off. The wrappers castjlongto pointers through SWIG's pointer typemaps (for exampleJava_Hash_Engine.cppline 1615), so those typemaps in bothhash_java.ifiles convert throughintptr_tormemcpy, andci/native-warnings.Tests.ps1then forbids the switch rather than asking for it./WXon MSVC only, with no-Wl,--fatal-warningson Linux or-Wl,-fatal_warningson macOS, andlib.exegets no/WXfor the static cxx libraries.hash_java.ichange.