Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to custom condition compile and passing argument by cargo?

I want to complie rust code with language option:

#[cfg(lang = "en")]
use xxx;

#[cfg(lang = "fr")]
use yyy;

and how to run cargo and passing argument ?

cargo release --feature "lang=en" // error!
like image 558
BorrowError Avatar asked Oct 28 '25 14:10

BorrowError


1 Answers

You can use #[cfg(en)] and pass --cfg en to rustc.

But, if you use cargo, then you can append to your .cargo/cargo.toml (must create this file if you don't have) this:

[build]
rustflags = ["--cfg", "en"]

You can also make script to build and run a project that generates this file and invokes cargo.

like image 88
TANDEX Avatar answered Oct 30 '25 12:10

TANDEX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!