Skip to content

Build the PowerShell extractor with Bazel - #398

Open
Paolo Tranquilli (redsun82) wants to merge 5 commits into
microsoft:mainfrom
redsun82:redsun82-powershell-extractor-bazel
Open

Build the PowerShell extractor with Bazel#398
Paolo Tranquilli (redsun82) wants to merge 5 commits into
microsoft:mainfrom
redsun82:redsun82-powershell-extractor-bazel

Conversation

@redsun82

@redsun82 Paolo Tranquilli (redsun82) commented Sep 10, 2026

Copy link
Copy Markdown

The PowerShell extractor is the only one Bazel does not know about: it is built by build-{linux64,osx64,win64}.ps1 shelling out to dotnet publish, so it gets no toolchain pinning, caching, codeql_pack layout or dependency lockfile.

This wires powershell/ into the existing Bazel setup, following the C# extractor. bazel build //powershell/... and bazel run //powershell:install now produce a pack equivalent to build-linux64.ps1. The .ps1 scripts and powershell.sln keep working.

Approach

Reuses the //misc/bazel:csharp.bzl macros and codeql_pack unchanged. Dependencies get their own paket group rather than sharing csharp/paket.*, since the two pin different Microsoft.CodeAnalysis versions (5.3.0 vs 4.13.0).

Two source changes were needed: projects move to net10.0, and GitInfo is dropped (an MSBuild-time generator that cannot run under rules_dotnet) in favour of AssemblyInformationalVersionAttribute, which C# already uses.

Semmle.Extraction.Tests is deleted: it references Semmle.Extraction.CSharp*, which does not exist in this repository, so it never built here. Semmle.Util.Tests was left targeting net6.0 against a net10.0 Semmle.Util, so it is bumped instead; its 37 tests pass. It is not wired into Bazel because codeql_xunit_test hardcodes @paket.main and //csharp/extractor/Testrunner, and routing PowerShell through those would couple it to the C# paket group. Worth doing separately.

Worth a careful look

  • rules_dotnet bumped to 0.21.5-codeql.2 with a new patch. System.Management.Automation pulls in a Windows-only package whose tfm_filegroup emits a select with no //conditions:default, so analysis fails on every other platform. The patch falls back to an empty filegroup, mirroring the neighbouring rid_filegroup. Needs forward-porting on the next upgrade.
  • Microsoft.ApplicationInsights pinned to 2.22.0. strategy: max resolved 3.1.2, dragging ~28 OpenTelemetry, Azure and Identity assemblies into the pack that dotnet publish does not produce.
  • New git_info stub under misc/bazel/semmle_code_stub. //csharp/scripts:git-assembly-info-src depends on @semmle_code//:git_info, which only exists internally, so previously no codeql_csharp_binary could be built from this repository alone. This incidentally fixes //csharp/extractor/... too.
  • CI keeps both build paths. The existing build-win64.ps1 job is unchanged; a powershell-bazel-build job (ubuntu + windows) adds build, install and an extraction smoke test.

Validation

  • bazel build //powershell/... and bazel run //powershell:install succeed; analysis is clean under win-x64, osx-arm64 and linux-arm64.
  • Pack contents match dotnet publish of the standalone project, except for _._, build.manifest* and Roslyn satellite .resources.dll / .pdb.
  • Trap output is byte-identical to the dotnet publish build.
  • codeql test run powershell/ql/test: 102 of 103. The failure (library-tests/ast/parent.ql) is pre-existing and order-dependent, passing in isolation; traps are identical between builds, so it is not caused by this change.
  • dotnet publish powershell/extractor/powershell.sln still works.

QL library and query pack packaging is intentionally out of scope, left as a follow-up.

`//csharp/scripts:git-assembly-info-src` depends on `@semmle_code//:git_info`, which
only exists in the internal repository, so no `codeql_csharp_binary` could be built
from this repository alone.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Packages that only ship assets for a subset of RIDs, such as
`Microsoft.Management.Infrastructure.Runtime.Win`, generate a `select` without a
`//conditions:default` branch and fail analysis everywhere else. `rid_filegroup`
already resolves to an empty list in that case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`bazel build //powershell/...` and `bazel run //powershell:install` now produce the
same extractor pack as `build-linux64.ps1`, which keeps working.

Projects move to `net10.0` to match the shared `codeql_csharp_library` macro, and
`GitInfo` goes away because it is an MSBuild-time source generator that cannot run
under `rules_dotnet`; the version string now comes from
`AssemblyInformationalVersionAttribute`, as in C#.

`Semmle.Extraction.Tests` referenced projects that do not exist here and
`Semmle.Pipeline.Tests` was in no solution, so both are removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`Semmle.Pipeline.Tests` builds and is self-contained, so removing it was unrelated
to this change. `Semmle.Util.Tests` targeted net6.0 against a net10.0
`Semmle.Util`; bumping it makes its 37 tests run again.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@redsun82

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

Three Windows-only problems: MSYS2 read the `:` in `//powershell:install` as a
path-list separator and rewrote the label to `/powershell:install`; `install`
resolved its destination into the runfiles copy instead of the workspace; and
the hand-rolled smoke test hardcoded the extractor binary name. The smoke test
now runs a QL test, so the binary name and wiring come from
`codeql-extractor.yml`.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@redsun82
Paolo Tranquilli (redsun82) force-pushed the redsun82-powershell-extractor-bazel branch from 74525a0 to 824ad3d Compare September 10, 2026 14:27
@redsun82
Paolo Tranquilli (redsun82) marked this pull request as ready for review September 10, 2026 15:45
@redsun82

Copy link
Copy Markdown
Author

cc Chanel (@chanel-y) 🙂

Sign up for free to 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.

1 participant