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

Cura 8640 PyQt6 upgrade #134

Merged
merged 66 commits into from
Apr 14, 2022
Merged

Cura 8640 PyQt6 upgrade #134

merged 66 commits into from
Apr 14, 2022

Conversation

jellespijker
Copy link
Member

@jellespijker jellespijker commented Apr 12, 2022

Because we are switching to Qt6 we also needed to update SIP to 5.0+
SIP5+ builds en generate the code using a new process and executable. We had a lot of trouble linking the sip generated binaries on all three systems using the QGIS CMake Macro's so we decided to let sip only generate the C++ source code from the sip files and leave compiling and linking in the CMake domain. This is achieved by using our own CMakebuilder.py which is then used by sip-build instead of its shipped builder. This Cmakebuilder is basically the same in every respect except the call to the build function has been removed.

Make sure that sip-build is installed and that it is added to the PYTHONPATH

In order to get this to work on our build-system and working for all three OSes we did a shit tons of boy scouting in our cmake. We removed old methods with variables and try to be consisted in a target-based approach. The idea is that we don't patch stuff down the line, but that the install should place everything with desired rpaths for each project.

There were also some changes needed in the namespace when using enums and the created Python module is called pySavitar. This was needed to ensure no naming conflicts downstream.

Part of

Fixes

Todo

  • Update Readme. But maybe best done in a separate ticket to prioritize with our other work for the 5.0 release
  • Fix failing CI/CT due to out date build environment. I think it will be best if we fix this in a separate ticket.

j.spijker@ultimaker.com and others added 30 commits February 23, 2022 18:07
A simple pyproject.toml which links to the sip, cpp and h files to be
used and a Custom build-factory which stops sip from building and
linking. These steps are to be done by CMake at a later stage.

Contributes to CURA-7924
This is taken directly from QGIS
https://github.com/qgis/QGIS/tree/master/cmake

Contributes to CURA-7924
To have better control over compiling and linking of the sip generated
source code. We decided to make CMake responsible for those processes.

The `add_sip_module`  will first generate the source-files using sip and
the previous commit build-factory. Which disables the compiling and
linking by sip. It will then collect and identify those generated files
and make a shared library of these. Compiler flags, user source files,
dependency libraries etc. can be specified in the main CMakeLists.txt

using an INTERFACE library.

The most basic usage is:
```cmake
find_package(SIP REQUIRED 6.5.0)

add_library(module_name INTERFACE <optional_cpp_source_files>)
target_link_libraries(module_name INTERFACE target_lib_for_the_bindings <optional_other_depending_targets>)
add_sip_module(module_name)
```

compile features and extra include directories can be specified in the
normal way, if needed.

```cmake
target_include_directories(module_name INTERFACE <optional_location_for_cpp_headers_and_sources>)
target_compile_features(module_name INTERFACE cxx_std_17)
```

The minimum pyproject.toml.in would consist of:
```toml
[build-system]
requires = ["sip >=6, <7"]
build-backend = "sipbuild.api"

[tool.sip.metadata]
name = "module_name"

[tool.sip.project]
builder-factory = "CMakeBuilder"
sip-files-dir = "location_of_the_sip_files"
build-dir = "${CMAKE_CURRENT_BINARY_DIR}/module_name/"

[tool.sip.bindings.module_name]
exceptions = true
release-gil = true
concatenate = 8
```

Make sure that the main sip definition file is named the same as the
module_name and that it contains the following line

```
%Module(name = module_name, call_super_init = True)
```
Contributes to CURA-7924
These are not needed for 'just' code generation

Contributes to CURA-7924
These changes are not fully tested locally. This is due to the way I
have personally setup my development environment.

This should generate a python module named `pyArcus.so` linking to in
Arcus.so both located in the build directory.

TODO: Add installing step.
TODO: propagate the name change to downstream dependencies

Contributes to CURA-7924
Contributes to CURA_7924
It can't find the CMakeBuilder.py on the build server otherwise

Contributes to CURA_7924
This should add the current build_dir to the PYTHONPATH

Contributes to CURA-7924
Arcus (non-py version) still seems to be static though, so it doesn't work yet completely.

part of CURA-7924
Not tested on MacOS.

part of CURA-7924
This file isn't project specific but an integral part of how the
CMake SIP build module works.

Contributes to CURA-7924
This will install the Python module and PEP 484 file in site-packages

Contributes to CURA-7924
Which is basically a call to sysconfig made by the find_package Python
and outputs the following extension

```python
sysconfig.get_config_var('EXT_SUFFIX')
'.cpython-310-x86_64-linux-gnu.so'
```

Contributes to CURA-7924
Not necessary for Arcus, but Savitar doesn't use user specified cpp
files and I think it's good practice to keep these modules in-sync.

Contributes to CURA-7924
Contributes to CURA-7924
Also, in earlier sip 4.x it was 'transparent' but now if you add that 'fix' of wrapping it in a namespace, you also have to refer to the namespace in Python, making awkward constructs like pyArcus.SocketState.SocketState.Closed or whatever.

done as part of CURA-7924
This module sets the rpaths relative from the executable
- rpath for Arcus -> ../lib
- rpath for pyArcus -> ../lib/python3.10/site-packages

It also transfers some other cmake logic out of the main CMakeLists.txt

Contributes to CURA-8640
Sets the RPATHS for targets (Linux and Windows,
these can either be absolute paths or relative to
the executable

Usage:
```
set_rpath(TARGETS <list of targets to set rpaths for>
           PATHS <list of paths>
           <optional> RELATIVE)
```
if the RELATIVE option is used the paths will be
specified from either $ORIGIN on Linux or
@executable_path on Mac

Contributes to CURA-8640
Contributes to CURA-8640
@jellespijker
Copy link
Member Author

This PR will close a lot of SIP and Arcus related questions. I understand the reasoning why questions could be kept open, but we also might have to reconsider how relevant the answer and information is in these questions

CMakeLists.txt Outdated Show resolved Hide resolved
cmake/StandardProjectSettings.cmake Outdated Show resolved Hide resolved
cmake/StandardProjectSettings.cmake Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
cmake/FindSIP.cmake Show resolved Hide resolved
cmake/FindSIP.py Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@jellespijker
Copy link
Member Author

Will change most of the suggestion.
Except the FindSIP.cmake and FindSIP.py since these are just copy pasted from QGis
Any changes here will also be ported to libSavitar and pynest2d

They are old and don't compile anymore, they are hardly used.
If people require an usage example they can look how Cura,
Uranium and CuraEngine use Arcus

Contributes to CURA-8640
Contributes to CURA-8640
We no longer use Jenkins

Contributes to CURA-8640
Contributes to CURA-8640
Contributes to CURA-8640
BUILD_STATIC was our own custom option while the BUILD_SHARED_LIBS
is a CMake global flag https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

Contributes to CURA-8640
We don't have any unit tests in this repo so no need for this
have this pipeline.

Contributes to CURA-8640
@jellespijker
Copy link
Member Author

I have removed the CI/CT completely.
We don't have unit tests and we don't need a build artifact atm So no need for a CI/CT pipeline

j.spijker@ultimaker.com added 3 commits April 14, 2022 11:44
Contributes to CURA-8640
@Ghostkeeper Ghostkeeper merged commit e4432f8 into 5.0 Apr 14, 2022
@jellespijker jellespijker deleted the CURA-8640_PyQt6_upgrade branch April 14, 2022 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment