Skip to content

Commit

Permalink
(#23663) azure-sdk-for-cpp/1.11.3:new recipe
Browse files Browse the repository at this point in the history
* azure-sdk-for-cpp/1.11.3:new recipe

* rmdir share folder

* create a cmake wrapper to build modules seperately

* add openssl as requirement

* build all modules as default and add individual tests

* add new line

* fix linking problems

* fix linter warning

* simplified cmake.configure() for azure-sdk

---------

Co-authored-by: trns1997 <[email protected]>
Co-authored-by: memsharded <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent a951d75 commit 04c33a8
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 0 deletions.
18 changes: 18 additions & 0 deletions recipes/azure-sdk-for-cpp/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.15)
project(cmake_wrapper)

# The cmake_wrapper allows users to build only modules they want and not the entire sdk,
# the CMakeLists.txt from source does not provide this modularity to users (it's all or nothing).

foreach(sdk ${BUILD_LIST})
if(${sdk} STREQUAL azure-core)
# Always build Core
add_subdirectory("src/sdk/core")
elseif(${sdk} STREQUAL azure-storage-common)
add_subdirectory("src/sdk/storage/azure-storage-common")
elseif(${sdk} STREQUAL azure-storage-blobs)
add_subdirectory("src/sdk/storage/azure-storage-blobs")
elseif(${sdk} STREQUAL azure-storage-files-shares)
add_subdirectory("src/sdk/storage/azure-storage-files-shares")
endif()
endforeach()
4 changes: 4 additions & 0 deletions recipes/azure-sdk-for-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.11.3":
url: "https://github.com/Azure/azure-sdk-for-cpp/archive/refs/tags/azure-core_1.11.3.tar.gz"
sha256: "c67e42622bf1ebafee29aa09f333e41adc24712b0c993ada5dd97c9265b444cc"
110 changes: 110 additions & 0 deletions recipes/azure-sdk-for-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout
from conan.tools.files import get, copy, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.54.0"

AZURE_SDK_MODULES = (
"azure-storage-common",
"azure-storage-blobs",
"azure-storage-files-shares"
)

class AzureSDKForCppConan(ConanFile):
name = "azure-sdk-for-cpp"
description = "Microsoft Azure Storage Client Library for C++"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Azure/azure-sdk-for-cpp"
topics = ("azure", "cpp", "cross-platform", "microsoft", "cloud")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
options.update({_name: [True, False] for _name in AZURE_SDK_MODULES})
default_options = {"shared": False, "fPIC": True}
default_options.update({_name: True for _name in AZURE_SDK_MODULES}) # Build all modules by default, let users pick what they do not want

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def configure(self):
if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

def requirements(self):
self.requires("openssl/[>=1.1 <4]")
self.requires("libcurl/[>=7.78 <9]")
self.requires("libxml2/[>=2.12.5 <3]")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 14)

# Open to contributions for windows and apple
if self.settings.os != "Linux":
raise ConanInvalidConfiguration(
f"{self.ref} Conan recipe in ConanCenter still does not support {self.settings.os}, contributions to the recipe welcome.")

if self.settings.compiler != "gcc":
raise ConanInvalidConfiguration(
f"{self.ref} Conan recipe in ConanCenter still does not support {self.settings.compiler}, contributions to the recipe welcome.")

if self.settings.compiler == 'gcc' and Version(self.settings.compiler.version) < "6":
raise ConanInvalidConfiguration("Building requires GCC >= 6")

def generate(self):
tc = CMakeToolchain(self)

build_list = ["azure-core"]
for sdk in AZURE_SDK_MODULES:
if self.options.get_safe(sdk):
build_list.append(sdk)
tc.cache_variables["BUILD_LIST"] = ";".join(build_list)

tc.variables["AZ_ALL_LIBRARIES"] = "ON"
tc.variables["FETCH_SOURCE_DEPS"] = "OFF"
tc.cache_variables["BUILD_TESTING"] = "OFF"
tc.cache_variables["BUILD_WINDOWS_UWP"] = "ON"
tc.cache_variables["DISABLE_AZURE_CORE_OPENTELEMETRY"] = "ON"
tc.cache_variables["BUILD_TRANSPORT_CURL"] = "ON"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE.txt",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "AzureSDK")

# core component
self.cpp_info.components["azure-core"].set_property("cmake_target_name", "Azure::azure-core")
self.cpp_info.components["azure-core"].libs = ["azure-core"]
self.cpp_info.components["azure-core"].requires.extend(["openssl::openssl", "libcurl::curl", "libxml2::libxml2"])

enabled_sdks = [sdk for sdk in AZURE_SDK_MODULES if self.options.get_safe(sdk)]
for sdk in enabled_sdks:
self.cpp_info.components[sdk].set_property("cmake_target_name", f"Azure::{sdk}")
self.cpp_info.components[sdk].libs = [sdk]
17 changes: 17 additions & 0 deletions recipes/azure-sdk-for-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.8)

project(test_package LANGUAGES CXX)

find_package(AzureSDK CONFIG REQUIRED)

add_executable(test_azure-core test_azure-core.cc)
target_link_libraries(test_azure-core PRIVATE Azure::azure-core)

add_executable(test_azure-storage-common test_azure-storage-common.cc)
target_link_libraries(test_azure-storage-common PRIVATE Azure::azure-core Azure::azure-storage-common)

add_executable(test_azure-storage-blobs test_azure-storage-blobs.cc)
target_link_libraries(test_azure-storage-blobs PRIVATE Azure::azure-core Azure::azure-storage-common Azure::azure-storage-blobs)

add_executable(test_azure-storage-files-shares test_azure-storage-files-shares.cc)
target_link_libraries(test_azure-storage-files-shares PRIVATE Azure::azure-core Azure::azure-storage-common Azure::azure-storage-files-shares)
33 changes: 33 additions & 0 deletions recipes/azure-sdk-for-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"

@property
def _tested_modules(self):
return ["azure-core",
"azure-storage-common",
"azure-storage-blobs",
"azure-storage-files-shares"]

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
for module in self._tested_modules:
bin_path = os.path.join(self.cpp.build.bindirs[0], f"test_{module}")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/azure-sdk-for-cpp/all/test_package/test_azure-core.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include <azure/core.hpp>

int main()
{
std::vector<uint8_t> data = {1, 2, 3, 4};
Azure::Core::IO::MemoryBodyStream stream(data);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <azure/storage/blobs.hpp>

using namespace Azure::Storage::Blobs;

int main()
{
BlobAudience audience{"TEST"};

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <azure/storage/common/storage_common.hpp>

using namespace Azure::Storage;

int main()
{
ContentHash contentHash{};

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <azure/storage/files/shares.hpp>

using namespace Azure::Storage::Files::Shares;

int main()
{
SetSharePropertiesOptions options;

return 0;
}
3 changes: 3 additions & 0 deletions recipes/azure-sdk-for-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.11.3":
folder: "all"

0 comments on commit 04c33a8

Please sign in to comment.