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

Building Seqwish on macOS #117

Open
kojix2 opened this issue Nov 10, 2023 · 0 comments
Open

Building Seqwish on macOS #117

kojix2 opened this issue Nov 10, 2023 · 0 comments

Comments

@kojix2
Copy link

kojix2 commented Nov 10, 2023

Hi

I compiled Seqwish on macOS.

I followed the recommended commands for compiling ODGI on macOS

See: pangenome/odgi#494

CC=/opt/homebrew/opt/llvm/bin/clang \
  CXX=/opt/homebrew/opt/llvm/bin/clang++ \
  LDFLAGS=-L/opt/homebrew/lib \
  cmake . -Bbuild
CC=/opt/homebrew/opt/llvm/bin/clang \
  CXX=/opt/homebrew/opt/llvm/bin/clang++ \
  LDFLAGS=-L/opt/homebrew/lib \
  cmake --build build -- -j

I modified CMakeLists.txt as follows.
There was a linking error, but I removed -latomic, as I read it's unnecessary on macOS.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,10 +48,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # untested
   # adapted from https://stackoverflow.com/questions/46414660/macos-cmake-and-openmp
   # find_package(OpenMP) does not work reliably on macOS, so we do its work ourselves
   set (OpenMP_C "${CMAKE_C_COMPILER}")
-  set (OpenMP_C_FLAGS " -Xpreprocessor -fopenmp -I/opt/local/include/libomp -I/usr/local/include -L/opt/local/lib/libomp -L/usr/local/lib")
+  set (OpenMP_C_FLAGS " -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/17.0.4/include/ -I/usr/local/include -L/opt/homebrew/Cellar/libomp/17.0.4/lib/ -L/usr/local/lib")
   set (OpenMP_C_LIB_NAMES "libomp" "libgomp" "libiomp5")
   set (OpenMP_CXX "${CMAKE_CXX_COMPILER}")
-  set (OpenMP_CXX_FLAGS " -Xpreprocessor -fopenmp -I/opt/local/include/libomp -I/usr/local/include -L/opt/local/lib/libomp -L/usr/local/lib")
+  set (OpenMP_CXX_FLAGS " -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/17.0.4/include/ -I/usr/local/include -L/opt/homebrew/Cellar/libomp/17.0.4/lib/ -L/usr/local/lib")
   set (OpenMP_CXX_LIB_NAMES "libomp" "libgomp" "libiomp5")
   set (OpenMP_libomp_LIBRARY "omp")
   set (OpenMP_libgomp_LIBRARY "gomp")
@@ -256,7 +256,6 @@ target_link_libraries(seqwish
   "${sdsl-lite_LIB}/libsdsl.a"
   "${sdsl-lite-divsufsort_LIB}/libdivsufsort.a"
   "${sdsl-lite-divsufsort_LIB}/libdivsufsort64.a"
-  "-latomic"
   Threads::Threads
   jemalloc
   z)

get_current_dir_name() does not work on macOS:

--- a/src/main.cpp
+++ b/src/main.cpp
@@ -116,7 +116,7 @@ int main(int argc, char** argv) {
     if (tmp_base) {
         temp_file::set_dir(args::get(tmp_base));
     } else {
-        char* cwd = get_current_dir_name();
+	char* cwd = getcwd(NULL, 0);
         temp_file::set_dir(std::string(cwd));
         free(cwd);
     }
--- a/src/tempfile.cpp
+++ b/src/tempfile.cpp
@@ -96,7 +96,7 @@ namespace temp_file {
 
         // Get the default temp dir from environment variables.
         if (temp_dir.empty()) {
-            char* cwd = get_current_dir_name();
+	    char* cwd = getcwd(NULL, 0);
             temp_dir = std::string(cwd);
             free(cwd);
             /*const char *system_temp_dir = nullptr;

I encountered an error with std::min(), but I am not familiar with the C++ language.
After consulting with ChatGPT, I made the following change:

--- a/paryfor.hpp
+++ b/paryfor.hpp
@@ -768,13 +768,13 @@ void parallel_for(const I& begin,
     for (uint64_t t = 0; t < nthreads; ++t) {
         workers.emplace_back(worker, t);
     }
-    std::pair<I, I> todo_range = std::make_pair(begin, std::min(begin + chunk_size, end));
+    std::pair<I, I> todo_range = std::make_pair(begin, std::min(begin + static_cast<I>(chunk_size), end));
     I& todo_i = todo_range.first;
     I& todo_j = todo_range.second;
     while (todo_i != end) {
         if (queue.try_push(todo_range)) {
-            todo_i = std::min(todo_i + chunk_size, end);
-            todo_j = std::min(todo_j + chunk_size, end);
+		todo_i = std::min(todo_i + static_cast<I>(chunk_size), end);
+		todo_j = std::min(todo_j + static_cast<I>(chunk_size), end);
         } else {
             std::this_thread::sleep_for(std::chrono::nanoseconds(1));
         }

These changes allow us to generate executables for M2 Mac.

I am not sure if it actually compiles correctly. But I write here because I know that GitHub issues are the first place people come to look for information. Someone will add more information on how to compile on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant