Skip to content

Commit

Permalink
Apply voutcn/megahit#368 as a patch to fix the build on Linux ARM64
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Apr 4, 2024
1 parent 8c811a6 commit 5d36890
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
74 changes: 74 additions & 0 deletions recipes/megahit/linux-aarch64-support-pr-368.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From 296ad6b5359ac5072a97fe0b7f72cad08031542f Mon Sep 17 00:00:00 2001
From: Martin Tzvetanov Grigorov <[email protected]>
Date: Wed, 27 Mar 2024 15:07:02 +0200
Subject: [PATCH 1/5] Add support for non-x86_64 architectures (e.g. Linux
ARM64)

Fixes https://github.com/voutcn/megahit/issues/320
Based on: https://github.com/voutcn/megahit/pull/329

Preserves the x86_64 specifics when building on x86_64 machine

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
---
CMakeLists.txt | 8 ++++++--
src/kmlib/kmrns.h | 2 ++
src/utils/cpu_dispatch.h | 6 ++++++
3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 172a03d..d21b2d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,8 +73,12 @@ add_executable(megahit_core_popcnt ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE
${CX1_SOURCE} ${TOOLKIT_SOURCE})
add_executable(megahit_core_no_hw_accel ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE} ${SDBG_SOURCE} ${LCASM_SOURCE}
${SEQ_SOURCE} ${CX1_SOURCE} ${TOOLKIT_SOURCE})
-set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")
-set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "-mpopcnt")
+
+if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)|(AMD64)")
+ set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")
+ set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "-mpopcnt")
+endif ()
+

if (STATIC_BUILD)
# TODO dirty
diff --git a/src/kmlib/kmrns.h b/src/kmlib/kmrns.h
index 9f2e9dd..0352858 100644
--- a/src/kmlib/kmrns.h
+++ b/src/kmlib/kmrns.h
@@ -8,7 +8,9 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#if defined(__x86_64__)
#include <x86intrin.h>
+#endif
#include <vector>

namespace kmlib {
diff --git a/src/utils/cpu_dispatch.h b/src/utils/cpu_dispatch.h
index ec01bb6..44ba1e2 100644
--- a/src/utils/cpu_dispatch.h
+++ b/src/utils/cpu_dispatch.h
@@ -5,6 +5,7 @@
#ifndef MEGAHIT_CPU_DISPATCH_H
#define MEGAHIT_CPU_DISPATCH_H

+#if defined(__x86_64__)
inline bool HasPopcnt() {
unsigned eax, ebx, ecx, edx;
#ifdef _MSC_VER
@@ -32,5 +33,10 @@ inline bool HasBmi2() {
#endif
return ebx >> 8U & 1U;
}
+#else
+inline bool HasPopcnt() { return false; }
+inline bool HasBmi2() { return false; }
+#endif
+

#endif // MEGAHIT_CPU_DISPATCH_H
2 changes: 2 additions & 0 deletions recipes/megahit/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package:
source:
sha256: '{{sha256}}'
url: https://github.com/voutcn/megahit/archive/v{{version}}.tar.gz
patches:
- linux-aarch64-support-pr-368.patch

build:
number: 5
Expand Down

0 comments on commit 5d36890

Please sign in to comment.