diff --git a/rust/BUILD.bazel b/rust/BUILD.bazel index 9cdc89dd52f..6536a4b6fd9 100644 --- a/rust/BUILD.bazel +++ b/rust/BUILD.bazel @@ -36,6 +36,7 @@ pkg_filegroup( srcs = [ ":tools-arch", "//rust/tools", + "//rust/tools/builtins", ], prefix = "tools", ) diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 0ec1769f1d1..b983a3217a3 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -17,6 +17,7 @@ use std::{ collections::HashMap, path::{Path, PathBuf}, }; +use std::{env, fs}; use tracing::{error, info, warn}; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -77,17 +78,19 @@ impl<'a> Extractor<'a> { } let no_location = (LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 }); if let Err(reason) = semantics_info { - let message = format!("semantic analyzer unavailable ({reason})"); - let full_message = format!( - "{message}: macro expansion, call graph, and type inference will be skipped." - ); - translator.emit_diagnostic( - trap::DiagnosticSeverity::Warning, - "semantics".to_owned(), - message, - full_message, - no_location, - ); + if !reason.is_empty() { + let message = format!("semantic analyzer unavailable ({reason})"); + let full_message = format!( + "{message}: macro expansion, call graph, and type inference will be skipped." + ); + translator.emit_diagnostic( + trap::DiagnosticSeverity::Warning, + "semantics".to_owned(), + message, + full_message, + no_location, + ); + } } translator.emit_source_file(ast); translator.trap.commit().unwrap_or_else(|err| { @@ -276,5 +279,16 @@ fn main() -> anyhow::Result<()> { } } } + let builtins_dir = env::var("CODEQL_EXTRACTOR_RUST_ROOT") + .map(|path| Path::new(&path).join("tools").join("builtins"))?; + let builtins = fs::read_dir(builtins_dir).context("failed to read builtins directory")?; + for entry in builtins { + let entry = entry.context("failed to read builtins directory")?; + let path = entry.path(); + if path.extension().is_some_and(|ext| ext == "rs") { + extractor.extract_without_semantics(&path, ""); + } + } + extractor.emit_extraction_diagnostics(start, &cfg) } diff --git a/rust/tools/builtins/BUILD.bazel b/rust/tools/builtins/BUILD.bazel new file mode 100644 index 00000000000..2c7da705dd2 --- /dev/null +++ b/rust/tools/builtins/BUILD.bazel @@ -0,0 +1,8 @@ +load("//misc/bazel:pkg.bzl", "codeql_pkg_files") + +codeql_pkg_files( + name = "builtins", + srcs = glob(["*.rs"]), + prefix = "builtins", + visibility = ["//rust:__subpackages__"], +) diff --git a/rust/tools/builtins/types.rs b/rust/tools/builtins/types.rs new file mode 100644 index 00000000000..91989b5262b --- /dev/null +++ b/rust/tools/builtins/types.rs @@ -0,0 +1,25 @@ +// The Language Prelude: https://doc.rust-lang.org/reference/names/preludes.html#language-prelude + +// Type namespace +// Boolean type +pub struct bool; +// Textual types +pub struct char; +pub struct str; +// Integer types +pub struct i8; +pub struct i16; +pub struct i32; +pub struct i64; +pub struct i128; +pub struct u8; +pub struct u16; +pub struct u32; +pub struct u64; +pub struct u128; +// Machine-dependent integer types +pub struct usize; +pub struct isize; +// floating-point types +pub struct f32; +pub struct f64;