From b4a31029e5d6f19a80f71fb5043521785a007416 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 28 Jul 2025 11:04:55 -0700 Subject: [PATCH] Upgrade Windows build image from windows-2019 to windows-2022 --- ...-vs2019.yaml => build-windows-vs2022.yaml} | 8 +- .github/workflows/codeql-analysis.yml | 17 ++-- .github/workflows/test-win-latest.yml | 2 +- README.md | 5 +- build-cmake-clang-vs2022.cmd | 81 ++++++++++++++++++ docs/cpp-start-windows.md | 8 +- .../maesdk/src/main/cpp/CMakeLists.txt | 17 ++++ .../applications/events/Sanitizer.java | 73 ++++++++++++++++ .../events/SanitizerConfiguration.java | 39 +++++++++ lib/include/public/Version.hpp | 6 +- lib/jni/SanitizerHelper.hpp | 18 ++++ lib/jni/Sanitizer_jni.cpp | 83 +++++++++++++++++++ lib/modules | 2 +- 13 files changed, 335 insertions(+), 24 deletions(-) rename .github/workflows/{build-windows-vs2019.yaml => build-windows-vs2022.yaml} (75%) create mode 100644 build-cmake-clang-vs2022.cmd create mode 100644 lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java create mode 100644 lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java create mode 100644 lib/jni/SanitizerHelper.hpp create mode 100644 lib/jni/Sanitizer_jni.cpp diff --git a/.github/workflows/build-windows-vs2019.yaml b/.github/workflows/build-windows-vs2022.yaml similarity index 75% rename from .github/workflows/build-windows-vs2019.yaml rename to .github/workflows/build-windows-vs2022.yaml index a454fb59c..a8a18394e 100644 --- a/.github/workflows/build-windows-vs2019.yaml +++ b/.github/workflows/build-windows-vs2022.yaml @@ -1,4 +1,4 @@ -name: C/C++ CI on Windows (vs2019) +name: C/C++ CI on Windows (vs2022) on: push: @@ -16,7 +16,7 @@ on: jobs: build: - runs-on: windows-2019 + runs-on: windows-2022 name: Build steps: @@ -29,7 +29,7 @@ jobs: env: SKIP_ARM_BUILD: 1 SKIP_ARM64_BUILD: 1 - PlatformToolset: v142 - VSTOOLS_VERSION: vs2019 + PlatformToolset: v143 + VSTOOLS_VERSION: vs2022 shell: cmd run: build-all.bat diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3861e74f7..b5d052ba2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,7 +17,7 @@ on: jobs: analyze: name: Analyze - runs-on: windows-2019 + runs-on: windows-2022 permissions: contents: read actions: read @@ -28,7 +28,7 @@ jobs: matrix: # Override automatic language detection by changing the below list # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - language: ['cpp', 'csharp', 'javascript', 'python'] + language: ['cpp', 'javascript', 'python'] # Learn more... # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection @@ -47,18 +47,17 @@ jobs: # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # Autobuild attempts to build any compiled languages (C/C++, or Java). # If this step fails, then you should remove it and run the build manually (see below) - # - name: Autobuild - # uses: github/codeql-action/autobuild@v3 - - name: Build + - name: Build C++ env: SKIP_ARM_BUILD: 1 SKIP_ARM64_BUILD: 1 - PlatformToolset: v142 - VSTOOLS_VERSION: vs2019 + PlatformToolset: v143 + VSTOOLS_VERSION: vs2022 + WindowsSDKVersion: 10.0.22621.0 shell: cmd - if: matrix.language == 'cpp' || matrix.language == 'csharp' + if: matrix.language == 'cpp' run: build-all.bat # ℹ️ Command-line programs to run using the OS shell. diff --git a/.github/workflows/test-win-latest.yml b/.github/workflows/test-win-latest.yml index 5f2780401..760c88fb0 100644 --- a/.github/workflows/test-win-latest.yml +++ b/.github/workflows/test-win-latest.yml @@ -27,7 +27,7 @@ jobs: matrix: arch: [Win32, x64] build: [Release, Debug] - os: [windows-2019] + os: [windows-2022] steps: diff --git a/README.md b/README.md index 6c8978858..892eb5d62 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Other resources to learn how to setup the build system: | Ubuntu 18.04 LTS | GCC 7.5.x | | Windows 10 | Android Studio/Gradle | | Windows Server 2016 | Visual Studio 2017 (vc141) | - | Windows Server 2019 | Visual Studio 2019 (vc142) | + | Windows Server 2022 | Visual Studio 2022 (vc143) | ## Target Platforms @@ -96,7 +96,8 @@ Other resources to learn how to setup the build system: | Windows 10.x | :white_check_mark: | | | Windows Server 2012 | :white_check_mark: | | | Windows Server 2016 | :white_check_mark: | | - | Windows Server 2019 | :white_check_mark: | :white_check_mark: | + | Windows Server 2019 | :white_check_mark: | | + | Windows Server 2022 | :white_check_mark: | :white_check_mark: | * **Supported** - these platforms are known to work well with the SDK in production. diff --git a/build-cmake-clang-vs2022.cmd b/build-cmake-clang-vs2022.cmd new file mode 100644 index 000000000..00197c980 --- /dev/null +++ b/build-cmake-clang-vs2022.cmd @@ -0,0 +1,81 @@ +@echo off + +set VSTOOLS_VERSION=vs2022 +cd %~dp0 + +echo Update all public submodules... +git -c submodule."lib/modules".update=none submodule update --init --recursive + +if DEFINED GIT_PULL_TOKEN ( + rd /s /q lib\modules + git clone https://%GIT_PULL_TOKEN%:x-oauth-basic@github.com/microsoft/cpp_client_telemetry_modules.git lib\modules +) + +call tools\vcvars.cmd + +setlocal enableextensions +setlocal enabledelayedexpansion +set ROOT=%~dp0 + +REM ******************************************************************** +REM Use cmake +REM ******************************************************************** +set "PATH=C:\Program Files\CMake\bin\;%PATH%" + +REM ******************************************************************** +REM Use clang compiler +REM ******************************************************************** +set CLANG_PATH="C:\Program Files\LLVM\bin" +set CC=%CLANG_PATH%\clang.exe +set CXX=%CLANG_PATH%\clang++.exe +set LLVM_VER=ClangCL + +REM ******************************************************************** +REM Set output directory, clean and/or create as-needed +REM ******************************************************************** +set OUTDIR=%ROOT%\Solutions\out +if "%1" == "clean" ( + @rmdir /s /q %OUTDIR% +) +if not exist "%OUTDIR%" mkdir %OUTDIR% + +REM ******************************************************************** +REM Build all deps using MSVC - Visual Studio 2022 (17) +REM ******************************************************************** +if "%1" == "nodeps" goto NODEPS +call tools\build-deps.cmd +:NODEPS + +cd %OUTDIR% + +REM ******************************************************************** +REM Invoke the build script +REM ******************************************************************** +set CMAKE_PACKAGE_TYPE=tgz +for %%a in ( m32 m64 ) do ( + for %%c in ( Release ) do ( + if "%%a"=="m32" ( + set ARCH=Win32 + set ARCH_GEN= Win32 + ) + if "%%a"=="m64" ( + set ARCH=x64 + set ARCH_GEN= x64 + ) + @mkdir %OUTDIR%\%%c\!ARCH! + cd %OUTDIR%\%%c\!ARCH! + set "CFLAGS=-%%a" + set "CXXFLAGS=-%%a -Wc++11-compat-pedantic -Wno-c++98-compat -Wno-everything" + cmake -G"Visual Studio 17 2022" -A !ARCH_GEN! ^ + -T"%LLVM_VER%" ^ + -DTARGET_ARCH=!ARCH! ^ + -DBUILD_SHARED_LIBS=OFF ^ + -DCMAKE_BUILD_TYPE=%%c ^ + -DCMAKE_PACKAGE_TYPE=%CMAKE_PACKAGE_TYPE% ^ + -DDEFAULT_PAL_IMPLEMENTATION=WIN32 ^ + %ROOT% + cmake --build . --config %%c -- /p:Configuration=%%c + ) +) + +cd %ROOT% \ No newline at end of file diff --git a/docs/cpp-start-windows.md b/docs/cpp-start-windows.md index dbdfda0aa..ef5850d84 100644 --- a/docs/cpp-start-windows.md +++ b/docs/cpp-start-windows.md @@ -16,7 +16,7 @@ If your project requires the Universal Telemetry Client (a.k.a. UTC) to send tel ## **Windows prerequisites and dependencies for building from source** -* Visual Studio 2017 or 2019 (2019 is recommended). +* Visual Studio 2019 or 2022 (2022 is recommended). * C++ Dev Tools ## **Option 1: Build the SDK from source using Visual Studio** @@ -58,11 +58,11 @@ Make sure you can build a simple "Hello World" using CMake before proceeding to To build SDK using cmake with clang on Windows, run: -```build-cmake-clang-vs2017.cmd``` +```build-cmake-clang-vs2019.cmd``` or -```build-cmake-clang-vs2019.cmd``` +```build-cmake-clang-vs2022.cmd``` depending on what Visual Studio version you are using. @@ -113,6 +113,6 @@ More examples can be found under *examples* folder. - [CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html) - [Runtime Library Variants: static vs dynamic runtime](https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s24.html) -If you encounter troubles building the project, please refer to our CI/Build pipeline settings [here](../.github/workflows/build-windows-vs2019.yaml). This pipeline runs on a standard GitHub image with a standard Visual Studio 2019 installation. If you are still stuck, please log your build question as [GitHub issue](https://github.com/microsoft/cpp_client_telemetry/issues) with labels `question` and `build infra`. We would be glad to help and adjust documentation accordingly. +If you encounter troubles building the project, please refer to our CI/Build pipeline settings [here](../.github/workflows/build-windows-vs2022.yaml). This pipeline runs on a standard GitHub image with a standard Visual Studio 2022 installation. If you are still stuck, please log your build question as [GitHub issue](https://github.com/microsoft/cpp_client_telemetry/issues) with labels `question` and `build infra`. We would be glad to help and adjust documentation accordingly. If you find that some documentation is incorrect, please send a PR to fix it. We ❤️ community contributions! diff --git a/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt b/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt index 824bbb278..cb70849b6 100644 --- a/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt +++ b/lib/android_build/maesdk/src/main/cpp/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD 11) option(BUILD_AZMON "Build for Azure Monitor" YES) option(BUILD_PRIVACYGUARD "Build Privacy Guard" YES) option(BUILD_SIGNALS "Build Signals" YES) +option(BUILD_SANITIZER "Build Sanitizer" YES) if(ENABLE_CAPI_HTTP_CLIENT) add_definitions(-DENABLE_CAPI_HTTP_CLIENT) @@ -113,6 +114,22 @@ if (EXISTS ${SDK_ROOT}/lib/modules/signals/ AND BUILD_SIGNALS) ) endif() +if (EXISTS ${SDK_ROOT}/lib/modules/sanitizer/ AND BUILD_SANITIZER) + list(APPEND SRCS + ${SDK_ROOT}/lib/jni/Sanitizer_jni.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/EmailAddressDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/JwtDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/SPOPassword.cpp + ${SDK_ROOT}/lib/modules/sanitizer/detectors/UrlDetector.cpp + ${SDK_ROOT}/lib/modules/sanitizer/Sanitizer.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerProvider.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerStringUtils.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTargets.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTrie.cpp + ${SDK_ROOT}/lib/modules/sanitizer/SanitizerTrieNode.cpp + ) +endif() + if (USE_ROOM) add_definitions("-DUSE_ROOM") list(APPEND SRCS ${SDK_ROOT}/lib/offline/OfflineStorage_Room.cpp) diff --git a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java new file mode 100644 index 000000000..eab0e2a41 --- /dev/null +++ b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/Sanitizer.java @@ -0,0 +1,73 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +package com.microsoft.applications.events; + +public class Sanitizer { + + /** + * Initializes the sanitizer with the provided configuration. + * + * @param config The configuration object containing logger and event name. + * @return true if initialization succeeds, false otherwise. + * @throws IllegalArgumentException if config or any required field is null or invalid. + */ + public static boolean initialize(SanitizerConfiguration config) { + + // Validate that the configuration object is not null + if(config == null) { + throw new IllegalArgumentException("initConfig cannot be null"); + } + + // Ensure the logger instance is provided + if(config.loggerInstance == null) { + throw new IllegalArgumentException(("loggerInstance cannot be null in config.")); + } + + // Ensure the notification event name is not null or empty + if (config.notificationEventName == null || config.notificationEventName.isEmpty()) { + throw new IllegalArgumentException(("notificationEventName cannot be null in config.")); + } + + return nativeInitialize(config.loggerInstance.getNativeILoggerPtr(), config.notificationEventName); + } + + /** + * Checks if the sanitizer is initialized. + * + * @return true if initialized, false otherwise. + */ + public static native boolean isInitialized(); + + /** + * Initializes the sanitizer with the given logger pointer and optional notification event name. + * + * @param loggerNativePtr Native pointer to ILogger. + * @param notificationEventName Optional event name for sanitizer notifications. + * @return true if initialization was successful, false otherwise. + */ + public static native boolean nativeInitialize(long loggerNativePtr, String notificationEventName); + + /** + * Uninitializes the sanitizer. + * + * @return true if uninitialization was successful, false otherwise. + */ + public static native boolean uninitialize(); + + /** + * Checks if the sanitizer is currently enabled. + * + * @return true if enabled, false otherwise. + */ + public static native boolean isEnabled(); + + /** + * Enables or disables the sanitizer. + * + * @param enabled true to enable, false to disable. + * @return true if the operation was successful, false otherwise. + */ + public static native boolean setEnabled(boolean enabled); +} \ No newline at end of file diff --git a/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java new file mode 100644 index 000000000..1a51511e1 --- /dev/null +++ b/lib/android_build/maesdk/src/main/java/com/microsoft/applications/events/SanitizerConfiguration.java @@ -0,0 +1,39 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +package com.microsoft.applications.events; + +/** + * Represents the configuration settings used to initialize a sanitizer instance. + */ + +public class SanitizerConfiguration { + + /** + * The logger instance used to record privacy concern events. + * This field is required. + */ + public final ILogger loggerInstance; + + /** +     * The custom event name used when logging sanitizer concerns. +     * Optional. Defaults to "SanitizerConcerns" if not specified. +     */ + public String notificationEventName = "SanitizerConcerns"; + + /** +     * Constructs a new SanitizerConfiguration with the specified logger. +     * +     * @param logger The ILogger implementation used to log privacy concern events. +     * @throws IllegalArgumentException if the logger is null. +     */ + public SanitizerConfiguration(ILogger logger) { + + if(logger == null) { + throw new IllegalArgumentException("logger cannot be null"); + } + + this.loggerInstance = logger; + } +} \ No newline at end of file diff --git a/lib/include/public/Version.hpp b/lib/include/public/Version.hpp index 8d7350af4..02d63dd76 100644 --- a/lib/include/public/Version.hpp +++ b/lib/include/public/Version.hpp @@ -6,8 +6,8 @@ #define MAT_VERSION_HPP // WARNING: DO NOT MODIFY THIS FILE! // This file has been automatically generated, manual changes will be lost. -#define BUILD_VERSION_STR "3.9.163.1" -#define BUILD_VERSION 3,9,163,1 +#define BUILD_VERSION_STR "3.9.205.1" +#define BUILD_VERSION 3,9,205,1 #ifndef RESOURCE_COMPILER_INVOKED #include "ctmacros.hpp" @@ -18,7 +18,7 @@ namespace MAT_NS_BEGIN { uint64_t const Version = ((uint64_t)3 << 48) | ((uint64_t)9 << 32) | - ((uint64_t)163 << 16) | + ((uint64_t)205 << 16) | ((uint64_t)1); } MAT_NS_END diff --git a/lib/jni/SanitizerHelper.hpp b/lib/jni/SanitizerHelper.hpp new file mode 100644 index 000000000..a2308fcad --- /dev/null +++ b/lib/jni/SanitizerHelper.hpp @@ -0,0 +1,18 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ctmacros.hpp" +#include "modules/sanitizer/Sanitizer.hpp" + +namespace MAT_NS_BEGIN +{ + struct Sanitizer { + /** + * Get the current instance of Sanitizer. + * @return SanitizerPtr if it is initialized, nullptr otherwise. + */ + static std::shared_ptr GetSanitizerPtr() noexcept; + }; +} MAT_NS_END \ No newline at end of file diff --git a/lib/jni/Sanitizer_jni.cpp b/lib/jni/Sanitizer_jni.cpp new file mode 100644 index 000000000..8f2d7c847 --- /dev/null +++ b/lib/jni/Sanitizer_jni.cpp @@ -0,0 +1,83 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ctmacros.hpp" +#include "JniConvertors.hpp" +#include "modules/sanitizer/Sanitizer.hpp" +#include "SanitizerHelper.hpp" + +using namespace MAT; + +std::shared_ptr spSanitizer; + +std::shared_ptr SanitizerHelper::GetSanitizerPtr() noexcept +{ + return spSanitizer; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_isInitialized(const JNIEnv *env, jclass/* this */) { + + return spSanitizer != nullptr; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_nativeInitialize( + JNIEnv *env, jclass /* this */, + jlong iLoggerNativePtr, + jstring notificationEventName) { + + if (spSanitizer != nullptr) { + return false; + } + + SanitizerConfiguration sanitizerConfig(reinterpret_cast(iLoggerNativePtr)); + + if (notificationEventName != nullptr) { + config.NotificationEventName = JStringToStdString(env, notificationEventName).c_str(); + } + + spSanitizer = std::make_shared(config); + return true; +} + + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_uninitialize(const JNIEnv *env, jclass /*this*/) { + + if(spSanitizer == nullptr) { + return false; + } + + spSanitizer.reset(); + + return true; +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_isEnabled(JNIEnv *env, jclass clazz) { + + if (spSanitizer == nullptr) { + return false; + } + + return spSanitizer.get()->IsEnabled(); +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_microsoft_applications_events_Sanitizer_setEnabled(JNIEnv *env, jclass clazz, + jboolean enabled) { + if (spDataInspector == nullptr) { + return false; + } + + spDataInspector->SetEnabled(static_cast(enabled)); + return true; +} \ No newline at end of file diff --git a/lib/modules b/lib/modules index eac5fe38a..bd40008a9 160000 --- a/lib/modules +++ b/lib/modules @@ -1 +1 @@ -Subproject commit eac5fe38a9bd3e54a1b609dc4ffc9b6f3e9336ea +Subproject commit bd40008a920f419c70c56fc5eed0f1f3e16fe58f