Skip to content

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Oct 26, 2023

Summary

This PR is a follow-up to #1451 and updates to the added .rc files:

  • Use MONGOC_OUTPUT_BASENAME and BSON_OUTPUT_BASENAME to define OriginalFilename
  • Use 2013 as copyright to match the project inception date taken from initial commit.
  • Generate .rc files with configure_file.

Verified with this patch: https://spruce.mongodb.com/version/653b0df40ae606a657a0ff91

Background & Motivation

Use of OUTPUT_BASENAME and updating the copyright date were identified in mongodb/mongo-cxx-driver#1046 when adding .rc files for the C++ driver.

Using configure_file

Generating the .rc files with configure_file was motivated by an observed issue with MinGW builds.

An initial attempt to pass BSON_OUTPUT_BASENAME set a quoted value in CMake:

set_source_files_properties (libbson.rc PROPERTIES COMPILE_DEFINITIONS BSON_OUTPUT_BASENAME="${BSON_OUTPUT_BASENAME}")

This worked for MSVC, but resulted in this error on MinGW.

C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin\windres.exe: C:\\data\\mci\\267100714150d40891944a5f1253aef3\\mongoc\\build-dir\\src\\libbson\\libbson.rc:32: syntax error

MinGW uses GNU windres as the resource compiler.

Using -DCMAKE_VERBOSE_MAKEFILE=ON showed the windres command included the argument -DBSON_OUTPUT_BASENAME=\"bson\":

cd /d C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson && C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin\windres.exe -O coff -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -Dbson_shared_EXPORTS -DBSON_OUTPUT_BASENAME=\"bson\" -I C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson\src -I C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\common  C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson\libbson.rc CMakeFiles\bson_shared.dir\libbson.rc.obj

Running the same windres command with --verbose showed the argument passed to the preprocessor command without backslashes (-DBSON_OUTPUT_BASENAME="bson"):

> cd /d C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson && C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin\windres.exe --verbose -O coff -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -Dbson_shared_EXPORTS -DBSON_OUTPUT_BASENAME=\"bson\" -I C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson\src -I C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\common  C:\cygwin\home\Administrator\code\tasks\ mongo-c-driver-C3091\build-dir\src\libbson\libbson.rc CMakeFiles\bson_shared.dir\libbson.rc.obj
Using `C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin\gcc -E -xc -DRC_INVOKED -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -Dbson_shared_EXPORTS -DBSON_OUTPUT_BASENAME="bson" -IC:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson\src -IC:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\common C:\cygwin\home\Administrator\code\tasks\mongo-c-driver-C3091\build-dir\src\libbson\libbson.rc'
Using popen to read preprocessor output
C:\mingw-w64\x86_64-4.9.1-posix-seh-rt_v3-rev1\mingw64\bin\windres.exe: C:\\cygwin\\home\\Administrator\\code\\tasks\\mongo-c-driver-C3091\\build-dir\\src\\libbson\\libbson.rc:32: syntax error

This resulted in the BSON_OUTPUT_BASENAME macro substituted without quotes:

VALUE "OriginalFilename", bson "-1.0.dll"

To work around, the configure_file is used to create the .rc files at configure time with variables substituted:

# In libbson.rc.in:
#define BSON_OUTPUT_BASENAME "@BSON_OUTPUT_BASENAME@"

windres handling of quoting is noted in https://sourceware.org/bugzilla/show_bug.cgi?id=27594#c2:

This means that any caller that wants to pass e.g. a define for a quoted string needs to escape quotes doubly

The MinGW resource compiler (windres) does not appear to keep quotes on arguments passed to the preprocessor.
@kevinAlbs kevinAlbs marked this pull request as ready for review October 27, 2023 12:56
@kevinAlbs kevinAlbs requested a review from eramongodb October 27, 2023 12:56
Copy link
Collaborator Author

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Latest commit verified with this patch: https://spruce.mongodb.com/version/653bd5b657e85a951471ce5a

@kevinAlbs kevinAlbs requested a review from eramongodb October 27, 2023 16:33
@kevinAlbs kevinAlbs requested a review from eramongodb October 27, 2023 17:49
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