In my project, I want to set the environment variable for bindgen before run cargo.
such as this:
[env]
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 build.rs
, but bindgen will run before build.rs.
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"
Hyeonu
April 3, 2023, 1:57pm
3
How do you run the bindgen? The recommended way is to call bindgen functions from the build.rs code.
I use the bindgen in my dependency ffmpeg-sys , so the bindgen will run before my build.rs.
bjorn3
April 4, 2023, 9:37am
5
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:
files:
/tmp/ffmpeg-test $ tree . -a
.
├── .cargo
│ └── config.toml
├── Cargo.lock
├── Cargo.toml
└── src
└── main.rs
3 directories, 4 files
env config:
/tmp/ffmpeg-test $ cat .cargo/config.toml
[env]
BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=./asset/wasi-sysroot --target=wasm32-wasi -fvisibility=default"
Cargo.toml:
/tmp/ffmpeg-test $ cat Cargo.toml
[package]
name = "ffmpeg-test"
version = "0.1.0"
edition = "2021"
[dependencies]
ffmpeg-sys-next="6"
main.rs:
/tmp/ffmpeg-test $ cat src/main.rs
fn main() {
println!("Hello, world!");
}
The bindgen will run in ffmpeg-sys-next's build.rs, I just want to set the environment BINDGEN_EXTRA_CLANG_ARGS
before the bindgen run.
system
Closed
July 3, 2023, 2:47pm
8
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.