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

[FEATURE] Nix CMake build process #3076

Closed
6 tasks done
pbek opened this issue Aug 6, 2024 · 37 comments
Closed
6 tasks done

[FEATURE] Nix CMake build process #3076

pbek opened this issue Aug 6, 2024 · 37 comments
Assignees
Labels
Milestone

Comments

@pbek
Copy link
Owner

pbek commented Aug 6, 2024

As requested by @NickCao in NixOS/nixpkgs#332556 (comment), it would be great to build QOwnNotes with CMake for nixpkgs.

Todo

  • Make build process work with nix
  • Get translations working
  • Scripting engine works
  • Add CI process with CMake for Qt5
  • Add CI process with CMake for Qt6
  • Update config for nixpkgs
@pbek pbek added Type: Feature adds functionality Importance: Low labels Aug 6, 2024
@pbek pbek self-assigned this Aug 6, 2024
pbek added a commit that referenced this issue Aug 6, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

@Waqar144, I was trying to build QOwnNotes with Qt6 and CMake in https://github.com/pbek/QOwnNotes/blob/feature/nix-cmake/default.nix via

QOwnNotes/Makefile

Lines 16 to 17 in 08c1657

nix-build:
nix-build -E '((import <nixpkgs> {}).qt6Packages.callPackage (import ./default.nix) { })'

I got the error message:

CMake Error at libraries/botan/CMakeLists.txt:14 (find_package):
  By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5" with any of
  the following names:

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files.  If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.

Does this ring any bell for you?

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

Note that I tried to use:

QOwnNotes/default.nix

Lines 47 to 50 in d307a41

cmakeFlags = [
"-DUSE_SYSTEM_BOTAN=1"
"-DBUILD_WITH_SYSTEM_BOTAN=1"
];

Have you ever built QOwnNotes with Qt6 and CMake? I only built it in Qt5 with CMake, as far as I remember...

pbek added a commit that referenced this issue Aug 6, 2024
@pbek pbek changed the title [FEATURE] Nix cmake build process [FEATURE] Nix CMake build process Aug 6, 2024
@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

QON_QT6_BUILD=ON got me one step further! 👍️

I'm now at:

CMake Error at libraries/botan/CMakeLists.txt:21 (find_package):
  By not providing "FindBotan2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Botan2", but
  CMake did not find one.

  Could not find a package configuration file provided by "Botan2" with any
  of the following names:

    Botan2Config.cmake
    botan2-config.cmake

  Add the installation prefix of "Botan2" to CMAKE_PREFIX_PATH or set
  "Botan2_DIR" to a directory containing one of the above files.  If "Botan2"
  provides a separate development package or SDK, be sure it has been
  installed.

@NickCao, do you maybe have an idea to get around that in nix?

pbek added a commit that referenced this issue Aug 6, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

Either we build botan2 with cmake, or locate botan2 with pkg-config instead.

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

Either we build botan2 with cmake, or locate botan2 with pkg-config instead.

@NickCao, thank you! The latter would be nice, I guess.
I haven't used pkg-config before. I only found derivations including it, but I actually don't know how to use it.
How do we locate botan2 with pkg-config?

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

Ah the cmake folder is missing from CMAKE_MODULE_PATH thus it wasn't used.

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

Which nix conjuration do we need to use? 😊

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

Which nix conjuration do we need to use? 😊

Surprise!

diff --git a/default.nix b/default.nix
index 604f1b831..10c8b8e31 100644
--- a/default.nix
+++ b/default.nix
@@ -25,7 +25,7 @@ in
 stdenv.mkDerivation {
   inherit pname appname version;

-  src = builtins.path { path = ./src; name = "qownnotes"; };
+  src = builtins.path { path = ./.; name = "qownnotes"; };

   nativeBuildInputs = [
     cmake

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

The line appending to CMAKE_MODULE_PATH is at

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

That was quick. 😂🤣 Thank you very much! I'll build and test for a while!

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

Meh, in the source archive on https://github.com/pbek/QOwnNotes/releases/download I only use the src folder. 😬 We will need some more trickery in https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/office/qownnotes/default.nix, wouldn't we?

@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

I'll build and test for a while!

And I'm getting an error after building:

Install the project...
-- Install configuration: "Release"
-- Installing: /nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm
CMake Error at src/cmake_install.cmake:54 (file):
  file INSTALL cannot copy file "/build/qownnotes/build/src/QOwnNotes_en.qm"
  to
  "/nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm":
  Permission denied.
Call Stack (most recent call first):
  cmake_install.cmake:47 (include)


make: *** [Makefile:100: install] Error 1
error: builder for '/nix/store/qs41bc4n38j6zap0ild1g1priwscgg5i-qownnotes-local-build.drv' failed with exit code 2;
       last 10 log lines:
       > CMake Error at src/cmake_install.cmake:54 (file):
       >   file INSTALL cannot copy file "/build/qownnotes/build/src/QOwnNotes_en.qm"
       >   to
       >   "/nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm":
       >   Permission denied.
       > Call Stack (most recent call first):
       >   cmake_install.cmake:47 (include)
       >
       > 
       > make: *** [Makefile:100: install] Error 1
       For full logs, run 'nix log /nix/store/qs41bc4n38j6zap0ild1g1priwscgg5i-qownnotes-local-build.drv'.
make: *** [Makefile:17: nix-build] Fehler 1

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

Meh, in the source archive on https://github.com/pbek/QOwnNotes/releases/download I only use the src folder. 😬 We will need some more trickery in https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/office/qownnotes/default.nix, wouldn't we?

We can move the entire cmake folder under src (it's a single file anyway), and also move the line appending CMAKE_MODULE_PATH from the top-level CMakeLists.txt to the one inside src.

pbek added a commit that referenced this issue Aug 6, 2024
@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

I'll build and test for a while!

And I'm getting an error after building:

Install the project...
-- Install configuration: "Release"
-- Installing: /nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm
CMake Error at src/cmake_install.cmake:54 (file):
  file INSTALL cannot copy file "/build/qownnotes/build/src/QOwnNotes_en.qm"
  to
  "/nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm":
  Permission denied.
Call Stack (most recent call first):
  cmake_install.cmake:47 (include)


make: *** [Makefile:100: install] Error 1
error: builder for '/nix/store/qs41bc4n38j6zap0ild1g1priwscgg5i-qownnotes-local-build.drv' failed with exit code 2;
       last 10 log lines:
       > CMake Error at src/cmake_install.cmake:54 (file):
       >   file INSTALL cannot copy file "/build/qownnotes/build/src/QOwnNotes_en.qm"
       >   to
       >   "/nix/store/gg3y5q6j549x74ld4l3frkmgc2r9avqh-qttranslations-6.7.2/translations/QOwnNotes_en.qm":
       >   Permission denied.
       > Call Stack (most recent call first):
       >   cmake_install.cmake:47 (include)
       >
       > 
       > make: *** [Makefile:100: install] Error 1
       For full logs, run 'nix log /nix/store/qs41bc4n38j6zap0ild1g1priwscgg5i-qownnotes-local-build.drv'.
make: *** [Makefile:17: nix-build] Fehler 1

Guess we have to set QT_TRANSLATIONS_DIR in cmakeFlags

pbek added a commit that referenced this issue Aug 6, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@pbek
Copy link
Owner Author

pbek commented Aug 6, 2024

Now I got to:

CMake Error at src/libraries/md4c/src/cmake_install.cmake:115 (file):
  file INSTALL cannot find "/build/qownnotes/build/src/md4c.pc": No such file
  or directory.
Call Stack (most recent call first):
  src/libraries/md4c/cmake_install.cmake:47 (include)
  src/cmake_install.cmake:118 (include)
  cmake_install.cmake:47 (include)

🤔

@NickCao
Copy link
Contributor

NickCao commented Aug 6, 2024

I believe this can be an upstream bug: https://github.com/qownnotes/md4c/blob/c64ee9ab326c53962b5bd8cca98c086461bbdd6b/src/CMakeLists.txt#L40, try changing CMAKE_BINARY_DIR to CMAKE_CURRENT_BINARY_DIR?

@Waqar144
Copy link
Contributor

Waqar144 commented Aug 6, 2024

I have a cmake patch that fixes the install, will push it soon

@Waqar144
Copy link
Contributor

Waqar144 commented Aug 6, 2024

Fixes the install == makes it work the same as qmake

So that it can be a drop in replacement

pbek added a commit that referenced this issue Aug 7, 2024
@pbek
Copy link
Owner Author

pbek commented Aug 7, 2024

Thank you, @Waqar144

@Waqar144
Copy link
Contributor

Waqar144 commented Aug 7, 2024

We can't use system md4c, we just need to force static linking or just compile md4c into QOwnNotes like qmake does.

@pbek
Copy link
Owner Author

pbek commented Aug 7, 2024

Plus, we are using https://github.com/qownnotes/md4c. 😉

pbek added a commit that referenced this issue Aug 7, 2024
pbek added a commit that referenced this issue Aug 7, 2024
@pbek
Copy link
Owner Author

pbek commented Aug 8, 2024

@NickCao, I tried to build for qt5 as a nix derivation and got the same error. Building and running the app with CMake in CLion (under NixOS) works tho (running with wrapQtAppsHook).

pbek added a commit that referenced this issue Aug 8, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@NickCao
Copy link
Contributor

NickCao commented Aug 8, 2024

@NickCao, I tried to build for qt5 as a nix derivation and got the same error. Building and running the app with CMake in CLion (under NixOS) works tho (running with wrapQtAppsHook).

I checked the build output, and md4c is indeed not installed.

Possible fix:

For md4c (don't know how to fix installation of these .pc files so dropped them altogether):

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 767c259..4800e97 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -37,7 +37,6 @@ install(
     PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
     INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 )
-install(FILES ${CMAKE_BINARY_DIR}/src/md4c.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

 install(
     TARGETS md4c-html
@@ -47,7 +46,5 @@ install(
     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
     PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 )
-install(FILES ${CMAKE_BINARY_DIR}/src/md4c-html.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

 install(EXPORT md4cConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/md4c/ NAMESPACE md4c::)

For qownnotes

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -29,8 +29,7 @@ include(libraries/sonnet/src/plugins/hunspell/hunspell/CMakeLists.txt)

 # noneed for md2html
 set(BUILD_MD2HTML_EXECUTABLE FALSE)
-set(BUILD_SHARED_LIBS OFF)
-add_subdirectory(libraries/md4c EXCLUDE_FROM_ALL)
+add_subdirectory(libraries/md4c)

 add_executable(QOwnNotes "")

@pbek
Copy link
Owner Author

pbek commented Aug 8, 2024

With #3080 of @Waqar144 the whole build process now went through! 🥳🎉
The translations and the script engine also works!

@pbek
Copy link
Owner Author

pbek commented Aug 8, 2024

https://github.com/pbek/QOwnNotes/blob/475afebce832a8d48d3f12a3668611912c204ff2/default.nix was used for building. I hope this will also work with a release archive and on Darwin.

@Waqar144
Copy link
Contributor

Waqar144 commented Aug 8, 2024

I think we should try to move all Qt6 builds to cmake, it has much better support (and documentation) everywhere. Once Qt6 is in place, one can think about moving the OBS builders and others slowly.

@pbek
Copy link
Owner Author

pbek commented Aug 8, 2024

There are so many build services QOwnNotes deploys to. 🙈 😁

pbek added a commit that referenced this issue Aug 8, 2024
pbek added a commit that referenced this issue Aug 8, 2024
pbek added a commit that referenced this issue Aug 8, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Aug 8, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Aug 8, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Aug 8, 2024
@sfatula
Copy link

sfatula commented Aug 13, 2024

https://github.com/pbek/QOwnNotes/blob/475afebce832a8d48d3f12a3668611912c204ff2/default.nix was used for building. I hope this will also work with a release archive and on Darwin.

Well, hopefully you don't mind me interjecting, and if you do, I will bow out. Actually note that xvfb-run does not exist in nix for darwin, either chip type, unless I am missing something as my nix build got an error for that. Looks like linux only. I'm trying on x86_64 (which is unnecessary since I could just download it), though I will have a M1 Mac shortly (delayed by USPS). I suppose I could try and build from source on the M1 but saw this case so tried it.

@pbek
Copy link
Owner Author

pbek commented Aug 13, 2024

Thank you for pointing that out! 👍🏻 I guess that discussion needs to be taken directly to nixpkgs or in a separate issue. It has nothing to do with CMake.

Is there any alternative? Something to put in a PR for:

https://github.com/NixOS/nixpkgs/blob/8de2d5efd579346ed6836ec34d738f9377e9a46c/pkgs/applications/office/qownnotes/default.nix#L55-L60

I'll do a PR for the CMake transition with the next release of QOwnNotes.

pbek added a commit that referenced this issue Aug 13, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
@pbek
Copy link
Owner Author

pbek commented Aug 13, 2024

@NickCao, I created NixOS/nixpkgs#334463.

@pbek pbek added this to the 24.8.5 milestone Aug 13, 2024
@pbek
Copy link
Owner Author

pbek commented Aug 13, 2024

24.8.5

  • The CMake build process was adapted to be production ready and to be used in Nix

@pbek pbek closed this as completed Aug 13, 2024
pbek added a commit that referenced this issue Aug 14, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
pbek added a commit that referenced this issue Aug 26, 2024
cmake: use IMPORTED_TARGET to create imported target for botan2
pbek added a commit that referenced this issue Aug 26, 2024
Signed-off-by: Patrizio Bekerle <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants