Rust: Set experimental features variable before language parsing

This commit is contained in:
Henry Mercer
2025-05-30 18:09:25 +01:00
parent 932be8feda
commit 1d22e8316c
3 changed files with 46 additions and 46 deletions

View File

@@ -342,6 +342,31 @@ async function run() {
}
core.endGroup();
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
if (getOptionalInput("languages")?.includes(String(KnownLanguage.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");
}
config = await initConfig({
languagesInput: getOptionalInput("languages"),
queriesInput: getOptionalInput("queries"),
@@ -590,31 +615,6 @@ async function run() {
core.exportVariable(bmnVar, value);
}
// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
if (config.languages.includes(KnownLanguage.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);