Re-checking loader.rc file
authorCharles Giessen <charles@lunarg.com>
Thu, 26 Jan 2023 22:11:25 +0000 (15:11 -0700)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 27 Jan 2023 03:47:06 +0000 (20:47 -0700)
The loader.rc file is now checked into the source, and is automatically updated
by python whenever the headers are updated so that it contains the version used
to build the loader.

If BUILD_DLL_VERSIONINFO is set in the command line, then the loader will use
that version to configure a new loader.rc and place it in the build directory.
Then it will use that loader.rc rather than the checked in file. This allows
Vulkan Runtimes to be built with an exact version.

The file is checked in to allow builds without modifying the source directory
and allowing GN builds to not need any additional configuration to work.

CMakeLists.txt
cmake/generated_header_version.cmake
loader/CMakeLists.txt
loader/loader.rc [new file with mode: 0644]
loader/loader.rc.in
scripts/generate_source.py
scripts/known_good.json

index ef7b06c82e3d92f49808a9897e0ca933aa3c104d..9dea536631c1523b4764b39ec497869925b6249a 100644 (file)
@@ -325,7 +325,7 @@ if(PYTHONINTERP_FOUND)
                               --generated-version ${VulkanHeaders_VERSION}
                               --incremental)
 else()
-    message("WARNING: VulkanLoader_generated_source target requires python 3")
+    message(WARNING "VulkanLoader_generated_source target requires python 3")
 endif()
 
 if(UNIX)
index 0f62a5a979bc28a5b51e5d20b7511f36ab245378..afac2febaf3485a53023e9090b3a1c1110ee8f45 100644 (file)
@@ -1,3 +1,3 @@
 # *** THIS FILE IS GENERATED - DO NOT EDIT ***
 # See generate_source.py for modifications
-set(LOADER_GENERATED_HEADER_VERSION 1.3.239)
\ No newline at end of file
+set(LOADER_GENERATED_HEADER_VERSION 1.3.239)
index 1e43130535dc1264bfe38600fc06969140e739e8..a68fd5489ea303f23ec184c91d0988367a6e0c3a 100644 (file)
@@ -65,28 +65,24 @@ if(WIN32)
     separate_arguments(MODIFIED_C_FLAGS_DEBUG WINDOWS_COMMAND ${MODIFIED_C_FLAGS_DEBUG})
 
     # ~~~
-    # Setup the loader.rc flie to contain the correct info
-    # Optionally uses the BUILD_DLL_VERSIONINFO build option to allow setting the exact build version
-    # Adds "Dev Build" to any build without the BUILD_DLL_VERSIONINFO option set
+    # Only generate the loader.rc file with CMake if BUILD_DLL_VERSIONINFO was set.
+    # This feature is for the Vulkan Runtime build
+    # Otherwise rely on the checked in loader.rc from the python script
     # ~~~
-    string(TIMESTAMP CURRENT_YEAR "%Y")
-    set(LOADER_CUR_COPYRIGHT_STR "${CURRENT_YEAR}")
-    if ("$CACHE{BUILD_DLL_VERSIONINFO}" STREQUAL "")
-        set(LOADER_RC_VERSION "${VulkanHeaders_VERSION}")
-        set(LOADER_VER_FILE_VERSION_STR "\"${LOADER_RC_VERSION}.Dev Build\"")
-        set(LOADER_VER_FILE_DESCRIPTION_STR "\"Vulkan Loader - Dev Build\"")
-    else()
+    if (NOT "$CACHE{BUILD_DLL_VERSIONINFO}" STREQUAL "")
+        string(TIMESTAMP CURRENT_YEAR "%Y")
+        set(LOADER_CUR_COPYRIGHT_YEAR "${CURRENT_YEAR}")
         set(LOADER_RC_VERSION "$CACHE{BUILD_DLL_VERSIONINFO}")
         set(LOADER_VER_FILE_VERSION_STR "\"${LOADER_RC_VERSION}\"")
         set(LOADER_VER_FILE_DESCRIPTION_STR "\"Vulkan Loader\"")
-    endif()
 
-    # RC file wants the value of FILEVERSION to separated by commas
-    string(REPLACE "." ", " LOADER_VER_FILE_VERSION "${LOADER_RC_VERSION}")
+        # RC file wants the value of FILEVERSION to separated by commas
+        string(REPLACE "." ", " LOADER_VER_FILE_VERSION "${LOADER_RC_VERSION}")
 
-    # Configure the file to include the versioning info
-    # Place it in the current directory for check-in - so the GN build has up to date info
-    configure_file(loader.rc.in ${CMAKE_CURRENT_BINARY_DIR}/loader.rc)
+        # Configure the file to include the versioning info
+        # Place it in the build directory - the GN build will use the checked in file
+        configure_file(loader.rc.in ${CMAKE_CURRENT_BINARY_DIR}/loader.rc)
+    endif()
 else()
     # Used to make alloca() and secure_getenv() available
     target_compile_definitions(loader_specific_options INTERFACE _GNU_SOURCE)
@@ -268,12 +264,18 @@ if(WIN32)
     add_dependencies(loader-opt loader_asm_gen_files)
     set_target_properties(loader-opt PROPERTIES CMAKE_C_FLAGS_DEBUG "${MODIFIED_C_FLAGS_DEBUG}")
 
