From c85f05ab1aa1f49b79fa5c7b0ff329e80c23d287 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 02:29:46 +0200 Subject: [PATCH 01/31] [vcpkg] Add ubuntu-insights --- .../ubuntu-insights/0001-c-api-free.patch | 18 ++++ .../vcpkg-ports/ubuntu-insights/insights.def | 12 +++ .../ubuntu-insights/portfile.cmake | 93 +++++++++++++++++++ .../ubuntu-insights-config.cmake.in | 28 ++++++ 3rd-party/vcpkg-ports/ubuntu-insights/usage | 13 +++ .../vcpkg-ports/ubuntu-insights/vcpkg.json | 13 +++ vcpkg.json | 3 +- 7 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/0001-c-api-free.patch create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/insights.def create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/usage create mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/0001-c-api-free.patch b/3rd-party/vcpkg-ports/ubuntu-insights/0001-c-api-free.patch new file mode 100644 index 0000000000..80eed4d47e --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/0001-c-api-free.patch @@ -0,0 +1,18 @@ +diff --git a/insights/C/libinsights.go b/insights/C/libinsights.go +--- a/insights/C/libinsights.go ++++ b/insights/C/libinsights.go +@@ -16,6 +16,14 @@ import ( + "github.com/ubuntu/ubuntu-insights/insights" + ) + ++// insights_free releases strings returned by the C API using the library's ++// allocator, including when the caller uses a different Windows C runtime. ++// ++//export insights_free ++func insights_free(ptr unsafe.Pointer) { ++ C.free(ptr) ++} ++ + /** + * insights_collect creates a report for the specified source. + * If config is NULL, defaults are used. diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/insights.def b/3rd-party/vcpkg-ports/ubuntu-insights/insights.def new file mode 100644 index 0000000000..7c5f0ecb86 --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/insights.def @@ -0,0 +1,12 @@ +LIBRARY libinsights.dll +EXPORTS + insights_free + insights_collect + insights_compile + insights_write + insights_upload + insights_get_consent_state + insights_set_consent_state + insights_get_system_opt_out_state + insights_set_system_opt_out_state + insights_set_log_callback diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake new file mode 100644 index 0000000000..95ad9c51fa --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -0,0 +1,93 @@ +set(VCPKG_BUILD_TYPE release) +set(VCPKG_POLICY_MISMATCHED_NUMBER_OF_BINARIES enabled) +vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) + +# Using patchelf on the server tools causes them to crash +set(VCPKG_FIXUP_ELF_RPATH OFF) + +if(VCPKG_TARGET_IS_LINUX) + set(INSIGHTS_LIBRARY libinsights.so.1) +elseif(VCPKG_TARGET_IS_OSX) + set(INSIGHTS_LIBRARY libinsights.1.dylib) +elseif(VCPKG_TARGET_IS_WINDOWS) + set(INSIGHTS_LIBRARY libinsights.dll) +else() + message(FATAL_ERROR "ubuntu-insights supports Linux, macOS, and Windows targets.") +endif() + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO ubuntu/ubuntu-insights + REF bd67ac2fafda18bfca97e3c4843e9e4d3ca71cf1 + SHA512 2d9d170e6b831c18daf6fda60e736200a29d843cf5baf9206b2fabb3f500216b7ec31e70ae430f2b46f43054d8d9243cb50ddac3d8853c0ece76825f370e2451 + PATCHES 0001-c-api-free.patch +) + +find_program(GO_EXECUTABLE NAMES go REQUIRED) + +set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") +file(MAKE_DIRECTORY "${tools_dir}") + +function(add_insights_tool tool package) + vcpkg_execute_required_process( + COMMAND "${GO_EXECUTABLE}" build -trimpath + -o "${tools_dir}/${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}" "${package}" + WORKING_DIRECTORY "${SOURCE_PATH}" + LOGNAME "build-${tool}" + ) + list(APPEND INSIGHTS_TOOLS "${tool}") + set(INSIGHTS_TOOLS "${INSIGHTS_TOOLS}" PARENT_SCOPE) +endfunction() + +set(INSIGHTS_TOOLS "") + +add_insights_tool(ubuntu-insights ./insights/cmd/insights) +if(VCPKG_TARGET_IS_LINUX) + add_insights_tool(web-service ./server/cmd/web-service) + add_insights_tool(ingest-service ./server/cmd/ingest-service) +endif() + +vcpkg_execute_required_process( + COMMAND "${GO_EXECUTABLE}" run -tags=tools ./generate/... + WORKING_DIRECTORY "${SOURCE_PATH}/insights/C" + LOGNAME build-c-api +) + +if(VCPKG_TARGET_IS_WINDOWS) + # Generate an import library, otherwise MSVC will not be able to link against the generated dll + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib") + set(INSIGHTS_IMPLIB insights.lib) + find_program(lib_tool NAMES lib.exe llvm-lib REQUIRED) + vcpkg_execute_required_process( + COMMAND "${lib_tool}" "/def:${CMAKE_CURRENT_LIST_DIR}/insights.def" /machine:x64 + "/out:${CURRENT_PACKAGES_DIR}/lib/${INSIGHTS_IMPLIB}" + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}" + LOGNAME import-library + ) + + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/bin") +else() + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/lib") +endif() + +file(INSTALL + "${SOURCE_PATH}/insights/generated/insights.h" + "${SOURCE_PATH}/insights/generated/types.h" + DESTINATION "${CURRENT_PACKAGES_DIR}/include/insights") + +configure_file("${CMAKE_CURRENT_LIST_DIR}/ubuntu-insights-config.cmake.in" + "${CURRENT_PACKAGES_DIR}/share/${PORT}/ubuntu-insights-config.cmake" @ONLY) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CURRENT_PACKAGES_DIR}/share/${PORT}/ubuntu-insights-config-version.cmake" + VERSION "${VERSION}" + COMPATIBILITY SameMajorVersion +) + +vcpkg_copy_tool_dependencies("${tools_dir}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in new file mode 100644 index 0000000000..269e22640f --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in @@ -0,0 +1,28 @@ +if(TARGET ubuntu-insights::insights) + return() +endif() + +get_filename_component(_insights_prefix "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +add_library(ubuntu-insights::insights SHARED IMPORTED) +set_target_properties(ubuntu-insights::insights PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_insights_prefix}/include" +) +if(WIN32) + set_target_properties(ubuntu-insights::insights PROPERTIES + IMPORTED_LOCATION "${_insights_prefix}/bin/@INSIGHTS_LIBRARY@" + IMPORTED_IMPLIB "${_insights_prefix}/lib/@INSIGHTS_IMPLIB@" + ) +else() + set_target_properties(ubuntu-insights::insights PROPERTIES + IMPORTED_LOCATION "${_insights_prefix}/lib/@INSIGHTS_LIBRARY@" + ) +endif() + +foreach(_insights_tool IN ITEMS @INSIGHTS_TOOLS@) + add_executable(ubuntu-insights::${_insights_tool} IMPORTED) + set_target_properties(ubuntu-insights::${_insights_tool} PROPERTIES + IMPORTED_LOCATION "${_insights_prefix}/tools/ubuntu-insights/${_insights_tool}@VCPKG_TARGET_EXECUTABLE_SUFFIX@" + ) +endforeach() +unset(_insights_prefix) +unset(_insights_tool) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/usage b/3rd-party/vcpkg-ports/ubuntu-insights/usage new file mode 100644 index 0000000000..7b64d79692 --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/usage @@ -0,0 +1,13 @@ +ubuntu-insights provides a CMake package: + + find_package(ubuntu-insights CONFIG REQUIRED) + target_link_libraries(my_app PRIVATE ubuntu-insights::insights) + +Include the generated C API with: + + #include + +Imported executable targets: + ubuntu-insights::ubuntu-insights + ubuntu-insights::web-service (Linux only) + ubuntu-insights::ingest-service (Linux only) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json new file mode 100644 index 0000000000..6522fa43b7 --- /dev/null +++ b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json @@ -0,0 +1,13 @@ +{ + "name": "ubuntu-insights", + "version": "1.0.1", + "description": "Ubuntu Insights client, server executables, and C shared library", + "homepage": "https://github.com/ubuntu/ubuntu-insights", + "license": "GPL-3.0-only", + "dependencies": [ + { + "name": "wayland", + "platform": "linux" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json index 3671752f95..e1db047fe2 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -28,7 +28,8 @@ "server" ] }, - "premock" + "premock", + "ubuntu-insights" ], "overrides": [ { From 563df73e7b4d72152248afb6643c2629f5cedd65 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 04:38:27 +0200 Subject: [PATCH 02/31] [insights] Add wrapper & smoke tests for insights --- include/ubuntu_insights/libinsights_wrapper.h | 63 +++++++++++++ src/CMakeLists.txt | 1 + src/ubuntu_insights/CMakeLists.txt | 21 +++++ src/ubuntu_insights/libinsights_wrapper.cpp | 91 +++++++++++++++++++ tests/unit/CMakeLists.txt | 2 + tests/unit/test_libinsights.cpp | 84 +++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 include/ubuntu_insights/libinsights_wrapper.h create mode 100644 src/ubuntu_insights/CMakeLists.txt create mode 100644 src/ubuntu_insights/libinsights_wrapper.cpp create mode 100644 tests/unit/test_libinsights.cpp diff --git a/include/ubuntu_insights/libinsights_wrapper.h b/include/ubuntu_insights/libinsights_wrapper.h new file mode 100644 index 0000000000..4cd423df20 --- /dev/null +++ b/include/ubuntu_insights/libinsights_wrapper.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +#include + +// cgo generates C99 _Bool, which is not valid in C++. +#define _Bool bool +#include +#undef _Bool + +#define MP_LIBINSIGHTS multipass::LibInsights::instance() + +namespace multipass +{ +class LibInsights : public Singleton +{ +public: + LibInsights(const Singleton::PrivatePass& pass) noexcept; + + virtual void insights_free(void* ptr) const; + [[nodiscard]] virtual char* insights_collect(insights_const_config* config, + insights_const_char* source, + insights_const_collect_flags* flags, + char** out_report) const; + [[nodiscard]] virtual char* insights_compile(insights_const_config* config, + insights_const_compile_flags* flags, + char** out_report) const; + [[nodiscard]] virtual char* insights_write(insights_const_config* config, + insights_const_char* source, + insights_const_char* report, + insights_const_write_flags* flags) const; + [[nodiscard]] virtual char* insights_upload(insights_const_config* config, + insights_const_char** sources, + size_t sources_len, + insights_const_upload_flags* flags) const; + [[nodiscard]] virtual insights_consent_state + insights_get_consent_state(insights_const_config* config, insights_const_char* source) const; + [[nodiscard]] virtual char* insights_set_consent_state(insights_const_config* config, + insights_const_char* source, + bool new_state) const; + [[nodiscard]] virtual bool insights_get_system_opt_out_state( + insights_const_config* config) const; + [[nodiscard]] virtual char* insights_set_system_opt_out_state(insights_const_config* config, + bool state) const; + virtual void insights_set_log_callback(insights_logger_callback callback) const; +}; +} // namespace multipass diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ad417fefe..7f3b51e0d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory(settings) add_subdirectory(simplestreams) add_subdirectory(ssh) add_subdirectory(sshfs_mount) +add_subdirectory(ubuntu_insights) add_subdirectory(user_messages) add_subdirectory(utils) add_subdirectory(xz_decoder) diff --git a/src/ubuntu_insights/CMakeLists.txt b/src/ubuntu_insights/CMakeLists.txt new file mode 100644 index 0000000000..5f22340a71 --- /dev/null +++ b/src/ubuntu_insights/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (C) Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +add_library(ubuntu_insights STATIC libinsights_wrapper.cpp) + +find_package(ubuntu-insights CONFIG REQUIRED) + +target_link_libraries(ubuntu_insights PUBLIC ubuntu-insights::insights) +target_include_directories(ubuntu_insights PUBLIC "${CMAKE_SOURCE_DIR}/include") diff --git a/src/ubuntu_insights/libinsights_wrapper.cpp b/src/ubuntu_insights/libinsights_wrapper.cpp new file mode 100644 index 0000000000..49bb435fa1 --- /dev/null +++ b/src/ubuntu_insights/libinsights_wrapper.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include + +namespace multipass +{ +LibInsights::LibInsights(const Singleton::PrivatePass& pass) noexcept + : Singleton{pass} +{ +} + +void LibInsights::insights_free(void* ptr) const +{ + ::insights_free(ptr); +} + +char* LibInsights::insights_collect(insights_const_config* config, + insights_const_char* source, + insights_const_collect_flags* flags, + char** out_report) const +{ + return ::insights_collect(config, source, flags, out_report); +} + +char* LibInsights::insights_compile(insights_const_config* config, + insights_const_compile_flags* flags, + char** out_report) const +{ + return ::insights_compile(config, flags, out_report); +} + +char* LibInsights::insights_write(insights_const_config* config, + insights_const_char* source, + insights_const_char* report, + insights_const_write_flags* flags) const +{ + return ::insights_write(config, source, report, flags); +} + +char* LibInsights::insights_upload(insights_const_config* config, + insights_const_char** sources, + size_t sources_len, + insights_const_upload_flags* flags) const +{ + return ::insights_upload(config, sources, sources_len, flags); +} + +insights_consent_state LibInsights::insights_get_consent_state(insights_const_config* config, + insights_const_char* source) const +{ + return ::insights_get_consent_state(config, source); +} + +char* LibInsights::insights_set_consent_state(insights_const_config* config, + insights_const_char* source, + bool new_state) const +{ + return ::insights_set_consent_state(config, source, new_state); +} + +bool LibInsights::insights_get_system_opt_out_state(insights_const_config* config) const +{ + return ::insights_get_system_opt_out_state(config); +} + +char* LibInsights::insights_set_system_opt_out_state(insights_const_config* config, + bool state) const +{ + return ::insights_set_system_opt_out_state(config, state); +} + +void LibInsights::insights_set_log_callback(insights_logger_callback callback) const +{ + ::insights_set_log_callback(callback); +} +} // namespace multipass diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 064d73c52d..f41c0dda72 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -26,12 +26,14 @@ add_executable(multipass_integration_tests common.cpp temp_dir.cpp test_libssh.cpp + test_libinsights.cpp ) target_link_libraries(multipass_integration_tests PRIVATE GTest::gmock_main Qt6::Core fmt::fmt-header-only libssh_wrapper + ubuntu_insights ) target_include_directories(multipass_integration_tests PRIVATE ${CMAKE_SOURCE_DIR} diff --git a/tests/unit/test_libinsights.cpp b/tests/unit/test_libinsights.cpp new file mode 100644 index 0000000000..547647b7d0 --- /dev/null +++ b/tests/unit/test_libinsights.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include + +#include + +#include +#include +#include + +namespace +{ +class UbuntuInsightsAPI : public testing::Test +{ +protected: + void SetUp() override + { + ASSERT_TRUE(directory.isValid()); + + consent_dir = directory.filePath("consent").toUtf8(); + insights_dir = directory.filePath("insights").toUtf8(); + system_config_dir = directory.filePath("system").toUtf8(); + + config = {consent_dir.constData(), + insights_dir.constData(), + system_config_dir.constData(), + false}; + } + + QTemporaryDir directory; + QByteArray consent_dir; + QByteArray insights_dir; + QByteArray system_config_dir; + insights_config config{}; +}; +} // namespace + +TEST_F(UbuntuInsightsAPI, missingConsentIsUnknown) +{ + EXPECT_EQ(MP_LIBINSIGHTS.insights_get_consent_state(&config, "multipass"), + INSIGHTS_CONSENT_UNKNOWN); +} + +TEST_F(UbuntuInsightsAPI, consentCanBeCreatedAndUpdated) +{ + for (const auto consent : {true, false}) + { + char* error = MP_LIBINSIGHTS.insights_set_consent_state(&config, "multipass", consent); + + EXPECT_EQ(error, nullptr) << error; + EXPECT_EQ(MP_LIBINSIGHTS.insights_get_consent_state(&config, "multipass"), + consent ? INSIGHTS_CONSENT_TRUE : INSIGHTS_CONSENT_FALSE); + + MP_LIBINSIGHTS.insights_free(error); + } +} + +TEST_F(UbuntuInsightsAPI, consentIsSpecificToSource) +{ + char* error = MP_LIBINSIGHTS.insights_set_consent_state(&config, "multipass", true); + + EXPECT_EQ(error, nullptr) << error; + EXPECT_EQ(MP_LIBINSIGHTS.insights_get_consent_state(&config, "other"), + INSIGHTS_CONSENT_UNKNOWN); + EXPECT_EQ(MP_LIBINSIGHTS.insights_get_consent_state(&config, "multipass"), + INSIGHTS_CONSENT_TRUE); + + MP_LIBINSIGHTS.insights_free(error); +} From 2952967f6666426656ce63049478a9522b0f6d2d Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 04:40:15 +0200 Subject: [PATCH 03/31] [snap] Support building multipass with insights Adds go as a build-dependency and adds the appropriate plugs to enable ubuntu-insights metric collection and upload functionalities --- packaging/gui-less/snap/snapcraft.yaml | 23 ++++++++++++++++++++++- snap/snapcraft.yaml | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index c10608ef58..c0bc745c7b 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -36,6 +36,14 @@ plugs: all-home: interface: home read: all + dot-config-ubuntu-insights: + interface: personal-files + read: + - $HOME/.config/ubuntu-insights + dot-cache-ubuntu-insights: + interface: personal-files + write: + - $HOME/.cache/ubuntu-insights apps: multipassd: @@ -63,6 +71,16 @@ apps: - network-observe # for network listing (to read `/sys/devices/**/net/*`) - removable-media - system-observe # to read the host's os-release + + # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. + - hardware-observe + - wayland + - x11 + - network # Needed for uploading + - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. + - dot-config-ubuntu-insights # Default config location + - dot-cache-ubuntu-insights # Default cache location + - block-devices # Required to see encrypted partitions. `dm-crypt` also works. multipass: environment: LD_LIBRARY_PATH: *library-path @@ -91,7 +109,7 @@ parts: plugin: cmake build-snaps: [] build-environment: - - PATH: /snap/bin:$PATH + - PATH: /usr/lib/go-1.26/bin:/snap/bin:$PATH - PYTHON: /usr/bin/python3 - PYTHONPATH: "" - VCPKG_FORCE_SYSTEM_BINARIES: 1 @@ -99,6 +117,7 @@ parts: - CLANG_VERSION: "19" - CXX: clang++-${CLANG_VERSION} - CC: clang-${CLANG_VERSION} + - GOTOOLCHAIN: local - CMAKE_PRESET: snap-gui-less build-packages: - on arm64: [libgles2-mesa-dev] @@ -132,6 +151,7 @@ parts: - bison # qtbase[dbus] -> glib2 -> gettext[tools] -> bison - gettext # provides msgfmt/msgmerge with matching libgettextsrc on the system loader path - rustup + - golang-1.26-go stage-packages: - apparmor @@ -144,6 +164,7 @@ parts: - libgtkmm-3.0-1t64 - libglibmm-2.4-1t64 - libpangomm-1.4-1v5 + - libwayland-dev stage: - -**/glvnd diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index f2f21faa82..7b1d572d73 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -32,6 +32,14 @@ plugs: all-home: interface: home read: all + dot-config-ubuntu-insights: + interface: personal-files + read: + - $HOME/.config/ubuntu-insights + dot-cache-ubuntu-insights: + interface: personal-files + write: + - $HOME/.cache/ubuntu-insights apps: multipassd: @@ -60,6 +68,16 @@ apps: - network-observe # for network listing (to read `/sys/devices/**/net/*`) - removable-media - system-observe # to read the host's os-release + + # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. + - hardware-observe + - wayland + - x11 + - network # Needed for uploading + - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. + - dot-config-ubuntu-insights # Default config location + - dot-cache-ubuntu-insights # Default cache location + - block-devices # Required to see encrypted partitions. `dm-crypt` also works. multipass: environment: LD_LIBRARY_PATH: *library-path @@ -113,7 +131,7 @@ parts: build-snaps: - cmake build-environment: - - PATH: /snap/bin:$PATH + - PATH: /usr/lib/go-1.26/bin:/snap/bin:$PATH - PYTHON: /usr/bin/python3 - PYTHONPATH: "" - VCPKG_FORCE_SYSTEM_BINARIES: 1 @@ -121,6 +139,7 @@ parts: - CLANG_VERSION: "19" - CXX: clang++-${CLANG_VERSION} - CC: clang-${CLANG_VERSION} + - GOTOOLCHAIN: local build-packages: - on arm64: [libgles2-mesa-dev] - build-essential @@ -153,6 +172,7 @@ parts: - bison # qtbase[dbus] -> glib2 -> gettext[tools] -> bison - gettext # provides msgfmt/msgmerge with matching libgettextsrc on the system loader path - rustup + - golang-1.26-go stage-packages: - apparmor @@ -166,6 +186,7 @@ parts: - libgtkmm-3.0-1t64 - libglibmm-2.4-1t64 - libpangomm-1.4-1v5 + - libwayland-dev stage: - -**/glvnd From 3664434c9002a0612557f46485d1892cfdb9794c Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 04:53:15 +0200 Subject: [PATCH 04/31] [ci] Set up Go for Ubuntu Insights --- .github/workflows/macos.yml | 7 +++++++ .github/workflows/tics.yml | 7 +++++++ .github/workflows/windows.yml | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2a931171aa..c60c00312a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -74,6 +74,7 @@ jobs: env: BUILD_DIR: ${{ github.workspace }}/build + GOTOOLCHAIN: local SCCACHE_DIR: ${{ github.workspace }}/.sccache RUST_DIR: ${{ github.workspace }}/rxx RUSTC_WRAPPER: "sccache" @@ -105,6 +106,12 @@ jobs: - name: Set up Rust uses: dtolnay/rust-toolchain@stable + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version: '1.26.x' + cache: false + - name: Install dependencies from brew run: | # Avoid reinstalling cmake diff --git a/.github/workflows/tics.yml b/.github/workflows/tics.yml index 6bbf46b3c3..056ab608f3 100644 --- a/.github/workflows/tics.yml +++ b/.github/workflows/tics.yml @@ -21,6 +21,7 @@ jobs: COVERAGE_DIR: ${{ github.workspace }}/coverage NEEDRESTART_SUSPEND: yes DEBIAN_FRONTEND: noninteractive + GOTOOLCHAIN: local steps: - name: Checkout code @@ -51,6 +52,12 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version: '1.26.x' + cache: false + - name: Install cmake uses: lukka/get-cmake@v4.4.4 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6f19ffa4c3..7835bc862e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -73,6 +73,7 @@ jobs: env: BUILD_DIR: ${{ github.workspace }}/build + GOTOOLCHAIN: local SCCACHE_DIR: ${{ github.workspace }}/.sccache #RUSTC_WRAPPER: "sccache" Removed due to concurrency issues between C++ and Rust @@ -96,6 +97,12 @@ jobs: - name: Set up Rust uses: dtolnay/rust-toolchain@stable + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version: '1.26.x' + cache: false + - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 with: From 401520f9b18286cda218937da07432a36f80f215 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 03:46:59 +0200 Subject: [PATCH 05/31] [ci] Disable plugs that require approval --- packaging/gui-less/snap/snapcraft.yaml | 12 ++++++------ snap/snapcraft.yaml | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index c0bc745c7b..4652ced441 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -20,7 +20,6 @@ platforms: amd64: s390x: ppc64el: - layout: /etc/fonts: bind: $SNAP/etc/fonts @@ -72,15 +71,16 @@ apps: - removable-media - system-observe # to read the host's os-release - # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. + # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. + # TODO: Acquire approval for these plugs + # - dot-config-ubuntu-insights # Default config location + # - dot-cache-ubuntu-insights # Default cache location + # - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. + # - block-devices # Required to see encrypted partitions. `dm-crypt` also works. - hardware-observe - wayland - x11 - network # Needed for uploading - - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. - - dot-config-ubuntu-insights # Default config location - - dot-cache-ubuntu-insights # Default cache location - - block-devices # Required to see encrypted partitions. `dm-crypt` also works. multipass: environment: LD_LIBRARY_PATH: *library-path diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7b1d572d73..7ad7ffca6e 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -70,14 +70,15 @@ apps: - system-observe # to read the host's os-release # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. + # TODO: Acquire approval for these plugs + # - dot-config-ubuntu-insights # Default config location + # - dot-cache-ubuntu-insights # Default cache location + # - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. + # - block-devices # Required to see encrypted partitions. `dm-crypt` also works. - hardware-observe - wayland - x11 - network # Needed for uploading - - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. - - dot-config-ubuntu-insights # Default config location - - dot-cache-ubuntu-insights # Default cache location - - block-devices # Required to see encrypted partitions. `dm-crypt` also works. multipass: environment: LD_LIBRARY_PATH: *library-path From 0cd8744bbf5b10dde6f80dc4529363638707dbba Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 04:24:35 +0200 Subject: [PATCH 06/31] [ci] Expose go toolchain to vcpkg builds --- .github/workflows/macos.yml | 5 +++++ .github/workflows/windows.yml | 6 ++++++ 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 2 +- 3rd-party/vcpkg-triplets/osx.cmake.in | 1 + 3rd-party/vcpkg-triplets/x64-windows-static-md.cmake | 2 +- packaging/gui-less/snap/snapcraft.yaml | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c60c00312a..83c72ace77 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -112,6 +112,11 @@ jobs: go-version: '1.26.x' cache: false + - name: Expose Go location to vcpkg + shell: pwsh + run: | + echo "GO_EXECUTABLE_DIR=$(dirname "$(which go)")" >> "$GITHUB_ENV" + - name: Install dependencies from brew run: | # Avoid reinstalling cmake diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7835bc862e..76df2b4c2c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -103,6 +103,12 @@ jobs: go-version: '1.26.x' cache: false + - name: Expose Go location to vcpkg + shell: pwsh + run: | + $goDir = Split-Path -Parent (Get-Command go -CommandType Application -ErrorAction Stop).Source + "GO_EXECUTABLE_DIR=$goDir" >> $env:GITHUB_ENV + - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 with: diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 95ad9c51fa..44bcbebb3c 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -23,7 +23,7 @@ vcpkg_from_github( PATCHES 0001-c-api-free.patch ) -find_program(GO_EXECUTABLE NAMES go REQUIRED) +find_program(GO_EXECUTABLE NAMES go HINTS ENV GO_EXECUTABLE_DIR REQUIRED) set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") file(MAKE_DIRECTORY "${tools_dir}") diff --git a/3rd-party/vcpkg-triplets/osx.cmake.in b/3rd-party/vcpkg-triplets/osx.cmake.in index b3b94a076b..fda444a244 100644 --- a/3rd-party/vcpkg-triplets/osx.cmake.in +++ b/3rd-party/vcpkg-triplets/osx.cmake.in @@ -2,6 +2,7 @@ set(VCPKG_TARGET_ARCHITECTURE @VCPKG_HOST_ARCH@) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Darwin) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) @VCPKG_BUILD_TYPE_SETTING@ set(VCPKG_OSX_DEPLOYMENT_TARGET "@CMAKE_OSX_DEPLOYMENT_TARGET@") diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 4525507b59..8d1ee70ca6 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -1,4 +1,4 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) - +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index 4652ced441..502a196d2b 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -20,6 +20,7 @@ platforms: amd64: s390x: ppc64el: + layout: /etc/fonts: bind: $SNAP/etc/fonts From a09f50c7afaa0116ffb372f653a7f6ce77660abd Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 08:36:33 +0200 Subject: [PATCH 07/31] [insights] Various fixes TODO: Clean up the git history of this PR to be more meaningful --- .github/workflows/windows.yml | 22 ++++++++++++++++++- .../ubuntu-insights/portfile.cmake | 15 ++++++++++++- .../x64-windows-static-md.cmake | 2 +- CMakeLists.txt | 5 +++++ packaging/gui-less/snap/snapcraft.yaml | 17 +++++++------- snap/snapcraft.yaml | 17 +++++++------- src/ubuntu_insights/CMakeLists.txt | 4 ++++ tests/unit/CMakeLists.txt | 6 +++-- vcpkg.json | 9 ++++++-- 9 files changed, 74 insertions(+), 23 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 76df2b4c2c..3bcecbb42f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -106,9 +106,29 @@ jobs: - name: Expose Go location to vcpkg shell: pwsh run: | - $goDir = Split-Path -Parent (Get-Command go -CommandType Application -ErrorAction Stop).Source + $goRoot = go env GOROOT + if ($LASTEXITCODE -ne 0) { + throw "Failed to determine Go installation root" + } + $goDir = Join-Path $goRoot 'bin' "GO_EXECUTABLE_DIR=$goDir" >> $env:GITHUB_ENV + - name: Set up GCC for cgo + shell: pwsh + run: | + & C:\msys64\usr\bin\bash.exe -lc 'pacman -S --needed --noconfirm mingw-w64-ucrt-x86_64-gcc' + if ($LASTEXITCODE -ne 0) { + throw "Failed to install MSYS2 UCRT64 GCC" + } + + $gcc = 'C:\msys64\ucrt64\bin\gcc.exe' + & $gcc --version + if ($LASTEXITCODE -ne 0) { + throw "MSYS2 UCRT64 GCC is not usable" + } + + "CGO_CC=$gcc" >> $env:GITHUB_ENV + - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 with: diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 44bcbebb3c..475de6c405 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -47,8 +47,21 @@ if(VCPKG_TARGET_IS_LINUX) add_insights_tool(ingest-service ./server/cmd/ingest-service) endif() +set(GO_ENV CGO_ENABLED=1) + +if(DEFINED ENV{CGO_CC}) + list(APPEND GO_ENV "CC=$ENV{CGO_CC}") + + # Usually gcc comes with other tools such as ar/as/ld. So we add the directory + # to the path to enable cgo to find these tools. + get_filename_component(CC_DIR "$ENV{CGO_CC}" DIRECTORY) + list(APPEND GO_ENV --modify "PATH=path_list_prepend:${CC_DIR}") +endif() + vcpkg_execute_required_process( - COMMAND "${GO_EXECUTABLE}" run -tags=tools ./generate/... + COMMAND + "${CMAKE_COMMAND}" -E env ${GO_ENV} + "${GO_EXECUTABLE}" run -tags=tools ./generate/... WORKING_DIRECTORY "${SOURCE_PATH}/insights/C" LOGNAME build-c-api ) diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 8d1ee70ca6..6d0e25a9d8 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -1,4 +1,4 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR;CGO_CC) diff --git a/CMakeLists.txt b/CMakeLists.txt index e67920d9a1..dc39cfcf60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ include(CMakeDependentOption) option(MULTIPASS_VCPKG_BUILD_DEFAULT "Enable or disable building the dependencies in the default configuration, which includes both debug and release variants." OFF) option(MULTIPASS_ENABLE_TESTS "Build tests" ON) +option(MULTIPASS_ENABLE_INSIGHTS "Enabled Ubuntu Insights" ON) is_running_in_ci(IS_RUNNING_IN_CI) message(STATUS "Running in CI environment? ${IS_RUNNING_IN_CI}") @@ -140,6 +141,10 @@ if(MULTIPASS_ENABLE_TESTS) list(APPEND VCPKG_MANIFEST_FEATURES "tests") endif() +if(MULTIPASS_ENABLE_INSIGHTS) + list(APPEND VCPKG_MANIFEST_FEATURES "ubuntu-insights") +endif() + # All the current backends depend on QEMU one way or the other. list(APPEND VCPKG_MANIFEST_FEATURES "qemu") diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index 502a196d2b..4319ca488f 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -33,17 +33,18 @@ environment: ARCH_TRIPLET: ${CRAFT_ARCH_TRIPLET_BUILD_FOR} plugs: + # TODO: Acquire approval for these plugs + # dot-config-ubuntu-insights: + # interface: personal-files + # read: + # - $HOME/.config/ubuntu-insights + # dot-cache-ubuntu-insights: + # interface: personal-files + # write: + # - $HOME/.cache/ubuntu-insights all-home: interface: home read: all - dot-config-ubuntu-insights: - interface: personal-files - read: - - $HOME/.config/ubuntu-insights - dot-cache-ubuntu-insights: - interface: personal-files - write: - - $HOME/.cache/ubuntu-insights apps: multipassd: diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7ad7ffca6e..0dde30614f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,17 +29,18 @@ environment: ARCH_TRIPLET: ${CRAFT_ARCH_TRIPLET_BUILD_FOR} plugs: + # TODO: Acquire approval for these plugs + # dot-config-ubuntu-insights: + # interface: personal-files + # read: + # - $HOME/.config/ubuntu-insights + # dot-cache-ubuntu-insights: + # interface: personal-files + # write: + # - $HOME/.cache/ubuntu-insights all-home: interface: home read: all - dot-config-ubuntu-insights: - interface: personal-files - read: - - $HOME/.config/ubuntu-insights - dot-cache-ubuntu-insights: - interface: personal-files - write: - - $HOME/.cache/ubuntu-insights apps: multipassd: diff --git a/src/ubuntu_insights/CMakeLists.txt b/src/ubuntu_insights/CMakeLists.txt index 5f22340a71..5b9d50966c 100644 --- a/src/ubuntu_insights/CMakeLists.txt +++ b/src/ubuntu_insights/CMakeLists.txt @@ -13,6 +13,10 @@ # along with this program. If not, see . # +if(NOT MULTIPASS_ENABLE_INSIGHTS) + return() +endif() + add_library(ubuntu_insights STATIC libinsights_wrapper.cpp) find_package(ubuntu-insights CONFIG REQUIRED) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index f41c0dda72..032096386a 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -26,20 +26,22 @@ add_executable(multipass_integration_tests common.cpp temp_dir.cpp test_libssh.cpp - test_libinsights.cpp ) target_link_libraries(multipass_integration_tests PRIVATE GTest::gmock_main Qt6::Core fmt::fmt-header-only libssh_wrapper - ubuntu_insights ) target_include_directories(multipass_integration_tests PRIVATE ${CMAKE_SOURCE_DIR} PRIVATE ${CMAKE_SOURCE_DIR}/src PRIVATE ${CMAKE_SOURCE_DIR}/src/platform/backends ) +if(MULTIPASS_ENABLE_INSIGHTS) + target_sources(multipass_integration_tests PRIVATE test_libinsights.cpp) + target_link_libraries(multipass_integration_tests PRIVATE ubuntu_insights) +endif() add_test(NAME multipass_integration_tests COMMAND multipass_integration_tests) ############################################################################## diff --git a/vcpkg.json b/vcpkg.json index e1db047fe2..83a2b28cff 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -28,8 +28,7 @@ "server" ] }, - "premock", - "ubuntu-insights" + "premock" ], "overrides": [ { @@ -60,6 +59,12 @@ "platform": "osx | linux" } ] + }, + "ubuntu-insights": { + "description": "Enable Ubuntu Insights integration", + "dependencies": [ + "ubuntu-insights" + ] } } } From fcd54b561becc66f2d944a6bc3ad3099ebb03bdb Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 11:00:56 +0200 Subject: [PATCH 08/31] [vcpkg] Drop CGO_CC --- .github/workflows/windows.yml | 16 -------- .../mingw}/generate-mingw-lockfile.py | 0 .../mingw/get-mingw-packages.cmake | 37 +++++++++++++++++++ .../mingw}/mingw64-toolchain.lock | 0 3rd-party/vcpkg-ports/qemu/portfile.cmake | 27 +++----------- .../ubuntu-insights/portfile.cmake | 21 +++++++---- .../x64-windows-static-md.cmake | 2 +- 7 files changed, 57 insertions(+), 46 deletions(-) rename 3rd-party/{vcpkg-ports/qemu => vcpkg-port-utils/mingw}/generate-mingw-lockfile.py (100%) create mode 100644 3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake rename 3rd-party/{vcpkg-ports/qemu => vcpkg-port-utils/mingw}/mingw64-toolchain.lock (100%) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3bcecbb42f..a3d6c82598 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -113,22 +113,6 @@ jobs: $goDir = Join-Path $goRoot 'bin' "GO_EXECUTABLE_DIR=$goDir" >> $env:GITHUB_ENV - - name: Set up GCC for cgo - shell: pwsh - run: | - & C:\msys64\usr\bin\bash.exe -lc 'pacman -S --needed --noconfirm mingw-w64-ucrt-x86_64-gcc' - if ($LASTEXITCODE -ne 0) { - throw "Failed to install MSYS2 UCRT64 GCC" - } - - $gcc = 'C:\msys64\ucrt64\bin\gcc.exe' - & $gcc --version - if ($LASTEXITCODE -ne 0) { - throw "MSYS2 UCRT64 GCC is not usable" - } - - "CGO_CC=$gcc" >> $env:GITHUB_ENV - - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 with: diff --git a/3rd-party/vcpkg-ports/qemu/generate-mingw-lockfile.py b/3rd-party/vcpkg-port-utils/mingw/generate-mingw-lockfile.py similarity index 100% rename from 3rd-party/vcpkg-ports/qemu/generate-mingw-lockfile.py rename to 3rd-party/vcpkg-port-utils/mingw/generate-mingw-lockfile.py diff --git a/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake b/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake new file mode 100644 index 0000000000..9af8da474b --- /dev/null +++ b/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake @@ -0,0 +1,37 @@ +# Reads the pinned MinGW closure into the requested output variables. +function(multipass_get_mingw_packages OUT_DIRECT_PACKAGES OUT_URLS OUT_SHA512S) + if(NOT ARGC EQUAL 3) + message(FATAL_ERROR "multipass_get_mingw_packages requires direct-packages, URLs, and SHA512 output variables") + endif() + + set(_lockfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mingw64-toolchain.lock") + set(_expected_lock_sha512 + "13e40c78ddbcbbec011257e8bd0496d52c3641d57ed3ee0f61a1a415876438f3e87e556643d8d39b6fca934001e9eec3efd64e9e2523a4c8aeff30c05b18eede") + file(SHA512 "${_lockfile}" _lockfile_sha512) + + # To ensure that if we changed the lockfile, we have to change this file as well, prompting + # vcpkg to build the port that included this file. + if(NOT "${_lockfile_sha512}" STREQUAL "${_expected_lock_sha512}") + message(FATAL_ERROR "mingw64-toolchain.lock changed; update its expected SHA512 in get-mingw-packages.cmake") + endif() + + set(_direct_packages "") + set(_urls "") + set(_sha512s "") + file(STRINGS "${_lockfile}" _lock_lines) + foreach(_line IN LISTS _lock_lines) + if(_line MATCHES "^#" OR _line STREQUAL "") + continue() + endif() + if(NOT _line MATCHES "^([^ \t]+)[ \t]+([0-9a-fA-F]+)$") + message(FATAL_ERROR "Malformed mingw64-toolchain.lock entry: ${_line}") + endif() + list(APPEND _direct_packages "${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") + list(APPEND _urls "${CMAKE_MATCH_1}") + list(APPEND _sha512s "${CMAKE_MATCH_2}") + endforeach() + + set(${OUT_DIRECT_PACKAGES} "${_direct_packages}" PARENT_SCOPE) + set(${OUT_URLS} "${_urls}" PARENT_SCOPE) + set(${OUT_SHA512S} "${_sha512s}" PARENT_SCOPE) +endfunction() diff --git a/3rd-party/vcpkg-ports/qemu/mingw64-toolchain.lock b/3rd-party/vcpkg-port-utils/mingw/mingw64-toolchain.lock similarity index 100% rename from 3rd-party/vcpkg-ports/qemu/mingw64-toolchain.lock rename to 3rd-party/vcpkg-port-utils/mingw/mingw64-toolchain.lock diff --git a/3rd-party/vcpkg-ports/qemu/portfile.cmake b/3rd-party/vcpkg-ports/qemu/portfile.cmake index d5b9cc9620..81393104e9 100644 --- a/3rd-party/vcpkg-ports/qemu/portfile.cmake +++ b/3rd-party/vcpkg-ports/qemu/portfile.cmake @@ -87,8 +87,8 @@ if(VCPKG_TARGET_IS_WINDOWS) # Windows: build only qemu-img (the sole QEMU tool Multipass uses here; no # system emulator). The GCC/MinGW toolchain is acquired hermetically via # vcpkg_acquire_msys() from packages pinned by URL + SHA512 -- vcpkg's own - # pinned msys shell layer plus the MinGW closure in mingw64-toolchain.lock - # (regenerate with generate-mingw-lockfile.py). + # pinned msys shell layer plus the shared MinGW closure in + # vcpkg-port-utils/mingw/mingw64-toolchain.lock. ########################################################################### if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") @@ -109,27 +109,10 @@ if(VCPKG_TARGET_IS_WINDOWS) set(${OUT_VAR} "${_p}" PARENT_SCOPE) endfunction() - # Pinned MinGW-w64 closure (regenerate with generate-mingw-lockfile.py). - # Each non-comment line is " ". Keep an interleaved list for - # vcpkg_acquire_msys(DIRECT_PACKAGES ...) plus parallel url/sha lists. - set(MINGW_DIRECT_PACKAGES "") - set(MINGW_URLS "") - set(MINGW_SHA512S "") - file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/mingw64-toolchain.lock" _lock_lines) - foreach(_line IN LISTS _lock_lines) - if(_line MATCHES "^#" OR _line STREQUAL "") - continue() - endif() - if(NOT _line MATCHES "^([^ \t]+)[ \t]+([0-9a-fA-F]+)$") - message(FATAL_ERROR "Malformed mingw64-toolchain.lock entry: ${_line}") - endif() - list(APPEND MINGW_DIRECT_PACKAGES "${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") - list(APPEND MINGW_URLS "${CMAKE_MATCH_1}") - list(APPEND MINGW_SHA512S "${CMAKE_MATCH_2}") - endforeach() - # Assemble a private, content-addressed MSYS2 root: vcpkg's pinned msys shell # utilities (plus findutils/perl for configure) and our pinned MinGW closure. + include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") + multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) vcpkg_acquire_msys(MSYS_ROOT PACKAGES findutils perl DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES} @@ -337,4 +320,4 @@ set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled) # even for static-linkage triplets. set(VCPKG_POLICY_ALLOW_EXES_IN_BIN enabled) set(VCPKG_POLICY_DLLS_IN_STATIC_LIBRARY enabled) -vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") \ No newline at end of file +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 475de6c405..29c46030a7 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -49,13 +49,20 @@ endif() set(GO_ENV CGO_ENABLED=1) -if(DEFINED ENV{CGO_CC}) - list(APPEND GO_ENV "CC=$ENV{CGO_CC}") - - # Usually gcc comes with other tools such as ar/as/ld. So we add the directory - # to the path to enable cgo to find these tools. - get_filename_component(CC_DIR "$ENV{CGO_CC}" DIRECTORY) - list(APPEND GO_ENV --modify "PATH=path_list_prepend:${CC_DIR}") +if(VCPKG_TARGET_IS_WINDOWS) + if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + message(FATAL_ERROR "Windows ubuntu-insights build currently only supports x64") + endif() + + # Reuse the pinned MinGW closure acquired by QEMU. + include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") + multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) + vcpkg_acquire_msys(MSYS_ROOT DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES}) + file(TO_NATIVE_PATH "${MSYS_ROOT}/mingw64/bin" MINGW_BIN) + list(APPEND GO_ENV + "CC=${MINGW_BIN}/gcc.exe" + --modify "PATH=path_list_prepend:${MINGW_BIN}" + ) endif() vcpkg_execute_required_process( diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 6d0e25a9d8..8d1ee70ca6 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -1,4 +1,4 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR;CGO_CC) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) From ec2247476c54b15806f5dedfc1265bcd90d6eb4c Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 11:12:46 +0200 Subject: [PATCH 09/31] [cmake] Pass Go location to vcpkg --- .github/workflows/macos.yml | 5 ----- .github/workflows/windows.yml | 10 ---------- .../vcpkg-port-utils/mingw/get-mingw-packages.cmake | 13 +------------ .../vcpkg-triplets/ppc64le-linux-release.cmake | 1 + 3rd-party/vcpkg-triplets/s390x-linux-release.cmake | 1 + 3rd-party/vcpkg-triplets/x64-linux.cmake | 1 + CMakeLists.txt | 5 +++++ 7 files changed, 9 insertions(+), 27 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 83c72ace77..c60c00312a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -112,11 +112,6 @@ jobs: go-version: '1.26.x' cache: false - - name: Expose Go location to vcpkg - shell: pwsh - run: | - echo "GO_EXECUTABLE_DIR=$(dirname "$(which go)")" >> "$GITHUB_ENV" - - name: Install dependencies from brew run: | # Avoid reinstalling cmake diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index a3d6c82598..7835bc862e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -103,16 +103,6 @@ jobs: go-version: '1.26.x' cache: false - - name: Expose Go location to vcpkg - shell: pwsh - run: | - $goRoot = go env GOROOT - if ($LASTEXITCODE -ne 0) { - throw "Failed to determine Go installation root" - } - $goDir = Join-Path $goRoot 'bin' - "GO_EXECUTABLE_DIR=$goDir" >> $env:GITHUB_ENV - - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 with: diff --git a/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake b/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake index 9af8da474b..86418e6430 100644 --- a/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake +++ b/3rd-party/vcpkg-port-utils/mingw/get-mingw-packages.cmake @@ -4,21 +4,10 @@ function(multipass_get_mingw_packages OUT_DIRECT_PACKAGES OUT_URLS OUT_SHA512S) message(FATAL_ERROR "multipass_get_mingw_packages requires direct-packages, URLs, and SHA512 output variables") endif() - set(_lockfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mingw64-toolchain.lock") - set(_expected_lock_sha512 - "13e40c78ddbcbbec011257e8bd0496d52c3641d57ed3ee0f61a1a415876438f3e87e556643d8d39b6fca934001e9eec3efd64e9e2523a4c8aeff30c05b18eede") - file(SHA512 "${_lockfile}" _lockfile_sha512) - - # To ensure that if we changed the lockfile, we have to change this file as well, prompting - # vcpkg to build the port that included this file. - if(NOT "${_lockfile_sha512}" STREQUAL "${_expected_lock_sha512}") - message(FATAL_ERROR "mingw64-toolchain.lock changed; update its expected SHA512 in get-mingw-packages.cmake") - endif() - set(_direct_packages "") set(_urls "") set(_sha512s "") - file(STRINGS "${_lockfile}" _lock_lines) + file(STRINGS "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/mingw64-toolchain.lock" _lock_lines) foreach(_line IN LISTS _lock_lines) if(_line MATCHES "^#" OR _line STREQUAL "") continue() diff --git a/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake b/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake index 5301da6f76..c8b24567b2 100644 --- a/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake +++ b/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake @@ -3,6 +3,7 @@ set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_BUILD_TYPE release) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) # Workaround for dbus and qtbase: when vcpkg sets VCPKG_CMAKE_SYSTEM_NAME, CMake may treat # native ppc64le builds as cross-compiling. diff --git a/3rd-party/vcpkg-triplets/s390x-linux-release.cmake b/3rd-party/vcpkg-triplets/s390x-linux-release.cmake index 671376d709..555962902a 100644 --- a/3rd-party/vcpkg-triplets/s390x-linux-release.cmake +++ b/3rd-party/vcpkg-triplets/s390x-linux-release.cmake @@ -3,6 +3,7 @@ set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_BUILD_TYPE release) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) # Workaround for dbus and qtbase: when vcpkg sets VCPKG_CMAKE_SYSTEM_NAME, CMake may treat # native s390x builds as cross-compiling. diff --git a/3rd-party/vcpkg-triplets/x64-linux.cmake b/3rd-party/vcpkg-triplets/x64-linux.cmake index 8822134560..45a025cb28 100644 --- a/3rd-party/vcpkg-triplets/x64-linux.cmake +++ b/3rd-party/vcpkg-triplets/x64-linux.cmake @@ -1,6 +1,7 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) set(VCPKG_CMAKE_SYSTEM_NAME Linux) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc39cfcf60..aac77c5951 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,11 @@ endif() if(MULTIPASS_ENABLE_INSIGHTS) list(APPEND VCPKG_MANIFEST_FEATURES "ubuntu-insights") + + # vcpkg builds in an isolated environment, so explicitly pass it Go's location. + find_program(GO_EXECUTABLE go REQUIRED) + get_filename_component(GO_EXECUTABLE_DIR "${GO_EXECUTABLE}" DIRECTORY) + set(ENV{GO_EXECUTABLE_DIR} "${GO_EXECUTABLE_DIR}") endif() # All the current backends depend on QEMU one way or the other. From 6bff7d6d94c866ce4ee80b539f7305d771020450 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 22:15:39 +0200 Subject: [PATCH 10/31] [vcpkg] Drop wayland from dependencies We require wayland as a system dependency on Linux Maybe this can change in the future if there is a good reason --- 3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json index 6522fa43b7..346421fe8c 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json +++ b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json @@ -3,11 +3,5 @@ "version": "1.0.1", "description": "Ubuntu Insights client, server executables, and C shared library", "homepage": "https://github.com/ubuntu/ubuntu-insights", - "license": "GPL-3.0-only", - "dependencies": [ - { - "name": "wayland", - "platform": "linux" - } - ] + "license": "GPL-3.0-only" } From 2110786e14b2698d5256de193c0989d998e88d98 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 22:17:21 +0200 Subject: [PATCH 11/31] [vcpkg] Use VCPKG_KEEP_ENV_VARS to pass go dir This makes it so that we don't have to edit every triplet, as we did before with VCPKG_ENV_PASSTHROUGH --- 3rd-party/vcpkg-triplets/osx.cmake.in | 1 - .../vcpkg-triplets/ppc64le-linux-release.cmake | 1 - 3rd-party/vcpkg-triplets/s390x-linux-release.cmake | 1 - 3rd-party/vcpkg-triplets/x64-linux.cmake | 1 - .../vcpkg-triplets/x64-windows-static-md.cmake | 1 - CMakeLists.txt | 14 +++++++++++++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/3rd-party/vcpkg-triplets/osx.cmake.in b/3rd-party/vcpkg-triplets/osx.cmake.in index fda444a244..b3b94a076b 100644 --- a/3rd-party/vcpkg-triplets/osx.cmake.in +++ b/3rd-party/vcpkg-triplets/osx.cmake.in @@ -2,7 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE @VCPKG_HOST_ARCH@) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Darwin) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) @VCPKG_BUILD_TYPE_SETTING@ set(VCPKG_OSX_DEPLOYMENT_TARGET "@CMAKE_OSX_DEPLOYMENT_TARGET@") diff --git a/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake b/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake index c8b24567b2..5301da6f76 100644 --- a/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake +++ b/3rd-party/vcpkg-triplets/ppc64le-linux-release.cmake @@ -3,7 +3,6 @@ set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_BUILD_TYPE release) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) # Workaround for dbus and qtbase: when vcpkg sets VCPKG_CMAKE_SYSTEM_NAME, CMake may treat # native ppc64le builds as cross-compiling. diff --git a/3rd-party/vcpkg-triplets/s390x-linux-release.cmake b/3rd-party/vcpkg-triplets/s390x-linux-release.cmake index 555962902a..671376d709 100644 --- a/3rd-party/vcpkg-triplets/s390x-linux-release.cmake +++ b/3rd-party/vcpkg-triplets/s390x-linux-release.cmake @@ -3,7 +3,6 @@ set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_BUILD_TYPE release) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) # Workaround for dbus and qtbase: when vcpkg sets VCPKG_CMAKE_SYSTEM_NAME, CMake may treat # native s390x builds as cross-compiling. diff --git a/3rd-party/vcpkg-triplets/x64-linux.cmake b/3rd-party/vcpkg-triplets/x64-linux.cmake index 45a025cb28..8822134560 100644 --- a/3rd-party/vcpkg-triplets/x64-linux.cmake +++ b/3rd-party/vcpkg-triplets/x64-linux.cmake @@ -1,7 +1,6 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) set(VCPKG_CMAKE_SYSTEM_NAME Linux) diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 8d1ee70ca6..63d6cde241 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -1,4 +1,3 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(VCPKG_ENV_PASSTHROUGH GO_EXECUTABLE_DIR) diff --git a/CMakeLists.txt b/CMakeLists.txt index aac77c5951..866db4ceb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,10 +144,22 @@ endif() if(MULTIPASS_ENABLE_INSIGHTS) list(APPEND VCPKG_MANIFEST_FEATURES "ubuntu-insights") - # vcpkg builds in an isolated environment, so explicitly pass it Go's location. + # vcpkg builds in an isolated environment, so keep Go's location in its build environment. find_program(GO_EXECUTABLE go REQUIRED) get_filename_component(GO_EXECUTABLE_DIR "${GO_EXECUTABLE}" DIRECTORY) + + # Set GO_EXECUTABLE_DIR environment variable, and ask vcpkg to keep it. + # NOTE: The resulting ubuntu-insights ABI hash will not depend on the go toolchain + # used to build it. So if a new go compiler is installed, the port will not be rebuilt. + # This is fine for now. set(ENV{GO_EXECUTABLE_DIR} "${GO_EXECUTABLE_DIR}") + + set(VCPKG_KEEP_ENV_VARS "$ENV{VCPKG_KEEP_ENV_VARS}") + list(APPEND VCPKG_KEEP_ENV_VARS GO_EXECUTABLE_DIR) + list(REMOVE_DUPLICATES VCPKG_KEEP_ENV_VARS) + + set(ENV{VCPKG_KEEP_ENV_VARS} "${VCPKG_KEEP_ENV_VARS}") + unset(VCPKG_KEEP_ENV_VARS) endif() # All the current backends depend on QEMU one way or the other. From 932d7315e4f0fc79a56d45056461c11f0bb573df Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Wed, 11 Nov 2026 22:19:01 +0200 Subject: [PATCH 12/31] [vcpkg] Copy libinsights dll to debug/bin as well Enables vcpkg's applocal to automatically deploy the dll beside any executable that uses it --- 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 12 ++++++++++-- .../ubuntu-insights/ubuntu-insights-config.cmake.in | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 29c46030a7..72626c0efc 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -1,4 +1,3 @@ -set(VCPKG_BUILD_TYPE release) set(VCPKG_POLICY_MISMATCHED_NUMBER_OF_BINARIES enabled) vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) @@ -23,6 +22,9 @@ vcpkg_from_github( PATCHES 0001-c-api-free.patch ) +# Ideally we should use `vcpkg_find_acquire_program` to automatically acquire go +# if it doesn't exist. Unfortunately the version provided by vcpkg (1.25) is less +# than the one required by ubuntu-insights (1.26). find_program(GO_EXECUTABLE NAMES go HINTS ENV GO_EXECUTABLE_DIR REQUIRED) set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") @@ -47,7 +49,7 @@ if(VCPKG_TARGET_IS_LINUX) add_insights_tool(ingest-service ./server/cmd/ingest-service) endif() -set(GO_ENV CGO_ENABLED=1) +set(GO_ENV CGO_ENABLED=1 --modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}") if(VCPKG_TARGET_IS_WINDOWS) if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") @@ -87,6 +89,12 @@ if(VCPKG_TARGET_IS_WINDOWS) file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" DESTINATION "${CURRENT_PACKAGES_DIR}/bin") + + # libinsights is built in a single configuration, but vcpkg's applocal + # searches only debug/bin for DLLs when building Debug executables. + # Copy the DLL there as well so it can be deployed automatically. + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin") else() file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib") diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in index 269e22640f..ad9ce359bf 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in +++ b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in @@ -7,9 +7,11 @@ add_library(ubuntu-insights::insights SHARED IMPORTED) set_target_properties(ubuntu-insights::insights PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_insights_prefix}/include" ) + if(WIN32) set_target_properties(ubuntu-insights::insights PROPERTIES IMPORTED_LOCATION "${_insights_prefix}/bin/@INSIGHTS_LIBRARY@" + IMPORTED_LOCATION_DEBUG "${_insights_prefix}/debug/bin/@INSIGHTS_LIBRARY@" IMPORTED_IMPLIB "${_insights_prefix}/lib/@INSIGHTS_IMPLIB@" ) else() @@ -24,5 +26,6 @@ foreach(_insights_tool IN ITEMS @INSIGHTS_TOOLS@) IMPORTED_LOCATION "${_insights_prefix}/tools/ubuntu-insights/${_insights_tool}@VCPKG_TARGET_EXECUTABLE_SUFFIX@" ) endforeach() + unset(_insights_prefix) unset(_insights_tool) From f0312913fe8ac28e5e21fb9acc81221eac5b215d Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Thu, 12 Nov 2026 12:12:58 +0200 Subject: [PATCH 13/31] [ci] No need to disable caching for go --- .github/workflows/macos.yml | 1 - .github/workflows/tics.yml | 1 - .github/workflows/windows.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c60c00312a..26cbc35c2c 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -110,7 +110,6 @@ jobs: uses: actions/setup-go@v7 with: go-version: '1.26.x' - cache: false - name: Install dependencies from brew run: | diff --git a/.github/workflows/tics.yml b/.github/workflows/tics.yml index 056ab608f3..a16ad0123c 100644 --- a/.github/workflows/tics.yml +++ b/.github/workflows/tics.yml @@ -56,7 +56,6 @@ jobs: uses: actions/setup-go@v7 with: go-version: '1.26.x' - cache: false - name: Install cmake uses: lukka/get-cmake@v4.4.4 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7835bc862e..9240229b97 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -101,7 +101,6 @@ jobs: uses: actions/setup-go@v7 with: go-version: '1.26.x' - cache: false - name: Install other packages from Choco uses: crazy-max/ghaction-chocolatey@v4 From c3e5e4ab0f24344cec891ca5c6b241ce09d29178 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Thu, 12 Nov 2026 22:34:54 +0200 Subject: [PATCH 14/31] [vcpkg] Both Ubuntu-insights and msys2 support arm --- 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 72626c0efc..0fb9cbd50a 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -52,10 +52,6 @@ endif() set(GO_ENV CGO_ENABLED=1 --modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}") if(VCPKG_TARGET_IS_WINDOWS) - if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") - message(FATAL_ERROR "Windows ubuntu-insights build currently only supports x64") - endif() - # Reuse the pinned MinGW closure acquired by QEMU. include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) From 7145daaf09bd87f81a1b94af3cc9976b5bf9f61e Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Thu, 12 Nov 2026 23:16:53 +0200 Subject: [PATCH 15/31] [snap] Fix ubuntu insights snap environment Mimic what ubuntu-insights/snap/snapcraft.yaml does --- packaging/gui-less/snap/snapcraft.yaml | 6 +++++- snap/snapcraft.yaml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index 4319ca488f..40f7ccf7fa 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -153,7 +153,9 @@ parts: - bison # qtbase[dbus] -> glib2 -> gettext[tools] -> bison - gettext # provides msgfmt/msgmerge with matching libgettextsrc on the system loader path - rustup + # Required by ubuntu-insights - golang-1.26-go + - libwayland-dev stage-packages: - apparmor @@ -166,7 +168,9 @@ parts: - libgtkmm-3.0-1t64 - libglibmm-2.4-1t64 - libpangomm-1.4-1v5 - - libwayland-dev + # Required by ubuntu-insights + - libwayland-client0 + - x11-xserver-utils # ubuntu-insights uses xrandr from x11 utils stage: - -**/glvnd diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 0dde30614f..e32fe1c698 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -174,7 +174,9 @@ parts: - bison # qtbase[dbus] -> glib2 -> gettext[tools] -> bison - gettext # provides msgfmt/msgmerge with matching libgettextsrc on the system loader path - rustup + # Required by ubuntu-insights - golang-1.26-go + - libwayland-dev stage-packages: - apparmor @@ -188,7 +190,9 @@ parts: - libgtkmm-3.0-1t64 - libglibmm-2.4-1t64 - libpangomm-1.4-1v5 - - libwayland-dev + # Required by ubuntu-insights + - libwayland-client0 + - x11-xserver-utils # ubuntu-insights uses xrandr from x11 utils stage: - -**/glvnd From 09a2047ec9b44deed79acc28bc582c0fb6e603d6 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Thu, 12 Nov 2026 23:49:40 +0200 Subject: [PATCH 16/31] [cmake] Fix typo in ENABLE_INSIGHTS description --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 866db4ceb2..d627bf7d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ include(CMakeDependentOption) option(MULTIPASS_VCPKG_BUILD_DEFAULT "Enable or disable building the dependencies in the default configuration, which includes both debug and release variants." OFF) option(MULTIPASS_ENABLE_TESTS "Build tests" ON) -option(MULTIPASS_ENABLE_INSIGHTS "Enabled Ubuntu Insights" ON) +option(MULTIPASS_ENABLE_INSIGHTS "Enable Ubuntu Insights" ON) is_running_in_ci(IS_RUNNING_IN_CI) message(STATUS "Running in CI environment? ${IS_RUNNING_IN_CI}") From 962d3bc4b1d0568c0092234eb0384836adab9420 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Thu, 12 Nov 2026 23:50:26 +0200 Subject: [PATCH 17/31] [cmake] Ship ubuntu insights shared library --- src/ubuntu_insights/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ubuntu_insights/CMakeLists.txt b/src/ubuntu_insights/CMakeLists.txt index 5b9d50966c..48b0cd6740 100644 --- a/src/ubuntu_insights/CMakeLists.txt +++ b/src/ubuntu_insights/CMakeLists.txt @@ -23,3 +23,8 @@ find_package(ubuntu-insights CONFIG REQUIRED) target_link_libraries(ubuntu_insights PUBLIC ubuntu-insights::insights) target_include_directories(ubuntu_insights PUBLIC "${CMAKE_SOURCE_DIR}/include") + +install(IMPORTED_RUNTIME_ARTIFACTS ubuntu-insights::insights + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib +) From 714adefe215f12f012514aa7d36086ad024b0ea1 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Mon, 16 Nov 2026 00:31:05 +0200 Subject: [PATCH 18/31] [snap] Drop new plug requirements for insights --- packaging/gui-less/snap/snapcraft.yaml | 20 -------------------- snap/snapcraft.yaml | 20 -------------------- 2 files changed, 40 deletions(-) diff --git a/packaging/gui-less/snap/snapcraft.yaml b/packaging/gui-less/snap/snapcraft.yaml index 40f7ccf7fa..0c2d5d4cfc 100644 --- a/packaging/gui-less/snap/snapcraft.yaml +++ b/packaging/gui-less/snap/snapcraft.yaml @@ -33,15 +33,6 @@ environment: ARCH_TRIPLET: ${CRAFT_ARCH_TRIPLET_BUILD_FOR} plugs: - # TODO: Acquire approval for these plugs - # dot-config-ubuntu-insights: - # interface: personal-files - # read: - # - $HOME/.config/ubuntu-insights - # dot-cache-ubuntu-insights: - # interface: personal-files - # write: - # - $HOME/.cache/ubuntu-insights all-home: interface: home read: all @@ -72,17 +63,6 @@ apps: - network-observe # for network listing (to read `/sys/devices/**/net/*`) - removable-media - system-observe # to read the host's os-release - - # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. - # TODO: Acquire approval for these plugs - # - dot-config-ubuntu-insights # Default config location - # - dot-cache-ubuntu-insights # Default cache location - # - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. - # - block-devices # Required to see encrypted partitions. `dm-crypt` also works. - - hardware-observe - - wayland - - x11 - - network # Needed for uploading multipass: environment: LD_LIBRARY_PATH: *library-path diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e32fe1c698..d0d19eaf0a 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,15 +29,6 @@ environment: ARCH_TRIPLET: ${CRAFT_ARCH_TRIPLET_BUILD_FOR} plugs: - # TODO: Acquire approval for these plugs - # dot-config-ubuntu-insights: - # interface: personal-files - # read: - # - $HOME/.config/ubuntu-insights - # dot-cache-ubuntu-insights: - # interface: personal-files - # write: - # - $HOME/.cache/ubuntu-insights all-home: interface: home read: all @@ -69,17 +60,6 @@ apps: - network-observe # for network listing (to read `/sys/devices/**/net/*`) - removable-media - system-observe # to read the host's os-release - - # Plugs required for ubuntu insights. The same as snapcraft.yaml from ubuntu-insights repo. - # TODO: Acquire approval for these plugs - # - dot-config-ubuntu-insights # Default config location - # - dot-cache-ubuntu-insights # Default cache location - # - ubuntu-pro-control # Used to read the Ubuntu Pro attach state over D-Bus. - # - block-devices # Required to see encrypted partitions. `dm-crypt` also works. - - hardware-observe - - wayland - - x11 - - network # Needed for uploading multipass: environment: LD_LIBRARY_PATH: *library-path From 499889615ff3db43ab36d1c137eefc1c1d872db9 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Mon, 16 Nov 2026 00:39:37 +0200 Subject: [PATCH 19/31] [cmake] Make insights support a feature flag --- 3rd-party/vcpkg-ports/ubuntu-insights/usage | 3 ++- CMakeLists.txt | 22 -------------------- feature-flags.cmake | 23 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/usage b/3rd-party/vcpkg-ports/ubuntu-insights/usage index 7b64d79692..f21103cb7d 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/usage +++ b/3rd-party/vcpkg-ports/ubuntu-insights/usage @@ -7,7 +7,8 @@ Include the generated C API with: #include -Imported executable targets: +Imported targets: + ubuntu-insights::ubuntu-insights ubuntu-insights::web-service (Linux only) ubuntu-insights::ingest-service (Linux only) diff --git a/CMakeLists.txt b/CMakeLists.txt index d627bf7d0a..e67920d9a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,6 @@ include(CMakeDependentOption) option(MULTIPASS_VCPKG_BUILD_DEFAULT "Enable or disable building the dependencies in the default configuration, which includes both debug and release variants." OFF) option(MULTIPASS_ENABLE_TESTS "Build tests" ON) -option(MULTIPASS_ENABLE_INSIGHTS "Enable Ubuntu Insights" ON) is_running_in_ci(IS_RUNNING_IN_CI) message(STATUS "Running in CI environment? ${IS_RUNNING_IN_CI}") @@ -141,27 +140,6 @@ if(MULTIPASS_ENABLE_TESTS) list(APPEND VCPKG_MANIFEST_FEATURES "tests") endif() -if(MULTIPASS_ENABLE_INSIGHTS) - list(APPEND VCPKG_MANIFEST_FEATURES "ubuntu-insights") - - # vcpkg builds in an isolated environment, so keep Go's location in its build environment. - find_program(GO_EXECUTABLE go REQUIRED) - get_filename_component(GO_EXECUTABLE_DIR "${GO_EXECUTABLE}" DIRECTORY) - - # Set GO_EXECUTABLE_DIR environment variable, and ask vcpkg to keep it. - # NOTE: The resulting ubuntu-insights ABI hash will not depend on the go toolchain - # used to build it. So if a new go compiler is installed, the port will not be rebuilt. - # This is fine for now. - set(ENV{GO_EXECUTABLE_DIR} "${GO_EXECUTABLE_DIR}") - - set(VCPKG_KEEP_ENV_VARS "$ENV{VCPKG_KEEP_ENV_VARS}") - list(APPEND VCPKG_KEEP_ENV_VARS GO_EXECUTABLE_DIR) - list(REMOVE_DUPLICATES VCPKG_KEEP_ENV_VARS) - - set(ENV{VCPKG_KEEP_ENV_VARS} "${VCPKG_KEEP_ENV_VARS}") - unset(VCPKG_KEEP_ENV_VARS) -endif() - # All the current backends depend on QEMU one way or the other. list(APPEND VCPKG_MANIFEST_FEATURES "qemu") diff --git a/feature-flags.cmake b/feature-flags.cmake index af86654a2a..8951cb2291 100644 --- a/feature-flags.cmake +++ b/feature-flags.cmake @@ -13,3 +13,26 @@ # along with this program. If not, see . include(src/cmake/feature-flag.cmake) + +feature_flag(MULTIPASS_ENABLE_INSIGHTS "Enable Ubuntu Insights") + +if(MULTIPASS_ENABLE_INSIGHTS) + list(APPEND VCPKG_MANIFEST_FEATURES "ubuntu-insights") + + # vcpkg uses an isolated build environment, so explicitly preserve Go's path. + find_program(GO_EXECUTABLE go REQUIRED) + get_filename_component(GO_EXECUTABLE_DIR "${GO_EXECUTABLE}" DIRECTORY) + + # Set GO_EXECUTABLE_DIR environment variable, and ask vcpkg to keep it. + # NOTE: The resulting ubuntu-insights ABI hash will not depend on the go toolchain + # used to build it. So if a new go compiler is installed, the port will not be rebuilt. + # This is fine for now. + set(ENV{GO_EXECUTABLE_DIR} "${GO_EXECUTABLE_DIR}") + + set(VCPKG_KEEP_ENV_VARS "$ENV{VCPKG_KEEP_ENV_VARS}") + list(APPEND VCPKG_KEEP_ENV_VARS GO_EXECUTABLE_DIR) + list(REMOVE_DUPLICATES VCPKG_KEEP_ENV_VARS) + + set(ENV{VCPKG_KEEP_ENV_VARS} "${VCPKG_KEEP_ENV_VARS}") + unset(VCPKG_KEEP_ENV_VARS) +endif() From 803e4894d28a3f3d0c1d8e972b5c7521bd7318cf Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Mon, 16 Nov 2026 01:28:22 +0200 Subject: [PATCH 20/31] [vcpkg] Use insights/v1.0.1 tag --- 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 0fb9cbd50a..a78f1e156d 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -17,8 +17,8 @@ endif() vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO ubuntu/ubuntu-insights - REF bd67ac2fafda18bfca97e3c4843e9e4d3ca71cf1 - SHA512 2d9d170e6b831c18daf6fda60e736200a29d843cf5baf9206b2fabb3f500216b7ec31e70ae430f2b46f43054d8d9243cb50ddac3d8853c0ece76825f370e2451 + REF insights/v1.0.1 + SHA512 54420dd09b3fa4b96a989214fbef649e2e294149d8a9ed9638cec7eac55b8f49a572111376873eaee155cab0198ecfed846e8124f97a736062b22afd23917a6f PATCHES 0001-c-api-free.patch ) From 7bf672a934f625d132403070c63f8684aef8dc95 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Mon, 16 Nov 2026 02:13:19 +0200 Subject: [PATCH 21/31] [tests] Drop Qt from LibInsights smoke tests --- tests/unit/CMakeLists.txt | 1 + tests/unit/test_libinsights.cpp | 49 +++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 032096386a..3c01075f53 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(multipass_integration_tests GTest::gmock_main Qt6::Core fmt::fmt-header-only libssh_wrapper + platform ) target_include_directories(multipass_integration_tests PRIVATE ${CMAKE_SOURCE_DIR} diff --git a/tests/unit/test_libinsights.cpp b/tests/unit/test_libinsights.cpp index 547647b7d0..ee14d00220 100644 --- a/tests/unit/test_libinsights.cpp +++ b/tests/unit/test_libinsights.cpp @@ -19,44 +19,50 @@ #include -#include -#include -#include +#include "temp_dir.h" -namespace +#include + +namespace multipass::test { -class UbuntuInsightsAPI : public testing::Test +class LibInsights : public testing::Test { protected: + const char* to_const_char_ptr(const char8_t* data) + { + return reinterpret_cast(data); + } + void SetUp() override { - ASSERT_TRUE(directory.isValid()); + std::filesystem::path tempdir_fs = tempdir; - consent_dir = directory.filePath("consent").toUtf8(); - insights_dir = directory.filePath("insights").toUtf8(); - system_config_dir = directory.filePath("system").toUtf8(); + consent_dir = (tempdir_fs / "consent").u8string(); + insights_dir = (tempdir_fs / "insights").u8string(); + system_config_dir = (tempdir_fs / "system").u8string(); - config = {consent_dir.constData(), - insights_dir.constData(), - system_config_dir.constData(), - false}; + config = { + .consent_dir = to_const_char_ptr(consent_dir.c_str()), + .insights_dir = to_const_char_ptr(insights_dir.c_str()), + .system_config_dir = to_const_char_ptr(system_config_dir.c_str()), + .verbose = false, + }; } - QTemporaryDir directory; - QByteArray consent_dir; - QByteArray insights_dir; - QByteArray system_config_dir; + TempDir tempdir; + std::u8string consent_dir; + std::u8string insights_dir; + std::u8string system_config_dir; insights_config config{}; }; -} // namespace -TEST_F(UbuntuInsightsAPI, missingConsentIsUnknown) +TEST_F(LibInsights, missingConsentIsUnknown) { EXPECT_EQ(MP_LIBINSIGHTS.insights_get_consent_state(&config, "multipass"), INSIGHTS_CONSENT_UNKNOWN); } -TEST_F(UbuntuInsightsAPI, consentCanBeCreatedAndUpdated) +TEST_F(LibInsights, consentCanBeCreatedAndUpdated) { for (const auto consent : {true, false}) { @@ -70,7 +76,7 @@ TEST_F(UbuntuInsightsAPI, consentCanBeCreatedAndUpdated) } } -TEST_F(UbuntuInsightsAPI, consentIsSpecificToSource) +TEST_F(LibInsights, consentIsSpecificToSource) { char* error = MP_LIBINSIGHTS.insights_set_consent_state(&config, "multipass", true); @@ -82,3 +88,4 @@ TEST_F(UbuntuInsightsAPI, consentIsSpecificToSource) MP_LIBINSIGHTS.insights_free(error); } +} // namespace multipass::test From 909d1ffa9a45651c0e23a3bdb9643e4d100c2e62 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 11:34:19 +0200 Subject: [PATCH 22/31] [ubuntu-insights] Support only x64 on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mustafa Kemal Gılor Signed-off-by: Ahmed Essam --- 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index a78f1e156d..fee4a80ffd 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -9,6 +9,9 @@ if(VCPKG_TARGET_IS_LINUX) elseif(VCPKG_TARGET_IS_OSX) set(INSIGHTS_LIBRARY libinsights.1.dylib) elseif(VCPKG_TARGET_IS_WINDOWS) + if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + message(FATAL_ERROR "ubuntu-insights on Windows requires x64 (the pinned MinGW closure is x86_64-only).") + endif() set(INSIGHTS_LIBRARY libinsights.dll) else() message(FATAL_ERROR "ubuntu-insights supports Linux, macOS, and Windows targets.") From b4ce3142c2de08220a3810bb1b38427a8086e28a Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 11:36:31 +0200 Subject: [PATCH 23/31] [vcpkg] Use $VERSION in ubuntu insights port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mustafa Kemal Gılor Signed-off-by: Ahmed Essam --- 3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index fee4a80ffd..bc139936a7 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -20,7 +20,7 @@ endif() vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO ubuntu/ubuntu-insights - REF insights/v1.0.1 + REF "insights/v${VERSION}" SHA512 54420dd09b3fa4b96a989214fbef649e2e294149d8a9ed9638cec7eac55b8f49a572111376873eaee155cab0198ecfed846e8124f97a736062b22afd23917a6f PATCHES 0001-c-api-free.patch ) From 6255646c820770f1d8f4985654f785a6a47af9c7 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 11:38:00 +0200 Subject: [PATCH 24/31] [vcpkg] Add supports clause in insights vcpkg.json --- 3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json | 1 + 1 file changed, 1 insertion(+) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json index 346421fe8c..38ea5202da 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json +++ b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json @@ -3,5 +3,6 @@ "version": "1.0.1", "description": "Ubuntu Insights client, server executables, and C shared library", "homepage": "https://github.com/ubuntu/ubuntu-insights", + "supports": "linux | osx | (windows & x64)", "license": "GPL-3.0-only" } From cb65d369a6404d7558cad499396b4f6eaf7af83e Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 11:44:44 +0200 Subject: [PATCH 25/31] [vcpkg] Fix ubuntu insights go environment --- .../vcpkg-ports/ubuntu-insights/portfile.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index bc139936a7..dce134af20 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -30,12 +30,26 @@ vcpkg_from_github( # than the one required by ubuntu-insights (1.26). find_program(GO_EXECUTABLE NAMES go HINTS ENV GO_EXECUTABLE_DIR REQUIRED) +set(GO_ENV + CGO_ENABLED=1 + # An unset CGO_CFLAGS makes the upstream generator add -Werror and pedantic warnings + "CGO_CFLAGS=-O2 -g" + # Read by insights/C/generate to stamp the library version (defaults to "Dev") + "DEB_VERSION_UPSTREAM=${VERSION}" + --modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}" +) +if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET) + list(APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}") +endif() + set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") file(MAKE_DIRECTORY "${tools_dir}") function(add_insights_tool tool package) vcpkg_execute_required_process( - COMMAND "${GO_EXECUTABLE}" build -trimpath + COMMAND + ${CMAKE_COMMAND} -E env {GO_ENV} + "${GO_EXECUTABLE}" build -trimpath -o "${tools_dir}/${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}" "${package}" WORKING_DIRECTORY "${SOURCE_PATH}" LOGNAME "build-${tool}" @@ -52,8 +66,6 @@ if(VCPKG_TARGET_IS_LINUX) add_insights_tool(ingest-service ./server/cmd/ingest-service) endif() -set(GO_ENV CGO_ENABLED=1 --modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}") - if(VCPKG_TARGET_IS_WINDOWS) # Reuse the pinned MinGW closure acquired by QEMU. include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") From 837d3476cfac2dedc5b77887c1ecf1d247fb5da3 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 11:57:27 +0200 Subject: [PATCH 26/31] [vcpkg] Put ubuntu insights tools behind a feature --- .../ubuntu-insights/portfile.cmake | 26 +++++++++++-------- 3rd-party/vcpkg-ports/ubuntu-insights/usage | 14 +++++----- .../vcpkg-ports/ubuntu-insights/vcpkg.json | 7 ++++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index dce134af20..6c3d5e0036 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -42,13 +42,10 @@ if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET) list(APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}") endif() -set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") -file(MAKE_DIRECTORY "${tools_dir}") - function(add_insights_tool tool package) vcpkg_execute_required_process( COMMAND - ${CMAKE_COMMAND} -E env {GO_ENV} + "${CMAKE_COMMAND}" -E env ${GO_ENV} "${GO_EXECUTABLE}" build -trimpath -o "${tools_dir}/${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}" "${package}" WORKING_DIRECTORY "${SOURCE_PATH}" @@ -60,12 +57,6 @@ endfunction() set(INSIGHTS_TOOLS "") -add_insights_tool(ubuntu-insights ./insights/cmd/insights) -if(VCPKG_TARGET_IS_LINUX) - add_insights_tool(web-service ./server/cmd/web-service) - add_insights_tool(ingest-service ./server/cmd/ingest-service) -endif() - if(VCPKG_TARGET_IS_WINDOWS) # Reuse the pinned MinGW closure acquired by QEMU. include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") @@ -78,6 +69,17 @@ if(VCPKG_TARGET_IS_WINDOWS) ) endif() +if("tools" IN_LIST FEATURES) + set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") + file(MAKE_DIRECTORY "${tools_dir}") + + add_insights_tool(client ./insights/cmd/insights) + if(VCPKG_TARGET_IS_LINUX) + add_insights_tool(web-service ./server/cmd/web-service) + add_insights_tool(ingest-service ./server/cmd/ingest-service) + endif() +endif() + vcpkg_execute_required_process( COMMAND "${CMAKE_COMMAND}" -E env ${GO_ENV} @@ -126,7 +128,9 @@ write_basic_package_version_file( COMPATIBILITY SameMajorVersion ) -vcpkg_copy_tool_dependencies("${tools_dir}") +if("tools" IN_LIST FEATURES) + vcpkg_copy_tool_dependencies("${tools_dir}") +endif() vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/usage b/3rd-party/vcpkg-ports/ubuntu-insights/usage index f21103cb7d..af5a4eb583 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/usage +++ b/3rd-party/vcpkg-ports/ubuntu-insights/usage @@ -1,14 +1,16 @@ -ubuntu-insights provides a CMake package: +ubuntu-insights provides a CMake package exposing its generated C API: find_package(ubuntu-insights CONFIG REQUIRED) target_link_libraries(my_app PRIVATE ubuntu-insights::insights) -Include the generated C API with: +Include the C API header with: #include -Imported targets: +The `ubuntu-insights::insights` target is always available. - ubuntu-insights::ubuntu-insights - ubuntu-insights::web-service (Linux only) - ubuntu-insights::ingest-service (Linux only) +Enable the optional `tools` feature (`ubuntu-insights[tools]`) to build and expose the following executable targets: + + ubuntu-insights::client + ubuntu-insights::web-service (Linux only) + ubuntu-insights::ingest-service (Linux only) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json index 38ea5202da..76ffd7edcf 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json +++ b/3rd-party/vcpkg-ports/ubuntu-insights/vcpkg.json @@ -4,5 +4,10 @@ "description": "Ubuntu Insights client, server executables, and C shared library", "homepage": "https://github.com/ubuntu/ubuntu-insights", "supports": "linux | osx | (windows & x64)", - "license": "GPL-3.0-only" + "license": "GPL-3.0-only", + "features": { + "tools": { + "description": "Build the Ubuntu Insights client and server executables (servers are Linux-only)" + } + } } From 3297e8235c853e63f7e431b3d1947fc83f7b413e Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 12:14:36 +0200 Subject: [PATCH 27/31] [docs] Add go compiler section in BUILD --- BUILD.linux.md | 15 +++++++++++++++ BUILD.macOS.md | 11 +++++++++++ BUILD.windows.md | 16 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/BUILD.linux.md b/BUILD.linux.md index 7decd0d89f..f4a9062928 100644 --- a/BUILD.linux.md +++ b/BUILD.linux.md @@ -31,6 +31,21 @@ sudo snap install rustup --classic rustup default stable ``` +### Install the Go compiler + +Building with Ubuntu Insights enabled (`MULTIPASS_ENABLE_INSIGHTS`) requires Go 1.26 or newer. +Install the Go snap: + +```sh +sudo snap install go --classic +``` + +Before running CMake, verify that the build terminal finds the required version: + +```sh +go version +``` + ## Building First, go into the repository root and get all the submodules: diff --git a/BUILD.macOS.md b/BUILD.macOS.md index 6d07cd4451..9ed6e9b3c2 100644 --- a/BUILD.macOS.md +++ b/BUILD.macOS.md @@ -47,6 +47,17 @@ To build multipass you will need the rust compiler. It can be installed using br brew install rustup ``` +### Go compiler + +Building with Ubuntu Insights enabled (`MULTIPASS_ENABLE_INSIGHTS`) requires Go 1.26 or newer. +Install Go using Homebrew: + +```sh +brew install go +``` + +Verify that `go version` reports Go 1.26 or newer before running CMake. + Building --------------------------------------- diff --git a/BUILD.windows.md b/BUILD.windows.md index c3d1183087..d11e8e37bc 100644 --- a/BUILD.windows.md +++ b/BUILD.windows.md @@ -34,6 +34,22 @@ compiler and related tooling or fix a broken `visualstudio2022buildtools` instal 6. Make sure that `vcpkg` is not installed in the same selection 7. Complete the installation +### Go compiler + +Building with Ubuntu Insights enabled (`MULTIPASS_ENABLE_INSIGHTS`) requires Go 1.26 or newer. +Install Go from an administrator PowerShell terminal: + +```[pwsh] +choco install golang -y +``` + +Open a new build terminal so it picks up the updated environment, and verify that it finds +Go 1.26 or newer before running CMake: + +```[pwsh] +go version +``` + ### Git You need to enable symlinks in Windows Git, have a look at From 2ed65f69a11b498c72861d9a4acd40ca5dc28223 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 10:59:15 +0200 Subject: [PATCH 28/31] [vcpkg] Add comment about syncing insights.def --- 3rd-party/vcpkg-ports/ubuntu-insights/insights.def | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/insights.def b/3rd-party/vcpkg-ports/ubuntu-insights/insights.def index 7c5f0ecb86..5f5a378252 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/insights.def +++ b/3rd-party/vcpkg-ports/ubuntu-insights/insights.def @@ -1,3 +1,7 @@ +; This file has to be synced with libinsights API. +; See: ubuntu-insights/insights/C/insights.go +; +; TODO: Use gendef tool to autogenerate this file LIBRARY libinsights.dll EXPORTS insights_free From 904aefb5b41cc027348c4b1fd56edc63d6f7d833 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 14:54:51 +0200 Subject: [PATCH 29/31] [vcpkg] Add mingw lockfile when computing abi hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mustafa Kemal Gılor Signed-off-by: Ahmed Essam --- 3rd-party/vcpkg-triplets/x64-windows-static-md.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 63d6cde241..558fc6bb03 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -1,3 +1,12 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) + +# The shared MinGW closure lives outside the port directories, so add it to the +# ABI hash explicitly; otherwise lockfile bumps won't invalidate cached binaries. +if(PORT MATCHES "^(qemu|ubuntu-insights)$") + list(APPEND VCPKG_HASH_ADDITIONAL_FILES + "${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/mingw64-toolchain.lock" + "${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/get-mingw-packages.cmake" + ) +endif() From 81eaf63113aee924217e282e2108db09602fc186 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Tue, 17 Nov 2026 15:10:09 +0200 Subject: [PATCH 30/31] [vcpkg] Share MSYS2 root between qemu and insights --- .../mingw/acquire-mingw-msys.cmake | 44 +++++++++++++++++++ 3rd-party/vcpkg-ports/qemu/portfile.cmake | 43 ++---------------- .../ubuntu-insights/portfile.cmake | 7 +-- .../x64-windows-static-md.cmake | 1 + 4 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 3rd-party/vcpkg-port-utils/mingw/acquire-mingw-msys.cmake diff --git a/3rd-party/vcpkg-port-utils/mingw/acquire-mingw-msys.cmake b/3rd-party/vcpkg-port-utils/mingw/acquire-mingw-msys.cmake new file mode 100644 index 0000000000..28d26026ed --- /dev/null +++ b/3rd-party/vcpkg-port-utils/mingw/acquire-mingw-msys.cmake @@ -0,0 +1,44 @@ +include("${CMAKE_CURRENT_LIST_DIR}/get-mingw-packages.cmake") + +# Acquire a shared MSYS2 root for all ports to avoid repeatedly setting up the +# same environment. +function(multipass_acquire_mingw_msys OUT_ROOT) + multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) + vcpkg_acquire_msys(MSYS_ROOT + PACKAGES findutils perl + DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES} + ) + + # vcpkg_acquire_msys() extracts the full MinGW packages but then deletes + # every mingw64/lib/pkgconfig on *every* call (the removal sits outside its + # "assemble the root once" guard). qemu-img's meson build needs the glib/zstd + # .pc files, so we keep a private backup of them (harvested once, gated on the + # backup dir) and copy it back into the canonical mingw64/lib/pkgconfig on + # every run. The canonical location matters: pkgconf's --define-prefix (on by + # default) only rewrites each .pc's absolute `prefix=/mingw64` into the real + # Windows path when the file is found under a `.../lib/pkgconfig` layout, and + # native mingw gcc can't resolve the bare `/mingw64` POSIX paths otherwise. + set(PKGCONFIG_BACKUP "${MSYS_ROOT}/.multipass-qemu-pkgconfig") + if(NOT EXISTS "${PKGCONFIG_BACKUP}") + # Re-extract the pinned packages into a scratch dir and copy out their + # .pc files (the headers/libs acquire already installed are untouched). + set(_harvest "${CURRENT_BUILDTREES_DIR}/pkgconfig-harvest") + file(REMOVE_RECURSE "${_harvest}") + list(LENGTH MINGW_URLS _mingw_count) + math(EXPR _mingw_last "${_mingw_count} - 1") + foreach(_i RANGE ${_mingw_last}) + list(GET MINGW_URLS ${_i} _url) + list(GET MINGW_SHA512S ${_i} _sha) + get_filename_component(_fn "${_url}" NAME) + vcpkg_download_distfile(_archive URLS "${_url}" FILENAME "${_fn}" SHA512 "${_sha}" QUIET) + file(ARCHIVE_EXTRACT INPUT "${_archive}" DESTINATION "${_harvest}") + endforeach() + file(GLOB _pc_files "${_harvest}/mingw64/lib/pkgconfig/*.pc") + file(COPY ${_pc_files} DESTINATION "${PKGCONFIG_BACKUP}") + file(REMOVE_RECURSE "${_harvest}") + endif() + file(GLOB _pc_backup "${PKGCONFIG_BACKUP}/*.pc") + file(COPY ${_pc_backup} DESTINATION "${MSYS_ROOT}/mingw64/lib/pkgconfig") + + set(${OUT_ROOT} "${MSYS_ROOT}" PARENT_SCOPE) +endfunction() diff --git a/3rd-party/vcpkg-ports/qemu/portfile.cmake b/3rd-party/vcpkg-ports/qemu/portfile.cmake index 81393104e9..7ee9a3ec3d 100644 --- a/3rd-party/vcpkg-ports/qemu/portfile.cmake +++ b/3rd-party/vcpkg-ports/qemu/portfile.cmake @@ -109,14 +109,8 @@ if(VCPKG_TARGET_IS_WINDOWS) set(${OUT_VAR} "${_p}" PARENT_SCOPE) endfunction() - # Assemble a private, content-addressed MSYS2 root: vcpkg's pinned msys shell - # utilities (plus findutils/perl for configure) and our pinned MinGW closure. - include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") - multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) - vcpkg_acquire_msys(MSYS_ROOT - PACKAGES findutils perl - DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES} - ) + include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake") + multipass_acquire_mingw_msys(MSYS_ROOT) # Run the MSYS2 tools under an explicit MINGW64 environment (no login shell): # mingw64/bin and usr/bin on PATH, MSYSTEM selecting the MinGW64 personality. @@ -139,37 +133,6 @@ if(VCPKG_TARGET_IS_WINDOWS) to_msys_path("${BUILD_DIR}" BUILD_DIR_UNIX) to_msys_path("${CURRENT_PACKAGES_DIR}" INSTALL_PREFIX_UNIX) - # vcpkg_acquire_msys() extracts the full MinGW packages but then deletes - # every mingw64/lib/pkgconfig on *every* call (the removal sits outside its - # "assemble the root once" guard). qemu-img's meson build needs the glib/zstd - # .pc files, so we keep a private backup of them (harvested once, gated on the - # backup dir) and copy it back into the canonical mingw64/lib/pkgconfig on - # every run. The canonical location matters: pkgconf's --define-prefix (on by - # default) only rewrites each .pc's absolute `prefix=/mingw64` into the real - # Windows path when the file is found under a `.../lib/pkgconfig` layout, and - # native mingw gcc can't resolve the bare `/mingw64` POSIX paths otherwise. - set(PKGCONFIG_BACKUP "${MSYS_ROOT}/.multipass-qemu-pkgconfig") - if(NOT EXISTS "${PKGCONFIG_BACKUP}") - # Re-extract the pinned packages into a scratch dir and copy out their - # .pc files (the headers/libs acquire already installed are untouched). - set(_harvest "${CURRENT_BUILDTREES_DIR}/pkgconfig-harvest") - file(REMOVE_RECURSE "${_harvest}") - list(LENGTH MINGW_URLS _mingw_count) - math(EXPR _mingw_last "${_mingw_count} - 1") - foreach(_i RANGE ${_mingw_last}) - list(GET MINGW_URLS ${_i} _url) - list(GET MINGW_SHA512S ${_i} _sha) - get_filename_component(_fn "${_url}" NAME) - vcpkg_download_distfile(_archive URLS "${_url}" FILENAME "${_fn}" SHA512 "${_sha}" QUIET) - file(ARCHIVE_EXTRACT INPUT "${_archive}" DESTINATION "${_harvest}") - endforeach() - file(GLOB _pc_files "${_harvest}/mingw64/lib/pkgconfig/*.pc") - file(COPY ${_pc_files} DESTINATION "${PKGCONFIG_BACKUP}") - file(REMOVE_RECURSE "${_harvest}") - endif() - file(GLOB _pc_backup "${PKGCONFIG_BACKUP}/*.pc") - file(COPY ${_pc_backup} DESTINATION "${MSYS_ROOT}/mingw64/lib/pkgconfig") - # meson build deps: distlib + QEMU's vendored meson wheel. site-packages # survives acquire's deletions, so this is a genuine one-time step. set(PYTHON_STAMP "${MSYS_ROOT}/.multipass-qemu-python-ready") @@ -182,7 +145,7 @@ if(VCPKG_TARGET_IS_WINDOWS) # skips the system emulator, --disable-docs avoids the sphinx dependency, and # pixman/zstd are pinned off/on so features don't depend on autodetection. # PKG_CONFIG_PATH/LIBDIR are cleared so pkgconf falls back to its default - # search (the canonical mingw64/lib/pkgconfig we restore above), which is what + # search (the canonical mingw64/lib/pkgconfig restored by the helper), which is what # triggers --define-prefix to emit real Windows include/lib paths. --prefix is # required (meson validates it) though we never install; the binary is copied # straight from the build tree. diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index 6c3d5e0036..be162ae0f1 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -36,7 +36,6 @@ set(GO_ENV "CGO_CFLAGS=-O2 -g" # Read by insights/C/generate to stamp the library version (defaults to "Dev") "DEB_VERSION_UPSTREAM=${VERSION}" - --modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}" ) if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET) list(APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}") @@ -58,10 +57,8 @@ endfunction() set(INSIGHTS_TOOLS "") if(VCPKG_TARGET_IS_WINDOWS) - # Reuse the pinned MinGW closure acquired by QEMU. - include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake") - multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S) - vcpkg_acquire_msys(MSYS_ROOT DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES}) + include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake") + multipass_acquire_mingw_msys(MSYS_ROOT) file(TO_NATIVE_PATH "${MSYS_ROOT}/mingw64/bin" MINGW_BIN) list(APPEND GO_ENV "CC=${MINGW_BIN}/gcc.exe" diff --git a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake index 558fc6bb03..0f380cbd65 100644 --- a/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake +++ b/3rd-party/vcpkg-triplets/x64-windows-static-md.cmake @@ -8,5 +8,6 @@ if(PORT MATCHES "^(qemu|ubuntu-insights)$") list(APPEND VCPKG_HASH_ADDITIONAL_FILES "${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/mingw64-toolchain.lock" "${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/get-mingw-packages.cmake" + "${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake" ) endif() From 6dc6b7408c1cac0c697a0b360aecd9c622ab6c37 Mon Sep 17 00:00:00 2001 From: Ahmed Essam Date: Fri, 20 Nov 2026 14:53:17 +0200 Subject: [PATCH 31/31] [vcpkg] Auto-generate insights import library def --- .../vcpkg-ports/ubuntu-insights/insights.def | 16 ----- .../ubuntu-insights/portfile.cmake | 70 ++++++++++++------- .../ubuntu-insights-config.cmake.in | 1 + 3 files changed, 45 insertions(+), 42 deletions(-) delete mode 100644 3rd-party/vcpkg-ports/ubuntu-insights/insights.def diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/insights.def b/3rd-party/vcpkg-ports/ubuntu-insights/insights.def deleted file mode 100644 index 5f5a378252..0000000000 --- a/3rd-party/vcpkg-ports/ubuntu-insights/insights.def +++ /dev/null @@ -1,16 +0,0 @@ -; This file has to be synced with libinsights API. -; See: ubuntu-insights/insights/C/insights.go -; -; TODO: Use gendef tool to autogenerate this file -LIBRARY libinsights.dll -EXPORTS - insights_free - insights_collect - insights_compile - insights_write - insights_upload - insights_get_consent_state - insights_set_consent_state - insights_get_system_opt_out_state - insights_set_system_opt_out_state - insights_set_log_callback diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake index be162ae0f1..47f7ab34d6 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake +++ b/3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake @@ -30,6 +30,7 @@ vcpkg_from_github( # than the one required by ubuntu-insights (1.26). find_program(GO_EXECUTABLE NAMES go HINTS ENV GO_EXECUTABLE_DIR REQUIRED) +# Set up the common go environment that will be used to build the tools and the C-API set(GO_ENV CGO_ENABLED=1 # An unset CGO_CFLAGS makes the upstream generator add -Werror and pedantic warnings @@ -41,21 +42,10 @@ if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET) list(APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}") endif() -function(add_insights_tool tool package) - vcpkg_execute_required_process( - COMMAND - "${CMAKE_COMMAND}" -E env ${GO_ENV} - "${GO_EXECUTABLE}" build -trimpath - -o "${tools_dir}/${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}" "${package}" - WORKING_DIRECTORY "${SOURCE_PATH}" - LOGNAME "build-${tool}" - ) - list(APPEND INSIGHTS_TOOLS "${tool}") - set(INSIGHTS_TOOLS "${INSIGHTS_TOOLS}" PARENT_SCOPE) -endfunction() - -set(INSIGHTS_TOOLS "") - +# If on Windows, acquire MinGW which is required for building the C API. +# +# TODO: The acquired MinGW targets the legacy C runtime (CRT). Update it to use +# the UCRT packages instead. For now this should be ok. if(VCPKG_TARGET_IS_WINDOWS) include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake") multipass_acquire_mingw_msys(MSYS_ROOT) @@ -64,9 +54,31 @@ if(VCPKG_TARGET_IS_WINDOWS) "CC=${MINGW_BIN}/gcc.exe" --modify "PATH=path_list_prepend:${MINGW_BIN}" ) + + set(C_API_ENV ${GO_ENV}) + set(INSIGHTS_DEF "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-insights.def") + list(APPEND C_API_ENV "CGO_LDFLAGS=-Wl,--output-def,${INSIGHTS_DEF}") +else() + set(C_API_ENV ${GO_ENV}) endif() +set(INSIGHTS_TOOLS "") + +# Build the tools if the feature is requested if("tools" IN_LIST FEATURES) + function(add_insights_tool tool package) + vcpkg_execute_required_process( + COMMAND + "${CMAKE_COMMAND}" -E env ${GO_ENV} + "${GO_EXECUTABLE}" build -trimpath + -o "${tools_dir}/${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX}" "${package}" + WORKING_DIRECTORY "${SOURCE_PATH}" + LOGNAME "build-${tool}" + ) + list(APPEND INSIGHTS_TOOLS "${tool}") + set(INSIGHTS_TOOLS "${INSIGHTS_TOOLS}" PARENT_SCOPE) + endfunction() + set(tools_dir "${CURRENT_PACKAGES_DIR}/tools/${PORT}") file(MAKE_DIRECTORY "${tools_dir}") @@ -77,9 +89,10 @@ if("tools" IN_LIST FEATURES) endif() endif() +# Build the C-API vcpkg_execute_required_process( COMMAND - "${CMAKE_COMMAND}" -E env ${GO_ENV} + "${CMAKE_COMMAND}" -E env ${C_API_ENV} "${GO_EXECUTABLE}" run -tags=tools ./generate/... WORKING_DIRECTORY "${SOURCE_PATH}/insights/C" LOGNAME build-c-api @@ -88,26 +101,31 @@ vcpkg_execute_required_process( if(VCPKG_TARGET_IS_WINDOWS) # Generate an import library, otherwise MSVC will not be able to link against the generated dll file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib") - set(INSIGHTS_IMPLIB insights.lib) + set(INSIGHTS_IMPLIB libinsights.lib) find_program(lib_tool NAMES lib.exe llvm-lib REQUIRED) vcpkg_execute_required_process( - COMMAND "${lib_tool}" "/def:${CMAKE_CURRENT_LIST_DIR}/insights.def" /machine:x64 - "/out:${CURRENT_PACKAGES_DIR}/lib/${INSIGHTS_IMPLIB}" + COMMAND "${lib_tool}" "/def:${INSIGHTS_DEF}" /machine:x64 + "/out:${CURRENT_PACKAGES_DIR}/lib/${INSIGHTS_IMPLIB}" WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}" LOGNAME import-library ) - file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" - DESTINATION "${CURRENT_PACKAGES_DIR}/bin") + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/bin") - # libinsights is built in a single configuration, but vcpkg's applocal + # libinsights is built with a single configuration, but vcpkg's applocal # searches only debug/bin for DLLs when building Debug executables. # Copy the DLL there as well so it can be deployed automatically. - file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" - DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin") + # + # We also copy the lib import library so that vcpkg doesn't issue a warning + # for a dll without an accompany import library. + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin") + file(INSTALL "${CURRENT_PACKAGES_DIR}/lib/${INSIGHTS_IMPLIB}" + DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib/") else() - file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" - DESTINATION "${CURRENT_PACKAGES_DIR}/lib") + file(INSTALL "${SOURCE_PATH}/insights/generated/${INSIGHTS_LIBRARY}" + DESTINATION "${CURRENT_PACKAGES_DIR}/lib") endif() file(INSTALL diff --git a/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in index ad9ce359bf..c3688c9d13 100644 --- a/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in +++ b/3rd-party/vcpkg-ports/ubuntu-insights/ubuntu-insights-config.cmake.in @@ -13,6 +13,7 @@ if(WIN32) IMPORTED_LOCATION "${_insights_prefix}/bin/@INSIGHTS_LIBRARY@" IMPORTED_LOCATION_DEBUG "${_insights_prefix}/debug/bin/@INSIGHTS_LIBRARY@" IMPORTED_IMPLIB "${_insights_prefix}/lib/@INSIGHTS_IMPLIB@" + IMPORTED_IMPLIB_DEBUG "${_insights_prefix}/debug/lib/@INSIGHTS_IMPLIB@" ) else() set_target_properties(ubuntu-insights::insights PROPERTIES