Repository navigation
Conversation
The build script chose compiler flags with `cfg!(target_feature)`, which describes the build script's own compilation rather than the target. It also emitted `-mcmpxchg16b`, which clang and gcc both reject (the flag is `-mcx16`), `-mfma4` (AMD FMA4) for `fma` instead of `-mfma`, and `-mbmi` alone for BMI2. Building with `-C target-cpu=x86-64-v3` failed with `clang++: error: unknown argument: '-mcmpxchg16b'`. Read the target features from `CARGO_CFG_TARGET_FEATURE` and map them with a table to flags that clang and gcc both accept: `-mcx16` for `cmpxchg16b`, `-mfma` for `fma`, and `-mbmi` and `-mbmi2` separately. Features that are not in the table emit no flag. The C++ now gets the target features explicitly, so results may differ in the last digits from before and are deterministic for a given `target-cpu`. The same table is in `bhtsne` in 10XDev/scan-rs; there is no shared crate, so each copy has its own unit tests. Jira: CELLRANGER-10331 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HbDsntotWVcM9MvHmktSa8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
star-sysbuild script chose C++ compiler flags withcfg!(target_feature = ...). That describes the compilation of the build script itself, not the target being built, and it gave wrong flags:cmpxchg16bproduced-mcmpxchg16b. Neither clang nor gcc accepts it; the flag is-mcx16. Building with-C target-cpu=x86-64-v3(which enablescmpxchg16b) failed withclang++: error: unknown argument: '-mcmpxchg16b', with clang 18, clang 21 and gcc 13.fmaproduced-mfma4, the AMD FMA4 instructions, which Intel CPUs do not have, instead of-mfma.bmi1andbmi2together produced only-mbmi, so-mbmi2was never passed, andavx2andf16cwere never mapped.The build script now reads
CARGO_CFG_TARGET_FEATURE, which describes the target, and maps each feature to a flag with a table instar-sys/flags.rs:-mcx16forcmpxchg16b,-mfmaforfma,-mbmiand-mbmi2separately, plussse3,ssse3,sse4.1,sse4.2,popcnt,avx,avx2,lzcnt,movbeandf16c. Features that are not in the table emit no flag. Every flag was checked against clang 18, clang 21 and gcc 13. The special case for macOS is removed, because-mcx16is a long-standing clang flag; this is not verified on macOS.The C++ now gets the target features explicitly, so results may differ in the last digits from before. They are deterministic for a given
target-cpu. A build with--targetand a build without it now get the same flags, and the script reruns when the features change.The same table is in
bhtsnein10XDev/scan-rs, which had the same bug (https://github.com/10XDev/scan-rs/pull/828); there is no shared crate, so each copy has its own unit tests. The motivation is the move of Cell Ranger tox86-64-v3in https://github.com/10XDev/cellranger/pull/21632.Testing
cargo test -p star-sys flagsruns three unit tests of the table, andcargo test --lockedpasses (14 tests in theorbitcrate).cargo fmt -- --checkand the CI clippy command pass, with Rust 1.99.1. CI pins Rust 1.88.0, which I did not run.lib/rustbuilds withcargo check --all-targets, with and without--target x86_64-unknown-linux-gnu, using this change through a local[patch]; the STAR compile line then contains-mcx16 -mavx2 -mfma -mbmi -mbmi2 -mlzcnt -mmovbe -mf16c.Not done
cargo denystep on an advisory forlibz-sys1.1.22 inCargo.lock, which this change does not touch, so the clippy and test steps did not run there.Jira: CELLRANGER-10331
🤖 Generated with Claude Code
https://claude.ai/code/session_01HbDsntotWVcM9MvHmktSa8