Skip to content

Commit 9856c48

Browse files
authored
Merge pull request #2773 from github/redsun82/rust
Support rust analysis
2 parents cf7e909 + 9572e09 commit 9856c48

File tree

11 files changed

+178
-4
lines changed

11 files changed

+178
-4
lines changed

.github/workflows/__rust.yml

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/feature-flags.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pr-checks/checks/rust.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Rust analysis"
2+
description: "Tests creation of a Rust database"
3+
versions: ["linked", "default", "nightly-latest"]
4+
operatingSystems: ["ubuntu"]
5+
steps:
6+
- uses: ./../action/init
7+
with:
8+
languages: rust
9+
tools: ${{ steps.prepare-test.outputs.tools-url }}
10+
env:
11+
CODEQL_ACTION_RUST_ANALYSIS: true
12+
- uses: ./../action/analyze
13+
id: analysis
14+
with:
15+
upload-database: false
16+
- name: Check database
17+
shell: bash
18+
run: |
19+
RUST_DB="${{ fromJson(steps.analysis.outputs.db-locations).rust }}"
20+
if [[ ! -d "$RUST_DB" ]]; then
21+
echo "Did not create a database for Rust."
22+
exit 1
23+
fi

src/feature-flags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export enum Feature {
5353
ExtractToToolcache = "extract_to_toolcache",
5454
PythonDefaultIsToNotExtractStdlib = "python_default_is_to_not_extract_stdlib",
5555
QaTelemetryEnabled = "qa_telemetry_enabled",
56+
RustAnalysis = "rust_analysis",
5657
ZstdBundleStreamingExtraction = "zstd_bundle_streaming_extraction",
5758
}
5859

@@ -148,6 +149,11 @@ export const featureConfig: Record<
148149
minimumVersion: undefined,
149150
toolsFeature: ToolsFeature.PythonDefaultIsToNotExtractStdlib,
150151
},
152+
[Feature.RustAnalysis]: {
153+
defaultValue: false,
154+
envVar: "CODEQL_ACTION_RUST_ANALYSIS",
155+
minimumVersion: "2.19.3",
156+
},
151157
[Feature.QaTelemetryEnabled]: {
152158
defaultValue: false,
153159
envVar: "CODEQL_ACTION_QA_TELEMETRY",

src/init-action.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path";
33

44
import * as core from "@actions/core";
55
import * as io from "@actions/io";
6+
import * as semver from "semver";
67
import { v4 as uuidV4 } from "uuid";
78

89
import {
@@ -13,6 +14,7 @@ import {
1314
getRequiredInput,
1415
getTemporaryDirectory,
1516
persistInputs,
17+
isDefaultSetup,
1618
} from "./actions-util";
1719
import { getGitHubVersion } from "./api-client";
1820
import {
@@ -30,7 +32,7 @@ import {
3032
makeDiagnostic,
3133
} from "./diagnostics";
3234
import { EnvVar } from "./environment";
33-
import { Feature, Features } from "./feature-flags";
35+
import { Feature, featureConfig, Features } from "./feature-flags";
3436
import {
3537
checkInstallPython311,
3638
cleanupDatabaseClusterDirectory,
@@ -72,7 +74,6 @@ import {
7274
getErrorMessage,
7375
} from "./util";
7476
import { validateWorkflow } from "./workflow";
75-
7677
/** Fields of the init status report that can be sent before `config` is populated. */
7778
interface InitStatusReport extends StatusReportBase {
7879
/** Value given by the user as the "tools" input. */
@@ -576,6 +577,31 @@ async function run() {
576577
core.exportVariable(bmnVar, value);
577578
}
578579

580+
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
581+
if (config.languages.includes(Language.rust)) {
582+
const feat = Feature.RustAnalysis;
583+
const minVer = featureConfig[feat].minimumVersion as string;
584+
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
585+
// if in default setup, it means the feature flag was on when rust was enabled
586+
// if the feature flag gets turned off, let's not have rust analysis throwing a configuration error
587+
// in that case rust analysis will be disabled only when default setup is refreshed
588+
if (isDefaultSetup() || (await features.getValue(feat, codeql))) {
589+
core.exportVariable(envVar, "true");
590+
}
591+
if (process.env[envVar] !== "true") {
592+
throw new ConfigurationError(
593+
`Experimental and not officially supported Rust analysis requires setting ${envVar}=true in the environment`,
594+
);
595+
}
596+
const actualVer = (await codeql.getVersion()).version;
597+
if (semver.lt(actualVer, minVer)) {
598+
throw new ConfigurationError(
599+
`Experimental rust analysis is supported by CodeQL CLI version ${minVer} or higher, but found version ${actualVer}`,
600+
);
601+
}
602+
logger.info("Experimental rust analysis enabled");
603+
}
604+
579605
// Restore dependency cache(s), if they exist.
580606
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
581607
await downloadDependencyCaches(config.languages, logger);

tests/multi-language-repo/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/multi-language-repo/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "test"
3+
version = "0.0.1"
4+
edition = "2021"
5+
[[bin]]
6+
name = "main"
7+
path = "main.rs"
8+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy