Skip to content

Commit

Permalink
Enable Rust based AMQP by default (#6362)
Browse files Browse the repository at this point in the history
* AMQP tests now pass; Integrate TestAmqpBroker with CI pipeline

* Updated changelogs to reflect API changes made during AMQP updates

* Replace uAMQP with Rust AMQP as the default AMQP transport; Updated build configurationj to reflect that

* Test fixes

* PR feedback; test fixes
  • Loading branch information
LarryOsterman committed Feb 4, 2025
1 parent 471080d commit a83dba3
Show file tree
Hide file tree
Showing 36 changed files with 990 additions and 523 deletions.
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
cmake_minimum_required (VERSION 3.13)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")

# Enable Rust based APIs in C++ SDK.
set(DISABLE_RUST_IN_BUILD OFF CACHE BOOL "Disable Rust based APIs in package")
set(DISABLE_AMQP OFF CACHE BOOL "Disable AMQP based functionality")
set(DISABLE_AZURE_CORE_OPENTELEMETRY OFF CACHE BOOL "Disable OpenTelemetry based functionality")

message(STATUS "Disabling Rust temporarily")
set(DISABLE_RUST_IN_BUILD ON)

# Variable to indicate whether the entire SDK is being built, as opposed to an individual library.
set(AZ_ALL_LIBRARIES ON)

Expand Down Expand Up @@ -40,6 +48,15 @@ if ((${VCPKG_TARGET_TRIPLET} MATCHES ".*-uwp"))
message(STATUS "Building for Windows Store, CMAKE_SYSTEM_NAME=" ${CMAKE_SYSTEM_NAME})
endif()

if (BUILD_WINDOWS_UWP)
if (DISABLE_RUST_IN_BUILD)
message(STATUS "uAMQP is incompatible with UWP builds.")
set(DISABLE_AMQP ON)
endif()
message(STATUS "opentelemetry-cpp package is incompatible with UWP builds.")
set(DISABLE_AZURE_CORE_OPENTELEMETRY ON)
endif()

# For MSVC, ensure that the compiler is operating in strict compliance mode.
if (MSVC)
# See also: https://learn.microsoft.com/cpp/build/reference/permissive-standards-conformance
Expand Down Expand Up @@ -161,8 +178,8 @@ add_subdirectory(sdk/core)
add_subdirectory(sdk/appconfiguration)
add_subdirectory(sdk/attestation)
# AMQP doesn't work for UWP yet, and eventhubs depends on AMQP, so we cannot include eventhubs on UWP.
if (NOT BUILD_WINDOWS_UWP)
add_subdirectory(sdk/eventhubs)
if (NOT DISABLE_AMQP)
add_subdirectory(sdk/eventhubs)
endif()
add_subdirectory(sdk/identity)
add_subdirectory(sdk/keyvault)
Expand Down
65 changes: 50 additions & 15 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@
}
},
{
"name": "rust-amqp",
"displayName": "Use Rust AMQP implementation",
"description": "Use Rust AMQP implementation (Hidden)",
"name": "no-rust-amqp",
"displayName": "Disable use of the Rust AMQP implementation",
"description": "Disable use of the Rust AMQP implementation (Hidden)",
"hidden": true,
"cacheVariables": {
"USE_RUST_AMQP": true
"DISABLE_RUST_IN_BUILD": true
}
},
{
Expand Down Expand Up @@ -480,30 +480,30 @@
]
},
{
"name": "x64-static-debug-perftests-rust",
"displayName": "x64 Debug, Rust AMQP, static With Perf Tests and samples, libcurl+winhttp",
"name": "x64-static-debug-perftests-no-rust",
"displayName": "x64 Debug, No Rust, static With Perf Tests and samples, libcurl+winhttp",
"inherits": [
"x64-static",
"debug-build",
"enable-tests",
"enable-samples",
"enable-perf",
"rust-amqp",
"no-rust-amqp",
"winhttp-transport",
"curl-transport"
]
},
{
"name": "x64-static-debug-asan-perftests-rust",
"displayName": "x64 Debug, ASAN Rust AMQP, static With Perf Tests and samples, libcurl+winhttp",
"name": "x64-static-debug-asan-perftests-no-rust",
"displayName": "x64 Debug, ASAN No Rust, static With Perf Tests and samples, libcurl+winhttp",
"inherits": [
"x64-static",
"enable-address-sanitizer",
"debug-build",
"enable-tests",
"enable-samples",
"enable-perf",
"rust-amqp",
"no-rust-amqp",
"winhttp-transport",
"curl-transport"
],
Expand All @@ -527,7 +527,7 @@
}
},
{
"name": "x86-msvc-static-debug-perftests",
"name": "x86-msvc-static-dbg-all",
"displayName": "x86 MSVC Debug static With Perf Tests and samples",
"inherits": [
"x86-msvc-static",
Expand All @@ -540,7 +540,7 @@
]
},
{
"name": "x64-msvc-static-debug-perftests",
"name": "x64-msvc-static-debug-all",
"displayName": "x64 MSVC Debug static With Perf Tests and samples",
"inherits": [
"x64-msvc-static",
Expand Down Expand Up @@ -659,6 +659,24 @@
"rhs": "Linux"
}
},
{
"name": "linux-basic-clang-18",
"displayName": "Linux clang-18",
"description": "Using compilers: C = /usr/bin/clang-18, CXX = /usr/bin/clang++-18",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"generator": "Ninja",
"hidden": true,
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_C_COMPILER": "/usr/bin/clang-18",
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-18"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-basic-g++",
"displayName": "Linux G++",
Expand Down Expand Up @@ -763,6 +781,23 @@
],
"displayName": "Linux clang 13 Debug+Tests"
},
{
"name": "linux-clang-18-debug",
"inherits": [
"linux-basic-clang-18",
"debug-build"
],
"displayName": "Linux clang 18 Debug"
},
{
"name": "linux-clang-18-debug-tests",
"inherits": [
"linux-basic-clang-18",
"debug-build",
"enable-tests"
],
"displayName": "Linux clang 18 Debug+Tests"
},
{
"name": "linux-g++-debug",
"displayName": "Linux c++ Debug",
Expand Down Expand Up @@ -800,12 +835,12 @@
"displayName": "Linux c++ Debug+Tests, samples"
},
{
"name": "linux-g++-rust-debug-tests-samples",
"name": "linux-g++-no-rust-debug-tests-samples",
"inherits": [
"linux-g++-debug-tests-samples",
"rust-amqp"
"no-rust-amqp"
],
"displayName": "Linux c++ Debug+Tests, samples, Rust AMQP"
"displayName": "Linux c++ Debug+Tests, samples, No Rust"
},
{
"name": "linux-g++-11-debug",
Expand Down
5 changes: 1 addition & 4 deletions cmake-modules/AddGoogleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ else()
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
FetchContent_MakeAvailable(googletest)
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake-modules/AzureVcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ macro(az_vcpkg_integrate)
FetchContent_GetProperties(vcpkg)
# make sure to pull vcpkg only once.
if(NOT vcpkg_POPULATED)
FetchContent_Populate(vcpkg)
FetchContent_MakeAvailable(vcpkg)
endif()
# use the vcpkg source path
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/jobs/ci.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
displayName: Test
- ${{ parameters.PostTestSteps }}


- pwsh: |
$ErrorActionPreference = 'SilentlyContinue'
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/stages/platform-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"UWP_release": {
"CMAKE_SYSTEM_NAME": "WindowsStore",
"CMAKE_SYSTEM_VERSION": "10.0",
"CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON -DDISABLE_AZURE_CORE_OPENTELEMETRY=ON ",
"CmakeArgs": " -DBUILD_TRANSPORT_WINHTTP=ON ",
"BuildArgs": "--parallel 8 --config Release"
}
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory(azure-core)

if (NOT BUILD_WINDOWS_UWP)
if (NOT DISABLE_AMQP)
message(STATUS "Including AMQP library")
add_subdirectory(azure-core-amqp)
endif()
Expand Down
4 changes: 4 additions & 0 deletions sdk/core/azure-core-amqp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

### Features Added

Rust based AMQP library is now available for use in the Azure SDK for C++. This replaces the uAMQP library with a library based on the azure_core_amqp Rust crate.

### Breaking Changes

Updated `MessageProperties`to remove `Azure::Nullable` from the types which are an `AmqpValue` because the `AmqpValue` already embeds the concept of nullability.

### Bugs Fixed

### Other Changes
Expand Down
39 changes: 39 additions & 0 deletions sdk/core/azure-core-amqp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ if(NOT AZ_ALL_LIBRARIES)
endif()
endif()

set(USE_RUST_AMQP ON CACHE BOOL "Enable Rust AMQP stack" FORCE)

if (DISABLE_RUST_IN_BUILD)
message(STATUS "Disabling Rust based functionality in build.")
set(USE_RUST_AMQP OFF CACHE BOOL "Enable Rust AMQP stack" FORCE)
endif()


if (USE_RUST_AMQP)
message(STATUS "Using RUST based AMQP stack")
set(VENDOR_UAMQP OFF CACHE BOOL "Use vendored uAMQP" FORCE)
set(USE_UAMQP OFF CACHE BOOL "Enable uAMQP AMQP stack" FORCE)
else()
set(USE_UAMQP ON CACHE BOOL "Enable uAMQP AMQP stack" FORCE)
set(VENDOR_UAMQP ON CACHE BOOL "Use vendored uamqp" FORCE)
Expand Down Expand Up @@ -71,13 +79,38 @@ if (USE_RUST_AMQP)
# install_rustup()

include(FetchContent)

# If the cmake build is x86, add the x86 target to the rust build
message("VCPKG_TARGET_TRIPLET: ${VCPKG_TARGET_TRIPLET}")
if (${VCPKG_TARGET_TRIPLET} MATCHES "x86.*")
message("Configure rust for x86 builds.")

if (${VCPKG_TARGET_TRIPLET} MATCHES ".*-windows.*")
message("Configure rust for Windows x86 builds.")

# Run the rustup command to install the toolchain
execute_process(COMMAND rustup toolchain install stable-i686-pc-windows-msvc)

set(Rust_TOOLCHAIN "stable-i686-pc-windows-msvc")
set(Rust_CARGO_TARGET "i686-pc-windows-msvc")
else()
message("Configure rust for Linux x86 builds.")
execute_process(COMMAND rustup toolchain install stable-i686-unknown-linux-gnu)
set(Rust_CARGO_TARGET "i686-unknown-linux-gnu")
endif()
else()
message("Configure rust for 64 builds.")
endif()


FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)


