Subchapter 78.3
references/compiled-languages.mdMarkdown9 KBView on GitHub
Detailed reference for how CodeQL handles compiled language analysis, including build modes, autobuild behavior, runner requirements, and hardware specifications.
CodeQL offers three build modes for compiled languages:
| Mode | Description | When to Use |
|---|---|---|
none | Analyze source without building. Dependencies inferred heuristically. | Default setup; quick scans; interpreted-like analysis |
autobuild | Automatically detect and run the build system. | When none produces inaccurate results; when Kotlin code is present |
manual | User provides explicit build commands. | Complex build systems; autobuild failures; custom build requirements |
none, autobuild, manual
Default setup mode: none
Accuracy considerations:
Improving accuracy:
Windows autodetection:
MSBuild.exe on .sln or .vcxproj closest to rootbuild.bat, build.cmd, build.exeLinux/macOS autodetection:
Supported build systems: MSBuild, Autoconf, Make, CMake, qmake, Meson, Waf, SCons, Linux Kbuild, build scripts
gcc compiler; may need clang or msvc. Build tools: msbuild, make, cmake, bazel. Utilities: python, perl, lex, yacc.CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES=true (enabled by default on GitHub-hosted; disabled on self-hosted). Requires Ubuntu with passwordless sudo apt-get.powershell.exe in PATHnone, autobuild, manual
Default setup mode: none
*.csproj, *.sln, nuget.config, packages.config, global.json, project.assets.jsonusing directives (implicit using feature).cshtml → .cs conversionAccuracy considerations:
Windows autodetection:
dotnet build on .sln or .csproj closest to rootMSBuild.exe on solution/project filesbuild.bat, build.cmd, build.exeLinux/macOS autodetection:
dotnet build on .sln or .csproj closest to rootMSbuild on solution/project filesbuild, build.shThe CodeQL tracer injects these flags into C# compiler invocations:
| Flag | Purpose |
|---|---|
/p:MvcBuildViews=true | Precompile ASP.NET MVC views for security analysis |
/p:UseSharedCompilation=false | Disable shared compilation server (required for tracer inspection) |
/p:EmitCompilerGeneratedFiles=true | Write generated source files to disk for extraction |
/p:EmitCompilerGeneratedFiles=truemay cause issues with legacy projects or.sqlprojfiles.
dotnet)mono, msbuild, nuget)build-mode: none: Requires internet access or private NuGet feedautobuild, manual (no none mode)
Default setup mode: autobuild
Autodetection sequence:
make, ninja, ./build, or ./build.sh until one succeeds and go list ./... worksgo.mod (go get), Gopkg.toml (dep ensure -v), or glide.yaml (glide install)GOPATH and use go getgo build ./...)Default setup automatically detects go.mod and installs compatible Go version.
| Environment Variable | Default | Description |
|---|---|---|
CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS | false | Include _test.go files in analysis |
CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_VENDOR_DIRS | false | Include vendor/ directories |
none, autobuild, manualautobuild, manual (no none mode)Default setup mode:
noneautobuildIf Kotlin code is added to a repo using
nonemode, disable and re-enable default setup to switch toautobuild.
Accuracy considerations:
Autodetection sequence:
Build systems: Gradle, Maven, Ant
none mode)none, autobuild, manual
Default setup mode: none
autobuild, manual (no none mode)
Default setup mode: autobuild
Runner requirement: macOS runners only. Not supported on Actions Runner Controller (ARC) — Linux only.
macOS runners are more expensive; consider scanning only the build step to optimize cost.
strategy:
fail-fast: false
matrix:
include:
- language: c-cpp
build-mode: manual
- language: csharp
build-mode: autobuild
- language: java-kotlin
build-mode: nonesteps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- if: matrix.build-mode == 'manual'
name: Build C/C++ code
run: |
make bootstrap
make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{ matrix.language }}"strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
runner: ubuntu-latest
- language: swift
build-mode: autobuild
runner: macos-latest
- language: csharp
build-mode: autobuild
runner: windows-latest
jobs:
analyze:
runs-on: ${{ matrix.runner }}| Codebase Size | Lines of Code | RAM | CPU Cores | Disk |
|---|---|---|---|---|
| Small | < 100K | 8 GB+ | 2 | SSD, ≥14 GB |
| Medium | 100K – 1M | 16 GB+ | 4–8 | SSD, ≥14 GB |
| Large | > 1M | 64 GB+ | 8 | SSD, ≥14 GB |
--threads=0 to use all available CPU coresnone build mode where accuracy is acceptable — significantly faster than autobuild- uses: github/codeql-action/init@v4
with:
languages: java-kotlin
dependency-caching: true| Value | Behavior |
|---|---|
false / none / off | Disabled (default for advanced setup) |
restore | Restore existing caches only |
store | Store new caches only |
true / full / on | Restore and store caches |
Default setup on GitHub-hosted runners has caching enabled automatically.