Skip to content

Commit

Permalink
Merge pull request #59177 from m-kuhn/macvcpkg
Browse files Browse the repository at this point in the history
Mac Qt6 Builds
  • Loading branch information
3nids authored Oct 30, 2024
2 parents c314b4b + bc74595 commit b167311
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 9 deletions.
9 changes: 7 additions & 2 deletions .github/actions/setup-vcpkg/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ runs:
if: runner.os != 'Windows'
shell: bash
run: |
. <(curl https://aka.ms/vcpkg-init.sh -L)
export VCPKG_ROOT=$HOME/.vcpkg
wget https://aka.ms/vcpkg-init.sh -O /tmp/vcpkg-init.sh
. /tmp/vcpkg-init.sh
echo "VCPKG_ROOT=$VCPKG_ROOT" >> $GITHUB_ENV
echo "PATH=$VCPKG_ROOT;$PATH" >> $GITHUB_ENV
# Integrate patch from https://github.com/microsoft/vcpkg/pull/41146
wget https://raw.githubusercontent.com/microsoft/vcpkg/6271c9bfab7ff6dbf3444c3600a28e7c6b0ea462/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake -O /Users/runner/.vcpkg/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake
- name: Setup vcpkg
if: runner.os == 'Windows'
Expand All @@ -25,4 +30,4 @@ runs:
$env:VCPKG_ROOT = "C:/.vcpkg"
iex (iwr -useb https://aka.ms/vcpkg-init.ps1)
echo "VCPKG_ROOT=$env:VCPKG_ROOT" >> $env:GITHUB_ENV
echo "PATH=$env:VCPKG_ROOT;$env:PATH" >> $env:GITHUB_ENV
echo "PATH=$env:VCPKG_ROOT;$env:PATH" >> $env:GITHUB_ENV
108 changes: 108 additions & 0 deletions .github/workflows/build-macos-qt6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
name: 🍎 Build - MacOS Qt6
on:
# push:
# branches:
# - main
# pull_request:
# release:
# types: ['published']
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
matrix:
include:
# - os: macos-13
# triplet: x64-osx
# deployment-target: "10.15"
- os: macos-14
triplet: arm64-osx-dynamic-release
deployment-target: "11.0"
name: build (macos)
runs-on: ${{ matrix.os }}

steps:
- name: 🐣 Checkout
uses: actions/checkout@v4

- name: 🐩 Install CMake and Ninja
uses: lukka/get-cmake@latest
with:
# Pin to specific version to avoid rebuilding too often
# Also helps to avoid spurious build failures like https://github.com/qgis/QGIS/pull/47098
cmakeVersion: 3.30.4

- name: 🎡 Setup vcpkg
id: setup-vcpkg
uses: ./.github/actions/setup-vcpkg

- name: 🔨 Prepare build env
run: |
brew install automake bison flex gnu-sed create-dmg autoconf-archive nasm libtool fdupes
echo $(brew --prefix bison)/bin >> $GITHUB_PATH
echo $(brew --prefix flex)/bin >> $GITHUB_PATH
echo $(brew --prefix libtool)/bin >> $GITHUB_PATH
- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: 🍭 Setup XCode
uses: maxim-lobanov/[email protected]
with:
xcode-version: latest-stable

- name: 🌱 Install dependencies and generate project files
run: |
echo "VCPKG_ROOT: ${VCPKG_ROOT}"
# Install first only with binarycaching, then deduplicate binaries and replace copies with symlinks.
# Nuget doesn't understand the symlink concept
cmake -S . \
-G Ninja \
-B build \
-D WITH_VCPKG=ON \
-D BUILD_WITH_QT6=ON \
-D WITH_QTWEBKIT=OFF \
-D WITH_BINDINGS=ON \
-D QGIS_MACAPP_FRAMEWORK=OFF \
-D VCPKG_TARGET_TRIPLET="${{ matrix.triplet }}" \
-D VCPKG_HOST_TRIPLET="${{ matrix.triplet }}" \
-D VCPKG_INSTALL_OPTIONS="--only-binarycaching" \
-D NUGET_USERNAME=${{ github.actor }} \
-D NUGET_TOKEN=${{ secrets.GITHUB_TOKEN }} || true
fdupes -r -1 build/vcpkg_installed/arm64-osx-dynamic/lib | grep libQt | while read line; do master=""; for file in ${line[*]}; do if [[ "x${master}" == "x" ]]; then master=$file; else rm "${file}"; ln -s $(basename "${master}") "${file}"; fi; done; done
cmake -D VCPKG_INSTALL_OPTIONS="" build
- name: 📑 Upload vcpkg build logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: build-logs-${{ matrix.triplet }}
path: |
${{ env.VCPKG_ROOT }}/buildtrees/**/*.log
- name: 📦 Create SDK
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
run: |
./build/_deps/vcpkg-src/vcpkg export --zip --output-dir=./sdk --x-install-root=./build/vcpkg_installed --x-manifest-root=vcpkg
- name: 📤 Upload sdk
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
uses: actions/upload-artifact@v4
with:
name: kadas-albireo2-sdk-${{ matrix.triplet }}
path: |
sdk/vcpkg-export-*.zip
- name: 🌋 Build
run: |
cmake --build build
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(NOT SDK_PATH STREQUAL "")
set(CMAKE_TOOLCHAIN_FILE "${SDK_PATH}/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_INSTALL_PREFIX "${SDK_PATH}/installed")
if(APPLE AND NOT VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "x64-osx-dynamic")
message(FATAL_ERROR "VCPKG_TARGET_TRIPLET not set (set it to arm64-osx-dynamic-release or x64-osx-dynamic-release")
endif()
set(WITH_VCPKG ON)
elseif(WITH_VCPKG)
Expand All @@ -45,7 +45,11 @@ else()
endif()

if(WITH_VCPKG)
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/tools/python3/Scripts/")
if(WIN32)
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/tools/python3/Scripts/")
else()
list(APPEND CMAKE_PROGRAM_PATH "${VCPKG_INSTALL_PREFIX}/${VCPKG_TARGET_TRIPLET}/bin")
endif()
set(PREFER_INTERNAL_LIBS FALSE)
else()
set(PREFER_INTERNAL_LIBS TRUE)
Expand Down
17 changes: 13 additions & 4 deletions cmake/VcpkgToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ if(WITH_GUI)
list(APPEND VCPKG_MANIFEST_FEATURES "gui")
endif()

# Setup binary cache
if(NOT "${NUGET_TOKEN}" STREQUAL "" AND WIN32)
set(_VCPKG_EXECUTABLE "vcpkg.exe")
# Binarycache can only be used on Windows or if mono is available.
find_program(_VCPKG_MONO mono)
if(NOT "${NUGET_TOKEN}" STREQUAL "" AND (_HOST_IS_WINDOWS OR EXISTS "${_VCPKG_MONO}"))
if(_HOST_IS_WINDOWS)
set(_VCPKG_EXECUTABLE "$ENV{VCPKG_ROOT}/vcpkg.exe")
else()
set(_VCPKG_EXECUTABLE "$ENV{VCPKG_ROOT}/vcpkg")
endif()

execute_process(
COMMAND ${_VCPKG_EXECUTABLE} fetch nuget
Expand All @@ -24,7 +29,11 @@ if(NOT "${NUGET_TOKEN}" STREQUAL "" AND WIN32)
STRING(REGEX REPLACE "\n" ";" _FETCH_NUGET_OUTPUT "${_FETCH_NUGET_OUTPUT}")
list(GET _FETCH_NUGET_OUTPUT -1 _NUGET_PATH)

set(_NUGET_EXE ${_NUGET_PATH})
if(_HOST_IS_WINDOWS)
set(_NUGET_EXE ${_NUGET_PATH})
else()
set(_NUGET_EXE ${_VCPKG_MONO} ${_NUGET_PATH})
endif()

set(_CONFIG_PATH "${CMAKE_BINARY_DIR}/github-NuGet.Config")

Expand Down
8 changes: 7 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ if (ANDROID)
# require c++17
target_compile_features(${QGIS_APP_NAME} PRIVATE cxx_std_17)
else()
add_executable(${QGIS_APP_NAME} MACOSX_BUNDLE WIN32 ${QGIS_APPMAIN_SRCS})
if(APPLE)
set (CREATE_MACOSX_BUNDLE TRUE CACHE BOOL "Create macosx bundle during build. Disable for development to avoid copying libraries and ease debugging.")
if(CREATE_MACOSX_BUNDLE)
set(MACOSX_BUNDLE "MACOSX_BUNDLE")
endif()
endif()
add_executable(${QGIS_APP_NAME} ${MACOSX_BUNDLE} WIN32 ${QGIS_APPMAIN_SRCS})

if(MSVC AND BUILD_WITH_QT6)
qt_disable_unicode_defines(${QGIS_APP_NAME})
Expand Down
61 changes: 61 additions & 0 deletions vcpkg/ports/py-setuptools/fix-prefix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/setuptools/_distutils/command/build_ext.py b/setuptools/_distutils/command/build_ext.py
index 06d949a..0dee0fe 100644
--- a/setuptools/_distutils/command/build_ext.py
+++ b/setuptools/_distutils/command/build_ext.py
@@ -209,6 +209,14 @@ class build_ext(Command):
elif isinstance(self.rpath, str):
self.rpath = self.rpath.split(os.pathsep)

+ prefix = os.path.normpath(sys.prefix)
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix)) # Add debug compile?
+
+ if self.debug:
+ self.library_dirs.append(os.path.join(vcpkg_prefix, 'debug', 'lib'))
+ else:
+ self.library_dirs.append(os.path.join(vcpkg_prefix, 'lib'))
+
# for extensions under windows use different directories
# for Release and Debug builds.
# also Python's library directory must be appended to library_dirs
@@ -216,9 +224,9 @@ class build_ext(Command):
# the 'libs' directory is for binary installs - we assume that
# must be the *native* platform. But we don't really support
# cross-compiling via a binary install anyway, so we let it go.
- self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
- if sys.base_exec_prefix != sys.prefix: # Issue 16116
- self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
+ # self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
+ # if sys.base_exec_prefix != sys.prefix: # Issue 16116
+ # self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
if self.debug:
self.build_temp = os.path.join(self.build_temp, "Debug")
else:
diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py
index 1a38e9f..2c8174d 100644
--- a/setuptools/_distutils/sysconfig.py
+++ b/setuptools/_distutils/sysconfig.py
@@ -191,18 +191,21 @@ def _get_python_inc_from_config(plat_specific, spec_prefix):
def _get_python_inc_posix_prefix(prefix):
implementation = 'pypy' if IS_PYPY else 'python'
python_dir = implementation + get_python_version() + build_flags
- return os.path.join(prefix, "include", python_dir)
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix))
+ return os.path.join(vcpkg_prefix, "include", python_dir)


