Cargo-Cranelift vs cargo

// deps
// spanner-rs = { git = "https://github.com/plaflamme/spanner-rs/", rev = "7fa4f1a7b3ec1902d1ee2cd317fecc5c32173687" }
// tokio = { version = "1.17.0", features = ["full"] }

codespaces_cf5f0c:/workspaces/spannerexample$ cargo r --bin spannerrs
   Compiling spannerexample v0.1.0 (/workspaces/spannerexample)
    Finished dev [unoptimized + debuginfo] target(s) in 8.03s

// alias cargoc="/workspaces/rustc_codegen_cranelift/build/cargo-clif"
codespaces_cf5f0c:/workspaces/spannerexample$ cargoc r --bin spannerrs
   Compiling spannerexample v0.1.0 (/workspaces/spannerexample)
    Finished dev [unoptimized + debuginfo] target(s) in 2.83s

The above numbers are for incremental builds only.

As you can see, the cranelift debug build is very fast, this is amazing, however, my question is how do I integrate cargo-clif with rust-analyzer and VS Code (set the default cargo path etc.)?

Actual code for reference

use color_eyre::Result;
use spanner_rs::{Client, ReadContext};

#[tokio::main]
async fn main() -> Result<()> {

    let client = Client::configure()
        .project("xxx")
        .instance("www")
        .database("yyy")
        .connect()
        .await?;

    let tx = client
        .read_write()
        .run(|tx| {
            tx.execute_update(
                "INSERT INTO dummyuserlist(userid, amount) VALUES(@user, @amount)",
                &[("user", &"darkseid"), ("amount", &100_000i32)],
            )
        })
        .await;

    match tx {
        Ok(rows) => println!("updated {rows} rows"),
        Err(_) => eprintln!("already exists"),
    }

    let result_set = client
        .read_only()
        .execute_query("SELECT * FROM dummyuserlist", &[])
        .await?;

    for row in result_set.iter() {
        let user: String = row.get("USERID")?;
        let amount: i64 = row.get("AMOUNT")?;
        println!("found person: {} {}", user, amount);
    }

    Ok(())
}

1 Like

Check out the Rust-analyzer > Runnables > Override Cargo setting. It lets you provide an alternate binary whenever rust-analyzer wants to run cargo.

Do you know the default configuration of RA?

{
    "rust-analyzer.linkedProjects": [
        "projects/spannerexample/Cargo.toml"
    ],
    "rust-analyzer.runnables.overrideCargo": "/workspaces/rustc_codegen_cranelift/build/cargo-clif"
}

Results in

> Executing task: /workspaces/rustc_codegen_cranelift/build/cargo-clif run --package spannerexample --bin spannerrs <


Terminal will be reused by tasks, press any key to close it.

The result is disappearing.

However, if I remove overrideCargo (use the default cargo)


    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/spannerrs`
already exists
found person: darkseid 100000

Terminal will be reused by tasks, press any key to close it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.