From a993b2743dc1a5e6f1d8e1df842a9b3d888358e2 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Fri, 11 Oct 2024 18:07:44 +0200 Subject: [PATCH 01/10] [Nix] initial packaging & flake --- flake.lock | 58 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 23 +++++++++++++++++ package.nix | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..70252702896 --- /dev/null +++ b/flake.lock @@ -0,0 +1,58 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..c931bb95b08 --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Real-time multi-physics simulation with an emphasis on medical simulation."; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = + inputs@{ flake-parts, nixpkgs, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + perSystem = + { pkgs, self', ... }: + { + devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; }; + packages = { + default = self'.packages.sofa; + sofa = pkgs.callPackage ./package.nix { }; + }; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 00000000000..fe7f464fd31 --- /dev/null +++ b/package.nix @@ -0,0 +1,74 @@ +{ + boost, + cmake, + cxxopts, + eigen, + #fetchFromGitHub, + glew, + gtest, + lib, + libsForQt5, + libGL, + metis, + stdenv, + tinyxml-2, + zlib, +}: + +stdenv.mkDerivation { + pname = "sofa"; + version = "24.06.00"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./applications + ./Authors.txt + ./cmake + ./CHANGELOG.md + ./CMakeLists.txt + ./CMakePresets.json + ./examples + ./extlibs + ./LICENSE-LGPL.md + ./package.cmake + ./README.md + ./scripts + ./share + ./Sofa + ./tools + ]; + }; + + propagatedNativeBuildInputs = [ + cmake + libsForQt5.wrapQtAppsHook + ]; + propagatedBuildInputs = [ + boost + cxxopts + eigen + glew + gtest + libsForQt5.libqglviewer + libGL + metis + tinyxml-2 + zlib + ]; + + cmakeFlags = [ + (lib.cmakeBool "SOFA_ALLOW_FETCH_DEPENDENCIES" false) + ]; + + doCheck = true; + + meta = { + description = "Real-time multi-physics simulation with an emphasis on medical simulation"; + homepage = "https://github.com/sofa-framework/sofa"; + license = lib.licenses.lgpl21Only; + maintainers = with lib.maintainers; [ nim65s ]; + mainProgram = "runSofa"; + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; +} From 86913f6f64983fdc2c4d509d0d8ed0e89b87e3fb Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sat, 12 Oct 2024 15:51:47 +0200 Subject: [PATCH 02/10] [Nix] setup CI --- .github/workflows/nix.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000000..7e82c8996b8 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,21 @@ +name: "CI - Nix" + +on: + push: + +jobs: + nix: + runs-on: "${{ matrix.os }}-latest" + strategy: + matrix: + #os: [ubuntu, macos] + os: [ubuntu] + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + # TODO: the "sofa" account on cachix does not exist yet + #- uses: cachix/cachix-action@v15 + #with: + #name: sofa + #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build -L From e51daca4909e230a824ffc7c11658868aba3b728 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 16:02:15 +0200 Subject: [PATCH 03/10] [CMake] FindQGLViewer: fix include dir computation we use `#include `, so `QGLViewer_INCLUDE_DIR` must not include `QGLViewer` component. Also, on darwin, headers are installed in Headers dir, not include, ref: https://github.com/GillesDebunne/libQGLViewer/blob/ba9a875784afbb7ee73088fe0e8701c31bc7277d/QGLViewer/QGLViewer.pro#L138 --- cmake/Modules/FindQGLViewer.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index ae6fe0d2091..ae05efcee7d 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -14,8 +14,8 @@ if(NOT TARGET QGLViewer) if(NOT QGLViewer_INCLUDE_DIR) find_path(QGLViewer_INCLUDE_DIR - NAMES qglviewer.h - PATH_SUFFIXES include/QGLViewer + NAMES QGLViewer/qglviewer.h + PATH_SUFFIXES include Headers ) endif() From 1708b79f00bc2c4caca3956ff334e98f513808e1 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 16:38:19 +0200 Subject: [PATCH 04/10] [Nix] fix build on macos This require fixes in upstream nixpkgs: https://github.com/NixOS/nixpkgs/pull/348549 So we can use the source of that PR for now --- flake.lock | 12 ++++++------ flake.nix | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index 70252702896..27bbec45b53 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", + "lastModified": 1728930054, + "narHash": "sha256-mCaSyViQyiLgZKVLpDcVacbPSNjvsBzfWnGaxvhTzs8=", + "owner": "nim65s", "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "rev": "8e906b3e2aa2274c9d0c555393b4801d3c0badee", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-unstable", + "owner": "nim65s", + "ref": "qt6-libqglviewer", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index c931bb95b08..bd4e832da58 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,9 @@ inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + # ref. https://github.com/NixOS/nixpkgs/pull/348549 + nixpkgs.url = "github:nim65s/nixpkgs/qt6-libqglviewer"; }; outputs = From a03a4584feb0533ccee6866481bb422180c11030 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 16:40:39 +0200 Subject: [PATCH 05/10] [CMake] FindQGLViewer: fix for Qt6 ref. https://github.com/GillesDebunne/libQGLViewer/blob/ba9a875784afbb7ee73088fe0e8701c31bc7277d/QGLViewer/QGLViewer.pro#L176 --- cmake/Modules/FindQGLViewer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindQGLViewer.cmake b/cmake/Modules/FindQGLViewer.cmake index ae05efcee7d..65eb618dfff 100644 --- a/cmake/Modules/FindQGLViewer.cmake +++ b/cmake/Modules/FindQGLViewer.cmake @@ -21,7 +21,7 @@ if(NOT TARGET QGLViewer) if(NOT QGLViewer_LIBRARY) find_library(QGLViewer_LIBRARY - NAMES QGLViewer QGLViewer2 QGLViewer-qt5 + NAMES QGLViewer QGLViewer2 QGLViewer-qt5 QGLViewer-qt6 PATH_SUFFIXES lib ) endif() From 6c3bfb7a107291fafcfbc84b986e9f90811745e8 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 16:44:44 +0200 Subject: [PATCH 06/10] [Nix] Qt5 -> Qt6 --- package.nix | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.nix b/package.nix index fe7f464fd31..11c492e6be3 100644 --- a/package.nix +++ b/package.nix @@ -7,7 +7,7 @@ glew, gtest, lib, - libsForQt5, + qt6Packages, libGL, metis, stdenv, @@ -42,7 +42,7 @@ stdenv.mkDerivation { propagatedNativeBuildInputs = [ cmake - libsForQt5.wrapQtAppsHook + qt6Packages.wrapQtAppsHook ]; propagatedBuildInputs = [ boost @@ -50,7 +50,8 @@ stdenv.mkDerivation { eigen glew gtest - libsForQt5.libqglviewer + qt6Packages.libqglviewer + qt6Packages.qtbase libGL metis tinyxml-2 From bd261b552b6afe0421dba154d23dfca034561dc6 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 18:19:22 +0200 Subject: [PATCH 07/10] [CMake] fix typo for Qt6 --- Sofa/GUI/Qt/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/GUI/Qt/CMakeLists.txt b/Sofa/GUI/Qt/CMakeLists.txt index 2989ce4279f..52fadf87084 100644 --- a/Sofa/GUI/Qt/CMakeLists.txt +++ b/Sofa/GUI/Qt/CMakeLists.txt @@ -25,7 +25,7 @@ endif() if (Qt6Core_FOUND) message("${PROJECT_NAME}: will use Qt6") sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) - set(SOFA_GUI_QT_TARETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) + set(SOFA_GUI_QT_TARGETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) elseif (Qt5Core_FOUND) message("${PROJECT_NAME}: will use Qt5 (deprecated)") sofa_find_package(Qt5 COMPONENTS Core Gui OpenGL REQUIRED) From 6489fd1e0226f526b6b5a5478d373f19aa92890e Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 18:59:55 +0200 Subject: [PATCH 08/10] [CMake] fix SOFA_GUI_QT_HAVE_QT6 definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit without this, `lib/cmake/Sofa.GUI.Qt/Sofa.GUI.QtConfig.cmake` has: > `set(SOFA_GUI_QT_HAVE_QT6 0)` and therefore, in SofaPython3, `find_package(QGLViewer QUIET REQUIRED)` is not called, and build ends up with: > [ 98%] Linking CXX shared library ../../lib/python3/site-packages/Sofa/Gui.cpython-312-x86_64-linux-gnu.so > […]/ld: cannot find -lQGLViewer: No such file or directory --- Sofa/GUI/Qt/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sofa/GUI/Qt/CMakeLists.txt b/Sofa/GUI/Qt/CMakeLists.txt index 52fadf87084..85ebe4e49ee 100644 --- a/Sofa/GUI/Qt/CMakeLists.txt +++ b/Sofa/GUI/Qt/CMakeLists.txt @@ -24,7 +24,10 @@ endif() if (Qt6Core_FOUND) message("${PROJECT_NAME}: will use Qt6") - sofa_find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) + find_package(Qt6 COMPONENTS Gui GuiTools Widgets WidgetsTools OpenGLWidgets REQUIRED) + # GuiTools & WidgetsTools does not define a Qt6::component CMake target + # So we can't look for those target to know how we should define SOFA_GUI_QT_HAVE_QT6 + sofa_find_package(Qt6 COMPONENTS Gui Widgets OpenGLWidgets REQUIRED) set(SOFA_GUI_QT_TARGETS ${SOFA_GUI_QT_TARGETS} Qt::Core Qt::Gui Qt::Widgets Qt::OpenGLWidgets ) elseif (Qt5Core_FOUND) message("${PROJECT_NAME}: will use Qt5 (deprecated)") From f9cfcd04f19d47230b404923d99b576adcea7e7e Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 19:50:46 +0200 Subject: [PATCH 09/10] [Nix] fixup lib path on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TODO: This should be fixed in CMake instead, but I have no clue. error was: > dyld[61665]: Library not loaded: /nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib > Referenced from: <8B75C775-7FE5-3755-A190-B11A3F4F6666> /nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/bin/.runSofa-24.12.99-wrapped > Reason: tried: '/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/nix/store/aalbn4pznxwy18ydjmb15c3y4izj8isi-sofa-24.06.00/lib/libSceneChecking.24.12.99.dylib' (no such file), '/usr/local/lib/libSceneChecking.24.12.99.dylib' (no such file), '/usr/lib/libSceneChecking.24.12.99.dylib' (no such file, not in dyld cache) > zsh: abort ./result/bin/runSofa --- package.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/package.nix b/package.nix index 11c492e6be3..ae66f505dbe 100644 --- a/package.nix +++ b/package.nix @@ -64,6 +64,13 @@ stdenv.mkDerivation { doCheck = true; + postFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' + install_name_tool -change \ + $out/lib/libSceneChecking.24.12.99.dylib \ + $out/plugins/SceneChecking/lib/libSceneChecking.24.12.99.dylib \ + $out/bin/.runSofa-24.12.99-wrapped + ''; + meta = { description = "Real-time multi-physics simulation with an emphasis on medical simulation"; homepage = "https://github.com/sofa-framework/sofa"; From 8808d2463a93229cc938b1bb29f362c36ba22321 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 16 Oct 2024 13:06:21 +0200 Subject: [PATCH 10/10] [Nix] CI on macos too --- .github/workflows/nix.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 7e82c8996b8..5fce46e9557 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -8,8 +8,7 @@ jobs: runs-on: "${{ matrix.os }}-latest" strategy: matrix: - #os: [ubuntu, macos] - os: [ubuntu] + os: [ubuntu, macos] steps: - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v27