From e337cdcb65cbc6941f30f1c88e099a5bddb19d78 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Wed, 12 Aug 2026 19:42:32 +1000 Subject: [PATCH] Remove gsl/span dependency from C++ API. --- sdk_v2/cpp/CMakeLists.txt | 3 +-- sdk_v2/cpp/docs/WrapperInterfacesDesign.md | 15 ++++++--------- .../cpp/include/foundry_local/foundry_local_cpp.h | 3 +-- .../foundry_local/foundry_local_cpp.inline.h | 10 ++++++++-- sdk_v2/cpp/test/sdk_api/catalog_test.cc | 8 +++----- sdk_v2/cpp/vcpkg.json | 1 - sdk_v2/js/native/src/catalog.cc | 2 +- sdk_v2/js/native/src/model.cc | 2 +- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/sdk_v2/cpp/CMakeLists.txt b/sdk_v2/cpp/CMakeLists.txt index d1020a1d5..b935e2ce4 100644 --- a/sdk_v2/cpp/CMakeLists.txt +++ b/sdk_v2/cpp/CMakeLists.txt @@ -94,7 +94,6 @@ include(cmake/Sanitizers.cmake) find_package(nlohmann_json CONFIG REQUIRED) find_package(azure-storage-blobs-cpp CONFIG REQUIRED) find_package(spdlog CONFIG REQUIRED) -find_package(Microsoft.GSL CONFIG REQUIRED) find_package(LibArchive REQUIRED) if(FOUNDRY_LOCAL_BUILD_SERVICE) @@ -557,7 +556,7 @@ target_include_directories(foundry_local_cpp $ $ ) -target_link_libraries(foundry_local_cpp INTERFACE foundry_local Microsoft.GSL::GSL) +target_link_libraries(foundry_local_cpp INTERFACE foundry_local) # -------------------------------------------------------------------------- # Split debug symbols (Linux / macOS, RelWithDebInfo only) diff --git a/sdk_v2/cpp/docs/WrapperInterfacesDesign.md b/sdk_v2/cpp/docs/WrapperInterfacesDesign.md index 6134ea9c0..bfa0b9599 100644 --- a/sdk_v2/cpp/docs/WrapperInterfacesDesign.md +++ b/sdk_v2/cpp/docs/WrapperInterfacesDesign.md @@ -153,22 +153,19 @@ Driven by the interface decisions: `std::unique_ptr`. Null = not found. - `Catalog::GetLatestVersion(const IModel&)` returns `std::unique_ptr`. - `Catalog::GetModels()` / `GetCachedModels()` / `GetLoadedModels()` return - `ModelList`. `ModelList::Models()` returns `gsl::span>`. + `ModelList`. `ModelList::Models()` returns `std::vector`; the pointers + remain valid for the lifetime of the `ModelList`. - `Session`, `ChatSession`, `AudioSession` constructors take `IModel&`. - `IModel::SelectVariant(const IModel&)` and `Catalog::GetLatestVersion(const IModel&)` internally use `static_cast(arg).native_handle()`. RTTI is not used; the downcast is sound because `Model` is the only concrete `IModel` produced by the SDK. -### 6. GSL dependency +### 6. Non-owning collections -`microsoft-gsl` is added as a vcpkg dependency. - -- `gsl::span` is used in public API where a non-owning view of a contiguous range is - returned (e.g. `ModelList::Models()`, `InputOutputInfo::inputs`/`outputs`). -- `gsl::not_null` is allowed for internal class members. It is **not** used in public - API parameters or return types — references convey the same non-null contract more - idiomatically. +- Public collection APIs use standard-library types so consumers do not need extra header dependencies. +- `ModelList::Models()` projects its internally owned models as non-owning `IModel*` values. It does not + expose the `std::unique_ptr` storage used to manage their lifetimes. ### 7. Removed types diff --git a/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.h b/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.h index 30b69a529..6076da0b1 100644 --- a/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.h +++ b/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -745,7 +744,7 @@ class ModelList { ModelList(const ModelList&) = delete; ModelList& operator=(const ModelList&) = delete; - gsl::span> Models() const noexcept; + std::vector Models() const; size_t size() const noexcept; auto begin() const noexcept { return models_.begin(); } auto end() const noexcept { return models_.end(); } diff --git a/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.inline.h b/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.inline.h index 15c34b4d1..f184fa9e0 100644 --- a/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.inline.h +++ b/sdk_v2/cpp/include/foundry_local/foundry_local_cpp.inline.h @@ -553,8 +553,14 @@ inline ModelList::ModelList(flModelList& model_list) } } -inline gsl::span> ModelList::Models() const noexcept { - return {models_.data(), models_.size()}; +inline std::vector ModelList::Models() const { + std::vector models; + models.reserve(models_.size()); + for (const auto& model : models_) { + models.push_back(model.get()); + } + + return models; } inline size_t ModelList::size() const noexcept { diff --git a/sdk_v2/cpp/test/sdk_api/catalog_test.cc b/sdk_v2/cpp/test/sdk_api/catalog_test.cc index 3284744f6..b30c0557c 100644 --- a/sdk_v2/cpp/test/sdk_api/catalog_test.cc +++ b/sdk_v2/cpp/test/sdk_api/catalog_test.cc @@ -2,7 +2,6 @@ // Licensed under the MIT License. // Catalog-focused SDK integration tests using only the public C++ API. -#include #include #include @@ -10,12 +9,11 @@ namespace { -const foundry_local::IModel* FindModelByAlias( - gsl::span> models, - std::string_view alias) { +const foundry_local::IModel* FindModelByAlias(const std::vector& models, + std::string_view alias) { for (const auto& model : models) { if (model->GetInfo().Alias() == alias) { - return model.get(); + return model; } } diff --git a/sdk_v2/cpp/vcpkg.json b/sdk_v2/cpp/vcpkg.json index 056d964aa..ebd9bbc77 100644 --- a/sdk_v2/cpp/vcpkg.json +++ b/sdk_v2/cpp/vcpkg.json @@ -21,7 +21,6 @@ "features": ["curl"], "platform": "!windows | uwp" }, - "ms-gsl", "zlib", "nlohmann-json", "spdlog" diff --git a/sdk_v2/js/native/src/catalog.cc b/sdk_v2/js/native/src/catalog.cc index 8372187a2..6ed66936d 100644 --- a/sdk_v2/js/native/src/catalog.cc +++ b/sdk_v2/js/native/src/catalog.cc @@ -25,7 +25,7 @@ Napi::Value WrapModelList(Napi::Env env, foundry_local::ModelList ml, Napi::Array arr = Napi::Array::New(env, models.size()); for (size_t i = 0; i < models.size(); ++i) { ModelCtorToken token; - token.impl = models[i].get(); + token.impl = models[i]; token.keepalive = list; token.manager = Napi::Reference::New(manager.Value(), 1); arr.Set(static_cast(i), Model::NewInstance(env, std::move(token))); diff --git a/sdk_v2/js/native/src/model.cc b/sdk_v2/js/native/src/model.cc index c7164778f..06ce2c697 100644 --- a/sdk_v2/js/native/src/model.cc +++ b/sdk_v2/js/native/src/model.cc @@ -149,7 +149,7 @@ Napi::Array WrapModelList(Napi::Env env, std::shared_ptr::New(manager.Value(), 1);