Skip to content

Commit

Permalink
Merge pull request #2773 from github/redsun82/rust
Browse files Browse the repository at this point in the history
Support rust analysis
  • Loading branch information
redsun82 authored Feb 20, 2025
2 parents cf7e909 + 9572e09 commit 9856c48
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 4 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/__rust.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions pr-checks/checks/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Rust analysis"
description: "Tests creation of a Rust database"
versions: ["linked", "default", "nightly-latest"]
operatingSystems: ["ubuntu"]
steps:
- uses: ./../action/init
with:
languages: rust
tools: ${{ steps.prepare-test.outputs.tools-url }}
env:
CODEQL_ACTION_RUST_ANALYSIS: true
- uses: ./../action/analyze
id: analysis
with:
upload-database: false
- name: Check database
shell: bash
run: |
RUST_DB="${{ fromJson(steps.analysis.outputs.db-locations).rust }}"
if [[ ! -d "$RUST_DB" ]]; then
echo "Did not create a database for Rust."
exit 1
fi
6 changes: 6 additions & 0 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum Feature {
ExtractToToolcache = "extract_to_toolcache",
PythonDefaultIsToNotExtractStdlib = "python_default_is_to_not_extract_stdlib",
QaTelemetryEnabled = "qa_telemetry_enabled",
RustAnalysis = "rust_analysis",
ZstdBundleStreamingExtraction = "zstd_bundle_streaming_extraction",
}

Expand Down Expand Up @@ -148,6 +149,11 @@ export const featureConfig: Record<
minimumVersion: undefined,
toolsFeature: ToolsFeature.PythonDefaultIsToNotExtractStdlib,
},
[Feature.RustAnalysis]: {
defaultValue: false,
envVar: "CODEQL_ACTION_RUST_ANALYSIS",
minimumVersion: "2.19.3",
},
[Feature.QaTelemetryEnabled]: {
defaultValue: false,
envVar: "CODEQL_ACTION_QA_TELEMETRY",
Expand Down
30 changes: 28 additions & 2 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from "path";

import * as core from "@actions/core";
import * as io from "@actions/io";
import * as semver from "semver";
import { v4 as uuidV4 } from "uuid";

import {
Expand All @@ -13,6 +14,7 @@ import {
getRequiredInput,
getTemporaryDirectory,
persistInputs,
isDefaultSetup,
} from "./actions-util";
import { getGitHubVersion } from "./api-client";
import {
Expand All @@ -30,7 +32,7 @@ import {
makeDiagnostic,
} from "./diagnostics";
import { EnvVar } from "./environment";
import { Feature, Features } from "./feature-flags";
import { Feature, featureConfig, Features } from "./feature-flags";
import {
checkInstallPython311,
cleanupDatabaseClusterDirectory,
Expand Down Expand Up @@ -72,7 +74,6 @@ import {
getErrorMessage,
} from "./util";
import { validateWorkflow } from "./workflow";

/** Fields of the init status report that can be sent before `config` is populated. */
interface InitStatusReport extends StatusReportBase {
/** Value given by the user as the "tools" input. */
Expand Down Expand Up @@ -576,6 +577,31 @@ async function run() {
core.exportVariable(bmnVar, value);
}

// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
if (config.languages.includes(Language.rust)) {
const feat = Feature.RustAnalysis;
const minVer = featureConfig[feat].minimumVersion as string;
const envVar = "CODEQL_ENABLE_EXPERIMENTAL_FEATURES";
// if in default setup, it means the feature flag was on when rust was enabled
// if the feature flag gets turned off, let's not have rust analysis throwing a configuration error
// in that case rust analysis will be disabled only when default setup is refreshed
if (isDefaultSetup() || (await features.getValue(feat, codeql))) {
core.exportVariable(envVar, "true");
}
if (process.env[envVar] !== "true") {
throw new ConfigurationError(
`Experimental and not officially supported Rust analysis requires setting ${envVar}=true in the environment`,
);
}
const actualVer = (await codeql.getVersion()).version;
if (semver.lt(actualVer, minVer)) {
throw new ConfigurationError(
`Experimental rust analysis is supported by CodeQL CLI version ${minVer} or higher, but found version ${actualVer}`,
);
}
logger.info("Experimental rust analysis enabled");
}

// Restore dependency cache(s), if they exist.
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
await downloadDependencyCaches(config.languages, logger);
Expand Down
7 changes: 7 additions & 0 deletions tests/multi-language-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/multi-language-repo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "test"
version = "0.0.1"
edition = "2021"
[[bin]]
name = "main"
path = "main.rs"

6 changes: 6 additions & 0 deletions tests/multi-language-repo/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
if true {
println!("Hello world!")
}
}

0 comments on commit 9856c48

Please sign in to comment.