Apply Address Sanitizer in cargo.toml without RUSTFLAGS

Hi all!
I wonder that how to apply the RUST Address Sanitizer in cargo.toml file without any RUSTFLAGS
It means that we can use address sanitizer in cargo package like below commend.

RUSTFLAGS="-Z sanitizer=address" cargo run

However, I want to use RUST ASan in cargo.toml files without RUSTFLAGS.
Is there any commend or solution to use ASan in cargo.toml files??

Thank you!
Have a nice day :slight_smile:

You can put them in .cargo/config.toml in your project directory:

[target.debug]
rustflags = ["-Z", "sanitizer=address"]
1 Like

Thank you for your comment!!

But I still wonder that it is possible to use RUST ASan to modify the cargo.toml?

It means that i add the code in cargo.toml like below.

[packge]
[package]
name = "temp"
version = "0.1.0"
edition = "2021"

[target.debug]
rustflags = ["-Z", "sanitizer=address"]

And then, I run the cargo package usinge cargo run.
Then, the cargo package build the program with address sanitizer?

Cargo.toml is not used to specify compilation parameters, that's what .cargo/config.toml is for.

1 Like

Tannk you for your comment!

It means that it should add rustflags in .cargo/config.toml ??