Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3fd|python3] switch to vcpkg-msbuild #33026

Merged
merged 9 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions ports/3fd/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ vcpkg_from_github(
)

# Build:
if (VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") # UWP:
vcpkg_install_msbuild(
if (VCPKG_TARGET_IS_UWP) # UWP:
vcpkg_msbuild_install(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH "3FD/3FD.WinRT.UWP.vcxproj"
USE_VCPKG_INTEGRATION
)
elseif (NOT VCPKG_CMAKE_SYSTEM_NAME) # Win32:
vcpkg_install_msbuild(
elseif (VCPKG_TARGET_IS_WINDOWS) # Win32:
vcpkg_msbuild_install(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH "3FD/3FD.vcxproj"
TARGET Build
USE_VCPKG_INTEGRATION
)
else()
message(FATAL_ERROR "Unsupported system: 3FD is not currently ported to VCPKG in ${VCPKG_CMAKE_SYSTEM_NAME}!")
Expand All @@ -34,24 +32,24 @@ endif()
file(GLOB HEADER_FILES LIST_DIRECTORIES false "${SOURCE_PATH}/3FD/*.h")
file(INSTALL
${HEADER_FILES}
DESTINATION ${CURRENT_PACKAGES_DIR}/include/3FD
DESTINATION "${CURRENT_PACKAGES_DIR}/include/3FD"
PATTERN "*_impl*.h" EXCLUDE
PATTERN "*example*.h" EXCLUDE
PATTERN "stdafx.h" EXCLUDE
PATTERN "targetver.h" EXCLUDE
)

file(INSTALL ${SOURCE_PATH}/btree DESTINATION ${CURRENT_PACKAGES_DIR}/include/3FD)
file(INSTALL ${SOURCE_PATH}/OpenCL/CL DESTINATION ${CURRENT_PACKAGES_DIR}/include/3FD)
file(INSTALL "${SOURCE_PATH}/btree" DESTINATION "${CURRENT_PACKAGES_DIR}/include/3FD")
file(INSTALL "${SOURCE_PATH}/OpenCL/CL" DESTINATION "${CURRENT_PACKAGES_DIR}/include/3FD")

file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/share/3FD)
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/share/3FD")
file(INSTALL
${SOURCE_PATH}/3FD/3fd-config-template.xml
DESTINATION ${CURRENT_PACKAGES_DIR}/share/3FD
"${SOURCE_PATH}/3FD/3fd-config-template.xml"
DESTINATION "${CURRENT_PACKAGES_DIR}/share/3FD"
)

# Handle copyright
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/3fd RENAME copyright)
file(INSTALL ${SOURCE_PATH}/Acknowledgements.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/3fd)
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
file(INSTALL "${SOURCE_PATH}/Acknowledgements.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/3fd")

vcpkg_copy_pdbs()
9 changes: 7 additions & 2 deletions ports/3fd/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "3fd",
"version": "2.6.3",
"port-version": 3,
"port-version": 4,
"description": "C++ Framework For Fast Development",
"supports": "windows & !static & !arm64",
"dependencies": [
Expand All @@ -18,6 +18,11 @@
"platform": "windows"
},
"rapidxml",
"sqlite3"
"sqlite3",
{
"name": "vcpkg-msbuild",
"host": true,
"platform": "windows"
}
]
}
13 changes: 13 additions & 0 deletions ports/python3/0015-dont-use-WINDOWS-def.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/PC/launcher.c b/PC/launcher.c
index 734e75333..7124927cf 100644
--- a/PC/launcher.c
+++ b/PC/launcher.c
@@ -2015,7 +2015,7 @@ installed, use -0 for available pythons", &p[1]);
return rc;
}

-#if defined(_WINDOWS)
+#if !defined(_CONSOLE) // _WINDOWS is defined by the vcpkg toolchain

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpstrCmd, int nShow)
34 changes: 34 additions & 0 deletions ports/python3/0016-fix-win-cross.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj
index 7d3423251f..7f607742fe 100644
--- a/PCbuild/_freeze_module.vcxproj
+++ b/PCbuild/_freeze_module.vcxproj
@@ -366,7 +366,7 @@
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<Target Name="_RebuildGetPath" AfterTargets="_RebuildFrozen" Condition="$(Configuration) != 'PGUpdate'">
- <Exec Command='"$(TargetPath)" "%(GetPath.ModName)" "%(GetPath.FullPath)" "%(GetPath.IntFile)"' />
+ <Exec Command='"_freeze_module.exe" "%(GetPath.ModName)" "%(GetPath.FullPath)" "%(GetPath.IntFile)"' />

<Copy SourceFiles="%(GetPath.IntFile)"
DestinationFiles="%(GetPath.OutFile)"
@@ -378,7 +378,7 @@
Condition="'@(_UpdatedGetPath)' != ''" Importance="high" />
</Target>
<Target Name="_RebuildFrozen" AfterTargets="AfterBuild" Condition="$(Configuration) != 'PGUpdate'">
- <Exec Command='"$(TargetPath)" "%(None.ModName)" "%(None.FullPath)" "%(None.IntFile)"' />
+ <Exec Command='"_freeze_module.exe" "%(None.ModName)" "%(None.FullPath)" "%(None.IntFile)"' />

<Copy SourceFiles="%(None.IntFile)"
DestinationFiles="%(None.OutFile)"
diff --git a/PCbuild/pcbuild.proj b/PCbuild/pcbuild.proj
index c49a8533ad..b1cdf7c8d7 100644
--- a/PCbuild/pcbuild.proj
+++ b/PCbuild/pcbuild.proj
@@ -14,6 +14,6 @@
<ItemDefinitionGroup>
<FreezeProjects>
- <Platform>$(PreferredToolArchitecture)</Platform>
+ <Platform>$(Platform)</Platform>
<Configuration>$(Configuration)</Configuration>
<Configuration Condition="$(Configuration) == 'PGInstrument'">Release</Configuration>
<Properties></Properties>
9 changes: 9 additions & 0 deletions ports/python3/openssl.props.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@
${CRYPTO_DEBUG};${SSL_DEBUG};%(AdditionalDependencies)
</AdditionalDependencies>
</Link>
<Lib>
<AdditionalDependencies>Crypt32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(IncludeExternals)'=='Release|true'">
${CRYPTO_RELEASE};${SSL_RELEASE};%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(IncludeExternals)'=='Debug|true'">
${CRYPTO_DEBUG};${SSL_DEBUG};%(AdditionalDependencies)
</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
</Project>
53 changes: 31 additions & 22 deletions ports/python3/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ set(PATCHES
0010-dont-skip-rpath.patch
0012-force-disable-curses.patch
0014-fix-get-python-inc-output.patch
0015-dont-use-WINDOWS-def.patch
)

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND PATCHES 0002-static-library.patch)
endif()

# Fix build failures with GCC for built-in modules (https://github.com/microsoft/vcpkg/issues/26573)
if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(VCPKG_TARGET_IS_LINUX)
list(APPEND PATCHES 0011-gcc-ldflags-fix.patch)
endif()

Expand All @@ -37,13 +38,16 @@ elseif(VCPKG_TARGET_IS_WINDOWS AND CMAKE_SYSTEM_VERSION EQUAL 6.1)
message(FATAL_ERROR "python3 requires the feature deprecated-win7-support when building on Windows 7.")
endif()

if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP)
if(VCPKG_TARGET_IS_WINDOWS)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" PYTHON_ALLOW_EXTENSIONS)
# The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that.
vcpkg_get_windows_sdk(WINSDK_VERSION)
if("${WINSDK_VERSION}" VERSION_GREATER_EQUAL "10.0.22000")
list(APPEND PATCHES "0007-workaround-windows-11-sdk-rc-compiler-error.patch")
endif()
if(VCPKG_CROSSCOMPILING)
list(APPEND PATCHES "0016-fix-win-cross.patch")
endif()
endif()

vcpkg_from_github(
Expand Down Expand Up @@ -94,20 +98,25 @@ if(VCPKG_TARGET_IS_WINDOWS)
find_library(SQLITE_DEBUG NAMES sqlite3 PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)
find_library(SSL_RELEASE NAMES libssl PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
find_library(SSL_DEBUG NAMES libssl PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)
list(APPEND add_libs_rel "${BZ2_RELEASE};${EXPAT_RELEASE};${FFI_RELEASE};${LZMA_RELEASE};${SQLITE_RELEASE}")
list(APPEND add_libs_dbg "${BZ2_DEBUG};${EXPAT_DEBUG};${FFI_DEBUG};${LZMA_DEBUG};${SQLITE_DEBUG}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this benefit from x_vcpkg_pkgconfig_get_modules()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could rather add DEPENDENT_PKGCONFIG to vcpkg_msbuild_install but didn't want to go there yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these libs duplicated in props file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ultimate cleanup plan would be to remove openssl.props.in and python_vcpkg.props.in completely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hoikas I assume the why is in response of dropping the props files as ultimate cleanup. Simply said no portfile should require a direct interaction with build system internals. In the case of MSBuild it is the injection of props files which every port would have needed to to manually. It is simply better to have an abstraction around that than having to deal with msbuild shenanigans.

else()
message(STATUS "WARNING: Static builds of Python will not have C extension modules available.")
endif()
find_library(ZLIB_RELEASE NAMES zlib PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
find_library(ZLIB_DEBUG NAMES zlib zlibd PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)
list(APPEND add_libs_rel "${ZLIB_RELEASE}")
list(APPEND add_libs_dbg "${ZLIB_DEBUG}")

configure_file("${SOURCE_PATH}/PC/pyconfig.h" "${SOURCE_PATH}/PC/pyconfig.h")
configure_file("${CMAKE_CURRENT_LIST_DIR}/python_vcpkg.props.in" "${SOURCE_PATH}/PCbuild/python_vcpkg.props")
configure_file("${CMAKE_CURRENT_LIST_DIR}/openssl.props.in" "${SOURCE_PATH}/PCbuild/openssl.props")
file(WRITE "${SOURCE_PATH}/PCbuild/libffi.props"
"<?xml version='1.0' encoding='utf-8'?>
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"
"<?xml version='1.0' encoding='utf-8'?>"
"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"
)

list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_SET_CHARSET_FLAG=OFF")
if(PYTHON_ALLOW_EXTENSIONS)
set(OPTIONS
"/p:IncludeExtensions=true"
Expand Down Expand Up @@ -137,27 +146,29 @@ if(VCPKG_TARGET_IS_WINDOWS)
list(APPEND OPTIONS "/p:_VcpkgPythonLinkage=StaticLibrary")
endif()

# _freeze_importlib.exe is run as part of the build process, so make sure the required dynamic libs are available.
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
vcpkg_add_to_path("${CURRENT_INSTALLED_DIR}/bin")
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
vcpkg_add_to_path("${CURRENT_INSTALLED_DIR}/debug/bin")
endif()
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
set(ENV{PythonForBuild} "${PYTHON3_DIR}/python.exe") # PythonForBuild is what's used on windows, despite the readme

vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
set(ENV{PythonForBuild} "${PYTHON3_DIR}/python.exe") # PythonForBuild is what's used on windows, despite the readme
if(VCPKG_CROSSCOMPILING)
vcpkg_add_to_path("${CURRENT_HOST_INSTALLED_DIR}/manual-tools/${PORT}")
endif()

vcpkg_install_msbuild(
vcpkg_msbuild_install(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH "PCbuild/pcbuild.proj"
ADD_BIN_TO_PATH
OPTIONS ${OPTIONS}
LICENSE_SUBPATH "LICENSE"
TARGET_PLATFORM_VERSION "${WINSDK_VERSION}"
SKIP_CLEAN
ADDITIONAL_LIBS_RELEASE ${add_libs_rel}
ADDITIONAL_LIBS_DEBUG ${add_libs_dbg}
)

if(NOT VCPKG_CROSSCOMPILING)
file(GLOB_RECURSE freeze_module "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/PCbuild/**/_freeze_module.exe")
file(COPY "${freeze_module}" DESTINATION "${CURRENT_PACKAGES_DIR}/manual-tools/${PORT}")
vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/manual-tools/${PORT}")
endif()

# The extension modules must be placed in the DLLs directory, so we can't use vcpkg_copy_tools()
if(PYTHON_ALLOW_EXTENSIONS)
file(GLOB_RECURSE PYTHON_EXTENSIONS_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/*.pyd")
Expand Down Expand Up @@ -203,8 +214,6 @@ if(VCPKG_TARGET_IS_WINDOWS)

vcpkg_fixup_pkgconfig()

vcpkg_clean_msbuild()

# Remove static library belonging to executable
if (VCPKG_LIBRARY_LINKAGE STREQUAL "static")
if (EXISTS "${CURRENT_PACKAGES_DIR}/lib/python.lib")
Expand Down Expand Up @@ -277,8 +286,6 @@ else()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug")

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "copyright")

vcpkg_fixup_pkgconfig()

# Perform some post-build checks on modules
Expand All @@ -302,6 +309,8 @@ else()
endif()
endif()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

file(READ "${CMAKE_CURRENT_LIST_DIR}/usage" usage)
if(VCPKG_TARGET_IS_WINDOWS)
if(PYTHON_ALLOW_EXTENSIONS)
Expand Down
21 changes: 16 additions & 5 deletions ports/python3/python_vcpkg.props.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
<AdditionalIncludeDirectories>
%(AdditionalIncludeDirectories);${CURRENT_INSTALLED_DIR}/include
</AdditionalIncludeDirectories>

<RuntimeLibrary Condition="'${VCPKG_CRT_LINKAGE}|$(Configuration)' == 'static|Debug'">MultiThreadedDebug</RuntimeLibrary>
<RuntimeLibrary Condition="'${VCPKG_CRT_LINKAGE}|$(Configuration)' == 'static|Release'">MultiThreaded</RuntimeLibrary>
<RuntimeLibrary Condition="'${VCPKG_CRT_LINKAGE}|$(Configuration)' == 'dynamic|Debug'">MultiThreadedDebugDLL</RuntimeLibrary>
<RuntimeLibrary Condition="'${VCPKG_CRT_LINKAGE}|$(Configuration)' == 'dynamic|Release'">MultiThreadedDLL</RuntimeLibrary>
</CLCompile>
<Link>
<!-- Required Libs -->
Expand All @@ -36,6 +31,22 @@
<!-- Required to prevent linker errors on Visual Studio 2017 with static CRT -->
<TargetMachine Condition="'${VCPKG_TARGET_ARCHITECTURE}'=='x86'">MachineX86</TargetMachine>
<TargetMachine Condition="'${VCPKG_TARGET_ARCHITECTURE}'=='x64'">MachineX64</TargetMachine>
<TargetMachine Condition="'${VCPKG_TARGET_ARCHITECTURE}'=='arm'">MachineARM</TargetMachine>
<!-- Required Libs -->
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">
${ZLIB_RELEASE};%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">
${ZLIB_DEBUG};%(AdditionalDependencies)
</AdditionalDependencies>

<!-- Extension modules -->
<AdditionalDependencies Condition="'$(Configuration)|$(IncludeExtensions)' == 'Release|true'">
${BZ2_RELEASE};${EXPAT_RELEASE};${FFI_RELEASE};${LZMA_RELEASE};${SQLITE_RELEASE};%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(IncludeExtensions)' == 'Debug|true'">
${BZ2_DEBUG};${EXPAT_DEBUG};${FFI_DEBUG};${LZMA_DEBUG};${SQLITE_DEBUG};%(AdditionalDependencies)
</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
</Project>
6 changes: 6 additions & 0 deletions ports/python3/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "python3",
"version": "3.11.4",
"port-version": 1,
"description": "The Python programming language",
"homepage": "https://github.com/python/cpython",
"license": "Python-2.0",
Expand Down Expand Up @@ -43,6 +44,11 @@
"name": "sqlite3",
"platform": "!(windows & static)"
},
{
"name": "vcpkg-msbuild",
"host": true,
"platform": "windows"
},
"zlib"
],
"features": {
Expand Down
2 changes: 1 addition & 1 deletion ports/vcpkg-msbuild/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vcpkg-msbuild",
"version-date": "2023-06-22",
"version-date": "2023-08-08",
"documentation": "https://vcpkg.io/en/docs/README.html",
"license": "MIT",
"supports": "native & windows",
Expand Down
Loading