Skip to content
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
12 changes: 11 additions & 1 deletion rust/extractor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ impl Config {

pub fn to_cargo_config(&self, dir: &AbsPath) -> (CargoConfig, LoadCargoConfig) {
let sysroot = self.sysroot(dir);
let mut extra_args = self.cargo_extra_args.clone();
// The fixed toolchain may be older than the project's declared minimum.
// If that's the case `cargo` will error. Passing the flag below ensures
// that the project's speified Rust version is ignored. With this
// failures will only occur if the project actually uses Rust features
// that rust-analyzer and/or the fixed toolchain is incompatible with
// (which is the best we can hope for).
if !extra_args.iter().any(|arg| arg == "--ignore-rust-version") {
extra_args.push("--ignore-rust-version".to_owned());
}
(
CargoConfig {
all_targets: self.cargo_all_targets,
Expand All @@ -205,7 +215,7 @@ impl Config {
.map(RustLibSource::Path),

extra_env: self.get_extra_env(),
extra_args: self.cargo_extra_args.clone(),
extra_args,
extra_includes: self
.extra_includes
.iter()
Expand Down
11 changes: 11 additions & 0 deletions rust/ql/integration-tests/rust-version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rust-version"
version = "0.1.0"
edition = "2024"
rust-version = "1.999.0"

[dependencies]
macros = { path = "macros" }

[workspace]
members = ["macros"]
9 changes: 9 additions & 0 deletions rust/ql/integration-tests/rust-version/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
std::fs::write(
std::path::Path::new(&out_dir).join("generated.rs"),
"pub fn from_build_script() -> u32 { 42 }\n",
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 2 additions & 0 deletions rust/ql/integration-tests/rust-version/functions.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| from_build_script |
| from_proc_macro |
5 changes: 5 additions & 0 deletions rust/ql/integration-tests/rust-version/functions.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import rust

from Function f
where f.fromSource() and f.getName().getText() = ["from_build_script", "from_proc_macro"]
select f.getName().getText()
7 changes: 7 additions & 0 deletions rust/ql/integration-tests/rust-version/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "macros"
version = "0.1.0"
edition = "2024"

[lib]
proc-macro = true
6 changes: 6 additions & 0 deletions rust/ql/integration-tests/rust-version/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern crate proc_macro;

#[proc_macro]
pub fn generate(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
"pub fn from_proc_macro() -> u32 { 43 }".parse().unwrap()
}
7 changes: 7 additions & 0 deletions rust/ql/integration-tests/rust-version/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include!(concat!(env!("OUT_DIR"), "/generated.rs"));

macros::generate!();

fn main() {
println!("{} {}", from_build_script(), from_proc_macro());
}
10 changes: 10 additions & 0 deletions rust/ql/integration-tests/rust-version/test_rust_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest


@pytest.mark.parametrize("rust_edition", [2024])
@pytest.mark.parametrize("extra_args", [None, "--offline", "--ignore-rust-version"])
def test_rust_version(codeql, rust, cargo, extra_args):
env = {}
if extra_args is not None:
env["CODEQL_EXTRACTOR_RUST_OPTION_CARGO_EXTRA_ARGS"] = extra_args
codeql.database.create(_env=env)
Loading