liblouis build: clang-cl target selection relies on PATH order, breaks on arm64 when multiple arch-specific clang-cl binaries are reachable

Open
#21,237 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
build-system

Research direction

Start with nvdaHelper/liblouis/sconscript and trace how TARGET_ARCH sets compiler flags and how SCons selects clang-cl. Check the build behavior for x86, x86_64, arm64, and arm64ec against the target triples described in the issue. Done means each architecture builds objects for its intended target regardless of PATH order; the issue author reports having a tested fix.

Written by the indexing model from the issue text.

Description

Title

liblouis build: clang-cl target selection relies on PATH order, breaks on arm64 when multiple arch-specific clang-cl binaries are reachable

Related issues, PRs or discussions

Related to #20316 (Fix Clang detection for Visual Studio 2026), which replaced a hardcoded Tools\Llvm\bin glob with env.WhereIs("clang-cl"). That fix is correct for the single-arch-toolchain case it targeted, but doesn't address target selection when more than one arch-specific clang-cl.exe is reachable via PATH, which is the root cause here.

What is the current state of the codebase?

nvdaHelper/liblouis/sconscript sets:

if env["TARGET_ARCH"] in ("x86_64", "arm64"):
    # We need to build as 64-bit
    env.Append(CCFLAGS="-m64")

-m64/-m32 are real clang-cl flags that select between the x86 and x86_64 targets specifically — they have no arm64 meaning. On a machine with Visual Studio's "C++ Clang Tools for Windows" component installed, there are multiple clang-cl.exe binaries under VC\Tools\Llvm\ (a generic one plus arch-specific ones, e.g. Llvm\bin\clang-cl.exe, Llvm\x64\bin\clang-cl.exe, Llvm\ARM64\bin\clang-cl.exe depending on VS version/layout), each defaulting to a different target triple when given no explicit target (confirmed: the generic Llvm\bin\clang-cl.exe on this machine defaults to i686-pc-windows-msvc, i.e. x86, regardless of which TARGET_ARCH SCons is building).

env.WhereIs("clang-cl") (introduced in #20316) resolves whichever clang-cl.exe happens to be first on the constructed PATH for that environment — this is not guaranteed to match TARGET_ARCH. With the -m64 flag applied only for x86_64/arm64, and removed/absent for arm64 as a one-line fix attempt, clang-cl silently falls back to its binary's own default target (x86 in the case above) instead of arm64, producing object files of the wrong architecture with no build-time error — the failure only surfaces much later as a confusing wall of unresolved CRT symbols at link time (malloc, memcpy, __security_cookie, etc. all unresolved, because the objects are the wrong machine type for libcmt.lib).

Why are changes required?

Building liblouis for arm64/arm64ec from source currently produces silently-wrong-architecture object files (or fails to link with misleading CRT-symbol errors) when the build environment's PATH exposes more than one arch-specific clang-cl.exe, which is the case on at least one real Visual Studio + "C++ Clang Tools for Windows" installation. This blocks building nvdaHelper's liblouis component for ARM64 from source.

What technical changes are required?

Pass an explicit --target= triple to clang-cl per TARGET_ARCH, instead of relying on -m64/-m32 (which don't cover arm64) or on whichever clang-cl.exe happens to resolve first:

clangTarget = {
    "x86": "i686-pc-windows-msvc",
    "x86_64": "x86_64-pc-windows-msvc",
    "arm64": "aarch64-pc-windows-msvc",
}[env["TARGET_ARCH"]]
env.Append(CCFLAGS=f"--target={clangTarget}")

This removes the dependency on -m64/-m32 entirely and makes target selection explicit and correct regardless of which clang-cl.exe binary ends up on PATH.

Are the proposed technical changes API breaking?

No.

Are there potential risks or issues with the proposed implementation?

Low risk. --target= is a standard, well-supported clang-cl flag; this is strictly more robust than the current -m64-only approach, including for the existing x86/x64 builds (it removes an implicit dependency on PATH ordering there too, even though it happens not to manifest as a bug today on typical single-arch-clang-cl setups).

I have a working fix and can open a PR once this issue is triaged, as part of getting a native ARM64 Python build of NVDA building from source end to end.


Investigated and drafted with AI assistance (Claude); I reviewed the technical content and built/tested the fix myself before filing this.

Dominant language
Python
Stars
2.7k
Forks
842
Avg merge
2d 4h
Merged PRs (30d)
56

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nvaccess/nvda

All issues in nvaccess/nvda

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.