+    # If BUILD_DLL_VERSIONINFO was set, use the loader.rc in the build dir, otherwise use the checked in file
+    set(RC_FILE_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/loader.rc)
+    if (NOT "$CACHE{BUILD_DLL_VERSIONINFO}" STREQUAL "")
+        set(RC_FILE_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/loader.rc)
+    endif()
+
     add_library(vulkan
                 SHARED
                 ${NORMAL_LOADER_SRCS}
                 $<TARGET_OBJECTS:loader-unknown-chain>
                 ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-1.def
-                ${CMAKE_CURRENT_BINARY_DIR}/loader.rc)
+                ${RC_FILE_LOCATION})
 
     target_link_libraries(vulkan PRIVATE loader_specific_options loader-opt)
 
diff --git a/loader/loader.rc b/loader/loader.rc
new file mode 100644 (file)
index 0000000..0bef712
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// Copyright (c) 2014-2023 The Khronos Group Inc.
+// Copyright (c) 2014-2023 Valve Corporation
+// Copyright (c) 2014-2023 LunarG, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: David Pinedo <david@lunarg.com>
+// Author: Charles Giessen <charles@lunarg.com>
+//
+
+#include "winres.h"
+
+// All set through CMake
+#define VER_FILE_VERSION 1, 3, 239
+#define VER_FILE_DESCRIPTION_STR "1.3.239.Dev Build"
+#define VER_FILE_VERSION_STR "Vulkan Loader - Dev Build"
+#define VER_COPYRIGHT_STR "Copyright (C) 2015-2023"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION VER_FILE_VERSION
+ PRODUCTVERSION VER_FILE_VERSION
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0x0L
+#endif
+
+ FILEOS 0x00000L
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "04090000"
+        BEGIN
+            VALUE "FileDescription", VER_FILE_DESCRIPTION_STR
+            VALUE "FileVersion", VER_FILE_VERSION_STR
+            VALUE "LegalCopyright", VER_COPYRIGHT_STR
+            VALUE "ProductName", "Vulkan Runtime"
+            VALUE "ProductVersion", VER_FILE_VERSION_STR
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 0000
+    END
+END
index e242f9bb0ba73a7652a451f631737154ae727c83..0dc4227da250d774fb2a0ed4eb3532568b4c1ca7 100644 (file)
@@ -1,7 +1,7 @@
 //
-// Copyright (c) 2014-2023 The Khronos Group Inc.
-// Copyright (c) 2014-2023 Valve Corporation
-// Copyright (c) 2014-2023 LunarG, Inc.
+// Copyright (c) 2014-${LOADER_CUR_COPYRIGHT_YEAR} The Khronos Group Inc.
+// Copyright (c) 2014-${LOADER_CUR_COPYRIGHT_YEAR} Valve Corporation
+// Copyright (c) 2014-${LOADER_CUR_COPYRIGHT_YEAR} LunarG, Inc.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
 #define VER_FILE_VERSION ${LOADER_VER_FILE_VERSION}
 #define VER_FILE_DESCRIPTION_STR ${LOADER_VER_FILE_DESCRIPTION_STR}
 #define VER_FILE_VERSION_STR ${LOADER_VER_FILE_VERSION_STR}
-#define VER_COPYRIGHT_STR "Copyright (C) 2015-${LOADER_CUR_COPYRIGHT_STR}"
+#define VER_COPYRIGHT_STR "Copyright (C) 2015-${LOADER_CUR_COPYRIGHT_YEAR}"
 
 VS_VERSION_INFO VERSIONINFO
  FILEVERSION VER_FILE_VERSION
index 59cabaeaf7d8137900c15a1753774b9dda24f7ad..97d1ff47c720d21bce5b206dc5712b3efeaff0b3 100755 (executable)
@@ -26,6 +26,7 @@ import shutil
 import subprocess
 import sys
 import tempfile
+import datetime
 
 # files to exclude from --verify check
 verify_exclude = ['.clang-format']
@@ -112,9 +113,20 @@ def main(argv):
         f = open(common_codegen.repo_relative('cmake/generated_header_version.cmake'), "w")
         f.write('# *** THIS FILE IS GENERATED - DO NOT EDIT ***\n')
         f.write('# See generate_source.py for modifications\n')
-        f.write(f'set(LOADER_GENERATED_HEADER_VERSION {args.generated_version})')
+        f.write(f'set(LOADER_GENERATED_HEADER_VERSION {args.generated_version})\n')
         f.close()
 
+        with open(common_codegen.repo_relative('loader/loader.rc.in'), "r") as rc_file:
+            rc_file_contents = rc_file.read()
+        rc_ver = ', '.join(args.generated_version.split('.'))
+        rc_file_contents = rc_file_contents.replace('${LOADER_VER_FILE_VERSION}', f'{rc_ver}')
+        rc_file_contents = rc_file_contents.replace('${LOADER_VER_FILE_DESCRIPTION_STR}', f'"{args.generated_version}.Dev Build"')
+        rc_file_contents = rc_file_contents.replace('${LOADER_VER_FILE_VERSION_STR}', f'"Vulkan Loader - Dev Build"')
+        rc_file_contents = rc_file_contents.replace('${LOADER_CUR_COPYRIGHT_YEAR}', f'{datetime.date.today().year}')
+        with open(common_codegen.repo_relative('loader/loader.rc'), "w") as rc_file_out:
+            rc_file_out.write(rc_file_contents)
+            rc_file_out.close()
+
     return 0
 
 if __name__ == '__main__':
index 1a7b8581424bf288f505cf60f30993c40d51e451..dc20fa035f4211d3d09622f66f7f45b8a82face5 100644 (file)
@@ -41,4 +41,4 @@
         "googletest": "GOOGLETEST_INSTALL_DIR",
         "detours": "DETOURS_INSTALL_DIR"
     }
-}
\ No newline at end of file
+}