From 765afdbae0a9464a9dda609944c196af542a7453 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Mon, 26 May 2025 18:21:35 +0200 Subject: [PATCH 1/2] Rust: add option to extract dependencies as source files --- rust/codeql-extractor.yml | 8 ++++++++ rust/extractor/src/config.rs | 1 + rust/extractor/src/main.rs | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/rust/codeql-extractor.yml b/rust/codeql-extractor.yml index 1c73a070e587..0ba77ee88d13 100644 --- a/rust/codeql-extractor.yml +++ b/rust/codeql-extractor.yml @@ -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: + title: Extract dependencies as source code + description: > + Extract the full source code of dependencies instead of only extracting signatures. + type: string + pattern: "^(false|true)$" diff --git a/rust/extractor/src/config.rs b/rust/extractor/src/config.rs index e66d54807be0..3f6b86d1f1f9 100644 --- a/rust/extractor/src/config.rs +++ b/rust/extractor/src/config.rs @@ -67,6 +67,7 @@ pub struct Config { pub extra_includes: Vec, pub proc_macro_server: Option, pub skip_path_resolution: bool, + pub extract_dependencies_as_source: bool, } impl Config { diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 99f470aa13e4..fd827f46d7c6 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -277,6 +277,16 @@ fn main() -> anyhow::Result<()> { } else { ResolvePaths::Yes }; + let library_mode = if cfg.extract_dependencies_as_source { + SourceKind::Source + } else { + SourceKind::Library + }; + let library_resolve_paths = if cfg.extract_dependencies_as_source { + resolve_paths + } else { + ResolvePaths::No + }; let mut processed_files: HashSet = HashSet::from_iter(files.iter().cloned()); for (manifest, files) in map.values().filter(|(_, files)| !files.is_empty()) { @@ -312,12 +322,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); } From ac724d2671df66ad4247850850743949de95db90 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Tue, 27 May 2025 13:08:20 +0200 Subject: [PATCH 2/2] Update rust/extractor/src/main.rs Co-authored-by: Simon Friis Vindum --- rust/extractor/src/main.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index fd827f46d7c6..928542c54226 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -277,15 +277,10 @@ fn main() -> anyhow::Result<()> { } else { ResolvePaths::Yes }; - let library_mode = if cfg.extract_dependencies_as_source { - SourceKind::Source + let (library_mode, library_resolve_paths) = if cfg.extract_dependencies_as_source { + (SourceKind::Source, resolve_paths) } else { - SourceKind::Library - }; - let library_resolve_paths = if cfg.extract_dependencies_as_source { - resolve_paths - } else { - ResolvePaths::No + (SourceKind::Library, ResolvePaths::No) }; let mut processed_files: HashSet = HashSet::from_iter(files.iter().cloned());