# Import targets defined in a package or workspace manifest `Cargo.toml` file
corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/impl/rust_amqp/rust_amqp/rust_wrapper/Cargo.toml)
endif()
Expand Down Expand Up @@ -257,6 +290,12 @@ elseif(USE_RUST_AMQP)

if (MSVC)
target_link_libraries(azure-core-amqp PRIVATE Secur32 ncrypt)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(azure-core-amqp PRIVATE "-lssl -lcrypto")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# target_link_libraries()
else()
target_link_libraries(azure-core-amqp PRIVATE "-lssl -lcrypto")
endif()
endif()

Expand Down
21 changes: 21 additions & 0 deletions sdk/core/azure-core-amqp/Test-Cleanup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# cspell: ignore JOBID

. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1"

Write-Host "Test Broker output:"
Receive-Job -Id $env:TEST_BROKER_JOBID

# Check if the test broker job is still running
$job = Get-Job -Id $env:TEST_BROKER_JOBID
if ($job.State -ne "Running") {
Write-Host "Test broker terminated unexpectedly."
exit 1
}

# Stop the test broker job started in Test-Setup.ps1
Write-Host "Stopping test broker"
Stop-Job -Id $env:TEST_BROKER_JOBID
Remove-Job -Id $env:TEST_BROKER_JOBID
Write-Host "Test broker stopped."
Loading

0 comments on commit a83dba3

Please sign in to comment.