Skip to content

Commit d047aca

Browse files
committed
[vcpkg] Share MSYS2 root between qemu and insights
1 parent bc33340 commit d047aca

4 files changed

Lines changed: 50 additions & 45 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
include("${CMAKE_CURRENT_LIST_DIR}/get-mingw-packages.cmake")
2+
3+
# Acquire a shared MSYS2 root for all ports to avoid repeatedly setting up the
4+
# same environment.
5+
function(multipass_acquire_mingw_msys OUT_ROOT)
6+
multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S)
7+
vcpkg_acquire_msys(MSYS_ROOT
8+
PACKAGES findutils perl
9+
DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES}
10+
)
11+
12+
# vcpkg_acquire_msys() extracts the full MinGW packages but then deletes
13+
# every mingw64/lib/pkgconfig on *every* call (the removal sits outside its
14+
# "assemble the root once" guard). qemu-img's meson build needs the glib/zstd
15+
# .pc files, so we keep a private backup of them (harvested once, gated on the
16+
# backup dir) and copy it back into the canonical mingw64/lib/pkgconfig on
17+
# every run. The canonical location matters: pkgconf's --define-prefix (on by
18+
# default) only rewrites each .pc's absolute `prefix=/mingw64` into the real
19+
# Windows path when the file is found under a `.../lib/pkgconfig` layout, and
20+
# native mingw gcc can't resolve the bare `/mingw64` POSIX paths otherwise.
21+
set(PKGCONFIG_BACKUP "${MSYS_ROOT}/.multipass-qemu-pkgconfig")
22+
if(NOT EXISTS "${PKGCONFIG_BACKUP}")
23+
# Re-extract the pinned packages into a scratch dir and copy out their
24+
# .pc files (the headers/libs acquire already installed are untouched).
25+
set(_harvest "${CURRENT_BUILDTREES_DIR}/pkgconfig-harvest")
26+
file(REMOVE_RECURSE "${_harvest}")
27+
list(LENGTH MINGW_URLS _mingw_count)
28+
math(EXPR _mingw_last "${_mingw_count} - 1")
29+
foreach(_i RANGE ${_mingw_last})
30+
list(GET MINGW_URLS ${_i} _url)
31+
list(GET MINGW_SHA512S ${_i} _sha)
32+
get_filename_component(_fn "${_url}" NAME)
33+
vcpkg_download_distfile(_archive URLS "${_url}" FILENAME "${_fn}" SHA512 "${_sha}" QUIET)
34+
file(ARCHIVE_EXTRACT INPUT "${_archive}" DESTINATION "${_harvest}")
35+
endforeach()
36+
file(GLOB _pc_files "${_harvest}/mingw64/lib/pkgconfig/*.pc")
37+
file(COPY ${_pc_files} DESTINATION "${PKGCONFIG_BACKUP}")
38+
file(REMOVE_RECURSE "${_harvest}")
39+
endif()
40+
file(GLOB _pc_backup "${PKGCONFIG_BACKUP}/*.pc")
41+
file(COPY ${_pc_backup} DESTINATION "${MSYS_ROOT}/mingw64/lib/pkgconfig")
42+
43+
set(${OUT_ROOT} "${MSYS_ROOT}" PARENT_SCOPE)
44+
endfunction()

‎3rd-party/vcpkg-ports/qemu/portfile.cmake‎

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,8 @@ if(VCPKG_TARGET_IS_WINDOWS)
109109
set(${OUT_VAR} "${_p}" PARENT_SCOPE)
110110
endfunction()
111111

112-
# Assemble a private, content-addressed MSYS2 root: vcpkg's pinned msys shell
113-
# utilities (plus findutils/perl for configure) and our pinned MinGW closure.
114-
include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake")
115-
multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S)
116-
vcpkg_acquire_msys(MSYS_ROOT
117-
PACKAGES findutils perl
118-
DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES}
119-
)
112+
include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake")
113+
multipass_acquire_mingw_msys(MSYS_ROOT)
120114

121115
# Run the MSYS2 tools under an explicit MINGW64 environment (no login shell):
122116
# mingw64/bin and usr/bin on PATH, MSYSTEM selecting the MinGW64 personality.
@@ -139,37 +133,6 @@ if(VCPKG_TARGET_IS_WINDOWS)
139133
to_msys_path("${BUILD_DIR}" BUILD_DIR_UNIX)
140134
to_msys_path("${CURRENT_PACKAGES_DIR}" INSTALL_PREFIX_UNIX)
141135

