Repository: gigabit-clowns/xmipp4-core
Pull request #146: Add action to create wheels
Author: login: oierlauzi
Labels: name: enhancement
description: New feature or request
name: github_actions
description: Pull requests that update GitHub Actions code
Created: 2025-04-11T10:35:38Z | Merged: 2025-04-15T09:30:24Z



Diff:
diff --git a/.github/workflows/build-wheel.yml b/.github/workflows/build-wheel.yml
new file mode 100644
index 000000000..1e06decd3
--- /dev/null
+++ b/.github/workflows/build-wheel.yml
@@ -0,0 +1,88 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  workflow_dispatch:
+
+jobs:
+  build_wheels:
+    name: Build wheels for ${{ matrix.os }} (${{ matrix.architectures }})
+    strategy:
+      matrix:
+        include:
+          - os: ubuntu-latest
+            architectures: "x86_64 i686 ppc64le s390x"
+            use_qemu: true
+          - os: ubuntu-24.04-arm
+            architectures: "aarch64"
+            use_qemu: false
+          - os: macos-latest
+            architectures: "x86_64 arm64 universal2"
+            use_qemu: false
+          - os: windows-latest
+            architectures: "AMD64 x86 ARM64"
+            use_qemu: false
+
+    runs-on: ${{ matrix.os }}
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v4
+
+      - name: Set up QEMU
+        if: matrix.use_qemu
+        uses: docker/setup-qemu-action@v3
+        with:
+          platforms: all
+
+      - name: Build wheels
+        uses: pypa/cibuildwheel@v2.23.2
+        env:
+          CIBW_ARCHS: "${{ matrix.architectures }}"
+          CIBW_BUILD: "cp39-*" # Python agnostic, pick any version
+    
+      - name: List wheels
+        run: ls -l ./wheelhouse
+      
+      - name: Upload wheels
+        uses: actions/upload-artifact@v4
+        with:
+          name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
+          path: ./wheelhouse/*.whl
+
+  build_sdist:
+    name: Build source distribution
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Build sdist
+        run: pipx run build --sdist
+
+      - uses: actions/upload-artifact@v4
+        with:
+          name: cibw-sdist
+          path: dist/*.tar.gz
+
+  # TODO add here the distribution job
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a11e20caa..4c9e1c4ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,8 +45,9 @@ set(XMIPP4_CORE_LIBRARY_TARGET "xmipp4-core")
 include(CTest)
 include(GNUInstallDirs)
 include(CMakePackageConfigHelpers)
-include(fetch_spdlog)
+include(fetch_ghc_filesystem)
 include(fetch_half)
+include(fetch_spdlog)
 
 # Only build docs if it is the main project
 if(XMIPP4_CORE_BUILD_DOC)
@@ -55,6 +56,7 @@ endif()
 
 # Find dependencies
 find_package(Threads REQUIRED)
+fetch_ghc_filesystem(VERSION 1.5.14)
 
 if (XMIPP4_CORE_BUILD_SPDLOG)
 	fetch_spdlog(VERSION 1.15.0)
@@ -74,6 +76,7 @@ else()
 	)
 endif()
 
+
 # Find all source and header files
 file(
 	GLOB_RECURSE 
@@ -131,6 +134,7 @@ target_link_libraries(
 		spdlog::spdlog_header_only
 		half
 	PRIVATE
+		ghc_filesystem # Eventually replace by std::filesystem (C++17)
 		${CMAKE_DL_LIBS}
 )
 
diff --git a/cmake/modules/fetch_ghc_filesystem.cmake b/cmake/modules/fetch_ghc_filesystem.cmake
new file mode 100644
index 000000000..2c9bdc68b
--- /dev/null
+++ b/cmake/modules/fetch_ghc_filesystem.cmake
@@ -0,0 +1,42 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+cmake_minimum_required(VERSION 3.12)
+
+include(FetchContent)
+
+function(fetch_ghc_filesystem)
+    set(options)
+    set(oneValueArgs VERSION)
+    set(multiValueArgs)
+    cmake_parse_arguments(PARSE_ARGV 0 arg
+        "${options}" "${oneValueArgs}" "${multiValueArgs}"
+    )
+
+	FetchContent_Declare(
+		ghc_filesystem
+		GIT_REPOSITORY https://github.com/gulrak/filesystem.git
+		GIT_TAG v${arg_VERSION}
+	)
+
+	FetchContent_MakeAvailable(ghc_filesystem)
+endfunction()
diff --git a/include/xmipp4/core/utils/bit.inl b/include/xmipp4/core/utils/bit.inl
index 97f0951b0..4f77affa7 100644
--- a/include/xmipp4/core/utils/bit.inl
+++ b/include/xmipp4/core/utils/bit.inl
@@ -41,7 +41,15 @@ namespace utils
 XMIPP4_NODISCARD XMIPP4_INLINE_CONSTEXPR 
 std::size_t bit(std::size_t i) noexcept
 {
-    return std::size_t(1) << i;
+    XMIPP4_CONSTEXPR auto n_bits = std::numeric_limits<std::size_t>::digits;
+    if (i >= n_bits)
+    {
+        return 0;
+    }
+    else
+    {
+        return std::size_t(1) << i;
+    }
 }
 
 template<typename T>
diff --git a/src/plugin_manager.cpp b/src/plugin_manager.cpp
index 6941896ce..480b8c2be 100644
--- a/src/plugin_manager.cpp
+++ b/src/plugin_manager.cpp
@@ -36,10 +36,11 @@
 
 #include <vector>
 #include <functional>
-#include <filesystem>
 #include <system_error>
 #include <cstdlib>
 
+#include <ghc/filesystem.hpp>
+
 static const char XMIPP4_PLUGINS_DIRECTORY_NAME[] = "xmipp4-plugins";
 static const char XMIPP4_PLUGINS_ENV_VARIABLE[] = "XMIPP4_PLUGINS_DIRECTORY";
 
@@ -128,7 +129,7 @@ std::string get_default_plugin_directory()
     const auto* symbol = 
         reinterpret_cast<const void*>(&get_default_plugin_directory);
 
-    auto path = std::filesystem::path(
+    auto path = ghc::filesystem::path(
         system::dynamic_library::query_symbol_filename(symbol)
     );
     if(path.empty())
@@ -161,12 +162,12 @@ std::string get_plugin_directory()
 
 void discover_plugins(const std::string& directory, plugin_manager &manager)
 {
-    std::filesystem::directory_iterator iterator;
+    ghc::filesystem::directory_iterator iterator;
     try
     {
-        iterator = std::filesystem::directory_iterator(directory);
+        iterator = ghc::filesystem::directory_iterator(directory);
     }
-    catch(const std::filesystem::filesystem_error& e)
+    catch(const ghc::filesystem::filesystem_error& e)
     {
         XMIPP4_LOG_WARN(
             "Failed to open plugin directory {}: {}", 


Reviews:
user: login: martin-s-a
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-14T14:51:44Z
user: login: martin-s-a
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-04-14T14:59:02Z
user: login: oierlauzi
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-14T15:26:00Z
user: login: martin-s-a
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-14T15:33:04Z
user: login: oierlauzi
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T08:58:03Z
user: login: oierlauzi
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T08:58:42Z
user: login: martin-s-a
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-15T09:30:03Z
user: login: martin-s-a
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-04-15T09:30:15Z

Review comments:
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: martin-s-a
body: Do we really want it to run every push on main? Maybe I would leave it as a manual dispatch job
created_at: 2025-04-14T14:58:59Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: oierlauzi
body: Maybe for now (as this does nothing) could be left as a manual dispatch job. Nevertheless it compiles on a very extensive set of platforms, so it would be a good idea to run it once in a while to assure that everything remains OK. Eventually, the artifacts from this action need to deployed to pipy 
created_at: 2025-04-14T15:26:00Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: martin-s-a
body: If your concern is testing if new code still compiles in all those architectures, maybe adding a build-wheel workflow in pull requests is a good idea (without the distribution part), and then have a release pipeline triggered manually that both builds the wheel & distributes it
created_at: 2025-04-14T15:33:04Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: oierlauzi
body: The problem with those architectures is that they take 1h+ to build (as they're compiled in an emulator) and they are not relevant. Therefore I would not include this in PR checks
created_at: 2025-04-15T08:58:03Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: oierlauzi
body: This is aimed to be a deploy pipeline
created_at: 2025-04-15T08:58:42Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,92 @@
+#***************************************************************************
+# Authors:     Oier Lauzirika Zarrabeitia (oierlauzi@bizkaia.eu)
+#              Martín Salinas Antón (ssalinasmartin@gmail.com)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+#
+#  All comments concerning this program package may be sent to the
+#  e-mail address 'xmipp@cnb.csic.es'
+# ***************************************************************************
+
+name: Build wheels and source distribution
+
+on:
+  push:
+    branches:
+      - main
path: .github/workflows/build-wheel.yml
user: login: martin-s-a
body: Then, maybe we could do the wheel build after every push on main, and only run the distribution job on demand using the artifacts generated by the wheel job. I'm approving for now to check what it does and how long it takes, but i'll try to think of a way to streamline this without affecting the prs.
created_at: 2025-04-15T09:30:03Z
author_association: COLLABORATOR

PR comments:
user: login: oierlauzi
created_at: 2025-04-11T14:15:43Z
body: Only merge if [278aa0b](https://github.com/gigabit-clowns/xmipp4-core/pull/146/commits/278aa0b4d8a85325571d6aabad6ac6c8cae0f028) succeeds
author_association: COLLABORATOR
user: login: sonarqubecloud[bot]
created_at: 2025-04-15T08:54:44Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=gigabit-clowns_xmipp4-core&pullRequest=146) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=gigabit-clowns_xmipp4-core&pullRequest=146&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=gigabit-clowns_xmipp4-core&pullRequest=146&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=gigabit-clowns_xmipp4-core&pullRequest=146&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=gigabit-clowns_xmipp4-core&pullRequest=146&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=gigabit-clowns_xmipp4-core&pullRequest=146&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=gigabit-clowns_xmipp4-core&pullRequest=146)


author_association: NONE