def _get_python_inc_nt(prefix, spec_prefix, plat_specific):
+ vcpkg_prefix = os.path.dirname(os.path.dirname(prefix))
+ python_dir = 'python' + get_python_version()
if python_build:
# Include both include dirs to ensure we can find pyconfig.h
return (
- os.path.join(prefix, "include")
+ os.path.join(vcpkg_prefix, "include", python_dir)
+ os.path.pathsep
+ os.path.dirname(sysconfig.get_config_h_filename())
)
- return os.path.join(prefix, "include")
+ return os.path.join(vcpkg_prefix, "include", python_dir)


# allow this behavior to be monkey-patched. Ref pypa/distutils#2.
18 changes: 18 additions & 0 deletions vcpkg/ports/py-setuptools/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
vcpkg_from_pythonhosted(
OUT_SOURCE_PATH SOURCE_PATH
PACKAGE_NAME setuptools
VERSION ${VERSION}
SHA512 d0a34f16dfa6bb9a6df39076cd43528cf854d343f6f801c448ea0ebab2a259aec3d03571e2a26709df6082ed2fcb6c43b86448be556fd559b6af41831b4f38e0
PATCHES
fix-prefix.patch
)

vcpkg_python_build_and_install_wheel(SOURCE_PATH "${SOURCE_PATH}")

set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled)

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
#execute_process(COMMAND ${PYTHON3} "${SOURCE_PATH}/setup.py" install "--prefix=${CURRENT_INSTALLED_DIR}/tools/python3" "--root=${CURRENT_PACKAGES_DIR}"
# COMMAND_ERROR_IS_FATAL ANY
# WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/python3"
#)
16 changes: 16 additions & 0 deletions vcpkg/ports/py-setuptools/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "py-setuptools",
"version": "72.1.0",
"description": "Official project repository for the Setuptools build system ",
"homepage": "https://pypi.org/project/setuptools/",
"license": "MIT",
"dependencies": [
"py-packaging",
"py-wheel",
"python3",
{
"name": "vcpkg-python-scripts",
"host": true
}
]
}
9 changes: 9 additions & 0 deletions vcpkg/triplets/arm64-osx-dynamic-release.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
set(VCPKG_OSX_ARCHITECTURES arm64)
set(VCPKG_BUILD_TYPE release)

set(VCPKG_FIXUP_MACHO_RPATH ON)
11 changes: 11 additions & 0 deletions vcpkg/triplets/x64-osx-dynamic-release.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
set(VCPKG_OSX_ARCHITECTURES x86_64)
set(VCPKG_BUILD_TYPE release)

set(VCPKG_FIXUP_MACHO_RPATH ON)
set(VCPKG_OSX_DEPLOYMENT_TARGET 10.15)

0 comments on commit b167311

Please sign in to comment.