From 0beb75ce772d11f71047ff622ca9315618361f3f Mon Sep 17 00:00:00 2001 From: Ori Levari Date: Fri, 7 Feb 2020 11:00:28 -0800 Subject: [PATCH] populate file metadata for onnxruntime.dll (#2978) --- cmake/CMakeLists.txt | 7 ++++- cmake/onnxruntime.cmake | 12 +++++++- cmake/winml.cmake | 17 ++++------- onnxruntime/core/dll/onnxruntime.rc | 45 +++++++++++++++++++++++++++++ tools/ci_build/build.py | 33 +++++++++++++++++++++ winml/dll/winml.rc | 3 ++ 6 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 onnxruntime/core/dll/onnxruntime.rc diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9b80c1c433..d9094007e2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -823,7 +823,12 @@ else() list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads) endif() - +# Default version parts for Windows.AI.MachineLearning.dll and onnxruntime.dll in non-ADO pipeline local builds +set(VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.") +set(VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product version.") +set(VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.") +set(VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.") +set(VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.") if (onnxruntime_USE_WINML) # WINML uses and depends on the shared lib. Note: You can build WINML without DML and you will get a diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 6f0e9b0f17..5e92b72166 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -26,7 +26,11 @@ add_custom_command(OUTPUT ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_s add_custom_target(onnxruntime_generate_def ALL DEPENDS ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c) if(WIN32) - add_library(onnxruntime SHARED ${SYMBOL_FILE} "${ONNXRUNTIME_ROOT}/core/dll/dllmain.cc") + add_library(onnxruntime SHARED + ${SYMBOL_FILE} + "${ONNXRUNTIME_ROOT}/core/dll/dllmain.cc" + "${ONNXRUNTIME_ROOT}/core/dll/onnxruntime.rc" + ) else() add_library(onnxruntime SHARED ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c) endif() @@ -36,6 +40,12 @@ add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEP target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT}) onnxruntime_add_include_to_target(onnxruntime) +target_compile_definitions(onnxruntime PRIVATE VER_MAJOR=${VERSION_MAJOR_PART}) +target_compile_definitions(onnxruntime PRIVATE VER_MINOR=${VERSION_MINOR_PART}) +target_compile_definitions(onnxruntime PRIVATE VER_BUILD=${VERSION_BUILD_PART}) +target_compile_definitions(onnxruntime PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART}) +target_compile_definitions(onnxruntime PRIVATE VER_STRING=\"${VERSION_STRING}\") + if (onnxruntime_USE_CUDA) target_include_directories(onnxruntime PRIVATE ${onnxruntime_CUDNN_HOME}/include ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) endif() diff --git a/cmake/winml.cmake b/cmake/winml.cmake index d3814c5949..4b245b7db7 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -18,13 +18,6 @@ set(winml_lib_api_ort_dir ${REPO_ROOT}/winml/lib/api.ort) set(winml_lib_common_dir ${REPO_ROOT}/winml/lib/common) set(winml_lib_telemetry_dir ${REPO_ROOT}/winml/lib/telemetry) -# Version parts for Windows.AI.MachineLearning.dll. -set(WINML_VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.") -set(WINML_VERSION_MINOR_PART 0 CACHE STRING "Second part of numeric file/product version.") -set(WINML_VERSION_BUILD_PART 0 CACHE STRING "Third part of numeric file/product version.") -set(WINML_VERSION_PRIVATE_PART 0 CACHE STRING "Fourth part of numeric file/product version.") -set(WINML_VERSION_STRING "Internal Build" CACHE STRING "String representation of file/product version.") - get_filename_component(exclusions "${winml_api_root}/exclusions.txt" ABSOLUTE) convert_forward_slashes_to_back(${exclusions} CPPWINRT_COMPONENT_EXCLUSION_LIST) @@ -516,11 +509,11 @@ target_compile_definitions(winml_dll PRIVATE ONNX_ML) target_compile_definitions(winml_dll PRIVATE LOTUS_LOG_THRESHOLD=2) target_compile_definitions(winml_dll PRIVATE LOTUS_ENABLE_STDERR_LOGGING) target_compile_definitions(winml_dll PRIVATE PLATFORM_WINDOWS) -target_compile_definitions(winml_dll PRIVATE VER_MAJOR=${WINML_VERSION_MAJOR_PART}) -target_compile_definitions(winml_dll PRIVATE VER_MINOR=${WINML_VERSION_MINOR_PART}) -target_compile_definitions(winml_dll PRIVATE VER_BUILD=${WINML_VERSION_BUILD_PART}) -target_compile_definitions(winml_dll PRIVATE VER_PRIVATE=${WINML_VERSION_PRIVATE_PART}) -target_compile_definitions(winml_dll PRIVATE VER_STRING=\"${WINML_VERSION_STRING}\") +target_compile_definitions(winml_dll PRIVATE VER_MAJOR=${VERSION_MAJOR_PART}) +target_compile_definitions(winml_dll PRIVATE VER_MINOR=${VERSION_MINOR_PART}) +target_compile_definitions(winml_dll PRIVATE VER_BUILD=${VERSION_BUILD_PART}) +target_compile_definitions(winml_dll PRIVATE VER_PRIVATE=${VERSION_PRIVATE_PART}) +target_compile_definitions(winml_dll PRIVATE VER_STRING=\"${VERSION_STRING}\") # Specify the usage of a precompiled header target_precompiled_header(winml_dll pch.h) diff --git a/onnxruntime/core/dll/onnxruntime.rc b/onnxruntime/core/dll/onnxruntime.rc new file mode 100644 index 0000000000..7ff2dfa026 --- /dev/null +++ b/onnxruntime/core/dll/onnxruntime.rc @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This file REQUIRES the following external definitions: +// VER_MAJOR, VER_MINOR, VER_BUILD, VER_PRIVATE, and VER_STRING + +#include + +#if defined(DEBUG) || defined(_DEBUG) +#define VER_DEBUG VS_FF_DEBUG +#else +#define VER_DEBUG 0 +#endif + +// ----------------------------------------------------------------------------- + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VER_MAJOR, VER_MINOR, VER_BUILD, VER_PRIVATE +PRODUCTVERSION VER_MAJOR, VER_MINOR, VER_BUILD, VER_PRIVATE +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS VER_DEBUG +FILEOS VOS__WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "CompanyName", "Microsoft Corporation" + VALUE "FileDescription", "ONNX Runtime" + VALUE "FileVersion", VER_STRING + VALUE "InternalName", "ONNX Runtime" + VALUE "LegalCopyright", "\251 Microsoft Corporation. All rights reserved." + VALUE "OriginalFilename", "onnxruntime.dll" + VALUE "ProductName", "Microsoft\256 Windows\256 Operating System" + VALUE "ProductVersion", VER_STRING + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END \ No newline at end of file diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index b2ce4914b9..ff9d032bc6 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -376,6 +376,39 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home if is_windows(): cmake_args += cmake_extra_args + # ADO pipelines will store the pipeline build number (e.g. 191101-2300.1.master) and + # source version in environment variables. If present, use these values to define the + # WinML/ORT DLL versions. + build_number = os.getenv('Build_BuildNumber') + source_version = os.getenv('Build_SourceVersion') + if build_number and source_version: + build_matches = re.match(r"^(\d\d)(\d\d)(\d\d)-(\d\d)(\d\d)\.(\d)\.(\S+)$", build_number) + if build_matches: + YY = build_matches.group(1) + MM = build_matches.group(2) + DD = build_matches.group(3) + HH = build_matches.group(4) + + # Get ORT major and minor number + with open(os.path.join(source_dir, 'VERSION_NUMBER')) as f: + first_line = f.readline() + ort_version_matches = re.match(r"(\d+).(\d+)", first_line) + if not ort_version_matches: + raise BuildError("Couldn't read version from VERSION_FILE") + ort_major = ort_version_matches.group(1) + ort_minor = ort_version_matches.group(2) + # Example (BuildNumber: 191101-2300.1.master, SourceVersion: 0bce7ae6755c792eda558e5d27ded701707dc404) + # MajorPart = 1 + # MinorPart = 0 + # BuildPart = 1911 + # PrivatePart = 123 + # String = 191101-2300.1.master.0bce7ae + cmake_args += ["-DVERSION_MAJOR_PART={}".format(ort_major), + "-DVERSION_MINOR_PART={}".format(ort_minor), + "-DVERSION_BUILD_PART={}{}".format(YY, MM), + "-DVERSION_PRIVATE_PART={}{}".format(DD, HH), + "-DVERSION_STRING={}.{}.{}.{}".format(ort_major, ort_minor, build_number, source_version[0:7])] + for config in configs: config_build_dir = get_config_build_dir(build_dir, config) os.makedirs(config_build_dir, exist_ok=True) diff --git a/winml/dll/winml.rc b/winml/dll/winml.rc index 50fdaf0f45..9027e5d607 100644 --- a/winml/dll/winml.rc +++ b/winml/dll/winml.rc @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + // This file REQUIRES the following external definitions: // VER_MAJOR, VER_MINOR, VER_BUILD, VER_PRIVATE, and VER_STRING