Generate map files (#3181)

* Generate map files in build

* Add .map file artifact publishing

* Add Xlinker to spelling exceptions

* Remove PublishMapFiles from clang builds

* Generate the map file artifact name

* CXX_COMPILER_ID and some logging for Clang which might be linking using the GNU linker by default

* More logging

* Move logging out of conditional

* Logging up high, use OS to determine which link flags to set

* Use linker options specific to AppleClang's context, publish map files for all platforms
This commit is contained in:
Daniel Jurek 2022-01-03 13:56:41 -08:00 committed by GitHub
parent 468b84c170
commit fa0fa97155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 98 additions and 10 deletions

3
.vscode/cspell.json vendored
View File

@ -170,7 +170,8 @@
"fprofile",
"ftest",
"mathjax",
"mdfile"
"mdfile",
"Xlinker"
]
}
],

View File

@ -84,6 +84,9 @@ endif()
# compiler warning flags globally
include(AzureGlobalCompileOptions)
# Add create_map_file function
include(CreateMapFile)
# Documentation automation function
include(AzureDoxygen)

View File

@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Instructs linker to generate map files and optimize build for minimal size
# Requires CMake version >= 3.13 to use add_link_options
function(create_map_file TARGET_NAME MAP_FILE_NAME)
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13")
if(MSVC)
target_link_options(${TARGET_NAME} PRIVATE /MAP)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
target_link_options(${TARGET_NAME} PRIVATE LINKER:SHELL:-Wl,-map,${MAP_FILE_NAME})
target_link_options(${TARGET_NAME} PRIVATE -Os)
else()
target_link_options(${TARGET_NAME} PRIVATE -Xlinker -Map=${MAP_FILE_NAME})
target_link_options(${TARGET_NAME} PRIVATE -Os)
endif()
else()
message("Skipping map file generation because CMake version does not support target_link_options")
endif()
endfunction()

View File

@ -200,3 +200,28 @@ jobs:
# Minimum baseline for branch coverage
coverageThreshold: ${{ parameters.BranchCoverageTarget }}
condition: and(succeededOrFailed(), eq(variables['CODE_COVERAGE'], 'enabled'), eq(variables['Skip.BranchCoverageEnforcement'], ''))
# Use the job name to create the artifact name for MAP file publishing.
# "Validate Windows2019_UWP_debug_x86" -> "Windows2019_UWP_debug_x86"
- pwsh: |
$artifactName = '$(Agent.JobName)'
$parts = $artifactName -split ' '
if ($parts[1]) {
$artifactName = $parts[1]
}
Write-Host "##vso[task.setvariable variable=MapFileArtifactName;]$artifactName"
displayName: Set map file artifact name
condition: eq(variables['PublishMapFiles'], 'true')
- task: CopyFiles@2
inputs:
contents: "**/*.map"
targetFolder: $(Build.ArtifactStagingDirectory)
flattenFolders: true
condition: eq(variables['PublishMapFiles'], 'true')
- task: PublishPipelineArtifact@1
inputs:
artifactName: map-files-$(MapFileArtifactName)
path: $(Build.ArtifactStagingDirectory)
condition: eq(variables['PublishMapFiles'], 'true')

View File

