Skip to content

Make CODEQL_PLATFORM architecture-aware for linux-arm64 - #22247

Merged
redsun82 merged 4 commits into
mainfrom
redsun82-arm64-platform-string
Jul 29, 2026
Merged

Make CODEQL_PLATFORM architecture-aware for linux-arm64#22247
redsun82 merged 4 commits into
mainfrom
redsun82-arm64-platform-string

Conversation

@redsun82

@redsun82redsun82 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Why

Today CODEQL_PLATFORM is OS-only: linux -> linux64, macos -> osx64, windows -> win64. There is no architecture dimension. macOS ships a single universal (lipo) binary that serves both arches, so it can keep osx64, but ELF has no fat-binary equivalent, so Linux arm64 needs its own distinct platform string.

What

Introduces a single source of truth, codeql_platform_select, and derives the platform string from os:linux AND cpu:arm64 -> linux-arm64, with every other configuration resolving byte-identically to its existing string.

  • misc/bazel/os.bzl: adds codeql_platform_select(linux64, linux_arm64, osx64, win64, otherwise) which works in both macro (select) and rule (ctx) contexts. os_select is kept as a thin OS-only wrapper implemented on top of it (Linux gets the same value on both arches), so all existing callers are unchanged. A _arm64_constraint attr is added to OS_DETECTION_ATTRS for the rule path.
  • misc/bazel/BUILD.bazel: adds a linux_arm64config_setting (os:linux + cpu:arm64), a strict specialization of @platforms//os:linux so Bazel picks it unambiguously.
  • defs.bzl and misc/bazel/pkg.bzl (_detect_platform, the load-bearing resolver for the {CODEQL_PLATFORM} placeholder): switched to codeql_platform_select and map the Linux arm64 slot to linux-arm64.

The linux-arm64 token is deliberate: the legacy linux64/osx64/win64 are CodeQL's own public release-asset identifiers and cannot be renamed, only added to. ${os}-arm64 matches the wider ecosystem (Node/.NET/Go) and codeql-action already uses the arm64 token.

There is intentionally no fallback between linux64 and linux_arm64 in codeql_platform_select: callers that only care about the OS should use os_select.

Additive and inert

Every configuration CI builds today resolves to the identical string, producing byte-identical outputs. Critically, the macOS universal build runs an @platforms//cpu:arm64 transition slice, but its OS is macos, so the OS discriminator dominates and it still resolves to osx64. The new linux-arm64 branch stays dormant because no current job builds Linux-on-arm64.

Validation (x86_64 host)

  • Confirmed via bazel cquery that existing configs still resolve exactly: linux x86_64 -> linux64, macos -> osx64, windows -> win64 (zero diff vs main).
  • Forced --platforms to an os:linux + cpu:arm64 platform and confirmed it resolves to linux-arm64 (analysis), with the linux_arm64 config_setting selected unambiguously over @platforms//os:linux.
  • Empirically confirmed the macOS + arm64 slice still resolves to osx64 using a real macOS analysis platform.
  • os_select consumers (e.g. Swift) re-checked and clean; buildifier/format clean.

CODEQL_PLATFORM is OS-only today (linux->linux64, macos->osx64,
windows->win64). ELF has no fat-binary equivalent, so Linux arm64 needs
its own string. Add `linux-arm64` for os:linux AND cpu:arm64 while
keeping every existing string byte-identical.
- Add a public `//misc/bazel:linux_arm64` config_setting (os:linux +
cpu:arm64).
- Turn `os_select` into `codeql_platform_select`, a full selector over
the four CodeQL platforms (`linux64`, `linux_arm64`, `osx64`, `win64`,
plus `otherwise`), working in both macro (select) and rule
(target_platform_has_constraint) contexts. There is deliberately no
fallback between the two Linux slots.
- Re-express `os_select` as a thin OS-only wrapper around it (Linux maps
to both `linux64` and `linux_arm64`), so its existing swift/xcode
callers keep working unchanged.
- Add an `_arm64_constraint` entry to OS_DETECTION_ATTRS.
- Drive the platform string from `codeql_platform_select` in pkg.bzl's
`_detect_platform` and defs.bzl's `codeql_platform`.
macOS keeps osx64 for both arch slices (universal binary): the
linux_arm64 key requires both constraints, so the OS discriminator
dominates. The new branch is dormant on existing CI (no job builds
linux-on-arm64), so all current configs produce byte-identical outputs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c5c5b0bf-4afa-468c-b2dd-197d80932b4b
CopilotAI review requested due to automatic review settings July 29, 2026 12:19
@redsun82
redsun82 requested review from a team as code ownersJuly 29, 2026 12:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds architecture-aware CodeQL platform selection for Linux ARM64.

Changes:

  • Introduces codeql_platform_select.
  • Maps Linux ARM64 to linux-arm64.
  • Preserves existing OS-only selection behavior.
Show a summary per file
FileDescription
defs.bzlUses the architecture-aware selector.
misc/bazel/BUILD.bazelDefines the Linux ARM64 configuration.
misc/bazel/os.bzlImplements platform and OS selectors.
misc/bazel/pkg.bzlResolves ARM64 package paths and names.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Medium

Comment threadmisc/bazel/pkg.bzl
Comment threadmisc/bazel/os.bzl Outdated
@redsun82
redsun82 requested a review from jketemaJuly 29, 2026 12:23
redsun82and others added 2 commits July 29, 2026 14:25
- codeql_pack docstring: include `linux-arm64` in the exhaustive list of
values the `{CODEQL_PLATFORM}` placeholder expands to (both mentions).
- codeql_platform_select: only fall back to `otherwise` on `None`, not on
any falsey value, via a small `_or_otherwise` helper, matching the
documented `None` defaults.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c5c5b0bf-4afa-468c-b2dd-197d80932b4b
`posix` sets the shared value for both `linux` and `macos`. It is mutually
exclusive with either of them and fails if supplied together with `linux`
or `macos`.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c5c5b0bf-4afa-468c-b2dd-197d80932b4b
@jketema

Copy link
Copy Markdown
Contributor

The C# checks seem to be broken now. The error is so generic that I have a hard time to understand what's going on though.

@redsun82

Copy link
Copy Markdown
ContributorAuthor

The C# checks seem to be broken now. The error is so generic that I have a hard time to understand what's going on though.

hmm, might be some sparse checkout problem, let me investigate

When `codeql_platform_select` builds its `select` from a macro invoked in
another workspace (e.g. semmle-code consuming this repo as `@codeql`), a bare
`//misc/bazel:linux_arm64` string key resolves against the consuming repo and
fails with "no such package 'misc/bazel'". Use `Label(...)`, which resolves
relative to this file's own repo, so the key always binds to
`@codeql//misc/bazel:linux_arm64` regardless of the calling workspace.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c5c5b0bf-4afa-468c-b2dd-197d80932b4b

@jketemajketema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if all tests pass.

@redsun82
redsun82 requested a review from jketemaJuly 29, 2026 14:05
@redsun82

redsun82 commented Jul 29, 2026

Copy link
Copy Markdown
ContributorAuthor
Rerun has been triggered: 2 restarted 🚀

@redsun82
redsun82 merged commit 1764c65 into mainJul 29, 2026
79 checks passed
@redsun82
redsun82 deleted the redsun82-arm64-platform-string branch July 29, 2026 15:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@redsun82@jketema