142-
# vcpkg_acquire_msys() extracts the full MinGW packages but then deletes
143-
# every mingw64/lib/pkgconfig on *every* call (the removal sits outside its
144-
# "assemble the root once" guard). qemu-img's meson build needs the glib/zstd
145-
# .pc files, so we keep a private backup of them (harvested once, gated on the
146-
# backup dir) and copy it back into the canonical mingw64/lib/pkgconfig on
147-
# every run. The canonical location matters: pkgconf's --define-prefix (on by
148-
# default) only rewrites each .pc's absolute `prefix=/mingw64` into the real
149-
# Windows path when the file is found under a `.../lib/pkgconfig` layout, and
150-
# native mingw gcc can't resolve the bare `/mingw64` POSIX paths otherwise.
151-
set(PKGCONFIG_BACKUP "${MSYS_ROOT}/.multipass-qemu-pkgconfig")
152-
if(NOT EXISTS "${PKGCONFIG_BACKUP}")
153-
# Re-extract the pinned packages into a scratch dir and copy out their
154-
# .pc files (the headers/libs acquire already installed are untouched).
155-
set(_harvest "${CURRENT_BUILDTREES_DIR}/pkgconfig-harvest")
156-
file(REMOVE_RECURSE "${_harvest}")
157-
list(LENGTH MINGW_URLS _mingw_count)
158-
math(EXPR _mingw_last "${_mingw_count} - 1")
159-
foreach(_i RANGE ${_mingw_last})
160-
list(GET MINGW_URLS ${_i} _url)
161-
list(GET MINGW_SHA512S ${_i} _sha)
162-
get_filename_component(_fn "${_url}" NAME)
163-
vcpkg_download_distfile(_archive URLS "${_url}" FILENAME "${_fn}" SHA512 "${_sha}" QUIET)
164-
file(ARCHIVE_EXTRACT INPUT "${_archive}" DESTINATION "${_harvest}")
165-
endforeach()
166-
file(GLOB _pc_files "${_harvest}/mingw64/lib/pkgconfig/*.pc")
167-
file(COPY ${_pc_files} DESTINATION "${PKGCONFIG_BACKUP}")
168-
file(REMOVE_RECURSE "${_harvest}")
169-
endif()
170-
file(GLOB _pc_backup "${PKGCONFIG_BACKUP}/*.pc")
171-
file(COPY ${_pc_backup} DESTINATION "${MSYS_ROOT}/mingw64/lib/pkgconfig")
172-
173136
# meson build deps: distlib + QEMU's vendored meson wheel. site-packages
174137
# survives acquire's deletions, so this is a genuine one-time step.
175138
set(PYTHON_STAMP "${MSYS_ROOT}/.multipass-qemu-python-ready")
@@ -182,7 +145,7 @@ if(VCPKG_TARGET_IS_WINDOWS)
182145
# skips the system emulator, --disable-docs avoids the sphinx dependency, and
183146
# pixman/zstd are pinned off/on so features don't depend on autodetection.
184147
# PKG_CONFIG_PATH/LIBDIR are cleared so pkgconf falls back to its default
185-
# search (the canonical mingw64/lib/pkgconfig we restore above), which is what
148+
# search (the canonical mingw64/lib/pkgconfig restored by the helper), which is what
186149
# triggers --define-prefix to emit real Windows include/lib paths. --prefix is
187150
# required (meson validates it) though we never install; the binary is copied
188151
# straight from the build tree.

‎3rd-party/vcpkg-ports/ubuntu-insights/portfile.cmake‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ set(GO_ENV
3636
"CGO_CFLAGS=-O2 -g"
3737
# Read by insights/C/generate to stamp the library version (defaults to "Dev")
3838
"DEB_VERSION_UPSTREAM=${VERSION}"
39-
--modify "PATH=path_list_prepend:${GO_EXECUTABLE_DIR}"
4039
)
4140
if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET)
4241
list(APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}")
@@ -58,10 +57,8 @@ endfunction()
5857
set(INSIGHTS_TOOLS "")
5958

6059
if(VCPKG_TARGET_IS_WINDOWS)
61-
# Reuse the pinned MinGW closure acquired by QEMU.
62-
include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/get-mingw-packages.cmake")
63-
multipass_get_mingw_packages(MINGW_DIRECT_PACKAGES MINGW_URLS MINGW_SHA512S)
64-
vcpkg_acquire_msys(MSYS_ROOT DIRECT_PACKAGES ${MINGW_DIRECT_PACKAGES})
60+
include("${CMAKE_CURRENT_LIST_DIR}/../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake")
61+
multipass_acquire_mingw_msys(MSYS_ROOT)
6562
file(TO_NATIVE_PATH "${MSYS_ROOT}/mingw64/bin" MINGW_BIN)
6663
list(APPEND GO_ENV
6764
"CC=${MINGW_BIN}/gcc.exe"

‎3rd-party/vcpkg-triplets/x64-windows-static-md.cmake‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ if(PORT MATCHES "^(qemu|ubuntu-insights)$")
88
list(APPEND VCPKG_HASH_ADDITIONAL_FILES
99
"${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/mingw64-toolchain.lock"
1010
"${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/get-mingw-packages.cmake"
11+
"${CMAKE_CURRENT_LIST_DIR}/../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake"
1112
)
1213
endif()

0 commit comments

Comments
 (0)