Skip to content

Rust: add option to extract dependencies as source files #19583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rust/codeql-extractor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ options:
title: Skip path resolution
description: >
Skip path resolution. This is experimental, while we move path resolution from the extractor to the QL library.
type: string
pattern: "^(false|true)$"
extract_dependencies_as_source:
Copy link
Preview

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema defines this option as a string with a boolean pattern, but Config expects a bool. Change type: string to type: boolean and remove the pattern to align with the Rust flag.

Copilot uses AI. Check for mistakes.

title: Extract dependencies as source code
description: >
Extract the full source code of dependencies instead of only extracting signatures.
type: string
pattern: "^(false|true)$"
1 change: 1 addition & 0 deletions rust/extractor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct Config {
pub extra_includes: Vec<PathBuf>,
pub proc_macro_server: Option<PathBuf>,
pub skip_path_resolution: bool,
pub extract_dependencies_as_source: bool,
}

impl Config {
Expand Down
10 changes: 8 additions & 2 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ fn main() -> anyhow::Result<()> {
} else {
ResolvePaths::Yes
};
let (library_mode, library_resolve_paths) = if cfg.extract_dependencies_as_source {
(SourceKind::Source, resolve_paths)
} else {
(SourceKind::Library, ResolvePaths::No)
};
let mut processed_files: HashSet<PathBuf, RandomState> =
HashSet::from_iter(files.iter().cloned());
for (manifest, files) in map.values().filter(|(_, files)| !files.is_empty()) {
Expand Down Expand Up @@ -312,12 +317,13 @@ fn main() -> anyhow::Result<()> {
.source_root(db)
.is_library
{
tracing::info!("file: {}", file.display());
extractor.extract_with_semantics(
file,
&semantics,
vfs,
ResolvePaths::No,
SourceKind::Library,
library_resolve_paths,
library_mode,
);
extractor.archiver.archive(file);
}
Expand Down