aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/vcpkg-get-python
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/vcpkg-get-python
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/ports/vcpkg-get-python')
-rw-r--r--vcpkg/ports/vcpkg-get-python/portfile.cmake7
-rw-r--r--vcpkg/ports/vcpkg-get-python/vcpkg-port-config.cmake80
-rw-r--r--vcpkg/ports/vcpkg-get-python/vcpkg.json6
3 files changed, 93 insertions, 0 deletions
diff --git a/vcpkg/ports/vcpkg-get-python/portfile.cmake b/vcpkg/ports/vcpkg-get-python/portfile.cmake
new file mode 100644
index 0000000..473b6b7
--- /dev/null
+++ b/vcpkg/ports/vcpkg-get-python/portfile.cmake
@@ -0,0 +1,7 @@
+
+file(INSTALL
+ "${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake"
+ DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
+
+vcpkg_install_copyright(FILE_LIST "${VCPKG_ROOT_DIR}/LICENSE.txt")
+set(VCPKG_POLICY_CMAKE_HELPER_PORT enabled)
diff --git a/vcpkg/ports/vcpkg-get-python/vcpkg-port-config.cmake b/vcpkg/ports/vcpkg-get-python/vcpkg-port-config.cmake
new file mode 100644
index 0000000..e38ba5f
--- /dev/null
+++ b/vcpkg/ports/vcpkg-get-python/vcpkg-port-config.cmake
@@ -0,0 +1,80 @@
+include_guard(GLOBAL)
+
+function(vcpkg_get_vcpkg_installed_python out_python)
+ cmake_parse_arguments(PARSE_ARGV 1 "arg" "INTERPRETER" "" "")
+ if(DEFINED arg_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
+ endif()
+ if(NOT VCPKG_TARGET_IS_WINDOWS)
+ # vcpkg installed python on !windows works as normal python would work.
+ set(${out_python} "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/python3" PARENT_SCOPE)
+ return()
+ endif()
+ if(DEFINED CACHE{z_vcpkg_get_vcpkg_installed_python})
+ set(${out_python} "${z_vcpkg_get_vcpkg_installed_python}" PARENT_SCOPE)
+ return()
+ elseif(arg_INTERPRETER AND DEFINED CACHE{z_vcpkg_get_vcpkg_installed_python_interpreter})
+ set(${out_python} "${z_vcpkg_get_vcpkg_installed_python_interpreter}" PARENT_SCOPE)
+ return()
+ endif()
+
+ # On windows python is unable to lookup DLLs, so a manual venv is created
+ set(python_home "${CURRENT_HOST_INSTALLED_DIR}/tools/python3")
+ set(python_base "${CURRENT_BUILDTREES_DIR}/python-${TARGET_TRIPLET}")
+
+ file(GLOB python_files LIST_DIRECTORIES false "${python_home}/*")
+ if(EXISTS "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/DLLs")
+ file(COPY "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/DLLs/" DESTINATION "${python_base}/DLLs")
+ endif()
+ file(COPY ${python_files} DESTINATION "${python_base}/Scripts")
+ file(MAKE_DIRECTORY "${python_base}/Lib/site-packages")
+
+ file(WRITE "${python_base}/pyvenv.cfg"
+"
+home = ${python_home}
+include-system-site-packages = false
+version = ${PYTHON3_VERSION}
+executable = ${python_home}/python.exe
+command = ${python_home}/python.exe -m venv ${python_base}
+"
+)
+
+ file(WRITE "${python_base}/Lib/site-packages/sitecustomize.py"
+"
+import os
+import sys
+from pathlib import Path
+
+import site
+#enable direct lookup of installed site-packages without the need to copy them
+site.addsitedir(sys.base_prefix + '/Lib/site-packages')
+
+vcpkg_bin_path = Path(sys.base_prefix + '/../../bin')
+if vcpkg_bin_path.is_dir():
+ os.add_dll_directory(vcpkg_bin_path)
+"
+)
+
+ # This part is intentionally copies headers and link libraries from the target
+ # installation (CURRENT_INSTALLED_DIR): The function provides infrastructure for
+ # building extensions for the target python while running the host python interpreter.
+ # The calling port is responsible to provided the target python3 dependency.
+ # However, it is possible to use just the interpreter,
+ # e.g. for running extensions already installed in the host triplet.
+ if(EXISTS "${CURRENT_INSTALLED_DIR}/lib/python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR}.lib")
+ file(COPY "${CURRENT_INSTALLED_DIR}/${PYTHON3_INCLUDE}/" DESTINATION "${python_base}/include")
+ set(suffix "PCBuild/AMD64") # TODO: ask python for the correct suffix.
+ file(COPY "${CURRENT_INSTALLED_DIR}/lib/python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR}.lib" DESTINATION "${python_base}/${suffix}")
+ set(z_vcpkg_get_vcpkg_installed_python "${python_base}/Scripts/python.exe" CACHE INTERNAL "")
+ elseif(arg_INTERPRETER)
+ set(z_vcpkg_get_vcpkg_installed_python_interpreter "${python_base}/Scripts/python.exe" CACHE INTERNAL "")
+ else()
+ message(${Z_VCPKG_BACKCOMPAT_MESSAGE_LEVEL}
+ "Target python3 installation was not found, and the INTERPRETER wasn't given."
+ " Either add a \"python3\" dependency to ${PORT},"
+ " or add 'INTERPRETER' to the '${CMAKE_CURRENT_FUNCTION}' call."
+ )
+ endif()
+
+ set(${out_python} "${python_base}/Scripts/python.exe" PARENT_SCOPE)
+endfunction()
diff --git a/vcpkg/ports/vcpkg-get-python/vcpkg.json b/vcpkg/ports/vcpkg-get-python/vcpkg.json
new file mode 100644
index 0000000..b66eaeb
--- /dev/null
+++ b/vcpkg/ports/vcpkg-get-python/vcpkg.json
@@ -0,0 +1,6 @@
+{
+ "name": "vcpkg-get-python",
+ "version-date": "2025-02-09",
+ "license": "MIT",
+ "supports": "native"
+}