Embed git commit hash into binary (#2494)

This commit is contained in:
Thad House 2022-03-10 04:59:00 -08:00 коммит произвёл GitHub
Родитель 6b798e3447
Коммит 19f8b40367
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 92 добавлений и 23 удалений

Просмотреть файл

@ -32,7 +32,7 @@ jobs:
solution: msquic.kernel.sln
platform: ${{ parameters.arch }}
configuration: debug
msbuildArgs: /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=$(Build.BuildId)
msbuildArgs: /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=$(Build.BuildId) /p:QUIC_VER_GIT_HASH=$(Build.SourceVersion)
- task: VSBuild@1
displayName: Build Source Code (Release)
@ -41,6 +41,6 @@ jobs:
solution: msquic.kernel.sln
platform: ${{ parameters.arch }}
configuration: release
msbuildArgs: /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=$(Build.BuildId)
msbuildArgs: /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=$(Build.BuildId) /p:QUIC_VER_GIT_HASH=$(Build.SourceVersion)
- template: ./upload-artifacts.yml

Просмотреть файл

@ -89,6 +89,7 @@ option(QUIC_UWP_BUILD "Build for UWP" OFF)
option(QUIC_GAMECORE_BUILD "Build for GameCore" OFF)
option(QUIC_PGO "Enables profile guided optimizations" OFF)
option(QUIC_SOURCE_LINK "Enables source linking on MSVC" ON)
option(QUIC_EMBED_GIT_HASH "Embed git commit hash in the binary" ON)
option(QUIC_PDBALTPATH "Enable PDBALTPATH setting on MSVC" ON)
option(QUIC_CODE_CHECK "Run static code checkers" OFF)
option(QUIC_OPTIMIZE_LOCAL "Optimize code for local machine architecture" OFF)
@ -123,6 +124,15 @@ if (QUIC_PDBALTPATH AND MSVC)
# message(STATUS ${CMAKE_EXE_LINKER_FLAGS})
endif()
include(${PROJECT_SOURCE_DIR}/cmake/GitCommands.cmake)
get_git_current_hash(${PROJECT_SOURCE_DIR} GIT_CURRENT_HASH)
if(NOT GIT_CURRENT_HASH)
message("Failed to get git hash. Binary will not contain git hash")
set(QUIC_SOURCE_LINK OFF)
set(QUIC_EMBED_GIT_HASH OFF)
endif()
if (QUIC_SOURCE_LINK AND MSVC)
if ("${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER_EQUAL "19.20")
include(${PROJECT_SOURCE_DIR}/cmake/SourceLink.cmake)
@ -153,8 +163,6 @@ else ()
set(QUIC_PGO_DIR ${QUIC_BUILD_DIR}/PGO)
endif ()
message(STATUS "QUIC PGO DIR: ${QUIC_PGO_DIR}")
set(QUIC_VER_BUILD_ID "0" CACHE STRING "The version build ID")
set(QUIC_VER_SUFFIX "-private" CACHE STRING "The version suffix")
@ -289,6 +297,10 @@ endif()
list(APPEND QUIC_COMMON_DEFINES VER_BUILD_ID=${QUIC_VER_BUILD_ID})
list(APPEND QUIC_COMMON_DEFINES VER_SUFFIX=${QUIC_VER_SUFFIX})
if (QUIC_EMBED_GIT_HASH)
list(APPEND QUIC_COMMON_DEFINES VER_GIT_HASH=${GIT_CURRENT_HASH})
endif()
if(QUIC_TELEMETRY_ASSERTS)
list(APPEND QUIC_COMMON_DEFINES QUIC_TELEMETRY_ASSERTS=1)
endif()

Просмотреть файл

@ -1,9 +1,9 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
find_package(Git REQUIRED QUIET)
find_package(Git QUIET)
if (NOT Git_FOUND)
message(FATAL_ERROR "Unable to find git, which is needed for versioning")
message(STATUS "Unable to find git, which is needed for versioning")
endif()
function(get_git_dir DIRECTORY OUTPUT_VAR)
@ -38,11 +38,11 @@ function(get_git_current_hash DIRECTORY OUTPUT_VAR)
)
if (NOT ("${GIT_CURRENT_HASH_RESULT}" STREQUAL "0"))
message(${GIT_CURRENT_HASH_OUTPUT})
message(FATAL_ERROR "Failed to get ${DIRECTORY} git hash")
message(STATUS ${GIT_CURRENT_HASH_OUTPUT})
message(STATUS "Failed to get ${DIRECTORY} git hash")
else()
set(${OUTPUT_VAR} ${GIT_CURRENT_HASH_OUTPUT} PARENT_SCOPE)
endif()
set(${OUTPUT_VAR} ${GIT_CURRENT_HASH_OUTPUT} PARENT_SCOPE)
endfunction()
function(get_git_remote_url DIRECTORY OUTPUT_VAR)

Просмотреть файл

@ -88,6 +88,7 @@ These parameters are accessed by calling [GetParam](./api/GetParam.md) or [SetPa
| `QUIC_PARAM_GLOBAL_SETTINGS`<br> 5 | QUIC_SETTINGS | Both | Globally change settings for all subsequent connections. |
| `QUIC_PARAM_GLOBAL_GLOBAL_SETTINGS`<br> 6 | QUIC_GLOBAL_SETTINGS | Both | Globally change global only settings. |
| `QUIC_PARAM_GLOBAL_VERSION_SETTINGS`<br> 7 | QUIC_VERSIONS_SETTINGS | Both | Globally change version settings for all subsequent connections. |
| `QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH`<br> 8 | char[64] | Get-only | Git hash used to build MsQuic (null terminated string) |
### Registration Parameters

Просмотреть файл

@ -13,7 +13,6 @@ fn main() {
// Builds the native MsQuic and installs it into $OUT_DIR.
let dst = Config::new(".")
.define("QUIC_SOURCE_LINK", "off")
.define("QUIC_ENABLE_LOGGING", logging_enabled)
.define("QUIC_TLS", "openssl")
.define("QUIC_OUTPUT_DIR", "../lib")

Просмотреть файл

@ -1,3 +1,3 @@
call C:\ewdk\BuildEnv\SetupBuildEnv.cmd
msbuild msquic.kernel.sln -t:restore -p:RestorePackagesConfig=true /p:Configuration=%1 /p:Platform=%2
msbuild msquic.kernel.sln -p:ONEBRANCH_BUILD=true /p:Configuration=%1 /p:Platform=%2 /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=%BUILD_BUILDID%
msbuild msquic.kernel.sln -p:ONEBRANCH_BUILD=true /p:Configuration=%1 /p:Platform=%2 /p:QUIC_VER_SUFFIX=-official /p:QUIC_VER_BUILD_ID=%BUILD_BUILDID% /p:QUIC_VER_GIT_HASH=%BUILD_SOURCEVERSION%

Просмотреть файл

@ -66,10 +66,11 @@
<PropertyGroup>
<QUIC_VER_BUILD_ID Condition="'$(QUIC_VER_BUILD_ID)' == ''">0</QUIC_VER_BUILD_ID>
<QUIC_VER_SUFFIX Condition="'$(QUIC_VER_SUFFIX)' == ''">-private</QUIC_VER_SUFFIX>
<QUIC_VER_GIT_HASH Condition="'$(QUIC_VER_GIT_HASH)' == ''">0</QUIC_VER_GIT_HASH>
</PropertyGroup>
<ItemGroup>
<ResourceCompile Include="msquic.rc">
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemGroup>
<PropertyGroup>
@ -106,12 +107,12 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

Просмотреть файл

@ -66,10 +66,11 @@
<PropertyGroup>
<QUIC_VER_BUILD_ID Condition="'$(QUIC_VER_BUILD_ID)' == ''">0</QUIC_VER_BUILD_ID>
<QUIC_VER_SUFFIX Condition="'$(QUIC_VER_SUFFIX)' == ''">-private</QUIC_VER_SUFFIX>
<QUIC_VER_GIT_HASH Condition="'$(QUIC_VER_GIT_HASH)' == ''">0</QUIC_VER_GIT_HASH>
</PropertyGroup>
<ItemGroup>
<ResourceCompile Include="msquicpriv.rc">
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemGroup>
<PropertyGroup>

Просмотреть файл

@ -120,6 +120,11 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<QUIC_VER_BUILD_ID Condition="'$(QUIC_VER_BUILD_ID)' == ''">0</QUIC_VER_BUILD_ID>
<QUIC_VER_SUFFIX Condition="'$(QUIC_VER_SUFFIX)' == ''">-private</QUIC_VER_SUFFIX>
<QUIC_VER_GIT_HASH Condition="'$(QUIC_VER_GIT_HASH)' == ''">0</QUIC_VER_GIT_HASH>
</PropertyGroup>
<PropertyGroup>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
@ -150,13 +155,13 @@
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;QUIC_TELEMETRY_ASSERTS=1;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
</ItemDefinitionGroup>

Просмотреть файл

@ -55,6 +55,7 @@ MsQuicLibraryLoad(
MsQuicLib.Version[1] = VER_MINOR;
MsQuicLib.Version[2] = VER_PATCH;
MsQuicLib.Version[3] = VER_BUILD_ID;
MsQuicLib.GitHash = VER_GIT_HASH_STR;
}
}
@ -957,6 +958,7 @@ QuicLibraryGetGlobalParam(
)
{
QUIC_STATUS Status;
uint32_t GitHashLength;
switch (Param) {
case QUIC_PARAM_GLOBAL_RETRY_MEMORY_PERCENT:
@ -1081,6 +1083,27 @@ QuicLibraryGetGlobalParam(
Status = QUIC_STATUS_SUCCESS;
break;
case QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH:
GitHashLength = (uint32_t)strlen(MsQuicLib.GitHash) + 1;
if (*BufferLength < GitHashLength) {
*BufferLength = GitHashLength;
Status = QUIC_STATUS_BUFFER_TOO_SMALL;
break;
}
if (Buffer == NULL) {
Status = QUIC_STATUS_INVALID_PARAMETER;
break;
}
*BufferLength = GitHashLength;
CxPlatCopyMemory(Buffer, MsQuicLib.GitHash, GitHashLength);
Status = QUIC_STATUS_SUCCESS;
break;
default:
Status = QUIC_STATUS_INVALID_PARAMETER;
break;

Просмотреть файл

@ -116,6 +116,11 @@ typedef struct QUIC_LIBRARY {
//
uint32_t Version[4];
//
// Binary Git Hash
//
const char* GitHash;
//
// Configurable (app & registry) settings.
//

Просмотреть файл

@ -2549,6 +2549,9 @@ namespace Microsoft.Quic
[NativeTypeName("#define QUIC_PARAM_GLOBAL_VERSION_SETTINGS 0x01000007")]
public const int QUIC_PARAM_GLOBAL_VERSION_SETTINGS = 0x01000007;
[NativeTypeName("#define QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH 0x01000008")]
public const int QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH = 0x01000008;
[NativeTypeName("#define QUIC_PARAM_CONFIGURATION_SETTINGS 0x03000000")]
public const int QUIC_PARAM_CONFIGURATION_SETTINGS = 0x03000000;

Просмотреть файл

@ -703,6 +703,7 @@ void
#define QUIC_PARAM_GLOBAL_GLOBAL_SETTINGS 0x01000006 // QUIC_GLOBAL_SETTINGS
#ifdef QUIC_API_ENABLE_PREVIEW_FEATURES
#define QUIC_PARAM_GLOBAL_VERSION_SETTINGS 0x01000007 // QUIC_VERSION_SETTINGS
#define QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH 0x01000008 // char[64]
#endif
//

Просмотреть файл

@ -23,6 +23,14 @@
#define VER_SUFFIX -private
#endif
#ifndef VER_GIT_HASH
#define VER_GIT_HASH_STR "Unknown"
#else
#define STR_HELPER_GIT_VER(x) #x
#define STR_GIT_VER(x) STR_HELPER_GIT_VER(x)
#define VER_GIT_HASH_STR STR_GIT_VER(VER_GIT_HASH)
#endif
#ifndef QUIC_VERSION_ONLY
#define VER_COMPANYNAME_STR "Microsoft Corporation"

Просмотреть файл

@ -553,14 +553,19 @@ pub const PARAM_GLOBAL_RETRY_MEMORY_PERCENT: u32 = 0x01000000;
pub const PARAM_GLOBAL_SUPPORTED_VERSIONS: u32 = 0x01000001;
pub const PARAM_GLOBAL_LOAD_BALACING_MODE: u32 = 0x01000002;
pub const PARAM_GLOBAL_PERF_COUNTERS: u32 = 0x01000003;
pub const PARAM_GLOBAL_SETTINGS: u32 = 0x01000004;
pub const PARAM_GLOBAL_VERSION: u32 = 0x01000005;
pub const PARAM_GLOBAL_VERSION: u32 = 0x01000004;
pub const PARAM_GLOBAL_SETTINGS: u32 = 0x01000005;
pub const PARAM_GLOBAL_GLOBAL_SETTINGS: u32 = 0x01000006;
pub const PARAM_GLOBAL_VERSION_SETTINGS: u32 = 0x01000007;
pub const PARAM_GLOBAL_LIBRARY_GIT_HASH: u32 = 0x01000008;
pub const PARAM_CONFIGURATION_SETTINGS: u32 = 0x03000000;
pub const PARAM_CONFIGURATION_TICKET_KEYS: u32 = 0x03000001;
pub const PARAM_CONFIGURATION_VERSION_SETTINGS: u32 = 0x03000002;
pub const PARAM_LISTENER_LOCAL_ADDRESS: u32 = 0x04000000;
pub const PARAM_LISTENER_STATS: u32 = 0x04000001;
pub const PARAM_LISTENER_CIBIR_ID: u32 = 0x04000002;
pub const PARAM_CONN_QUIC_VERSION: u32 = 0x05000000;
pub const PARAM_CONN_LOCAL_ADDRESS: u32 = 0x05000001;

Просмотреть файл

@ -58,6 +58,11 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<QUIC_VER_BUILD_ID Condition="'$(QUIC_VER_BUILD_ID)' == ''">0</QUIC_VER_BUILD_ID>
<QUIC_VER_SUFFIX Condition="'$(QUIC_VER_SUFFIX)' == ''">-private</QUIC_VER_SUFFIX>
<QUIC_VER_GIT_HASH Condition="'$(QUIC_VER_GIT_HASH)' == ''">0</QUIC_VER_GIT_HASH>
</PropertyGroup>
<PropertyGroup>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
@ -92,13 +97,13 @@ mc.exe -um -h $(SolutionDir)build\winkernel\$(Platform)_$(Configuration)_schanne
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;SECURITY_KERNEL;SECURITY_WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>VER_BUILD_ID=$(QUIC_VER_BUILD_ID);VER_SUFFIX=$(QUIC_VER_SUFFIX);VER_GIT_HASH=$(QUIC_VER_GIT_HASH);QUIC_EVENTS_MANIFEST_ETW;QUIC_LOGS_MANIFEST_ETW;SECURITY_KERNEL;SECURITY_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
</ItemDefinitionGroup>

Просмотреть файл

@ -479,7 +479,7 @@ void SpinQuicSetRandomStreamParam(HQUIC Stream)
}
const uint32_t ParamCounts[] = {
QUIC_PARAM_GLOBAL_VERSION_SETTINGS + 1,
QUIC_PARAM_GLOBAL_LIBRARY_GIT_HASH + 1,
0,
QUIC_PARAM_CONFIGURATION_VERSION_SETTINGS + 1,
QUIC_PARAM_LISTENER_CIBIR_ID + 1,