Skip to content

Commit

Permalink
Save generated CLOG files in Repo, use them for linux build (#1845)
Browse files Browse the repository at this point in the history
* Pregenerate clog files

This removes the build time dependency on clog, which removes the build time dependency on .NET

* Add a few missing logs, cleanup

* Fixup linux build

* Make linux builds default to parallel

* Only install clog for dev, fix builds without logging

* Only link include dirs to logged programs
  • Loading branch information
thhous-msft authored Jul 23, 2021
1 parent 6ee2ec9 commit b00fb5e
Show file tree
Hide file tree
Showing 299 changed files with 55,442 additions and 168 deletions.
35 changes: 3 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,9 @@ if(WIN32)

if(QUIC_ENABLE_LOGGING)
message(STATUS "Configuring for manifested ETW tracing")
set(CMAKE_CLOG_CONFIG_PROFILE windows)
list(APPEND QUIC_COMMON_DEFINES QUIC_EVENTS_MANIFEST_ETW QUIC_LOGS_MANIFEST_ETW)
else()
message(STATUS "Disabling tracing")
set(CMAKE_CLOG_CONFIG_PROFILE stubs)
list(APPEND QUIC_COMMON_DEFINES QUIC_EVENTS_STUB QUIC_LOGS_STUB)
endif()

Expand Down Expand Up @@ -368,24 +366,17 @@ else() #!WIN32

if(QUIC_ENABLE_LOGGING)
if (APPLE)
message(STATUS "Configuring for macos tracing")
# macos will print all logs to stdout. If that is wanted, uncomment, and comment the line below.
# set(CMAKE_CLOG_CONFIG_PROFILE macos)
# set(CMAKE_CLOG_CONFIG_PROFILE stubs)
# for now, stubs clog is broken, so disable logging completely on macos
set (QUIC_ENABLE_LOGGING OFF)
message(STATUS "Disablign all tracing on macos")
set(CMAKE_CLOG_CONFIG_PROFILE stubs)
message(STATUS "Disabling all tracing on macos")
list(APPEND QUIC_COMMON_DEFINES QUIC_EVENTS_STUB QUIC_LOGS_STUB)
else()
message(STATUS "Configuring for LTTng tracing")
set(CMAKE_CLOG_CONFIG_PROFILE linux)
list(APPEND QUIC_COMMON_DEFINES QUIC_CLOG)
set (QUIC_LTTNG_PLATFORM linux)
include(FindLTTngUST)
endif()
else()
message(STATUS "Disabling tracing")
set(CMAKE_CLOG_CONFIG_PROFILE stubs)
list(APPEND QUIC_COMMON_DEFINES QUIC_EVENTS_STUB QUIC_LOGS_STUB)
endif()

Expand Down Expand Up @@ -522,27 +513,6 @@ if(QUIC_TLS STREQUAL "openssl")
endif()
endif()

if (QUIC_ENABLE_LOGGING)
execute_process(COMMAND clog --installDirectory ${QUIC_BUILD_DIR}/clog)

set(CMAKE_CLOG_OUTPUT_DIRECTORY ${QUIC_BUILD_DIR}/inc)
set(CMAKE_CLOG_SIDECAR_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest)
set(CLOG_INCLUDE_DIRECTORY ${QUIC_BUILD_DIR}/clog)
set(CMAKE_CLOG_GENERATE_FILE ${QUIC_BUILD_DIR}/clog/CLog.cmake)
set(CMAKE_CLOG_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/manifest/msquic.clog_config)
include(${CMAKE_CLOG_GENERATE_FILE})

function(add_clog_library)
CLOG_GENERATE_TARGET(${ARGV})
target_link_libraries(${ARGV0} PRIVATE inc)
set_property(TARGET ${ARGV0} PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}helpers")
endfunction()
else()
function(add_clog_library)
add_library(${ARGV0} INTERFACE)
endfunction()
endif()

if(QUIC_CODE_CHECK)
find_program(CLANGTIDY NAMES clang-tidy)
if(CLANGTIDY)
Expand Down Expand Up @@ -599,6 +569,7 @@ if(QUIC_CODE_CHECK)
endif()

add_subdirectory(src/inc)
add_subdirectory(src/generated)

# Product code
add_subdirectory(src/core)
Expand Down
10 changes: 9 additions & 1 deletion scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ param (
[switch]$Clean = $false,

[Parameter(Mandatory = $false)]
[int32]$Parallel = -1,
[int32]$Parallel = -2,

[Parameter(Mandatory = $false)]
[switch]$DynamicCRT = $false,
Expand Down Expand Up @@ -191,6 +191,14 @@ param (
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'

if ($Parallel -lt -1) {
if ($IsWindows) {
$Parallel = -1
} else {
$Parallel = 0
}
}

$BuildConfig = & (Join-Path $PSScriptRoot get-buildconfig.ps1) -Platform $Platform -Tls $Tls -Arch $Arch -ExtraArtifactDir $ExtraArtifactDir -Config $Config

$Platform = $BuildConfig.Platform
Expand Down
39 changes: 0 additions & 39 deletions scripts/generate_kernel_clog.bat

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/prepare-machine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function Install-ClogTool {
}
}

if (($Configuration -eq "Dev") -or ($Configuration -eq "Build")) {
if (($Configuration -eq "Dev")) {
Install-ClogTool "Microsoft.Logging.CLOG"
}

Expand Down
31 changes: 25 additions & 6 deletions scripts/update-sidecar.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,34 @@ $Files.Sort([SimpleStringComparer]::new())
$Sidecar = Join-Path $SrcDir "manifest" "clog.sidecar"
$ConfigFile = Join-Path $SrcDir "manifest" "msquic.clog_config"

$OutputDir = Join-Path $RootDir "build" "tmp"
$TmpOutputDir = Join-Path $RootDir "build" "tmp"

$OutputDir = Join-Path $RootDir "src" "generated"
if (Test-Path $OutputDir) {
Remove-Item $OutputDir -Recurse -Force
}
New-Item -Path $OutputDir -ItemType Directory -Force | Out-Null

Remove-Item $Sidecar -Force -ErrorAction Ignore | Out-Null

clog --installDirectory (Join-Path $OutputDir common)

foreach ($File in $Files) {
clog -p windows --scopePrefix "QUIC" -s $Sidecar -c $ConfigFile -i $File --outputDirectory "$OutputDir"
clog -p windows_kernel --scopePrefix "QUIC" -s $Sidecar -c $ConfigFile -i $File --outputDirectory "$OutputDir"
clog -p stubs --scopePrefix "QUIC" -s $Sidecar -c $ConfigFile -i $File --outputDirectory "$OutputDir"
clog -p linux --scopePrefix "QUIC" -s $Sidecar -c $ConfigFile -i $File --outputDirectory "$OutputDir"
clog -p macos --scopePrefix "QUIC" -s $Sidecar -c $ConfigFile -i $File --outputDirectory "$OutputDir"
$FileToCheck = [System.IO.Path]::GetFileName($File) + ".clog.h"
$FileContents = (Get-Content -path $File -Raw)
if ($null -eq $FileContents -or !$FileContents.Contains($FileToCheck)) {
continue
}
clog -p windows --dynamicTracepointProvider --scopePrefix "quic.clog" -s $Sidecar -c $ConfigFile -i $File --outputDirectory $TmpOutputDir
clog -p windows_kernel --dynamicTracepointProvider --scopePrefix "quic.clog" -s $Sidecar -c $ConfigFile -i $File --outputDirectory $TmpOutputDir
clog -p stubs --dynamicTracepointProvider --scopePrefix "quic.clog" -s $Sidecar -c $ConfigFile -i $File --outputDirectory $TmpOutputDir
clog -p linux --dynamicTracepointProvider --scopePrefix "quic.clog" -s $Sidecar -c $ConfigFile -i $File --outputDirectory (Join-Path $OutputDir linux)
clog -p macos --dynamicTracepointProvider --scopePrefix "quic.clog" -s $Sidecar -c $ConfigFile -i $File --outputDirectory $TmpOutputDir
}

# Perform fixups
$GenFiles = Get-ChildItem -Path "$OutputDir\*" -Recurse -File
$ToRemovePath = "$OutputDir\linux\"
foreach ($File in $GenFiles) {
((Get-Content -path $File -Raw).Replace($ToRemovePath, "")) | Set-Content -Path $File
}
12 changes: 2 additions & 10 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ endif()

if(BUILD_SHARED_LIBS)
add_library(msquic SHARED ${SOURCES})
target_link_libraries(msquic PRIVATE core platform inc warnings)
target_link_libraries(msquic PRIVATE core platform inc warnings logging)
set_target_properties(msquic PROPERTIES OUTPUT_NAME ${QUIC_LIBRARY_NAME})
else()
add_library(msquic_static STATIC static/empty.c)
target_link_libraries(msquic_static PRIVATE core platform inc)
target_link_libraries(msquic_static PRIVATE core platform inc logging)
target_compile_definitions(msquic_static PUBLIC QUIC_BUILD_STATIC)
set_property(TARGET msquic_static PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries")

Expand Down Expand Up @@ -245,14 +245,6 @@ if(BUILD_SHARED_LIBS)
install(EXPORT msquic DESTINATION ${msquic_dest})
endif()

if(WIN32)
add_library(msquic.lttng INTERFACE)
elseif(QUIC_ENABLE_LOGGING)
add_library(msquic.lttng SHARED $<TARGET_OBJECTS:platform.clog.provider> $<TARGET_OBJECTS:core.clog.provider>)
target_link_libraries(msquic.lttng inc)
install(TARGETS msquic.lttng DESTINATION "${main_lib_dest}")
endif()

if (MSVC AND NOT QUIC_ENABLE_SANITIZERS AND BUILD_SHARED_LIBS)
target_compile_options(msquic PRIVATE /analyze)
endif()
8 changes: 1 addition & 7 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,13 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(SOURCES ${SOURCES} inline.c)
endif()

# Allow CLOG to preprocess all the source files.
add_clog_library(core.clog DYNAMIC ${SOURCES})
if(QUIC_ENABLE_LOGGING)
set_property(TARGET core.clog.provider PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}helpers")
endif()

add_library(core STATIC ${SOURCES})

if(NOT QUIC_BUILD_SHARED)
target_compile_definitions(core PUBLIC QUIC_BUILD_STATIC)
endif()

target_link_libraries(core PUBLIC core.clog inc)
target_link_libraries(core PUBLIC inc)

target_link_libraries(core PRIVATE warnings)

Expand Down
5 changes: 1 addition & 4 deletions src/core/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ set(SOURCES
VersionNegExtTest.cpp
)

# Allow CLOG to preprocess all the source files.
add_clog_library(msquiccoretest.clog STATIC ${SOURCES})

add_executable(msquiccoretest ${SOURCES})

target_include_directories(msquiccoretest PRIVATE ${PROJECT_SOURCE_DIR}/src/core)

set_property(TARGET msquiccoretest PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}tests")

target_link_libraries(msquiccoretest msquic core platform inc gtest msquiccoretest.clog warnings)
target_link_libraries(msquiccoretest msquic core platform inc gtest warnings logging)

add_test(NAME msquiccoretest
COMMAND msquiccoretest
Expand Down
29 changes: 29 additions & 0 deletions src/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

add_library(logging_inc INTERFACE)
target_link_libraries(inc INTERFACE logging_inc)

if(QUIC_ENABLE_LOGGING)
if(WIN32)
target_link_libraries(inc INTERFACE MsQuicEtw_Header)
add_library(logging INTERFACE)
else()
target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/common)
target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${QUIC_LTTNG_PLATFORM})
target_link_libraries(logging_inc INTERFACE ${LTTNGUST_INCLUDE_DIRS})

FILE(GLOB LOGGING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${QUIC_LTTNG_PLATFORM}/*.c)
add_library(logging STATIC ${LOGGING_FILES})
target_link_libraries(logging PRIVATE inc)

add_library(msquic.lttng SHARED ${LOGGING_FILES})
target_compile_definitions(msquic.lttng PRIVATE BUILDING_TRACEPOINT_PROVIDER)
target_link_libraries(msquic.lttng PRIVATE logging_inc inc)
target_link_libraries(msquic.lttng PRIVATE ${LTTNGUST_LIBRARIES})

install(TARGETS msquic.lttng DESTINATION "${main_lib_dest}")
endif()
else()
add_library(logging INTERFACE)
endif()
68 changes: 68 additions & 0 deletions src/generated/common/CLog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#
# Creates a target to build all generated clog files of the input
# sources
#
function(CLOG_GENERATE_TARGET)
set(library ${ARGV0})
set(library_type ${ARGV1})
list(REMOVE_AT ARGV 0)
list(REMOVE_AT ARGV 0)
# message(STATUS "****************<<<<<<< CLOG(${library})) >>>>>>>>>>>>>>>*******************")
# message(STATUS ">>>> CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}")
# message(STATUS ">>>> CMAKE_CLOG_SIDECAR_DIRECTORY = ${CMAKE_CLOG_SIDECAR_DIRECTORY}")
# message(STATUS ">>>> CMAKE_CLOG_CONFIG_PROFILE = ${CMAKE_CLOG_CONFIG_PROFILE}")
# message(STATUS ">>>> CLOG Library = ${library}")
# message(STATUS ">>>> CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")

foreach(arg IN LISTS ARGV)
get_filename_component(RAW_FILENAME ${arg} NAME)
set(ARG_CLOG_FILE ${CMAKE_CLOG_OUTPUT_DIRECTORY}/${library}/${RAW_FILENAME}.clog.h)
set(ARG_CLOG_C_FILE ${CMAKE_CLOG_OUTPUT_DIRECTORY}/${library}/${library}_${RAW_FILENAME}.clog.h.c)

# message(STATUS ">>>>>>> CLOG Source File = ${RAW_FILENAME}")

set(ARG_CLOG_DYNAMIC_TRACEPOINT "")
if (${library_type} STREQUAL "DYNAMIC")
set(ARG_CLOG_DYNAMIC_TRACEPOINT "--dynamicTracepointProvider")
endif()

add_custom_command(
OUTPUT ${ARG_CLOG_FILE} ${ARG_CLOG_C_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${arg}
DEPENDS ${CMAKE_CLOG_CONFIG_FILE}
DEPENDS ${CMAKE_CLOG_EXTRA_DEPENDENCIES}
COMMENT "CLOG: clog --readOnly ${ARG_CLOG_DYNAMIC_TRACEPOINT} -p ${CMAKE_CLOG_CONFIG_PROFILE} --scopePrefix ${library} -c ${CMAKE_CLOG_CONFIG_FILE} -s ${CMAKE_CLOG_SIDECAR_DIRECTORY}/clog.sidecar -i ${CMAKE_CURRENT_SOURCE_DIR}/${arg} -o ${ARG_CLOG_FILE}"
COMMAND clog --readOnly ${ARG_CLOG_DYNAMIC_TRACEPOINT} -p ${CMAKE_CLOG_CONFIG_PROFILE} --scopePrefix ${library} -c ${CMAKE_CLOG_CONFIG_FILE} -s ${CMAKE_CLOG_SIDECAR_DIRECTORY}/clog.sidecar -i ${CMAKE_CURRENT_SOURCE_DIR}/${arg} -o ${ARG_CLOG_FILE}
)

set_property(SOURCE ${arg}
APPEND PROPERTY OBJECT_DEPENDS ${ARG_CLOG_FILE}
)

list(APPEND clogfiles ${ARG_CLOG_C_FILE})
endforeach()

if (${library_type} STREQUAL "DYNAMIC")
add_library(${library} STATIC ${clogfiles})

add_library("${library}.provider" OBJECT ${clogfiles})
target_compile_definitions("${library}.provider" PRIVATE BUILDING_TRACEPOINT_PROVIDER)
set_property(TARGET "${library}.provider" PROPERTY POSITION_INDEPENDENT_CODE ON)

target_include_directories("${library}.provider" PUBLIC $<BUILD_INTERFACE:${CLOG_INCLUDE_DIRECTORY}>)
target_include_directories("${library}.provider" PUBLIC $<BUILD_INTERFACE:${CMAKE_CLOG_OUTPUT_DIRECTORY}/${library}>)
else()
add_library(${library} ${library_type} ${clogfiles})
add_library("${library}.provider" INTERFACE)
endif()

target_link_libraries(${library} PUBLIC ${CMAKE_DL_LIBS})
target_include_directories(${library} PUBLIC $<BUILD_INTERFACE:${CLOG_INCLUDE_DIRECTORY}>)
target_include_directories(${library} PUBLIC $<BUILD_INTERFACE:${CMAKE_CLOG_OUTPUT_DIRECTORY}/${library}>)

# message(STATUS "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
endfunction()

Loading

0 comments on commit b00fb5e

Please sign in to comment.