Bug #110873 CMake checks for clang 15 need to be updated for Apple clang
Submitted: 1 May 2023 9:22 Modified: 3 May 2023 13:37
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.33 OS:MacOS
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: Clang, cmake, llvm, macos

[1 May 2023 9:22] Laurynas Biveinis
Description:
On macOS with the latest XCode,

/Users/laurynas/vilniusdb/mysql-8.0.33/_build-debug/sql/sql_hints.yy.cc:1175:9: error: variable 'HINT_PARSER_nerrs' set but not used [-Werror,-Wunused-but-set-variable]
    int yynerrs = 0;
        ^
/Users/laurynas/vilniusdb/mysql-8.0.33/_build-debug/sql/sql_hints.yy.cc:72:25: note: expanded from macro 'yynerrs'
#define yynerrs         HINT_PARSER_nerrs
                        ^
1 error generated.
make[2]: *** [sql/CMakeFiles/sql_main.dir/sql_hints.yy.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/Users/laurynas/vilniusdb/mysql-8.0.33/_build-debug/sql/sql_yacc.cc:25005:9: error: variable 'MYSQLnerrs' set but not used [-Werror,-Wunused-but-set-variable]
    int yynerrs = 0;
        ^
/Users/laurynas/vilniusdb/mysql-8.0.33/_build-debug/sql/sql_yacc.cc:72:25: note: expanded from macro 'yynerrs'
#define yynerrs         MYSQLnerrs
                        ^

CMake (sql/CMakeLists.txt) already tries to disable this warning:

  IF(MY_COMPILER_IS_CLANG AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
    ADD_COMPILE_FLAGS(${CMAKE_CURRENT_BINARY_DIR}/sql_yacc.cc
                      ${CMAKE_CURRENT_BINARY_DIR}/sql_hints.yy.cc
                      COMPILE_FLAGS "-Wno-unused-but-set-variable")
  ENDIF()

But this does not work with Apple clang. The reason is that LLVM 15 codebase is used in XCode clang, which reports version 14.

$ clang --version 
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

How to repeat:
Build 8.0.33 with the latest XCode on macOS

Suggested fix:
One option is to have a precise check with both clang and AppleClang cases. But, in this case, the -Wunused-but-set-variable has been introduced in an older LLVM version, thus just replacing 15 with 14 in the CMake if condition will work just as well.
[2 May 2023 14:36] MySQL Verification Team
Hi Mr. Laurynas,

This is just to inform you that we have built entire MySQL 8.0.33 package for macOS in 5 (six) different versions, including the following ones:

* Debug
* Release
* MinSizeRel
* RelWithDebInfo
* Profile

We used 100 % the exact version of XCode and 100 % the same Clang compiler. We did not make any changes to the script.

We ran all these builds twice. Once for the Unix Makefile and once for the XCode.

Your error comes , most probably, from your CMake options, which are not correct. Hence, first check them out correctly. Also, lease use CMake 3.26.3.
[3 May 2023 6:30] Laurynas Biveinis
The CMake options are

-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DWITH_DEBUG=ON -DMYSQL_MAINTAINER_MODE=ON -DDOWNLOAD_BOOST=ON -DWITH_BOOST=~/vilniusdb/mysql-boost/ -DWITH_SYSTEM_LIBS=ON -DWITH_RAPIDJSON=bundled -DFORCE_COLORED_OUTPUT=ON -DWITH_DEVELOPER_ENTITLEMENTS=ON
[3 May 2023 12:46] MySQL Verification Team
Hi,

We use latest stable CMake GUI, we set the options correctly and we truly do not encounter any problems.

You are using your own options , which we do not support .....
[3 May 2023 12:59] MySQL Verification Team
Hi,

We shall still discuss it with relevant Dev teams, but we use the same software as you do and we do not encounter any of the problems that you hit.
[3 May 2023 13:15] Tor Didriksen
it is being fixed as we speak :)

note that you cannot in general expect a warning-free build for bleeding-edge compiler versions, I need to have those tools available myself in order to fix warnings. and then it takes a few months for that code to show up on github.

but thanks for the notice
[3 May 2023 13:22] MySQL Verification Team
Hi Mr. Biveinis,

This is just to inform you that 8.0 will soon  receive a push that will help in recognising the compiler version.

It might help in your case.

It will come up in 8.0.34 and it can be pulled during next week.

This is the info about a commit:

---------------------------------------
  Bug#34638573 Compile MySQL with clang 15 
    
   Additional patch for MacOS 
   The most recent clang identifies itself as 
     Apple clang version 14.0.3 (clang-1403.0.22.14.1) 
   but it is based on LLVM 15 
---------------------------------------

We must point out that some of us are using exactly the same compiler on macOS as you do and we have not problems what so ever .......
[3 May 2023 13:37] Laurynas Biveinis
Thank you Tor for the fix, of course I am not expecting that the existing codebase will build with the newest compilers without any warnings, and you have been great at tracking the newest compiler releases.

MySQL Verification Team, I have also reproduced this with the following CMake option, which is hopefully supported, maybe with a different path:
-DWITH_BOOST=~/vilniusdb/mysql-boost
In this case the build warning is non-fatal, so you have to scroll back the output to see it.

I have also reproduced it, fatally, with the following two options:
 -DWITH_BOOST=~/vilniusdb/mysql-boost -DMYSQL_MAINTAINER_MODE=ON 

Please let me know if WITH_BOOST or MYSQL_MAINTAINER_MODE are unsupported options, as at least one of them must be, and I'll file a bug at once to remove such dangerous thing, or at least document them at https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html as unsupported.
[3 May 2023 13:56] Tor Didriksen
"maintainer mode" will handle all warnings as errors, you need to switch it off for the time being when using Xcode 14.3