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

WIP: Extensions #118

Open
wants to merge 14 commits into
base: dev/vcpkg
Choose a base branch
from
Open
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
50 changes: 40 additions & 10 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,50 @@ on:
pull_request:
types: [opened, synchronize, reopened]

env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

jobs:
build:
runs-on: windows-2022
steps:
- name: Build Plugin Python
id: build-plugin-python
uses: ModOrganizer2/build-with-mob-action@master
# https://learn.microsoft.com/en-us/vcpkg/consume/binary-caching-github-actions-cache
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
mo2-third-parties: gtest python spdlog boost sip pyqt pybind11
mo2-dependencies: cmake_common uibase
mo2-cmake-command: -DPLUGIN_PYTHON_TESTS=1 ..
- name: Build Plugin Python Tests
run: cmake --build vsbuild --config RelWithDebInfo -j4 --target python-tests --target runner-tests
working-directory: ${{ steps.build-plugin-python.outputs.working-directory }}
setup-python: false
version: 6.7.1
modules:
cache: true

- uses: actions/checkout@v4

- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV

- name: Configure Plugin Python build
shell: pwsh
run: |
cmake --preset vs2022-windows-standalone `
"-DCMAKE_PREFIX_PATH=${env:QT_ROOT_DIR}\msvc2019_64" `
-DPLUGIN_PYTHON_TESTING=ON

