Is there any method to preprocess enviroment variable before cargo run?

In my project, I want to set the environment variable for bindgen before run cargo.

such as this:

BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=./asset/wasi-sysroot --target=wasm32-wasi -fvisibility=default"

But it's a relative path, the bindgen cannot use it.
I also try set environment variable in, but bindgen will run before

toml does not have the function of parsing environment variables, if it can, i want use it:

SYS_ROOT={ value = "./asset/wasi-sysroot", relative = true }
BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=${SYS_ROOT} --target=wasm32-wasi -fvisibility=default"

How do you run the bindgen? The recommended way is to call bindgen functions from the code.

I use the bindgen in my dependency ffmpeg-sys, so the bindgen will run before my

Do you need the bindings from ffmpeg-sys's build script? Or only in the main ffmpeg-sys library? If the later you can use bindgen from ffmpeg-sys's build script. If the former, you did have to generate bindings twice when cross-compiling. Once for the host to run the build script and once for the target to build ffmpeg-sys itself.

This is my full project:


 /tmp/ffmpeg-test $ tree . -a
├── .cargo
│   └── config.toml
├── Cargo.lock
├── Cargo.toml
└── src

3 directories, 4 files

env config:

 /tmp/ffmpeg-test $ cat .cargo/config.toml
BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=./asset/wasi-sysroot --target=wasm32-wasi -fvisibility=default"


/tmp/ffmpeg-test $ cat Cargo.toml
name = "ffmpeg-test"
version = "0.1.0"
edition = "2021"


 /tmp/ffmpeg-test $ cat src/
fn main() {
    println!("Hello, world!");

The bindgen will run in ffmpeg-sys-next's, I just want to set the environment BINDGEN_EXTRA_CLANG_ARGS before the bindgen run.

I see what you mean now.

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.