Skip to content

Commit 2e7e01b

Browse files
authored
bwa-mem2 2.2.1 (#1786)
1 parent 5e428d5 commit 2e7e01b

1 file changed

Lines changed: 93 additions & 8 deletions

File tree

Formula/bwa-mem2.rb

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class BwaMem2 < Formula
22
desc "Next version of bwa-mem short read aligner"
33
homepage "https://github.com/bwa-mem2/bwa-mem2"
44
url "https://github.com/bwa-mem2/bwa-mem2.git",
5-
tag: "v2.0",
6-
revision: "cbcc183c0843d20d45c84e066177eb8d58be2f9b"
5+
tag: "v2.2.1",
6+
revision: "bf3d376e95f4321b0d37a27d7ff1c77da4d289ff"
77
head "https://github.com/bwa-mem2/bwa-mem2.git"
88

99
bottle do
@@ -12,16 +12,101 @@ class BwaMem2 < Formula
1212
sha256 cellar: :any_skip_relocation, x86_64_linux: "943583113491f963bd0e8460994ec17a95f19208a62b07a8d514d18e648ddf7d"
1313
end
1414

15+
depends_on "cmake" => :build
16+
depends_on "dos2unix" => :build
1517
uses_from_macos "zlib"
1618

19+
resource "sse2neon" do
20+
url "https://raw.githubusercontent.com/DLTcollab/sse2neon/v1.7.0/sse2neon.h"
21+
sha256 "c36e1355c1a22d9c3357c945d1ef8bd005cb1f0f7b378e6577a45ea96931a083"
22+
end
23+
24+
resource "safestringlib" do
25+
url "https://github.com/intel/safestringlib/archive/refs/tags/v1.2.0.tar.gz"
26+
sha256 "3f16492460eb6dc40fc63f4a1c018e7e32db9db65b86a1294aa6c3bf1e31310e"
27+
end
28+
29+
resource "patch" do
30+
url "https://gist.githubusercontent.com/YoshitakaMo/eb6e6df7a621a9c9737bcc9363cf9bfc/raw/5936f4884daac3c961c6c9a62d9a0c676f578bbb/fastmap.patch"
31+
sha256 "cbba705412b8a1139be752759490606a988eee0483a3c0ee65aa0a03c1c9c9e8"
32+
end
33+
34+
resource "patch2" do
35+
url "https://gist.githubusercontent.com/YoshitakaMo/c4cabc8e1e4b618047507bc354dbb51e/raw/1265ecf70a976476bd3e55d06804b94f9969310e/bandedSWA.cpp.patch"
36+
sha256 "cdc13b153a23beb890d258eeb41d13aa0b777c1747bdefa49c399634c176cda7"
37+
end
38+
1739
def install
18-
# Fix the error: error: conflicting types for 'memset_s'
19-
# See https://github.com/intel/safestringlib/issues/14
20-
inreplace "ext/safestringlib/include/safe_mem_lib.h",
21-
"extern errno_t memset_s",
22-
"//xxx extern errno_t memset_s"
40+
# patch for fastmap.cpp
41+
system "dos2unix", "src/fastmap.cpp"
42+
system "dos2unix", "src/bandedSWA.cpp"
43+
buildpath.install resource("patch")
44+
buildpath.install resource("patch2")
45+
system "patch", "-p1", "src/fastmap.cpp", "fastmap.patch"
46+
system "patch", "-p1", "src/bandedSWA.cpp", "bandedSWA.cpp.patch"
47+
# patch for src/utils.h to fix build error
48+
# https://aur.archlinux.org/cgit/aur.git/tree/gcc_rdtsc.patch?h=bwa-mem2
49+
inreplace "src/utils.h", "defined(__GNUC__) && !defined(__clang__)",
50+
"defined(__GNUC__) && __GNUC__ < 11 && !defined(__clang__)"
51+
# install safestringlib v1.2.0 first
52+
(buildpath/"safestringlib-1.2.0").install resource("safestringlib")
53+
cd "safestringlib-1.2.0" do
54+
inreplace "makefile", "LDFLAGS=-z noexecstack -z relo -z now", "LDFLAGS="
55+
inreplace "CMakeLists.txt", " -z noexecstack -z relro -z now", ""
56+
inreplace "include/safe_mem_lib.h", "extern errno_t memset_s", "//xxx extern errno_t memset_s"
57+
system "cmake", "-S", ".", "-B", "build", *std_cmake_args(install_prefix: buildpath/"safestringlib")
58+
system "cmake", "--build", "build"
59+
end
60+
inreplace "Makefile" do |s|
61+
s.gsub! "SAFE_STR_LIB= ext/safestringlib/libsafestring.a",
62+
"SAFE_STR_LIB= safestringlib-1.2.0/build/libsafestring_static.a"
63+
s.gsub! "-Iext/safestringlib/include",
64+
"-Isafestringlib-1.2.0/include"
65+
end
66+
67+
# use sse2neon for Apple Silicon
68+
if OS.mac? && Hardware::CPU.arm?
69+
(buildpath/"src").install resource("sse2neon")
70+
inreplace "src/sse2neon.h", "FORCE_INLINE uint64_t _rdtsc(void)", "FORCE_INLINE uint64_t __rdtsc(void)"
71+
inreplace ["src/FMI_search.h", "src/kswv.h", "src/bandedSWA.h"] do |s|
72+
s.gsub! "#include <immintrin.h>", "#include \"sse2neon.h\""
73+
end
74+
inreplace ["src/ksw.h", "src/ksw.cpp"] do |s|
75+
s.gsub! "#include <emmintrin.h>", "#include \"sse2neon.h\""
76+
end
77+
inreplace "src/bandedSWA.h", "#include <smmintrin.h>", "#include \"sse2neon.h\""
78+
end
79+
80+
# Use safestringlib v1.2.0 instead of the bundled version
81+
inreplace "Makefile", "-Lext/safestringlib -lsafestring",
82+
"-Lsafestringlib-1.2.0/build/ -lsafestring_static"
83+
inreplace "Makefile", "-Lext/safestringlib/ -lsafestring",
84+
"-Lsafestringlib-1.2.0/build/ -lsafestring_static"
85+
# fix build error with latest compilers
86+
inreplace "src/FMI_search.cpp" do |s|
87+
s.gsub! "_mm_prefetch((const char *)", "_mm_prefetch(reinterpret_cast<const char*>"
88+
s.gsub! "_mm_prefetch(&sa_ls_word[pos >> SA_COMPX]",
89+
"_mm_prefetch(reinterpret_cast<const char*>(&sa_ls_word[pos >> SA_COMPX])"
90+
s.gsub! "_mm_prefetch(&sa_ms_byte[pos >> SA_COMPX]",
91+
"_mm_prefetch(reinterpret_cast<const char*>(&sa_ms_byte[pos >> SA_COMPX])"
92+
s.gsub! "_mm_prefetch(&sa_ls_word[sp >> SA_COMPX]",
93+
"_mm_prefetch(reinterpret_cast<const char*>(&sa_ls_word[sp >> SA_COMPX])"
94+
s.gsub! "_mm_prefetch(&sa_ms_byte[sp >> SA_COMPX]",
95+
"_mm_prefetch(reinterpret_cast<const char*>(&sa_ms_byte[sp >> SA_COMPX])"
96+
s.gsub! "_mm_prefetch(&cp_occ[occ_id_pp_]",
97+
"_mm_prefetch(reinterpret_cast<const char*>(&cp_occ[occ_id_pp_])"
98+
end
99+
inreplace "src/bwamem.cpp" do |s|
100+
s.gsub! "__m512i zero512 = _mm512_setzero_si512()", "__m128i zero128 = _mm_setzero_si128();"
101+
s.gsub! "_mm512_store_si512((__m512i *)(hist + i), zero512)", "_mm_store_si128((__m128i *)(hist + i), zero128)"
102+
end
103+
inreplace "ext/safestringlib/safeclib/safeclib_private.h",
104+
"#include \"safe_lib.h\"", "#include <safe_lib.h>"
23105

24-
system "make"
106+
cflags = "-Wno-implicit-function-declaration" if DevelopmentTools.clang_build_version >= 1403
107+
# arch=avx2 for Linux, but it's not best for all CPUs.
108+
arch = OS.mac? ? "native" : "avx2"
109+
system "make", "arch=#{arch}", "CFLAGS=#{cflags}"
25110
bin.install "bwa-mem2"
26111
end
27112

0 commit comments

Comments
 (0)