- name: Build Plugin Python
run: cmake --build vsbuild --config RelWithDebInfo --verbose `
--target python-tests --target runner-tests --target proxy

- name: Test Plugin Python
run: ctest --test-dir vsbuild -C RelWithDebInfo --output-on-failure
working-directory: ${{ steps.build-plugin-python.outputs.working-directory }}
40 changes: 14 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,32 @@ cmake_minimum_required(VERSION 3.16)

cmake_policy(SET CMP0144 NEW)

if(DEFINED DEPENDENCIES_DIR)
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
else()
include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake)
endif()

project(plugin_python CXX)

set(PYTHON_BUILD_PATH ${PYTHON_ROOT}/PCBuild/amd64)
set(Python_FIND_VIRTUALENV STANDARD)

# find Python - lots of "Hints" since we have a weird setup
set(Python_USE_STATIC_LIBS False)
set(Python_INCLUDE_DIR ${PYTHON_ROOT}/Include)
set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python.exe)
if (EXISTS "${PYTHON_BUILD_PATH}/python_d.exe")
set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python_d.exe)
endif()
file(GLOB Python_LIBRARY ${PYTHON_BUILD_PATH}/python[0-9][0-9]*.lib)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
# find Python before include mo2-cmake, otherwise this will trigger a bunch of CMP0111
# due to the imported configuration mapping variables defined in mo2.cmake
find_package(Python ${MO2_PYTHON_VERSION} COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 CONFIG REQUIRED)

# pybind11 needs uppercase (at least EXECUTABLE and LIBRARY)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIR})
set(PYTHON_LIBRARY ${Python_LIBRARY})
find_package(mo2-cmake CONFIG REQUIRED)

get_filename_component(Python_HOME ${Python_EXECUTABLE} PATH)
set(Python_DLL_DIR "${Python_HOME}/DLLs")
set(Python_LIB_DIR "${Python_HOME}/Lib")

mo2_python_install_pyqt()

# useful for naming DLL, zip, etc. (3.10 -> 310)
set(Python_VERSION_SHORT ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})

# pybind11
add_subdirectory(${MO2_BUILD_PATH}/pybind11 ${CMAKE_CURRENT_BINARY_DIR}/pybind11)

# projects
add_subdirectory(src)
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT proxy)

# tests (if requested)
set(PLUGIN_PYTHON_TESTS ${PLUGIN_PYTHON_TESTS} CACHE BOOL "build tests for plugin_python")
if (PLUGIN_PYTHON_TESTS)
set(PLUGIN_PYTHON_TESTING ${BUILD_TESTING} CACHE BOOL "build tests for plugin_python")
if (PLUGIN_PYTHON_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
73 changes: 73 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"configurePresets": [
{
"errors": {
"deprecated": true
},
"hidden": true,
"name": "cmake-dev",
"warnings": {
"deprecated": true,
"dev": true
}
},
{
"cacheVariables": {
"VCPKG_MANIFEST_NO_DEFAULT_FEATURES": {
"type": "BOOL",
"value": "ON"
}
},
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"hidden": true,
"name": "vcpkg"
},
{
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "testing"
}
},
"hidden": true,
"inherits": ["vcpkg"],
"name": "vcpkg-dev"
},
{
"binaryDir": "${sourceDir}/vsbuild",
"architecture": {
"strategy": "set",
"value": "x64"
},
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4",
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows-static-md"
}
},
"generator": "Visual Studio 17 2022",
"inherits": ["cmake-dev", "vcpkg-dev"],
"name": "vs2022-windows",
"toolset": "v143"
},
{
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "standalone;testing"
}
},
"inherits": "vs2022-windows",
"name": "vs2022-windows-standalone"
}
],
"buildPresets": [
{
"name": "vs2022-windows",
"resolvePackageReferences": "on",
"configurePreset": "vs2022-windows"
}
],
"version": 4
}
34 changes: 30 additions & 4 deletions src/mobase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
cmake_minimum_required(VERSION 3.16)

find_package(Qt6 COMPONENTS Core)
find_package(mo2-uibase CONFIG REQUIRED)

pybind11_add_module(mobase MODULE)
mo2_configure_library(mobase
SOURCE_TREE
mo2_default_source_group()
mo2_configure_target(mobase
NO_SOURCES
WARNINGS 4
EXTERNAL_WARNINGS 4
AUTOMOC ON
TRANSLATIONS OFF
PRIVATE_DEPENDS uibase Qt::Core
)
target_link_libraries(mobase PRIVATE pybind11::qt pybind11::utils)
mo2_target_sources(mobase
FOLDER src
PRIVATE
deprecation.cpp
deprecation.h
mobase.cpp
pybind11_all.h
)
mo2_target_sources(mobase
FOLDER src/wrappers
PRIVATE
./wrappers/basic_classes.cpp
./wrappers/game_features.cpp
./wrappers/known_folders.h
./wrappers/pyfiletree.cpp
./wrappers/pyfiletree.h
./wrappers/pyplugins.cpp
./wrappers/pyplugins.h
./wrappers/utils.cpp
./wrappers/widgets.cpp
./wrappers/wrappers.cpp
./wrappers/wrappers.h
)
target_link_libraries(mobase PRIVATE pybind11::qt pybind11::utils mo2::uibase Qt6::Core)
2 changes: 1 addition & 1 deletion src/mobase/deprecation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <QCoreApplication>

#include "log.h"
#include <uibase/log.h>

namespace py = pybind11;

Expand Down
30 changes: 12 additions & 18 deletions src/mobase/mobase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,16 @@
#include <tuple>
#include <variant>

#include <uibase/exceptions.h>
#include <uibase/versioning.h>

#include <pybind11/embed.h>

#include "pybind11_all.h"

#include "wrappers/pyfiletree.h"
#include "wrappers/wrappers.h"

// TODO: remove these include (only for testing)
#include <QDir>
#include <QFile>
#include <QWidget>
#include <iplugin.h>
#include <iplugindiagnose.h>
#include <ipluginfilemapper.h>
#include <iplugingame.h>
#include <iplugininstaller.h>
#include <iplugininstallersimple.h>
#include <ipluginlist.h>
#include <ipluginmodpage.h>
#include <ipluginpreview.h>
#include <iplugintool.h>
#include <isavegame.h>
#include <isavegameinfowidget.h>

using namespace MOBase;
namespace py = pybind11;

Expand All @@ -41,6 +27,13 @@ PYBIND11_MODULE(mobase, m)
m.add_object("PyQt6.QtGui", py::module_::import("PyQt6.QtGui"));
m.add_object("PyQt6.QtWidgets", py::module_::import("PyQt6.QtWidgets"));

// exceptions
//
py::register_exception<Exception>(m, "MO2Exception");
py::register_exception<InvalidNXMLinkException>(m, "InvalidNXMLinkException");
py::register_exception<IncompatibilityException>(m, "IncompatibilityException");
py::register_exception<InvalidVersionException>(m, "InvalidVersionException");

// bindings
//
mo2::python::add_basic_bindings(m);
Expand Down Expand Up @@ -86,7 +79,8 @@ PYBIND11_MODULE(mobase, m)
//
m.add_object(
"MoVariant",
py::eval("None | bool | int | str | list[object] | dict[str, object]"));
py::eval(
"None | bool | int | str | float | list[object] | dict[str, object]"));

// same thing for GameFeatureType
//
Expand Down
6 changes: 3 additions & 3 deletions src/mobase/pybind11_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include "pybind11_utils/shared_cpp_owner.h"
#include "pybind11_utils/smart_variant_wrapper.h"

#include <game_feature.h>
#include <isavegame.h>
#include <pluginrequirements.h>
#include <uibase/game_features/game_feature.h>
#include <uibase/isavegame.h>
#include <uibase/pluginrequirements.h>

namespace mo2::python {

Expand Down
Loading
Loading