@ -19,7 +19,8 @@
"VcpkgInstall": "curl[ssl] libxml2 openssl",
"BuildArgs": "-j 10",
"VCPKG_DEFAULT_TRIPLET": "x64-osx",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON"
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON",
"PublishMapFiles": "true"
}
},
"BuildConfig": {
@ -48,11 +49,13 @@
"Win32Api_release_curl": {
"VcpkgInstall": "curl[winssl]",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON",
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"PublishMapFiles": "true"
},
"Win32Api_debug_tests": {
"VcpkgInstall": "curl[winssl]",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON"
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON",
"PublishMapFiles": "true"
}
},
"TargetArchitecture": {
@ -73,7 +76,8 @@
"Pool": "azsdk-pool-mms-win-2019-general",
"BuildArgs": "--parallel 8",
"CMAKE_GENERATOR": "Visual Studio 16 2019",
"CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON"
"CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON",
"PublishMapFiles": "true"
}
},
"TargetPlatform": {
@ -126,15 +130,18 @@
"AptDependencies": "gcovr lcov",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_CODE_COVERAGE=ON -DCMAKE_VERBOSE_MAKEFILE=ON",
"CODE_COVERAGE_COLLECT_ONLY": "1",
"CODE_COVERAGE": "enabled"
"CODE_COVERAGE": "enabled",
"PublishMapFiles": "true"
},
"included": {},
"included_release": {
"CMAKE_BUILD_TYPE": "Release",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON"
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON",
"PublishMapFiles": "true"
},
"included_samples": {
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_SAMPLES=ON -DBUILD_STORAGE_SAMPLES=ON"
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_SAMPLES=ON -DBUILD_STORAGE_SAMPLES=ON",
"PublishMapFiles": "true"
}
}
},
@ -148,7 +155,8 @@
"BuildArgs": "-j 10",
"CC": "/usr/bin/clang-11",
"CXX": "/usr/bin/clang++-11",
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON"
"CmakeArgs": " -DBUILD_TESTING=ON -DBUILD_PERFORMANCE_TESTS=ON -DRUN_LONG_UNIT_TESTS=ON",
"PublishMapFiles": "true"
}
},
"BuildSettings": {

View File

@ -48,3 +48,4 @@ target_include_directories (azure-core-test-fw
# make sure that users can consume the project as a library.
add_library (Azure::Core::Test ALIAS azure-core-test-fw)
target_link_libraries(azure-core-test-fw PRIVATE azure-core gtest)
create_map_file(azure-core-test-fw azure-core-test-fw.map)

View File

@ -15,3 +15,5 @@ add_executable (
)
target_link_libraries(azure-core-test-fault-injector PRIVATE azure-core)
create_map_file(azure-core-test-fault-injector azure-core-test-fault-injector.map)

View File

@ -100,11 +100,16 @@ target_include_directories (azure-core-test PRIVATE $<BUILD_INTERFACE:${CMAKE_CU
target_link_libraries(azure-core-test PRIVATE azure-core gtest gmock)
create_map_file(azure-core-test azure-core-test.map)
## Global context test
add_executable (
azure-core-global-context-test
global_context_test.cpp
)
create_map_file(azure-core-global-context-test azure-core-global-context-test.map)
if (MSVC)
# Disable gtest warnings for MSVC
target_compile_options(azure-core-global-context-test PUBLIC /wd26495 /wd26812 /wd6326 /wd28204 /wd28020 /wd6330 /wd4389)
@ -128,6 +133,8 @@ if(BUILD_TRANSPORT_CURL)
azure_libcurl_core_main_test.cpp
)
create_map_file(azure-core-libcurl-test azure-core-libcurl-test.map)
if (MSVC)
# warning C4389: '==': signed/unsigned mismatch
# warning C6326: Google comparisons

View File

@ -50,6 +50,7 @@ endif()
# make sure that users can consume the project as a library.
add_library (Azure::Perf ALIAS azure-perf)
target_link_libraries(azure-perf PUBLIC azure-core)
create_map_file(azure-perf azure-perf.map)
set_target_properties(azure-perf PROPERTIES FOLDER "Core")

View File

@ -29,6 +29,8 @@ add_executable (
${AZURE_PERF_TEST_HEADER} ${AZURE_PERF_TEST_SOURCE}
)
create_map_file(azure-perf-test azure-perf-test.map)
# Include the headers from the project.
target_include_directories(
azure-perf-test

View File

@ -11,5 +11,5 @@ add_executable (
azure-identity-e2e-test
azure_identity_e2e_test.cpp
)
create_map_file(azure-identity-e2e-test azure-identity-e2e-test.map)
target_link_libraries(azure-identity-e2e-test PRIVATE azure-identity)

View File

@ -23,6 +23,8 @@ add_executable (
${AZURE_IDENTITY_PERF_TEST_HEADER} ${AZURE_IDENTITY_PERF_TEST_SOURCE}
)
create_map_file(azure-identity-perf azure-identity-perf.map)
# Include the headers from the project.
target_include_directories(
azure-identity-perf

View File

@ -27,6 +27,8 @@ add_executable (
token_credential_test.cpp
)
create_map_file(azure-identity-test azure-identity-test.map)
if (MSVC)
# Disable warnings:
# - C26495: Variable

View File

@ -18,6 +18,8 @@ add_executable (
certificate_client_test.cpp
certificate_client_base_test.hpp)
create_map_file(azure-security-keyvault-certificates-test azure-security-keyvault-certificates-test.map)
if (MSVC)
target_compile_options(azure-security-keyvault-certificates-test PUBLIC /wd6326 /wd26495 /wd26812 /wd4389)
endif()

View File

@ -23,6 +23,8 @@ add_executable (
${AZURE_KEYVAULT_KEY_PERF_TEST_HEADER} ${AZURE_KEYVAULT_KEY_PERF_TEST_SOURCE}
)
create_map_file(azure-security-keyvault-keys-perf azure-security-keyvault-keys-perf.map)
# Include the headers from the project.
target_include_directories(
azure-security-keyvault-keys-perf

View File

@ -30,6 +30,8 @@ add_executable (
mocked_transport_adapter_test.hpp
)
create_map_file(azure-security-keyvault-keys-test azure-security-keyvault-keys-test.map)
if (MSVC)
target_compile_options(azure-security-keyvault-keys-test PUBLIC /wd6326 /wd26495 /wd26812)
endif()

View File

@ -13,6 +13,8 @@ add_executable (
macro_guard.cpp
)
create_map_file(keyvault-secrets-test-app keyvault-secrets-test-app.map)
if (MSVC)
target_compile_options(keyvault-secrets-test-app PUBLIC /wd6326 /wd26495 /wd26812)
endif()

View File

@ -26,6 +26,8 @@ add_executable (
secret_paged_deserialize_test.hpp
secret_client_base_test.hpp)
create_map_file(azure-security-keyvault-secrets-test azure-security-keyvault-secrets-test.map)
if (MSVC)
target_compile_options(azure-security-keyvault-secrets-test PUBLIC /wd6326 /wd26495 /wd26812)
endif()

View File

@ -14,6 +14,7 @@ if(BUILD_TESTING)
endif()
add_executable(azure-storage-test)
create_map_file(azure-storage-test azure-storage-test.map)
add_gtest(azure-storage-test)
endif()

View File

@ -17,6 +17,8 @@ add_executable (
ut/template_test.cpp
)
create_map_file(azure-template-test azure-template-test.map)
target_link_libraries(azure-template-test PRIVATE Azure::azure-template gtest_main)
if (MSVC)