Skip to content

feat: native ARM64 / Apple Silicon and macOS clang build support#2694

Open
BenjaminDEMAILLE wants to merge 2 commits into
alexdobin:masterfrom
BenjaminDEMAILLE:feat/arm64-macos-build
Open

feat: native ARM64 / Apple Silicon and macOS clang build support#2694
BenjaminDEMAILLE wants to merge 2 commits into
alexdobin:masterfrom
BenjaminDEMAILLE:feat/arm64-macos-build

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown

Summary

Make STAR build out-of-the-box on ARM64 / Apple Silicon and on macOS with Apple clang, instead of failing with unrecognized command-line option -mavx2 (#2104, #1754) or missing OpenMP / link flags (#1901, #2108). Addresses the long-standing "Plans for ARM Support?" request (#1833).

Changes (source/Makefile)

  • Arch detection via uname -m: x86_64/amd64 use -mavx2; arm64/aarch64 use -march=armv8-a+simd, so opal's SIMDe maps AVX2 intrinsics onto NEON automatically (building on the already-merged SIMDe support, simple, but inelegant support for non-x86 using SIMDe #1163).
  • macOS OpenMP: Apple clang has no bundled OpenMP, so use -Xpreprocessor -fopenmp with a Homebrew libomp include/lib path (brew --prefix libomp, with /opt/homebrew and /usr/local fallbacks) and -lomp at link time.
  • macOS link flags: no -static-libgcc / full -static (unsupported by Apple clang); link htslib as a static archive and libomp dynamically. Add STARforMac / STARlongForMac targets.
  • Portable build date for BSD/macOS date(1).

README is updated to document ARM64/Apple Silicon support and the native make STARforMac CXX=clang++ build.

This supersedes the stale, broken #1863 (variable typo avxCXXFLAGS_SIMD + inverted x86 logic).

Verification

make STARforMac CXX=clang++ produces an arm64-native binary on Apple Silicon; genome generation + alignment verified working.

Closes #2104, closes #1754, closes #1901, closes #2108, closes #1833.

🤖 Generated with Claude Code

BenjaminDEMAILLE and others added 2 commits June 26, 2026 14:51
…nMP + STARforMac

Make the build work out-of-the-box on non-x86 and on macOS, instead of failing
with 'unrecognized command-line option -mavx2' (issues alexdobin#2104, alexdobin#1754) or missing
OpenMP/link flags on Apple Silicon (issues alexdobin#1901, alexdobin#2108).

- Detect uname -s/-m. On x86_64/amd64 use -mavx2; on arm64/aarch64 use
  -march=armv8-a+simd so opal's SIMDe maps AVX2 intrinsics onto NEON.
- macOS + Apple clang OpenMP: -Xpreprocessor -fopenmp with a Homebrew libomp
  include/lib path (brew --prefix libomp, with /opt/homebrew and /usr/local
  fallbacks) and -lomp at link time.
- macOS link flags: no -static-libgcc / full -static (unsupported by Apple
  clang); link htslib as a static archive and libomp dynamically. Add
  STARforMac / STARlongForMac (dynamic) targets.
- Portable build date for BSD/macOS date(1).

Supersedes the stale, broken PR alexdobin#1863 (variable typo + inverted x86 logic).
Verified: native arm64 build via 'make STARforMac CXX=clang++'.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…dobin#1833)

The README stated x86-64 only and the macOS instructions required Homebrew gcc.
STAR builds and runs on ARM64/AArch64 (incl. Apple Silicon) via SIMDe, and now
has a native Apple clang target.

- Hardware requirements: note ARM64/Apple Silicon support via SIMDe.
- macOS: document 'make STARforMac CXX=clang++' with Homebrew libomp as the
  recommended native build (arm64 or x86_64), keeping the gcc path as an
  alternative.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BenjaminDEMAILLE BenjaminDEMAILLE marked this pull request as ready for review June 26, 2026 12:56
@BenjaminDEMAILLE

Copy link
Copy Markdown
Author

@alexdobin apologies for the direct ping. This is a small series of focused, independent fixes that make STAR build and run natively on macOS / Apple Silicon (on a clean 2.7.11b base), each verified on a native arm64 build (genome generation + alignment, plain and gzipped input):

They can be reviewed and merged independently and in any order. Would you be open to taking a look when you have a moment? Happy to adjust anything.

birdingman0626 added a commit to birdingman0626/STAR-Cross that referenced this pull request Jun 29, 2026
…ndian support (#7)

* fix(macos): spawn readFilesCommand via posix_spawnp

The POSIX path used vfork()+execlp()+exit(0) to run the generated
readsCommand script. On macOS this fails ("Failed spawning
readFilesCommand", upstream issue alexdobin#2663) because the script has no
shebang and posix_spawn-style exec has no ENOEXEC->/bin/sh fallback;
calling exit() in a vfork child is also undefined behavior.

Replace with posix_spawnp invoking "<shell> <script>" explicitly, with
proper error checking. POSIX-only branch; the Windows system()-based
path is unchanged. Ported from upstream PR alexdobin#2693.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat: big-endian support with guarded little-endian fast path

STAR read the genome, suffix array and packed arrays through native
uint*/uint128* casts, assuming little-endian byte order, which caused
"next index is smaller than previous" failures on big-endian hosts
(s390x, ppc64).

Add byteOrder.h with loadUintLE/storeUintLE helpers and route the four
endian-sensitive sites (PackedArray::operator[]/writePacked,
funCompareSuffixes, funCalcSAiFromSA) through them. The helpers are
guarded by STAR_BIG_ENDIAN: little-endian builds keep the original
single-instruction native load (zero performance/behavior change), and
only known big-endian compiles take the portable byte-wise path. The
existing MSVC byte-access path in funCalcSAiFromSA is reused for BE.

The byte-wise implementation is exposed by name and unit-tested
(test_byteOrder.cpp) so the BE algorithm is validated on the LE CI
runner. Ported from the patch in upstream issue alexdobin#2690.

Note: compile-validated only; CI has no big-endian runner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* feat: referenceless CRAM output (--outSAMtype CRAM)

Add CRAM as an output container. STAR produces its BAM via the proven
output path, then transcodes it to referenceless CRAM at finalization
(cramOutput.cpp, using bundled HTSlib with CRAM_OPT_NO_REF, so no
external reference FASTA is required). On conversion failure the
original BAM is kept and the run continues.

- Parameters_runtimeSetup: accept "CRAM" as outSAMtype[0], reusing the
  BAM Unsorted/SortedByCoordinate logic; set outCRAMbool and CRAM names.
- STAR.cpp: transcode Aligned.out.bam / Aligned.sortedByCoord.out.bam
  to .cram after wiggle output, removing the intermediate BAM.
- Hot per-record output code is untouched; the transcriptome BAM stays
  BAM for RSEM/Salmon. CRAM is incompatible with --outStd.
- WebUI: CRAM options in the outSAMtype dropdown, .cram artifacts and
  MIME type.
- Registered cramOutput in CMake build.

Implemented properly rather than porting the incomplete upstream draft
PR alexdobin#2670 (which wrote a NULL header and rerouted the working BAM path).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* build: Makefile ARM64/macOS/libomp parity and cramOutput

Port the platform-detection from upstream PR alexdobin#2694 to the Makefile (CI
uses CMake, which already handles ARM64; this is for `make` users):
- detect UNAME_S/UNAME_M; select -mavx2 on x86_64, -march=armv8-a+simd
  on ARM64/AArch64
- macOS + Apple clang OpenMP: -Xpreprocessor -fopenmp + libomp include,
  -lomp at link; add native STARforMac target (dynamic libomp)
- portable BSD/macOS date fallback for the build timestamp
- add cramOutput.o to OBJECTS

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* docs: document CRAM output, ARM64/macOS, and big-endian support

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant